26require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
75 public $evenunsubscribe = 0;
97 $langs->load(
"mails");
98 $transstring =
"MailingModuleDesc".$this->name;
101 if ($langs->trans($this->name) != $this->name) {
102 $s = $langs->trans($this->
name);
103 } elseif ($langs->trans($transstring) != $transstring) {
104 $s = $langs->trans($transstring);
109 if ($this->tooltip && is_object($form)) {
110 $s .=
' '.$form->textwithpicto(
'', $langs->trans($this->tooltip), 1, 1);
133 $result = $this->db->query($sql);
136 while ($obj = $this->db->fetch_object($result)) {
141 $this->error = $this->db->lasterror();
168 $sql =
"SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
169 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
170 $result = $this->db->query($sql);
172 $obj = $this->db->fetch_object($result);
175 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing";
176 $sql .=
" SET nbemail = ".((int) $nb).
" WHERE rowid = ".((int) $mailing_id);
177 if (!$this->db->query($sql)) {
179 $this->error = $this->db->error();
203 $num = count($cibles);
204 foreach ($cibles as $targetarray) {
205 if (!empty($targetarray[
'email'])) {
206 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_cibles";
207 $sql .=
" (fk_mailing,";
208 $sql .=
" fk_contact,";
209 $sql .=
" lastname, firstname, email, other, source_url, source_id,";
211 $sql .=
" source_type)";
212 $sql .=
" VALUES (".((int) $mailing_id).
",";
213 $sql .= (empty($targetarray[
'fk_contact']) ?
'0' : (int) $targetarray[
'fk_contact']).
",";
214 $sql .=
"'".$this->db->escape($targetarray[
'lastname']).
"',";
215 $sql .=
"'".$this->db->escape($targetarray[
'firstname']).
"',";
216 $sql .=
"'".$this->db->escape($targetarray[
'email']).
"',";
217 $sql .=
"'".$this->db->escape($targetarray[
'other']).
"',";
218 $sql .=
"'".$this->db->escape($targetarray[
'source_url']).
"',";
219 $sql .= (empty($targetarray[
'source_id']) ?
'null' :
"'".$this->db->escape($targetarray[
'source_id']).
"'").
",";
220 $sql .=
"'".$this->db->escape(
dol_hash($conf->file->instance_unique_id.
";".$targetarray[
'email'].
";".$targetarray[
'lastname'].
";".((
int) $mailing_id).
";".
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY'),
'md5')).
"',";
221 $sql .=
"'".$this->db->escape($targetarray[
'source_type']).
"')";
223 $result = $this->db->query($sql);
227 if ($this->db->errno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
229 dol_syslog($this->db->error().
' : '.$targetarray[
'email']);
230 $this->error = $this->db->error().
' : '.$targetarray[
'email'];
231 $this->db->rollback();
238 dol_syslog(__METHOD__.
": mailing ".$j.
" targets added");
258 if (empty($this->evenunsubscribe)) {
259 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
260 $sql .=
" SET mc.statut = 3";
261 $sql .=
" WHERE mc.fk_mailing = ".((int) $mailing_id);
262 $sql .=
" AND EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int) $conf->entity).
")";
264 dol_syslog(__METHOD__.
":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
265 $result = $this->db->query($sql);
289 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
290 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
292 if (!$this->db->query($sql)) {
314 $iscoreorexternal = array();
319 $diremailselector = array(
'/core/modules/mailings/');
320 if (is_array($forcedir)) {
321 $diremailselector = $forcedir;
324 foreach ($diremailselector as $reldir) {
329 if (!is_dir($newdir)) {
333 $handle = opendir($newdir);
334 if (is_resource($handle)) {
335 while (($file = readdir($handle)) !==
false) {
337 if (is_readable($newdir.
'/'.$file) && preg_match(
'/^(.+)\.modules.php/', $file, $reg)) {
338 if (preg_match(
'/\.back$/', $file) || preg_match(
'/^(.+)\.disabled\.php/', $file)) {
345 $modName =
'mailing_'.$reg[1];
347 if (in_array($modName, $modules)) {
348 $langs->load(
"errors");
349 print
'<div class="error">'.$langs->trans(
"Error").
' : '.$langs->trans(
"ErrorDuplicateEmalingSelector", $modName,
"").
'</div>';
353 include_once $newdir.
'/'.$file;
355 print $e->getMessage();
360 $fullpath[$i] = $dir.
'/'.$file;
361 $relpath[$i] = preg_replace(
'/^\//',
'', $reldir).
'/'.$file;
362 $iscoreorexternal[$i] = ($reldir ==
'/core/modules/mailings/' ?
'internal' :
'external');
363 $modules[$i] = $modName;
364 $orders[$i] = $part1;
380 foreach ($orders as $key => $value) {
381 $modName = $modules[$key];
382 if (empty($modName)) {
386 if (!class_exists($modName)) {
387 print
'Error: An emailing selector file was found but its class "'.$modName.
'" was not found.'.
"<br>\n";
391 $objMod =
new $modName($db);
392 if (is_object($objMod)) {
395 $disabledbymodule = 0;
399 if (preg_match(
'/NORUN$/i', $files[$key])) {
404 $widget[$j][
'picto'] = (empty($objMod->picto) ? (empty($objMod->boximg) ?
img_object(
'',
'generic') : $objMod->boximg) :
img_object(
'', $objMod->picto));
405 $widget[$j][
'file'] = $files[$key];
406 $widget[$j][
'fullpath'] = $fullpath[$key];
407 $widget[$j][
'relpath'] = $relpath[$key];
408 $widget[$j][
'iscoreorexternal'] = $iscoreorexternal[$key];
409 $widget[$j][
'version'] = empty($objMod->version) ?
'' : $objMod->version;
410 $widget[$j][
'status'] =
img_picto($langs->trans(
"Active"),
'tick');
411 if ($disabledbyname > 0 || $disabledbymodule > 1) {
412 $widget[$j][
'status'] =
'';
415 $text =
'<b>'.$langs->trans(
"Description").
':</b><br>';
416 $text .= $objMod->boxlabel.
'<br>';
417 $text .=
'<br><b>'.$langs->trans(
"Status").
':</b><br>';
418 if ($disabledbymodule == 2) {
419 $text .= $langs->trans(
"WidgetDisabledAsModuleDisabled", $module).
'<br>';
422 $widget[$j][
'info'] = $text;
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.
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 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.