26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
66 $langs->load(
"mails");
67 $transstring =
"MailingModuleDesc".$this->name;
70 if ($langs->trans($this->name) != $this->name) $s = $langs->trans($this->name);
71 elseif ($langs->trans($transstring) != $transstring) $s = $langs->trans($transstring);
72 else $s = $this->desc;
74 if ($this->tooltip && is_object($form)) $s .=
' '.$form->textwithpicto(
'', $langs->trans($this->tooltip), 1, 1);
96 $result = $this->
db->query($sql);
99 $obj = $this->
db->fetch_object($result);
102 $this->error = $this->
db->lasterror();
129 $sql =
"SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
130 $sql .=
" WHERE fk_mailing = ".$mailing_id;
131 $result = $this->
db->query($sql);
134 $obj = $this->
db->fetch_object($result);
137 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing";
138 $sql .=
" SET nbemail = ".$nb.
" WHERE rowid = ".$mailing_id;
139 if (!$this->
db->query($sql))
142 $this->error = $this->
db->error();
161 global $dolibarr_main_instance_unique_id;
167 $num = count($cibles);
168 foreach ($cibles as $targetarray)
170 if (!empty($targetarray[
'email']))
172 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_cibles";
173 $sql .=
" (fk_mailing,";
174 $sql .=
" fk_contact,";
175 $sql .=
" lastname, firstname, email, other, source_url, source_id,";
177 $sql .=
" source_type)";
178 $sql .=
" VALUES (".$mailing_id.
",";
179 $sql .= (empty($targetarray[
'fk_contact']) ?
'0' :
"'".$this->db->escape($targetarray[
'fk_contact']).
"'").
",";
180 $sql .=
"'".$this->db->escape($targetarray[
'lastname']).
"',";
181 $sql .=
"'".$this->db->escape($targetarray[
'firstname']).
"',";
182 $sql .=
"'".$this->db->escape($targetarray[
'email']).
"',";
183 $sql .=
"'".$this->db->escape($targetarray[
'other']).
"',";
184 $sql .=
"'".$this->db->escape($targetarray[
'source_url']).
"',";
185 $sql .= (empty($targetarray[
'source_id']) ?
'null' :
"'".$this->db->escape($targetarray[
'source_id']).
"'").
",";
186 $sql .=
"'".$this->db->escape(
dol_hash($dolibarr_main_instance_unique_id.
';'.$targetarray[
'email'].
';'.$targetarray[
'lastname'].
';'.$mailing_id.
';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY),
'md5').
"',";
187 $sql .=
"'".$this->db->escape($targetarray[
'source_type']).
"')";
189 $result = $this->
db->query($sql);
194 if ($this->
db->errno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS')
197 dol_syslog($this->
db->error().
' : '.$targetarray[
'email']);
198 $this->error = $this->
db->error().
' : '.$targetarray[
'email'];
199 $this->
db->rollback();
206 dol_syslog(__METHOD__.
": mailing ".$j.
" targets added");
226 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
227 $sql .=
" SET statut=3";
228 $sql .=
" WHERE fk_mailing=".$mailing_id.
" AND email IN (SELECT mu.email FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe AS mu WHERE mu.entity IN ('".
getEntity(
'mailing').
"'))";
230 dol_syslog(__METHOD__.
":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
231 $result = $this->
db->query($sql);
254 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
255 $sql .=
" WHERE fk_mailing = ".$mailing_id;
257 if (!$this->
db->query($sql))
__construct($db)
Constructor.
dol_hash($chain, $type= '0')
Returns a hash of a string.
formFilter()
Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings...
$conf db
API class for accounts.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
update_nb($mailing_id)
Met a jour nombre de destinataires.
clear_target($mailing_id)
Supprime tous les destinataires de la table des cibles.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getNbOfRecipients($sql)
Retourne nombre de destinataires.
getDesc()
Return description of email selector.
addTargetsToDatabase($mailing_id, $cibles)
Add a list of targets int the database.
Parent class of emailing target selectors modules.
getNbOfRecords()
Return number of records for email selector.