79 public $evenunsubscribe = 0;
101 $langs->load(
"mails");
102 $transstring =
"MailingModuleDesc".$this->name;
105 if ($langs->trans($this->name) != $this->name) {
106 $s = $langs->trans($this->
name);
107 } elseif ($langs->trans($transstring) != $transstring) {
108 $s = $langs->trans($transstring);
113 if ($this->tooltip && is_object($form)) {
114 $s .=
' '.$form->textwithpicto(
'', $langs->trans($this->tooltip), 1,
'help');
131 if (!empty($this->evenunsubscribe)) {
136 $sql =
" AND NOT EXISTS (SELECT rowid FROM ".$this->db->prefix().
"mailing_unsubscribe as mu";
137 $sql .=
" WHERE ".$this->db->sanitize($emailfield).
" = mu.email";
138 $sql .=
" AND mu.entity = ".((int)
$conf->entity).
")";
161 $result = $this->db->query($sql);
164 while ($obj = $this->db->fetch_object($result)) {
165 $total += (int) $obj->nb;
169 $this->error = $this->db->lasterror();
195 $sql =
"SELECT COUNT(*) nb FROM ".$this->db->prefix().
"mailing_cibles";
196 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
197 $result = $this->db->query($sql);
199 $obj = $this->db->fetch_object($result);
200 $nb = (int) $obj->nb;
202 $sql =
"UPDATE ".$this->db->prefix().
"mailing";
203 $sql .=
" SET nbemail = ".((int) $nb).
" WHERE rowid = ".((int) $mailing_id);
204 if (!$this->db->query($sql)) {
206 $this->error = $this->db->error();
231 $num = count($cibles);
232 foreach ($cibles as $targetarray) {
233 if (!empty($targetarray[
'email'])) {
234 $sql =
"INSERT INTO ".$this->db->prefix().
"mailing_cibles";
235 $sql .=
" (fk_mailing,";
236 $sql .=
" fk_contact,";
237 $sql .=
" lastname, firstname, email, other, source_url, source_id,";
239 $sql .=
" source_type)";
240 $sql .=
" VALUES (".((int) $mailing_id).
",";
241 $sql .= (empty($targetarray[
'fk_contact']) ?
'0' : (int) $targetarray[
'fk_contact']).
",";
242 $sql .=
"'".$this->db->escape($targetarray[
'lastname']).
"',";
243 $sql .=
"'".$this->db->escape($targetarray[
'firstname']).
"',";
244 $sql .=
"'".$this->db->escape($targetarray[
'email']).
"',";
245 $sql .=
"'".$this->db->escape($targetarray[
'other']).
"',";
246 $sql .=
"'".$this->db->escape($targetarray[
'source_url']).
"',";
247 $sql .= (empty($targetarray[
'source_id']) ?
'null' : (int) $targetarray[
'source_id']).
",";
248 $sql .=
"'".$this->db->escape(
dol_hash(
$conf->file->instance_unique_id.
";".$targetarray[
'email'].
";".$targetarray[
'lastname'].
";".((
int) $mailing_id).
";".
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY'),
'md5')).
"',";
249 $sql .=
"'".$this->db->escape($targetarray[
'source_type']).
"')";
251 $result = $this->db->query($sql);
255 if ($this->db->errno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
257 dol_syslog($this->db->error().
' : '.$targetarray[
'email']);
258 $this->error = $this->db->error().
' : '.$targetarray[
'email'];
259 $this->db->rollback();
266 dol_syslog(__METHOD__.
": mailing ".$j.
" targets added");
286 if (empty($this->evenunsubscribe)) {
287 $sql =
"UPDATE ".$this->db->prefix().
"mailing_cibles as mc";
288 $sql .=
" SET statut = 3";
289 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
290 $sql .=
" AND EXISTS (SELECT rowid FROM ".$this->db->prefix().
"mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int)
$conf->entity).
")";
292 dol_syslog(__METHOD__.
":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
293 $result = $this->db->query($sql);
317 $sql =
"DELETE FROM ".$this->db->prefix().
"mailing_cibles";
318 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
320 if (!$this->db->query($sql)) {
342 $iscoreorexternal = array();
347 $diremailselector = array(
'/core/modules/mailings/');
348 if (is_array($forcedir)) {
349 $diremailselector = $forcedir;
352 foreach ($diremailselector as $reldir) {
357 if (!is_dir($newdir)) {
361 $handle = opendir($newdir);
362 if (is_resource($handle)) {
363 while (($file = readdir($handle)) !==
false) {
365 if (is_readable($newdir.
'/'.$file) && preg_match(
'/^(.+)\.modules.php/', $file, $reg)) {
366 if (preg_match(
'/\.back$/', $file) || preg_match(
'/^(.+)\.disabled\.php/', $file)) {
373 $modName =
'mailing_'.$reg[1];
375 if (in_array($modName, $modules)) {
376 $langs->load(
"errors");
377 print
'<div class="error">'.$langs->trans(
"Error").
' : '.$langs->trans(
"ErrorDuplicateEmalingSelector", $modName,
"").
'</div>';
381 include_once $newdir.
'/'.$file;
383 print $e->getMessage();
388 $fullpath[$i] = $dir.
'/'.$file;
389 $relpath[$i] = preg_replace(
'/^\//',
'', $reldir).
'/'.$file;
390 $iscoreorexternal[$i] = ($reldir ==
'/core/modules/mailings/' ?
'internal' :
'external');
391 $modules[$i] = $modName;
392 $orders[$i] = $part1;
408 foreach ($orders as $key => $value) {
409 $modName = $modules[$key];
410 if (empty($modName)) {
414 if (!class_exists($modName)) {
415 print
'Error: An emailing selector file was found but its class "'.$modName.
'" was not found.'.
"<br>\n";
419 $objMod =
new $modName(
$db);
420 if (is_object($objMod)) {
421 '@phan-var-force ModeleBoxes $objMod';
424 $disabledbymodule = 0;
428 if (preg_match(
'/NORUN$/i', $files[$key])) {
433 $widget[$j][
'picto'] = (empty($objMod->picto) ? (empty($objMod->boximg) ?
img_object(
'',
'generic') : $objMod->boximg) :
img_object(
'', $objMod->picto));
434 $widget[$j][
'file'] = $files[$key];
435 $widget[$j][
'fullpath'] = $fullpath[$key];
436 $widget[$j][
'relpath'] = $relpath[$key];
437 $widget[$j][
'iscoreorexternal'] = $iscoreorexternal[$key];
438 $widget[$j][
'version'] = empty($objMod->version) ?
'' : $objMod->version;
439 $widget[$j][
'status'] =
img_picto($langs->trans(
"Active"),
'tick',
'class="pictofixedwidth"');
440 if ($disabledbyname > 0 || $disabledbymodule > 1) {
441 $widget[$j][
'status'] =
'';
444 $text =
'<b>'.$langs->trans(
"Description").
':</b><br>';
445 $text .= $objMod->boxlabel.
'<br>';
446 $text .=
'<br><b>'.$langs->trans(
"Status").
':</b><br>';
447 if ($disabledbymodule == 2) {
448 $text .= $langs->trans(
"WidgetDisabledAsModuleDisabled", $module).
'<br>';
451 $widget[$j][
'info'] = $text;
471 $msg = get_class($this).
"::".__FUNCTION__.
" not implemented";
487 $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.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
$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.