diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index a48f4be148f..baa4fd9a711 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -1005,13 +1005,6 @@ if ($action == 'create') { } print ''; - // Even if unsubscribe - print ''; - print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); - print ''; - print $form->editfieldval("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); - print ''; - // Other attributes. Fields from hook formObjectOptions and Extrafields. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; @@ -1282,13 +1275,6 @@ if ($action == 'create') { } print ''; - // Even if unsubscribe - print ''; - print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); - print ''; - print $form->editfieldval("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); - print ''; - // Other attributes $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 73ffb9837c7..caa371ac59e 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmailing.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; // Load translation files required by the page $langs->load("mails"); @@ -345,7 +346,7 @@ if ($object->fetch($id) >= 0) { } } if (empty($nbemail)) { - $nbemail .= ' '.img_warning('');//.' '.$langs->trans("NoTargetYet").''; + $nbemail .= ' '.img_warning($langs->trans('ToAddRecipientsChooseHere'));//.' '.$langs->trans("NoTargetYet").''; } if ($text) { print $form->textwithpicto($nbemail, $text, 1, 'warning'); @@ -355,13 +356,6 @@ if ($object->fetch($id) >= 0) { } print ''; - // Even if unsubscribe - print ''; - print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); - print ''; - print $form->editfieldval("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); - print ''; - // Other attributes. Fields from hook formObjectOptions and Extrafields. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; @@ -376,7 +370,7 @@ if ($object->fetch($id) >= 0) { print '
'; - $allowaddtarget = ($object->statut == 0); + $allowaddtarget = ($object->statut == $object::STATUS_DRAFT); // Show email selectors if ($allowaddtarget && $user->rights->mailing->creer) { @@ -389,7 +383,11 @@ if ($object->fetch($id) >= 0) { print '
'; print '
'.$langs->trans("RecipientSelectionModules").'
'; print '
'.$langs->trans("NbOfUniqueEMails").'
'; - print '
'.$langs->trans("Filter").'
'; + print '
'.$langs->trans("Filters"); + print '    
'.$langs->trans("EvenUnsubscribe").' '; + print ajax_object_onoff($object, 'evenunsubscribe', 'evenunsubscribe', 'EvenUnsubscribe:switch_on:warning', 'EvenUnsubscribe', array(), 'small valignmiddle', '', 1); + print '
'; + print '
'; print '
 
'; print ''; // End tr diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index e5cda94aa9f..9ad466f9671 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -357,9 +357,10 @@ class Mailing extends CommonObject * Get object from database * * @param int $rowid Id of emailing + * @param string $ref Title to search from title * @return int <0 if KO, >0 if OK */ - public function fetch($rowid) + public function fetch($rowid, $ref = '') { global $conf; @@ -372,7 +373,12 @@ class Mailing extends CommonObject $sql .= ", m.date_envoi"; $sql .= ", m.extraparams"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m"; - $sql .= " WHERE m.rowid = ".(int) $rowid; + $sql .= " WHERE entity IN (".getEntity('mailing').")"; + if ($ref) { + $sql .= " AND m.titre = '".$this->db->escape($ref)."'"; + } else { + $sql .= " AND m.rowid = ".(int) $rowid; + } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $result = $this->db->query($sql); diff --git a/htdocs/core/ajax/objectonoff.php b/htdocs/core/ajax/objectonoff.php index ed670627a90..5166ba52b52 100644 --- a/htdocs/core/ajax/objectonoff.php +++ b/htdocs/core/ajax/objectonoff.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2015-2023 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ /** * \file htdocs/core/ajax/objectonoff.php - * \brief File to set status for an object + * \brief File to set status for an object. Called when ajax_object_onoff() is used. * This Ajax service is oftenly called when option MAIN_DIRECT_STATUS_UPDATE is set. */ @@ -45,6 +45,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; $action = GETPOST('action', 'aZ09'); +$backtopage = GETPOST('backtopage'); $id = GETPOST('id', 'int'); $element = GETPOST('element', 'alpha'); // 'myobject' (myobject=mymodule) or 'myobject@mymodule' or 'myobject_mysubobject' (myobject=mymodule) @@ -79,7 +80,7 @@ if (!empty($user->socid)) { // We check permission. // Check is done on $user->rights->element->create or $user->rights->element->subelement->create (because $action = 'set') -if (preg_match('/status$/', $field)) { +if (preg_match('/status$/', $field) || ($field == 'evenunsubscribe' && $object->table_element == 'mailing')) { restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission); } elseif ($element == 'product' && in_array($field, array('tosell', 'tobuy', 'tobatch'))) { // Special case for products restrictedArea($user, 'produit|service', $object, 'product&product', '', '', 'rowid'); @@ -114,4 +115,9 @@ if (($action == 'set') && !empty($id)) { http_response_code(500); exit; } + + if ($backtopage) { + header('Location: '.$backtopage); + exit; + } } diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 043d9e6e18e..3a95809e6d4 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -690,29 +690,33 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof } /** - * On/off button to change status of an object - * This is called when MAIN_DIRECT_STATUS_UPDATE is set and it use tha ajax service objectonoff.php + * On/off button to change a property status of an object + * This uses the ajax service objectonoff.php (May be called when MAIN_DIRECT_STATUS_UPDATE is set for some pages) * * @param Object $object Object to set * @param string $code Name of property in object : 'status' or 'status_buy' for product by example * @param string $field Name of database field : 'tosell' or 'tobuy' for product by example - * @param string $text_on Text if on ('Text' or 'Text:css picto on') - * @param string $text_off Text if off ('Text' or 'Text:css picto on') + * @param string $text_on Text if on ('Text' or 'Text:Picto on:Css picto on') + * @param string $text_off Text if off ('Text' or 'Text:Picto off:Css picto off') * @param array $input Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid')) * @param string $morecss More CSS - * @param string $htmlname Name of HTML component. Keep '' or use a different value if you need to use this component several time on same page for same property. + * @param string $htmlname Name of HTML component. Keep '' or use a different value if you need to use this component several time on the same page for the same field. + * @param int $forcenojs Force the component to work as link post (without javascript) instead of ajax call * @return string html for button on/off */ -function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '', $htmlname = '') +function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '', $htmlname = '', $forcenojs = 0) { - global $langs; + global $conf, $langs; if (empty($htmlname)) { $htmlname = $code; } //var_dump($object->module); var_dump($object->element); - $out = ''; + } $switchon = 'switch_on'; $switchoff = 'switch_off'; + $cssswitchon = ''; + $cssswitchoff = ''; $tmparray = explode(':', $text_on); if (!empty($tmparray[1])) { $text_on = $tmparray[0]; $switchon = $tmparray[1]; + if (!empty($tmparray[2])) { + $cssswitchon = $tmparray[2]; + } } $tmparray = explode(':', $text_off); if (!empty($tmparray[1])) { $text_off = $tmparray[0]; $switchoff = $tmparray[1]; + if (!empty($tmparray[2])) { + $cssswitchoff = $tmparray[2]; + } } - $out .= ''.img_picto($langs->trans($text_off), $switchoff).''; - $out .= ''.img_picto($langs->trans($text_on), $switchon).''; + if (empty($conf->use_javascript_ajax) || $forcenojs) { + $out .= ''.img_picto($langs->trans($text_off), $switchoff, '', false, 0, 0, '', $cssswitchoff).''; + $out .= ''.img_picto($langs->trans($text_on), $switchon, '', false, 0, 0, '', $cssswitchon).''; + } else { + $out .= ''.img_picto($langs->trans($text_off), $switchoff, '', false, 0, 0, '', $cssswitchoff).''; + $out .= ''.img_picto($langs->trans($text_on), $switchon, '', false, 0, 0, '', $cssswitchon).''; + } return $out; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d3276916747..c3fdbf377a3 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -11328,6 +11328,12 @@ function getElementProperties($element_type) $classpath = 'contrat/class'; $module = 'contrat'; $subelement = 'contrat'; + } elseif ($element_type == 'mailing') { + $classpath = 'comm/mailing/class'; + $module = 'mailing'; + $classfile = 'mailing'; + $classname = 'Mailing'; + $subelement = ''; } elseif ($element_type == 'member') { $classpath = 'adherents/class'; $module = 'adherent'; @@ -11424,7 +11430,6 @@ function fetchObjectByElement($element_id, $element_type, $element_ref = '') $ret = 0; $element_prop = getElementProperties($element_type); - //var_dump($element_prop); if (is_array($element_prop) && isModEnabled($element_prop['module'])) { dol_include_once('/'.$element_prop['classpath'].'/'.$element_prop['classfile'].'.class.php'); diff --git a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql index a5b1406cfdb..f8c48e6c3ee 100644 --- a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql +++ b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql @@ -388,5 +388,6 @@ ALTER TABLE llx_bordereau_cheque ADD COLUMN label varchar(255) AFTER ref; ALTER TABLE llx_c_email_templates add COLUMN defaultfortype smallint DEFAULT 0; +ALTER TABLE llx_mailing ADD COLUMN fk_user_modif integer AFTER fk_user_creat; ALTER TABLE llx_mailing ADD COLUMN evenunsubscribe smallint DEFAULT 0; diff --git a/htdocs/install/mysql/tables/llx_mailing-mailing.sql b/htdocs/install/mysql/tables/llx_mailing-mailing.sql index 39392502053..fa97a3944aa 100644 --- a/htdocs/install/mysql/tables/llx_mailing-mailing.sql +++ b/htdocs/install/mysql/tables/llx_mailing-mailing.sql @@ -46,6 +46,7 @@ create table llx_mailing date_envoi datetime, -- date d'envoi tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, fk_user_creat integer, -- user creator + fk_user_modif integer, -- user of last modification fk_user_valid integer, -- user validator fk_user_appro integer, -- not used extraparams varchar(255), -- for stock other parameters with json format