27require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
76 public $evenunsubscribe = 0;
98 $langs->load(
"mails");
99 $transstring =
"MailingModuleDesc".$this->name;
102 if ($langs->trans($this->name) != $this->name) {
103 $s = $langs->trans($this->
name);
104 } elseif ($langs->trans($transstring) != $transstring) {
105 $s = $langs->trans($transstring);
110 if ($this->tooltip && is_object($form)) {
111 $s .=
' '.$form->textwithpicto(
'', $langs->trans($this->tooltip), 1, 1);
134 $result = $this->db->query($sql);
137 while ($obj = $this->db->fetch_object($result)) {
142 $this->error = $this->db->lasterror();
169 $sql =
"SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
170 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
171 $result = $this->db->query($sql);
173 $obj = $this->db->fetch_object($result);
176 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing";
177 $sql .=
" SET nbemail = ".((int) $nb).
" WHERE rowid = ".((int) $mailing_id);
178 if (!$this->db->query($sql)) {
180 $this->error = $this->db->error();
204 $num = count($cibles);
205 foreach ($cibles as $targetarray) {
206 if (!empty($targetarray[
'email'])) {
207 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_cibles";
208 $sql .=
" (fk_mailing,";
209 $sql .=
" fk_contact,";
210 $sql .=
" lastname, firstname, email, other, source_url, source_id,";
212 $sql .=
" source_type)";
213 $sql .=
" VALUES (".((int) $mailing_id).
",";
214 $sql .= (empty($targetarray[
'fk_contact']) ?
'0' : (int) $targetarray[
'fk_contact']).
",";
215 $sql .=
"'".$this->db->escape($targetarray[
'lastname']).
"',";
216 $sql .=
"'".$this->db->escape($targetarray[
'firstname']).
"',";
217 $sql .=
"'".$this->db->escape($targetarray[
'email']).
"',";
218 $sql .=
"'".$this->db->escape($targetarray[
'other']).
"',";
219 $sql .=
"'".$this->db->escape($targetarray[
'source_url']).
"',";
220 $sql .= (empty($targetarray[
'source_id']) ?
'null' :
"'".$this->db->escape($targetarray[
'source_id']).
"'").
",";
221 $sql .=
"'".$this->db->escape(
dol_hash($conf->file->instance_unique_id.
";".$targetarray[
'email'].
";".$targetarray[
'lastname'].
";".((
int) $mailing_id).
";".
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY'),
'md5')).
"',";
222 $sql .=
"'".$this->db->escape($targetarray[
'source_type']).
"')";
224 $result = $this->db->query($sql);
228 if ($this->db->errno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
230 dol_syslog($this->db->error().
' : '.$targetarray[
'email']);
231 $this->error = $this->db->error().
' : '.$targetarray[
'email'];
232 $this->db->rollback();
239 dol_syslog(__METHOD__.
": mailing ".$j.
" targets added");
259 if (empty($this->evenunsubscribe)) {
260 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
261 $sql .=
" SET mc.statut = 3";
262 $sql .=
" WHERE mc.fk_mailing = ".((int) $mailing_id);
263 $sql .=
" AND EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int) $conf->entity).
")";
265 dol_syslog(__METHOD__.
":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
266 $result = $this->db->query($sql);
290 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
291 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
293 if (!$this->db->query($sql)) {
315 $iscoreorexternal = array();
320 $diremailselector = array(
'/core/modules/mailings/');
321 if (is_array($forcedir)) {
322 $diremailselector = $forcedir;
325 foreach ($diremailselector as $reldir) {
330 if (!is_dir($newdir)) {
334 $handle = opendir($newdir);
335 if (is_resource($handle)) {
336 while (($file = readdir($handle)) !==
false) {
338 if (is_readable($newdir.
'/'.$file) && preg_match(
'/^(.+)\.modules.php/', $file, $reg)) {
339 if (preg_match(
'/\.back$/', $file) || preg_match(
'/^(.+)\.disabled\.php/', $file)) {
346 $modName =
'mailing_'.$reg[1];
348 if (in_array($modName, $modules)) {
349 $langs->load(
"errors");
350 print
'<div class="error">'.$langs->trans(
"Error").
' : '.$langs->trans(
"ErrorDuplicateEmalingSelector", $modName,
"").
'</div>';
354 include_once $newdir.
'/'.$file;
356 print $e->getMessage();
361 $fullpath[$i] = $dir.
'/'.$file;
362 $relpath[$i] = preg_replace(
'/^\//',
'', $reldir).
'/'.$file;
363 $iscoreorexternal[$i] = ($reldir ==
'/core/modules/mailings/' ?
'internal' :
'external');
364 $modules[$i] = $modName;
365 $orders[$i] = $part1;
381 foreach ($orders as $key => $value) {
382 $modName = $modules[$key];
383 if (empty($modName)) {
387 if (!class_exists($modName)) {
388 print
'Error: An emailing selector file was found but its class "'.$modName.
'" was not found.'.
"<br>\n";
392 $objMod =
new $modName($db);
393 if (is_object($objMod)) {
394 '@phan-var-force ModeleBoxes $objMod';
397 $disabledbymodule = 0;
401 if (preg_match(
'/NORUN$/i', $files[$key])) {
406 $widget[$j][
'picto'] = (empty($objMod->picto) ? (empty($objMod->boximg) ?
img_object(
'',
'generic') : $objMod->boximg) :
img_object(
'', $objMod->picto));
407 $widget[$j][
'file'] = $files[$key];
408 $widget[$j][
'fullpath'] = $fullpath[$key];
409 $widget[$j][
'relpath'] = $relpath[$key];
410 $widget[$j][
'iscoreorexternal'] = $iscoreorexternal[$key];
411 $widget[$j][
'version'] = empty($objMod->version) ?
'' : $objMod->version;
412 $widget[$j][
'status'] =
img_picto($langs->trans(
"Active"),
'tick');
413 if ($disabledbyname > 0 || $disabledbymodule > 1) {
414 $widget[$j][
'status'] =
'';
417 $text =
'<b>'.$langs->trans(
"Description").
':</b><br>';
418 $text .= $objMod->boxlabel.
'<br>';
419 $text .=
'<br><b>'.$langs->trans(
"Status").
':</b><br>';
420 if ($disabledbymodule == 2) {
421 $text .= $langs->trans(
"WidgetDisabledAsModuleDisabled", $module).
'<br>';
424 $widget[$j][
'info'] = $text;
444 $msg = get_class($this).
"::".__FUNCTION__.
" not implemented";
Parent class of emailing target selectors modules.
__construct($db)
Constructor.
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.
$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.