28require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
80 public $evenunsubscribe = 0;
100 global $langs, $form;
102 $langs->load(
"mails");
103 $transstring =
"MailingModuleDesc".$this->name;
106 if ($langs->trans($this->name) != $this->name) {
107 $s = $langs->trans($this->
name);
108 } elseif ($langs->trans($transstring) != $transstring) {
109 $s = $langs->trans($transstring);
114 if ($this->tooltip && is_object($form)) {
115 $s .=
' '.$form->textwithpicto(
'', $langs->trans($this->tooltip), 1,
'help');
138 $result = $this->db->query($sql);
141 while ($obj = $this->db->fetch_object($result)) {
146 $this->error = $this->db->lasterror();
173 $sql =
"SELECT COUNT(*) nb FROM ".$this->db->prefix().
"mailing_cibles";
174 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
175 $result = $this->db->query($sql);
177 $obj = $this->db->fetch_object($result);
178 $nb = (int) $obj->nb;
180 $sql =
"UPDATE ".$this->db->prefix().
"mailing";
181 $sql .=
" SET nbemail = ".((int) $nb).
" WHERE rowid = ".((int) $mailing_id);
182 if (!$this->db->query($sql)) {
184 $this->error = $this->db->error();
209 $num = count($cibles);
210 foreach ($cibles as $targetarray) {
211 if (!empty($targetarray[
'email'])) {
212 $sql =
"INSERT INTO ".$this->db->prefix().
"mailing_cibles";
213 $sql .=
" (fk_mailing,";
214 $sql .=
" fk_contact,";
215 $sql .=
" lastname, firstname, email, other, source_url, source_id,";
217 $sql .=
" source_type)";
218 $sql .=
" VALUES (".((int) $mailing_id).
",";
219 $sql .= (empty($targetarray[
'fk_contact']) ?
'0' : (int) $targetarray[
'fk_contact']).
",";
220 $sql .=
"'".$this->db->escape($targetarray[
'lastname']).
"',";
221 $sql .=
"'".$this->db->escape($targetarray[
'firstname']).
"',";
222 $sql .=
"'".$this->db->escape($targetarray[
'email']).
"',";
223 $sql .=
"'".$this->db->escape($targetarray[
'other']).
"',";
224 $sql .=
"'".$this->db->escape($targetarray[
'source_url']).
"',";
225 $sql .= (empty($targetarray[
'source_id']) ?
'null' : (int) $targetarray[
'source_id']).
",";
226 $sql .=
"'".$this->db->escape(
dol_hash($conf->file->instance_unique_id.
";".$targetarray[
'email'].
";".$targetarray[
'lastname'].
";".((
int) $mailing_id).
";".
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY'),
'md5')).
"',";
227 $sql .=
"'".$this->db->escape($targetarray[
'source_type']).
"')";
229 $result = $this->db->query($sql);
233 if ($this->db->errno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
235 dol_syslog($this->db->error().
' : '.$targetarray[
'email']);
236 $this->error = $this->db->error().
' : '.$targetarray[
'email'];
237 $this->db->rollback();
244 dol_syslog(__METHOD__.
": mailing ".$j.
" targets added");
264 if (empty($this->evenunsubscribe)) {
265 $sql =
"UPDATE ".$this->db->prefix().
"mailing_cibles as mc";
266 $sql .=
" SET statut = 3";
267 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
268 $sql .=
" AND EXISTS (SELECT rowid FROM ".$this->db->prefix().
"mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int) $conf->entity).
")";
270 dol_syslog(__METHOD__.
":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
271 $result = $this->db->query($sql);
295 $sql =
"DELETE FROM ".$this->db->prefix().
"mailing_cibles";
296 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
298 if (!$this->db->query($sql)) {
320 $iscoreorexternal = array();
325 $diremailselector = array(
'/core/modules/mailings/');
326 if (is_array($forcedir)) {
327 $diremailselector = $forcedir;
330 foreach ($diremailselector as $reldir) {
335 if (!is_dir($newdir)) {
339 $handle = opendir($newdir);
340 if (is_resource($handle)) {
341 while (($file = readdir($handle)) !==
false) {
343 if (is_readable($newdir.
'/'.$file) && preg_match(
'/^(.+)\.modules.php/', $file, $reg)) {
344 if (preg_match(
'/\.back$/', $file) || preg_match(
'/^(.+)\.disabled\.php/', $file)) {
351 $modName =
'mailing_'.$reg[1];
353 if (in_array($modName, $modules)) {
354 $langs->load(
"errors");
355 print
'<div class="error">'.$langs->trans(
"Error").
' : '.$langs->trans(
"ErrorDuplicateEmalingSelector", $modName,
"").
'</div>';
359 include_once $newdir.
'/'.$file;
361 print $e->getMessage();
366 $fullpath[$i] = $dir.
'/'.$file;
367 $relpath[$i] = preg_replace(
'/^\//',
'', $reldir).
'/'.$file;
368 $iscoreorexternal[$i] = ($reldir ==
'/core/modules/mailings/' ?
'internal' :
'external');
369 $modules[$i] = $modName;
370 $orders[$i] = $part1;
386 foreach ($orders as $key => $value) {
387 $modName = $modules[$key];
388 if (empty($modName)) {
392 if (!class_exists($modName)) {
393 print
'Error: An emailing selector file was found but its class "'.$modName.
'" was not found.'.
"<br>\n";
397 $objMod =
new $modName($db);
398 if (is_object($objMod)) {
399 '@phan-var-force ModeleBoxes $objMod';
402 $disabledbymodule = 0;
406 if (preg_match(
'/NORUN$/i', $files[$key])) {
411 $widget[$j][
'picto'] = (empty($objMod->picto) ? (empty($objMod->boximg) ?
img_object(
'',
'generic') : $objMod->boximg) :
img_object(
'', $objMod->picto));
412 $widget[$j][
'file'] = $files[$key];
413 $widget[$j][
'fullpath'] = $fullpath[$key];
414 $widget[$j][
'relpath'] = $relpath[$key];
415 $widget[$j][
'iscoreorexternal'] = $iscoreorexternal[$key];
416 $widget[$j][
'version'] = empty($objMod->version) ?
'' : $objMod->version;
417 $widget[$j][
'status'] =
img_picto($langs->trans(
"Active"),
'tick',
'class="pictofixedwidth"');
418 if ($disabledbyname > 0 || $disabledbymodule > 1) {
419 $widget[$j][
'status'] =
'';
422 $text =
'<b>'.$langs->trans(
"Description").
':</b><br>';
423 $text .= $objMod->boxlabel.
'<br>';
424 $text .=
'<br><b>'.$langs->trans(
"Status").
':</b><br>';
425 if ($disabledbymodule == 2) {
426 $text .= $langs->trans(
"WidgetDisabledAsModuleDisabled", $module).
'<br>';
429 $widget[$j][
'info'] = $text;
449 $msg = get_class($this).
"::".__FUNCTION__.
" not implemented";
465 $msg = get_class($this).
"::".__FUNCTION__.
" not implemented";
Parent class of emailing target selectors modules.
__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)
Retourne nombre de destinataires.
clear_target($mailing_id)
Supprime tous les destinataires de la table des cibles.
update_nb($mailing_id)
Met a jour nombre de destinataires.
formFilter()
Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings.
getNbOfRecords()
Return number of records for email selector.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
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)
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.