79 public $evenunsubscribe = 0;
84 public $require_module = array();
89 public $require_admin = 0;
94 public $picto =
false;
114 global $langs, $form;
116 $langs->load(
"mails");
117 $transstring =
"MailingModuleDesc".$this->name;
120 if ($langs->trans($this->name) != $this->name) {
121 $s = $langs->trans($this->
name);
122 } elseif ($langs->trans($transstring) != $transstring) {
123 $s = $langs->trans($transstring);
128 if ($this->tooltip && is_object($form)) {
129 $s .=
' '.$form->textwithpicto(
'', $langs->trans($this->tooltip), 1,
'help');
146 if (!empty($this->evenunsubscribe)) {
151 $sql =
" AND NOT EXISTS (SELECT rowid FROM ".$this->db->prefix().
"mailing_unsubscribe as mu";
152 $sql .=
" WHERE ".$this->db->sanitize($emailfield).
" = mu.email";
153 $sql .=
" AND mu.entity = ".((int)
$conf->entity).
")";
176 $result = $this->db->query($sql);
179 while ($obj = $this->db->fetch_object($result)) {
180 $total += (int) $obj->nb;
184 $this->error = $this->db->lasterror();
210 $sql =
"SELECT COUNT(*) nb FROM ".$this->db->prefix().
"mailing_cibles";
211 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
212 $result = $this->db->query($sql);
214 $obj = $this->db->fetch_object($result);
215 $nb = (int) $obj->nb;
217 $sql =
"UPDATE ".$this->db->prefix().
"mailing";
218 $sql .=
" SET nbemail = ".((int) $nb).
" WHERE rowid = ".((int) $mailing_id);
219 if (!$this->db->query($sql)) {
221 $this->error = $this->db->error();
246 $num = count($cibles);
247 foreach ($cibles as $targetarray) {
248 if (!empty($targetarray[
'email'])) {
249 $sql =
"INSERT INTO ".$this->db->prefix().
"mailing_cibles";
250 $sql .=
" (fk_mailing,";
251 $sql .=
" fk_contact,";
252 $sql .=
" lastname, firstname, email, other, source_url, source_id,";
254 $sql .=
" source_type)";
255 $sql .=
" VALUES (".((int) $mailing_id).
",";
256 $sql .= (empty($targetarray[
'fk_contact']) ?
'0' : (int) $targetarray[
'fk_contact']).
",";
257 $sql .=
"'".$this->db->escape($targetarray[
'lastname']).
"',";
258 $sql .=
"'".$this->db->escape($targetarray[
'firstname']).
"',";
259 $sql .=
"'".$this->db->escape($targetarray[
'email']).
"',";
260 $sql .=
"'".$this->db->escape($targetarray[
'other']).
"',";
261 $sql .=
"'".$this->db->escape($targetarray[
'source_url']).
"',";
262 $sql .= (empty($targetarray[
'source_id']) ?
'null' : (int) $targetarray[
'source_id']).
",";
263 $sql .=
"'".$this->db->escape(
dol_hash(
$conf->file->instance_unique_id.
";".$targetarray[
'email'].
";".$targetarray[
'lastname'].
";".((
int) $mailing_id).
";".
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY'),
'md5')).
"',";
264 $sql .=
"'".$this->db->escape($targetarray[
'source_type']).
"')";
266 $result = $this->db->query($sql);
270 if ($this->db->errno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
272 dol_syslog($this->db->error().
' : '.$targetarray[
'email']);
273 $this->error = $this->db->error().
' : '.$targetarray[
'email'];
274 $this->db->rollback();
281 dol_syslog(__METHOD__.
": mailing ".$j.
" targets added");
301 if (empty($this->evenunsubscribe)) {
302 $sql =
"UPDATE ".$this->db->prefix().
"mailing_cibles as mc";
303 $sql .=
" SET statut = 3";
304 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
305 $sql .=
" AND EXISTS (SELECT rowid FROM ".$this->db->prefix().
"mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int)
$conf->entity).
")";
307 dol_syslog(__METHOD__.
":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
308 $result = $this->db->query($sql);
310 dol_print_error($this->db);
332 $sql =
"DELETE FROM ".$this->db->prefix().
"mailing_cibles";
333 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
335 if (!$this->db->query($sql)) {
357 $iscoreorexternal = array();
362 $diremailselector = array(
'/core/modules/mailings/');
363 if (is_array($forcedir)) {
364 $diremailselector = $forcedir;
367 foreach ($diremailselector as $reldir) {
372 if (!is_dir($newdir)) {
376 $handle = opendir($newdir);
377 if (is_resource($handle)) {
378 while (($file = readdir($handle)) !==
false) {
380 if (is_readable($newdir.
'/'.$file) && preg_match(
'/^(.+)\.modules.php/', $file, $reg)) {
381 if (preg_match(
'/\.back$/', $file) || preg_match(
'/^(.+)\.disabled\.php/', $file)) {
388 $modName =
'mailing_'.$reg[1];
390 if (in_array($modName, $modules)) {
391 $langs->load(
"errors");
392 print
'<div class="error">'.$langs->trans(
"Error").
' : '.$langs->trans(
"ErrorDuplicateEmalingSelector", $modName,
"").
'</div>';
396 include_once $newdir.
'/'.$file;
398 print $e->getMessage();
403 $fullpath[$i] = $dir.
'/'.$file;
404 $relpath[$i] = preg_replace(
'/^\//',
'', $reldir).
'/'.$file;
405 $iscoreorexternal[$i] = ($reldir ==
'/core/modules/mailings/' ?
'internal' :
'external');
406 $modules[$i] = $modName;
407 $orders[$i] = $part1;
423 foreach ($orders as $key => $value) {
424 $modName = $modules[$key];
425 if (empty($modName)) {
429 if (!class_exists($modName)) {
430 print
'Error: An emailing selector file was found but its class "'.$modName.
'" was not found.'.
"<br>\n";
434 $objMod =
new $modName($db);
435 if (is_object($objMod)) {
436 '@phan-var-force ModeleBoxes $objMod';
439 $disabledbymodule = 0;
443 if (preg_match(
'/NORUN$/i', $files[$key])) {
448 $widget[$j][
'picto'] = (empty($objMod->picto) ? (empty($objMod->boximg) ? img_object(
'',
'generic') : $objMod->boximg) : img_object(
'', $objMod->picto));
449 $widget[$j][
'file'] = $files[$key];
450 $widget[$j][
'fullpath'] = $fullpath[$key];
451 $widget[$j][
'relpath'] = $relpath[$key];
452 $widget[$j][
'iscoreorexternal'] = $iscoreorexternal[$key];
453 $widget[$j][
'version'] = empty($objMod->version) ?
'' : $objMod->version;
454 $widget[$j][
'status'] = img_picto($langs->trans(
"Active"),
'tick',
'class="pictofixedwidth"');
455 if ($disabledbyname > 0 || $disabledbymodule > 1) {
456 $widget[$j][
'status'] =
'';
459 $text =
'<b>'.$langs->trans(
"Description").
':</b><br>';
460 $text .= $objMod->boxlabel.
'<br>';
461 $text .=
'<br><b>'.$langs->trans(
"Status").
':</b><br>';
462 if ($disabledbymodule == 2) {
463 $text .= $langs->trans(
"WidgetDisabledAsModuleDisabled",
$module).
'<br>';
466 $widget[$j][
'info'] = $text;
486 $msg = get_class($this).
"::".__FUNCTION__.
" not implemented";
502 $msg = get_class($this).
"::".__FUNCTION__.
" not implemented";
Parent class of emailing target selectors modules.
getSqlToExcludeUnsubscribed($emailfield)
Return the SQL fragment that excludes email addresses which opted out of emailings for the current en...
__construct($db)
Constructor.
add_to_target($mailing_id)
Add destinations in the targets table.
static getEmailingSelectorsList($forcedir=null)
Return list of widget.
addTargetsToDatabase($mailing_id, $cibles)
Add a list of targets into the database.
getDesc()
Return description of email selector.
getNbOfRecipients($sql)
Return the number of recipients.
clear_target($mailing_id)
Deletes all recipients from the targets table.
update_nb($mailing_id)
Update the number of recipients.
formFilter()
Displays filter form that appears on the mailing recipient selection page.
getNbOfRecords()
Return number of records for email selector.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
if(! $sortfield) if(! $sortorder) $module
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.