27require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
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, 1);
137 $result = $this->db->query($sql);
140 while ($obj = $this->db->fetch_object($result)) {
145 $this->error = $this->db->lasterror();
172 $sql =
"SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
173 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
174 $result = $this->db->query($sql);
176 $obj = $this->db->fetch_object($result);
179 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing";
180 $sql .=
" SET nbemail = ".((int) $nb).
" WHERE rowid = ".((int) $mailing_id);
181 if (!$this->db->query($sql)) {
183 $this->error = $this->db->error();
208 $num = count($cibles);
209 foreach ($cibles as $targetarray) {
210 if (!empty($targetarray[
'email'])) {
211 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_cibles";
212 $sql .=
" (fk_mailing,";
213 $sql .=
" fk_contact,";
214 $sql .=
" lastname, firstname, email, other, source_url, source_id,";
216 $sql .=
" source_type)";
217 $sql .=
" VALUES (".((int) $mailing_id).
",";
218 $sql .= (empty($targetarray[
'fk_contact']) ?
'0' : (int) $targetarray[
'fk_contact']).
",";
219 $sql .=
"'".$this->db->escape($targetarray[
'lastname']).
"',";
220 $sql .=
"'".$this->db->escape($targetarray[
'firstname']).
"',";
221 $sql .=
"'".$this->db->escape($targetarray[
'email']).
"',";
222 $sql .=
"'".$this->db->escape($targetarray[
'other']).
"',";
223 $sql .=
"'".$this->db->escape($targetarray[
'source_url']).
"',";
224 $sql .= (empty($targetarray[
'source_id']) ?
'null' : (int) $targetarray[
'source_id']).
",";
225 $sql .=
"'".$this->db->escape(
dol_hash(
$conf->file->instance_unique_id.
";".$targetarray[
'email'].
";".$targetarray[
'lastname'].
";".((
int) $mailing_id).
";".
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY'),
'md5')).
"',";
226 $sql .=
"'".$this->db->escape($targetarray[
'source_type']).
"')";
228 $result = $this->db->query($sql);
232 if ($this->db->errno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
234 dol_syslog($this->db->error().
' : '.$targetarray[
'email']);
235 $this->error = $this->db->error().
' : '.$targetarray[
'email'];
236 $this->db->rollback();
243 dol_syslog(__METHOD__.
": mailing ".$j.
" targets added");
263 if (empty($this->evenunsubscribe)) {
264 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
265 $sql .=
" SET mc.statut = 3";
266 $sql .=
" WHERE mc.fk_mailing = ".((int) $mailing_id);
267 $sql .=
" AND EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int)
$conf->entity).
")";
269 dol_syslog(__METHOD__.
":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
270 $result = $this->db->query($sql);
294 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
295 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
297 if (!$this->db->query($sql)) {
319 $iscoreorexternal = array();
324 $diremailselector = array(
'/core/modules/mailings/');
325 if (is_array($forcedir)) {
326 $diremailselector = $forcedir;
329 foreach ($diremailselector as $reldir) {
334 if (!is_dir($newdir)) {
338 $handle = opendir($newdir);
339 if (is_resource($handle)) {
340 while (($file = readdir($handle)) !==
false) {
342 if (is_readable($newdir.
'/'.$file) && preg_match(
'/^(.+)\.modules.php/', $file, $reg)) {
343 if (preg_match(
'/\.back$/', $file) || preg_match(
'/^(.+)\.disabled\.php/', $file)) {
350 $modName =
'mailing_'.$reg[1];
352 if (in_array($modName, $modules)) {
353 $langs->load(
"errors");
354 print
'<div class="error">'.$langs->trans(
"Error").
' : '.$langs->trans(
"ErrorDuplicateEmalingSelector", $modName,
"").
'</div>';
358 include_once $newdir.
'/'.$file;
360 print $e->getMessage();
365 $fullpath[$i] = $dir.
'/'.$file;
366 $relpath[$i] = preg_replace(
'/^\//',
'', $reldir).
'/'.$file;
367 $iscoreorexternal[$i] = ($reldir ==
'/core/modules/mailings/' ?
'internal' :
'external');
368 $modules[$i] = $modName;
369 $orders[$i] = $part1;
385 foreach ($orders as $key => $value) {
386 $modName = $modules[$key];
387 if (empty($modName)) {
391 if (!class_exists($modName)) {
392 print
'Error: An emailing selector file was found but its class "'.$modName.
'" was not found.'.
"<br>\n";
396 $objMod =
new $modName($db);
397 if (is_object($objMod)) {
398 '@phan-var-force ModeleBoxes $objMod';
401 $disabledbymodule = 0;
405 if (preg_match(
'/NORUN$/i', $files[$key])) {
410 $widget[$j][
'picto'] = (empty($objMod->picto) ? (empty($objMod->boximg) ?
img_object(
'',
'generic') : $objMod->boximg) :
img_object(
'', $objMod->picto));
411 $widget[$j][
'file'] = $files[$key];
412 $widget[$j][
'fullpath'] = $fullpath[$key];
413 $widget[$j][
'relpath'] = $relpath[$key];
414 $widget[$j][
'iscoreorexternal'] = $iscoreorexternal[$key];
415 $widget[$j][
'version'] = empty($objMod->version) ?
'' : $objMod->version;
416 $widget[$j][
'status'] =
img_picto($langs->trans(
"Active"),
'tick');
417 if ($disabledbyname > 0 || $disabledbymodule > 1) {
418 $widget[$j][
'status'] =
'';
421 $text =
'<b>'.$langs->trans(
"Description").
':</b><br>';
422 $text .= $objMod->boxlabel.
'<br>';
423 $text .=
'<br><b>'.$langs->trans(
"Status").
':</b><br>';
424 if ($disabledbymodule == 2) {
425 $text .= $langs->trans(
"WidgetDisabledAsModuleDisabled", $module).
'<br>';
428 $widget[$j][
'info'] = $text;
448 $msg = get_class($this).
"::".__FUNCTION__.
" not implemented";
464 $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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$conf db name
Only used if Module[ID]Name translation string is not found.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.