Add info for opt out email

This commit is contained in:
Laurent Destailleur 2023-04-08 17:16:22 +02:00
parent 038fcd69a0
commit 516232a190
12 changed files with 193 additions and 40 deletions

View File

@ -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)) { if (empty($user->rights->mailing->lire) || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->socid > 0)) {
accessforbidden(); 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'); $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
/* /*
* Actions * Actions
*/ */
@ -748,6 +752,7 @@ llxHeader(
array() array()
); );
if ($action == 'create') { if ($action == 'create') {
// EMailing in creation mode // EMailing in creation mode
print '<form name="new_mailing" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n"; print '<form name="new_mailing" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
@ -761,7 +766,7 @@ if ($action == 'create') {
$htmltext .= '</span></i>'; $htmltext .= '</span></i>';
$availablelink = $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar'); $availablelink = $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("AvailableVariables").'</span>', $htmltext, 1, 'help', '', 0, 2, 'availvar');
//print '<a href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$objMod->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto($langs->trans("ClickToShowDescription"), $imginfo).'</a>'; //print '<a href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$objMod->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto($langs->trans("ClickToShowDescription"), $imginfo).'</a>';
@ -967,6 +972,14 @@ if ($action == 'create') {
} }
print '</td></tr>'; print '</td></tr>';
print '</table>';
print '</div>';
print '<div class="fichehalfright">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
// Number of distinct emails // Number of distinct emails
print '<tr><td>'; print '<tr><td>';
print $langs->trans("TotalNbOfDistinctRecipients"); print $langs->trans("TotalNbOfDistinctRecipients");
@ -992,15 +1005,6 @@ if ($action == 'create') {
} }
print '</td></tr>'; print '</td></tr>';
print '</table>';
print '</div>';
print '<div class="fichehalfright">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
// Even if unsubscribe // Even if unsubscribe
print '<tr><td class="titlefield">'; print '<tr><td class="titlefield">';
print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');
@ -1244,6 +1248,15 @@ if ($action == 'create') {
// To // To
print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'</td></tr>'; print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'</td></tr>';
print '</table>';
print '</div>';
print '<div class="fichehalfright">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
// Number of distinct emails // Number of distinct emails
print '<tr><td>'; print '<tr><td>';
print $langs->trans("TotalNbOfDistinctRecipients"); print $langs->trans("TotalNbOfDistinctRecipients");
@ -1269,15 +1282,6 @@ if ($action == 'create') {
} }
print '</td></tr>'; print '</td></tr>';
print '</table>';
print '</div>';
print '<div class="fichehalfright">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
// Even if unsubscribe // Even if unsubscribe
print '<tr><td class="titlefield">'; print '<tr><td class="titlefield">';
print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox'); print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');

View File

@ -99,14 +99,22 @@ if ($action == 'add' && $user->hasRight('mailing', 'creer')) { // Add recipient
$classname = "mailing_".$module; $classname = "mailing_".$module;
if (file_exists($file)) { if (file_exists($file)) {
require_once $file; include_once $file;
// Add targets into database // Add targets into database
$obj = new $classname($db); dol_syslog("Call add_to_target() on class ".$classname." evenunsubscribe=".$object->evenunsubscribe);
dol_syslog("Call add_to_target on class ".$classname);
$result = $obj->add_to_target($id);
$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) { if ($result > 0) {
@ -198,6 +206,38 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
$search_dest_status = ''; $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 <email>'
} elseif ($action == 'setemail_replyto') {
$object->email_replyto = trim(GETPOST('email_replyto', 'alphawithlgt')); // Must allow 'name <email>'
} elseif ($action == 'setemail_errorsto') {
$object->email_errorsto = trim(GETPOST('email_errorsto', 'alphawithlgt')); // Must allow 'name <email>'
} 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); dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
print '<div class="fichecenter">'; print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">'; print '<table class="border centpercent tableforfield">';
@ -280,6 +321,15 @@ if ($object->fetch($id) >= 0) {
} }
print '</td></tr>'; print '</td></tr>';
print '</table>';
print '</div>';
print '<div class="fichehalfright">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
// Nb of distinct emails // Nb of distinct emails
print '<tr><td>'; print '<tr><td>';
print $langs->trans("TotalNbOfDistinctRecipients"); print $langs->trans("TotalNbOfDistinctRecipients");
@ -305,9 +355,21 @@ if ($object->fetch($id) >= 0) {
} }
print '</td></tr>'; print '</td></tr>';
print '</table>'; // Even if unsubscribe
print '<tr><td class="titlefield">';
print $form->editfieldkey("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');
print '</td><td>';
print $form->editfieldval("EvenUnsubscribe", 'evenunsubscribe', $object->evenunsubscribe, $object, $user->hasRight('mailing', 'creer') && $object->statut < 3, 'checkbox');
print '</td></tr>';
print "</div>"; // Other attributes. Fields from hook formObjectOptions and Extrafields.
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
print '</table>';
print '</div>';
print '</div>';
print '<div class="clearboth"></div>';
print dol_get_fiche_end(); print dol_get_fiche_end();
@ -386,8 +448,9 @@ if ($object->fetch($id) >= 0) {
$var = !$var; $var = !$var;
if ($allowaddtarget) { if ($allowaddtarget) {
print '<form '.$bctag[$var].' name="'.$modulename.'" action="'.$_SERVER['PHP_SELF'].'?action=add&token='.newToken().'&id='.$object->id.'&module='.$modulename.'" method="POST" enctype="multipart/form-data">'; print '<form '.$bctag[$var].' name="'.$modulename.'" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&module='.$modulename.'" method="POST" enctype="multipart/form-data">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="page_y" value="'.newToken().'">'; print '<input type="hidden" name="page_y" value="'.newToken().'">';
} else { } else {
print '<div '.$bctag[$var].'>'; print '<div '.$bctag[$var].'>';
@ -404,6 +467,8 @@ if ($object->fetch($id) >= 0) {
print '</div>'; print '</div>';
try { try {
$obj->evenunsubscribe = $object->evenunsubscribe; // Set flag to include/exclude email that has opt-out.
$nbofrecipient = $obj->getNbOfRecipients(''); $nbofrecipient = $obj->getNbOfRecipients('');
} catch (Exception $e) { } catch (Exception $e) {
dol_syslog($e->getMessage(), LOG_ERR); dol_syslog($e->getMessage(), LOG_ERR);
@ -470,8 +535,10 @@ if ($object->fetch($id) >= 0) {
// List of selected targets // List of selected targets
$sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.tms,"; $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 .= " 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); $sql .= " WHERE mc.fk_mailing=".((int) $object->id);
$asearchcriteriahasbeenset = 0; $asearchcriteriahasbeenset = 0;
if ($search_lastname) { if ($search_lastname) {
@ -494,8 +561,10 @@ if ($object->fetch($id) >= 0) {
$sql .= " AND mc.statut = ".((int) $search_dest_status); $sql .= " AND mc.statut = ".((int) $search_dest_status);
$asearchcriteriahasbeenset++; $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); $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records // Count total nb of records
$nbtotalofrecords = ''; $nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
@ -656,10 +725,21 @@ if ($object->fetch($id) >= 0) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td class="tdoverflowmax150">'.img_picto('$obj->email', 'email', 'class="paddingright"').dol_escape_htmltag($obj->email).'</td>';
print '<td class="tdoverflowmax150">';
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 '</td>';
print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">'.dol_escape_htmltag($obj->lastname).'</td>'; print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">'.dol_escape_htmltag($obj->lastname).'</td>';
print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">'.dol_escape_htmltag($obj->firstname).'</td>'; print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">'.dol_escape_htmltag($obj->firstname).'</td>';
print '<td><span class="small">'.dol_escape_htmltag($obj->other).'</small></td>'; print '<td><span class="small">'.dol_escape_htmltag($obj->other).'</small></td>';
print '<td class="center tdoverflowmax150">'; print '<td class="center tdoverflowmax150">';
if (empty($obj->source_id) || empty($obj->source_type)) { if (empty($obj->source_id) || empty($obj->source_type)) {
print empty($obj->source_url) ? '' : $obj->source_url; // For backward compatibility print empty($obj->source_url) ? '' : $obj->source_url; // For backward compatibility

View File

@ -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 .= " 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 .= " WHERE s.entity IN (".getEntity('societe').")";
$sql .= " AND s.rowid IN (".$this->db->sanitize(implode(',', $socid)).")"; $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"; $sql .= " ORDER BY email";
// Stock recipients emails into targets table // Stock recipients emails into targets table
@ -132,6 +135,9 @@ class mailing_advthirdparties extends MailingTargets
if (count($socid) > 0) { if (count($socid) > 0) {
$sql .= " AND socp.fk_soc IN (".$this->db->sanitize(implode(',', $socid)).")"; $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"; $sql .= " ORDER BY email";
// Stock recipients emails into targets table // Stock recipients emails into targets table
@ -211,6 +217,9 @@ class mailing_advthirdparties extends MailingTargets
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE s.email != ''"; $sql .= " WHERE s.email != ''";
$sql .= " AND s.entity IN (".getEntity('societe').")"; $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 // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql); return parent::getNbOfRecipients($sql);

View File

@ -82,7 +82,6 @@ class mailing_contacts1 extends MailingTargets
$statssql[0] .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; $statssql[0] .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
$statssql[0] .= " WHERE c.entity IN (".getEntity('contact').")"; $statssql[0] .= " WHERE c.entity IN (".getEntity('contact').")";
$statssql[0] .= " AND c.email <> ''"; // Note that null != '' is false $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"; $statssql[0] .= " AND c.statut = 1";
return $statssql; 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 .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc";
$sql .= " WHERE c.entity IN (".getEntity('contact').")"; $sql .= " WHERE c.entity IN (".getEntity('contact').")";
$sql .= " AND c.email <> ''"; // Note that null != '' is false $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 // exclude unsubscribed users
$sql .= " AND c.statut = 1"; $sql .= " AND c.statut = 1";
@ -331,7 +332,7 @@ class mailing_contacts1 extends MailingTargets
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // 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 * @param int $mailing_id Id of emailing
* @return int <0 si erreur, nb ajout si ok * @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 .= " WHERE sp.entity IN (".getEntity('contact').")";
$sql .= " AND sp.email <> ''"; $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 // Exclude unsubscribed email adresses
$sql .= " AND sp.statut = 1"; $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).")"; $sql .= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";

View File

@ -85,6 +85,9 @@ class mailing_eventorganization extends MailingTargets
$sql .= " AND p.entity IN (".getEntity('project').")"; $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.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')); $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"; $sql .= " ORDER BY e.email";
// Stock recipients emails into targets table // Stock recipients emails into targets table
@ -159,14 +162,15 @@ class mailing_eventorganization extends MailingTargets
*/ */
public function getNbOfRecipients($sql = '') public function getNbOfRecipients($sql = '')
{ {
global $conf;
$sql = "SELECT COUNT(DISTINCT(e.email)) as nb"; $sql = "SELECT COUNT(DISTINCT(e.email)) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee as e, "; $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee as e, ";
$sql .= " ".MAIN_DB_PREFIX."projet as p"; $sql .= " ".MAIN_DB_PREFIX."projet as p";
$sql .= " WHERE e.email <> ''"; $sql .= " WHERE e.email <> ''";
$sql .= " AND e.fk_project = p.rowid"; $sql .= " AND e.fk_project = p.rowid";
$sql .= " AND p.entity IN (".getEntity('project').")"; $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; //print $sql;

View File

@ -101,6 +101,9 @@ class mailing_fraise extends MailingTargets
$sql = "SELECT count(distinct(a.email)) as nb"; $sql = "SELECT count(distinct(a.email)) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as a"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
$sql .= " WHERE (a.email IS NOT NULL AND a.email != '') AND a.entity IN (".getEntity('member').")"; $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 // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql); return parent::getNbOfRecipients($sql);
@ -278,6 +281,9 @@ class mailing_fraise extends MailingTargets
if (GETPOST('filter_type', 'int') > 0) { if (GETPOST('filter_type', 'int') > 0) {
$sql .= " AND ta.rowid = ".((int) GETPOST('filter_type', 'int')); $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"; $sql .= " ORDER BY a.email";
//print $sql; //print $sql;

View File

@ -53,6 +53,12 @@ class MailingTargets // This can't be abstract as it is used for some method
*/ */
public $sql; 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 * Constructor
@ -111,8 +117,11 @@ class MailingTargets // This can't be abstract as it is used for some method
{ {
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
$obj = $this->db->fetch_object($result); $total = 0;
return $obj->nb; while ($obj = $this->db->fetch_object($result)) {
$total += $obj->nb;
}
return $total;
} else { } else {
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
return -1; return -1;

View File

@ -86,6 +86,9 @@ class mailing_partnership extends MailingTargets
if (GETPOST('filter', 'int') > 0) { if (GETPOST('filter', 'int') > 0) {
$sql .= " AND pt.rowid=".((int) GETPOST('filter', 'int')); $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 "; $sql .= " UNION ";
@ -99,6 +102,9 @@ class mailing_partnership extends MailingTargets
if (GETPOST('filter', 'int') > 0) { if (GETPOST('filter', 'int') > 0) {
$sql .= " AND pt.rowid=".((int) GETPOST('filter', 'int')); $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"; $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 .= " FROM ".MAIN_DB_PREFIX."partnership as p, ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE s.rowid = p.fk_soc AND s.email <> ''"; $sql .= " WHERE s.rowid = p.fk_soc AND s.email <> ''";
$sql .= " AND s.entity IN (".getEntity('societe').")"; $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 "; $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 .= " FROM ".MAIN_DB_PREFIX."partnership as p, ".MAIN_DB_PREFIX."adherent as s";
$sql .= " WHERE s.rowid = p.fk_member AND s.email <> ''"; $sql .= " WHERE s.rowid = p.fk_member AND s.email <> ''";
$sql .= " AND s.entity IN (".getEntity('member').")"; $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; //print $sql;

View File

@ -78,6 +78,7 @@ class mailing_pomme extends MailingTargets
$sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
$sql .= " AND u.entity IN (0,".$conf->entity.")"; $sql .= " AND u.entity IN (0,".$conf->entity.")";
$statssql[0] = $sql; $statssql[0] = $sql;
return $statssql; return $statssql;
@ -100,6 +101,9 @@ class mailing_pomme extends MailingTargets
$sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test $sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
$sql .= " AND u.entity IN (0,".$conf->entity.")"; $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 // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql); return parent::getNbOfRecipients($sql);
@ -183,6 +187,9 @@ class mailing_pomme extends MailingTargets
if (GETPOSTISSET("filteremployee") && GETPOST("filteremployee") == '0') { if (GETPOSTISSET("filteremployee") && GETPOST("filteremployee") == '0') {
$sql .= " AND u.employee=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"; $sql .= " ORDER BY u.email";
// Stocke destinataires dans cibles // Stocke destinataires dans cibles

View File

@ -142,6 +142,9 @@ class mailing_thirdparties extends MailingTargets
$sql .= " WHERE s.email <> ''"; $sql .= " WHERE s.email <> ''";
$sql .= " AND s.entity IN (".getEntity('societe').")"; $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).")"; $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; $sql .= $addFilter;
} else { } 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"; $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) { if (GETPOST('filter_thirdparties', 'int') > 0) {
$sql .= " AND c.rowid=".((int) GETPOST('filter_thirdparties', 'int')); $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 .= $addFilter;
$sql .= " UNION "; $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"; $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) { if (GETPOST('filter_thirdparties', 'int') > 0) {
$sql .= " AND c.rowid=".((int) GETPOST('filter_thirdparties', 'int')); $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 .= $addFilter;
} }
$sql .= " ORDER BY email"; $sql .= " ORDER BY email";
@ -250,7 +259,10 @@ class mailing_thirdparties extends MailingTargets
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE s.email <> ''"; $sql .= " WHERE s.email <> ''";
$sql .= " AND s.entity IN (".getEntity('societe').")"; $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 // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql); return parent::getNbOfRecipients($sql);
} }

View File

@ -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 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.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)."'"; $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"; $sql .= " ORDER BY s.email";
// Stocke destinataires dans cibles // 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 cd.statut= 4 AND cd.fk_product=p.rowid";
$sql .= " AND p.ref IN (".$this->db->sanitize("'".join("','", $this->arrayofproducts)."'", 1).")"; $sql .= " AND p.ref IN (".$this->db->sanitize("'".join("','", $this->arrayofproducts)."'", 1).")";
$sql .= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; $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); $a = parent::getNbOfRecipients($sql);

View File

@ -180,5 +180,6 @@ DefaultBlacklistMailingStatus=Default value for field '%s' when creating a new c
DefaultStatusEmptyMandatory=Empty but mandatory DefaultStatusEmptyMandatory=Empty but mandatory
WarningLimitSendByDay=WARNING: The setup or contract of your instance limits your number of emails per day to <b>%s</b>. Trying to send more may result in having your instance slow down or suspended. Please contact your support if you need a higher quota. WarningLimitSendByDay=WARNING: The setup or contract of your instance limits your number of emails per day to <b>%s</b>. 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 NoMoreRecipientToSendTo=No more recipient to send the email to
EvenUnsubscribe=Include opt-outed emails EmailOptedOut=Email owner has requested to not contact him with this email anymore
EvenUnsubscribeDesc=Force the send of email even to opt-outed emails. Usefull for mandatory service emails for example. EvenUnsubscribe=Include opt-out emails
EvenUnsubscribeDesc=Include opt-out emails when you select emails as targets. Usefull for mandatory service emails for example.