From 516232a1908da42506a90af52d6f4638e01367ae Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 8 Apr 2023 17:16:22 +0200 Subject: [PATCH] Add info for opt out email --- htdocs/comm/mailing/card.php | 42 ++++---- htdocs/comm/mailing/cibles.php | 100 ++++++++++++++++-- .../mailings/advthirdparties.modules.php | 9 ++ .../modules/mailings/contacts1.modules.php | 11 +- .../mailings/eventorganization.modules.php | 8 +- .../core/modules/mailings/fraise.modules.php | 6 ++ .../modules/mailings/modules_mailings.php | 13 ++- .../modules/mailings/partnership.modules.php | 12 +++ .../core/modules/mailings/pomme.modules.php | 7 ++ .../modules/mailings/thirdparties.modules.php | 14 ++- .../thirdparties_services_expired.modules.php | 6 ++ htdocs/langs/en_US/mails.lang | 5 +- 12 files changed, 193 insertions(+), 40 deletions(-) diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 095802ee556..a48f4be148f 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -84,10 +84,14 @@ $listofmethods['smtps'] = 'SMTP/SMTPS socket library'; if (empty($user->rights->mailing->lire) || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) { accessforbidden(); } +if (empty($action) && empty($object->id)) { + accessforbidden('Object not found'); +} $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing'); + /* * Actions */ @@ -748,6 +752,7 @@ llxHeader( array() ); + if ($action == 'create') { // EMailing in creation mode print '
'."\n"; @@ -761,7 +766,7 @@ if ($action == 'create') { $htmltext .= ''; - $availablelink = $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar'); + $availablelink = $form->textwithpicto(''.$langs->trans("AvailableVariables").'', $htmltext, 1, 'help', '', 0, 2, 'availvar'); //print ''.img_picto($langs->trans("ClickToShowDescription"), $imginfo).''; @@ -967,6 +972,14 @@ if ($action == 'create') { } print ''; + print ''; + print ''; + + print '
'; + print '
'; + + print ''; + // Number of distinct emails print ''; - print '
'; print $langs->trans("TotalNbOfDistinctRecipients"); @@ -992,15 +1005,6 @@ if ($action == 'create') { } print '
'; - print '
'; - - - print '
'; - print '
'; - - print ''; - // Even if unsubscribe print ''; + print '
'; print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); @@ -1244,6 +1248,15 @@ if ($action == 'create') { // To print '
'.$langs->trans("MailErrorsTo").''.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'
'; + print '
'; + + + print '
'; + print '
'; + + print ''; + // Number of distinct emails print ''; - print '
'; print $langs->trans("TotalNbOfDistinctRecipients"); @@ -1269,15 +1282,6 @@ if ($action == 'create') { } print '
'; - print '
'; - - - print '
'; - print '
'; - - print ''; - // Even if unsubscribe print ''; - print ""; + // Other attributes. Fields from hook formObjectOptions and Extrafields. + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + print '
'; print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 206909d1602..73ffb9837c7 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -99,14 +99,22 @@ if ($action == 'add' && $user->hasRight('mailing', 'creer')) { // Add recipient $classname = "mailing_".$module; if (file_exists($file)) { - require_once $file; + include_once $file; // Add targets into database - $obj = new $classname($db); - dol_syslog("Call add_to_target on class ".$classname); - $result = $obj->add_to_target($id); + dol_syslog("Call add_to_target() on class ".$classname." evenunsubscribe=".$object->evenunsubscribe); - $sqlmessage = $obj->sql; + if (class_exists($classname)) { + $obj = new $classname($db); + $obj->evenunsubscribe = $object->evenunsubscribe; + + $result = $obj->add_to_target($id); + + $sqlmessage = $obj->sql; + } else { + $result = -1; + break; + } } } if ($result > 0) { @@ -198,6 +206,38 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $search_dest_status = ''; } +// Action update description of emailing +if ($action == 'settitle' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto' || $action == 'setevenunsubscribe') { + $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing'); + + if ($action == 'settitle') { + $object->title = trim(GETPOST('title', 'alpha')); + } elseif ($action == 'setemail_from') { + $object->email_from = trim(GETPOST('email_from', 'alphawithlgt')); // Must allow 'name ' + } elseif ($action == 'setemail_replyto') { + $object->email_replyto = trim(GETPOST('email_replyto', 'alphawithlgt')); // Must allow 'name ' + } elseif ($action == 'setemail_errorsto') { + $object->email_errorsto = trim(GETPOST('email_errorsto', 'alphawithlgt')); // Must allow 'name ' + } elseif ($action == 'settitle' && empty($object->title)) { + $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle")); + } elseif ($action == 'setfrom' && empty($object->email_from)) { + $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailFrom")); + } elseif ($action == 'setevenunsubscribe') { + $object->evenunsubscribe = (GETPOST('evenunsubscribe') ? 1 : 0); + } + + if (!$mesg) { + $result = $object->update($user); + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + $mesg = $object->error; + } + + setEventMessages($mesg, null, 'errors'); + $action = ""; +} /* @@ -239,6 +279,7 @@ if ($object->fetch($id) >= 0) { dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); print '
'; + print '
'; print '
'; print ''; @@ -280,6 +321,15 @@ if ($object->fetch($id) >= 0) { } print ''; + print '
'; + print '
'; + + + print '
'; + print '
'; + + print ''; + // Nb of distinct emails print ''; - print '
'; print $langs->trans("TotalNbOfDistinctRecipients"); @@ -305,9 +355,21 @@ 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 '
'; + print '
'; + print ''; + + print '
'; print dol_get_fiche_end(); @@ -386,8 +448,9 @@ if ($object->fetch($id) >= 0) { $var = !$var; if ($allowaddtarget) { - print ''; + print ''; print ''; + print ''; print ''; } else { print '
'; @@ -404,6 +467,8 @@ if ($object->fetch($id) >= 0) { print '
'; try { + $obj->evenunsubscribe = $object->evenunsubscribe; // Set flag to include/exclude email that has opt-out. + $nbofrecipient = $obj->getNbOfRecipients(''); } catch (Exception $e) { dol_syslog($e->getMessage(), LOG_ERR); @@ -470,8 +535,10 @@ if ($object->fetch($id) >= 0) { // List of selected targets $sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.tms,"; - $sql .= " mc.source_url, mc.source_id, mc.source_type, mc.error_text"; + $sql .= " mc.source_url, mc.source_id, mc.source_type, mc.error_text,"; + $sql .= " COUNT(mu.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mailing_unsubscribe as mu ON mu.email = mc.email"; $sql .= " WHERE mc.fk_mailing=".((int) $object->id); $asearchcriteriahasbeenset = 0; if ($search_lastname) { @@ -494,8 +561,10 @@ if ($object->fetch($id) >= 0) { $sql .= " AND mc.statut = ".((int) $search_dest_status); $asearchcriteriahasbeenset++; } + $sql .= ' GROUP BY mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.tms, mc.source_url, mc.source_id, mc.source_type, mc.error_text'; $sql .= $db->order($sortfield, $sortorder); + // Count total nb of records $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { @@ -656,10 +725,21 @@ if ($object->fetch($id) >= 0) { $obj = $db->fetch_object($resql); print ''; - print ''.img_picto('$obj->email', 'email', 'class="paddingright"').dol_escape_htmltag($obj->email).''; + + print ''; + print img_picto($obj->email, 'email', 'class="paddingright"'); + if ($obj->nb > 0) { + print img_warning($langs->trans("EmailOptedOut"), 'warning', 'pictofixedwidth'); + } + print dol_escape_htmltag($obj->email); + print ''; + print ''.dol_escape_htmltag($obj->lastname).''; + print ''.dol_escape_htmltag($obj->firstname).''; + print ''.dol_escape_htmltag($obj->other).''; + print ''; if (empty($obj->source_id) || empty($obj->source_type)) { print empty($obj->source_url) ? '' : $obj->source_url; // For backward compatibility diff --git a/htdocs/core/modules/mailings/advthirdparties.modules.php b/htdocs/core/modules/mailings/advthirdparties.modules.php index 7649c255d04..6137bcca2ff 100644 --- a/htdocs/core/modules/mailings/advthirdparties.modules.php +++ b/htdocs/core/modules/mailings/advthirdparties.modules.php @@ -82,6 +82,9 @@ class mailing_advthirdparties extends MailingTargets $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe_extrafields se ON se.fk_object=s.rowid"; $sql .= " WHERE s.entity IN (".getEntity('societe').")"; $sql .= " AND s.rowid IN (".$this->db->sanitize(implode(',', $socid)).")"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + } $sql .= " ORDER BY email"; // Stock recipients emails into targets table @@ -132,6 +135,9 @@ class mailing_advthirdparties extends MailingTargets if (count($socid) > 0) { $sql .= " AND socp.fk_soc IN (".$this->db->sanitize(implode(',', $socid)).")"; } + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = socp.email and mu.entity = ".((int) $conf->entity).")"; + } $sql .= " ORDER BY email"; // Stock recipients emails into targets table @@ -211,6 +217,9 @@ class mailing_advthirdparties extends MailingTargets $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= " WHERE s.email != ''"; $sql .= " AND s.entity IN (".getEntity('societe').")"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + } // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients return parent::getNbOfRecipients($sql); diff --git a/htdocs/core/modules/mailings/contacts1.modules.php b/htdocs/core/modules/mailings/contacts1.modules.php index 2b8d17723cb..80db8513395 100644 --- a/htdocs/core/modules/mailings/contacts1.modules.php +++ b/htdocs/core/modules/mailings/contacts1.modules.php @@ -82,7 +82,6 @@ class mailing_contacts1 extends MailingTargets $statssql[0] .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; $statssql[0] .= " WHERE c.entity IN (".getEntity('contact').")"; $statssql[0] .= " AND c.email <> ''"; // Note that null != '' is false - $statssql[0] .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = c.email) = 0"; $statssql[0] .= " AND c.statut = 1"; return $statssql; @@ -104,7 +103,9 @@ class mailing_contacts1 extends MailingTargets $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc"; $sql .= " WHERE c.entity IN (".getEntity('contact').")"; $sql .= " AND c.email <> ''"; // Note that null != '' is false - $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = c.email) = 0"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = c.email and mu.entity = ".((int) $conf->entity).")"; + } // exclude unsubscribed users $sql .= " AND c.statut = 1"; @@ -331,7 +332,7 @@ class mailing_contacts1 extends MailingTargets // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Ajoute destinataires dans table des cibles + * Add some recipients into target table * * @param int $mailing_id Id of emailing * @return int <0 si erreur, nb ajout si ok @@ -389,7 +390,9 @@ class mailing_contacts1 extends MailingTargets $sql .= " WHERE sp.entity IN (".getEntity('contact').")"; $sql .= " AND sp.email <> ''"; - $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = sp.email) = 0"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = sp.email and mu.entity = ".((int) $conf->entity).")"; + } // Exclude unsubscribed email adresses $sql .= " AND sp.statut = 1"; $sql .= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")"; diff --git a/htdocs/core/modules/mailings/eventorganization.modules.php b/htdocs/core/modules/mailings/eventorganization.modules.php index 0d0ffb63c3a..27af7ab52d8 100644 --- a/htdocs/core/modules/mailings/eventorganization.modules.php +++ b/htdocs/core/modules/mailings/eventorganization.modules.php @@ -85,6 +85,9 @@ class mailing_eventorganization extends MailingTargets $sql .= " AND p.entity IN (".getEntity('project').")"; $sql .= " AND e.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")"; $sql .= " AND e.fk_project = ".((int) GETPOST('filter_eventorganization', 'int')); + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = e.email and mu.entity = ".((int) $conf->entity).")"; + } $sql .= " ORDER BY e.email"; // Stock recipients emails into targets table @@ -159,14 +162,15 @@ class mailing_eventorganization extends MailingTargets */ public function getNbOfRecipients($sql = '') { - global $conf; - $sql = "SELECT COUNT(DISTINCT(e.email)) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee as e, "; $sql .= " ".MAIN_DB_PREFIX."projet as p"; $sql .= " WHERE e.email <> ''"; $sql .= " AND e.fk_project = p.rowid"; $sql .= " AND p.entity IN (".getEntity('project').")"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = e.email and mu.entity = ".((int) $conf->entity).")"; + } //print $sql; diff --git a/htdocs/core/modules/mailings/fraise.modules.php b/htdocs/core/modules/mailings/fraise.modules.php index 8d55ac65864..65bb106ceb4 100644 --- a/htdocs/core/modules/mailings/fraise.modules.php +++ b/htdocs/core/modules/mailings/fraise.modules.php @@ -101,6 +101,9 @@ class mailing_fraise extends MailingTargets $sql = "SELECT count(distinct(a.email)) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a"; $sql .= " WHERE (a.email IS NOT NULL AND a.email != '') AND a.entity IN (".getEntity('member').")"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = a.email and mu.entity = ".((int) $conf->entity).")"; + } // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients return parent::getNbOfRecipients($sql); @@ -278,6 +281,9 @@ class mailing_fraise extends MailingTargets if (GETPOST('filter_type', 'int') > 0) { $sql .= " AND ta.rowid = ".((int) GETPOST('filter_type', 'int')); } + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = a.email and mu.entity = ".((int) $conf->entity).")"; + } $sql .= " ORDER BY a.email"; //print $sql; diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php index b745934d94d..b99d012f6a9 100644 --- a/htdocs/core/modules/mailings/modules_mailings.php +++ b/htdocs/core/modules/mailings/modules_mailings.php @@ -53,6 +53,12 @@ class MailingTargets // This can't be abstract as it is used for some method */ public $sql; + public $desc; + + public $name; + + public $evenunsubscribe = 0; // Set this to 1 if you want to flag you also want to include email in target that has opt-out. + /** * Constructor @@ -111,8 +117,11 @@ class MailingTargets // This can't be abstract as it is used for some method { $result = $this->db->query($sql); if ($result) { - $obj = $this->db->fetch_object($result); - return $obj->nb; + $total = 0; + while ($obj = $this->db->fetch_object($result)) { + $total += $obj->nb; + } + return $total; } else { $this->error = $this->db->lasterror(); return -1; diff --git a/htdocs/core/modules/mailings/partnership.modules.php b/htdocs/core/modules/mailings/partnership.modules.php index b4a8e9d8fd9..07405c9f7ad 100644 --- a/htdocs/core/modules/mailings/partnership.modules.php +++ b/htdocs/core/modules/mailings/partnership.modules.php @@ -86,6 +86,9 @@ class mailing_partnership extends MailingTargets if (GETPOST('filter', 'int') > 0) { $sql .= " AND pt.rowid=".((int) GETPOST('filter', 'int')); } + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + } $sql .= " UNION "; @@ -99,6 +102,9 @@ class mailing_partnership extends MailingTargets if (GETPOST('filter', 'int') > 0) { $sql .= " AND pt.rowid=".((int) GETPOST('filter', 'int')); } + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + } $sql .= " ORDER BY email"; @@ -180,6 +186,9 @@ class mailing_partnership extends MailingTargets $sql .= " FROM ".MAIN_DB_PREFIX."partnership as p, ".MAIN_DB_PREFIX."societe as s"; $sql .= " WHERE s.rowid = p.fk_soc AND s.email <> ''"; $sql .= " AND s.entity IN (".getEntity('societe').")"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + } $sql .= " UNION "; @@ -187,6 +196,9 @@ class mailing_partnership extends MailingTargets $sql .= " FROM ".MAIN_DB_PREFIX."partnership as p, ".MAIN_DB_PREFIX."adherent as s"; $sql .= " WHERE s.rowid = p.fk_member AND s.email <> ''"; $sql .= " AND s.entity IN (".getEntity('member').")"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + } //print $sql; diff --git a/htdocs/core/modules/mailings/pomme.modules.php b/htdocs/core/modules/mailings/pomme.modules.php index 907028ca881..2d2dd7e1809 100644 --- a/htdocs/core/modules/mailings/pomme.modules.php +++ b/htdocs/core/modules/mailings/pomme.modules.php @@ -78,6 +78,7 @@ class mailing_pomme extends MailingTargets $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test $sql .= " AND u.entity IN (0,".$conf->entity.")"; + $statssql[0] = $sql; return $statssql; @@ -100,6 +101,9 @@ class mailing_pomme extends MailingTargets $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test $sql .= " AND u.entity IN (0,".$conf->entity.")"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = u.email and mu.entity = ".((int) $conf->entity).")"; + } // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients return parent::getNbOfRecipients($sql); @@ -183,6 +187,9 @@ class mailing_pomme extends MailingTargets if (GETPOSTISSET("filteremployee") && GETPOST("filteremployee") == '0') { $sql .= " AND u.employee=0"; } + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = u.email and mu.entity = ".((int) $conf->entity).")"; + } $sql .= " ORDER BY u.email"; // Stocke destinataires dans cibles diff --git a/htdocs/core/modules/mailings/thirdparties.modules.php b/htdocs/core/modules/mailings/thirdparties.modules.php index fd91e5e849f..f34eb600228 100644 --- a/htdocs/core/modules/mailings/thirdparties.modules.php +++ b/htdocs/core/modules/mailings/thirdparties.modules.php @@ -142,6 +142,9 @@ class mailing_thirdparties extends MailingTargets $sql .= " WHERE s.email <> ''"; $sql .= " AND s.entity IN (".getEntity('societe').")"; $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = s.email) = 0"; + } $sql .= $addFilter; } else { $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; @@ -154,6 +157,9 @@ class mailing_thirdparties extends MailingTargets if (GETPOST('filter_thirdparties', 'int') > 0) { $sql .= " AND c.rowid=".((int) GETPOST('filter_thirdparties', 'int')); } + if (empty($this->evenunsubscribe)) { + $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = s.email) = 0"; + } $sql .= $addFilter; $sql .= " UNION "; $sql .= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; @@ -166,6 +172,9 @@ class mailing_thirdparties extends MailingTargets if (GETPOST('filter_thirdparties', 'int') > 0) { $sql .= " AND c.rowid=".((int) GETPOST('filter_thirdparties', 'int')); } + if (empty($this->evenunsubscribe)) { + $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = s.email) = 0"; + } $sql .= $addFilter; } $sql .= " ORDER BY email"; @@ -250,7 +259,10 @@ class mailing_thirdparties extends MailingTargets $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= " WHERE s.email <> ''"; $sql .= " AND s.entity IN (".getEntity('societe').")"; - $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + } + // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients return parent::getNbOfRecipients($sql); } diff --git a/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php b/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php index 9fc43e37388..acbbe4db46c 100644 --- a/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php +++ b/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php @@ -116,6 +116,9 @@ class mailing_thirdparties_services_expired extends MailingTargets $sql .= " AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''"; $sql .= " AND cd.statut= 4 AND cd.fk_product=p.rowid AND p.ref = '".$this->db->escape($product)."'"; $sql .= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + } $sql .= " ORDER BY s.email"; // Stocke destinataires dans cibles @@ -201,6 +204,9 @@ class mailing_thirdparties_services_expired extends MailingTargets $sql .= " AND cd.statut= 4 AND cd.fk_product=p.rowid"; $sql .= " AND p.ref IN (".$this->db->sanitize("'".join("','", $this->arrayofproducts)."'", 1).")"; $sql .= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; + if (empty($this->evenunsubscribe)) { + $sql .= " AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX."mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).")"; + } $a = parent::getNbOfRecipients($sql); diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index a9e21851ac6..4c217677375 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -180,5 +180,6 @@ DefaultBlacklistMailingStatus=Default value for field '%s' when creating a new c DefaultStatusEmptyMandatory=Empty but mandatory WarningLimitSendByDay=WARNING: The setup or contract of your instance limits your number of emails per day to %s. Trying to send more may result in having your instance slow down or suspended. Please contact your support if you need a higher quota. NoMoreRecipientToSendTo=No more recipient to send the email to -EvenUnsubscribe=Include opt-outed emails -EvenUnsubscribeDesc=Force the send of email even to opt-outed emails. Usefull for mandatory service emails for example. \ No newline at end of file +EmailOptedOut=Email owner has requested to not contact him with this email anymore +EvenUnsubscribe=Include opt-out emails +EvenUnsubscribeDesc=Include opt-out emails when you select emails as targets. Usefull for mandatory service emails for example. \ No newline at end of file