26require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
60 public $evenunsubscribe = 0;
82 $langs->load(
"mails");
83 $transstring =
"MailingModuleDesc".$this->name;
86 if ($langs->trans($this->name) != $this->name) {
87 $s = $langs->trans($this->
name);
88 } elseif ($langs->trans($transstring) != $transstring) {
89 $s = $langs->trans($transstring);
94 if ($this->tooltip && is_object($form)) {
95 $s .=
' '.$form->textwithpicto(
'', $langs->trans($this->tooltip), 1, 1);
118 $result = $this->db->query($sql);
121 while ($obj = $this->db->fetch_object($result)) {
126 $this->error = $this->db->lasterror();
153 $sql =
"SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
154 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
155 $result = $this->db->query($sql);
157 $obj = $this->db->fetch_object($result);
160 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing";
161 $sql .=
" SET nbemail = ".((int) $nb).
" WHERE rowid = ".((int) $mailing_id);
162 if (!$this->db->query($sql)) {
164 $this->error = $this->db->error();
188 $num = count($cibles);
189 foreach ($cibles as $targetarray) {
190 if (!empty($targetarray[
'email'])) {
191 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_cibles";
192 $sql .=
" (fk_mailing,";
193 $sql .=
" fk_contact,";
194 $sql .=
" lastname, firstname, email, other, source_url, source_id,";
196 $sql .=
" source_type)";
197 $sql .=
" VALUES (".((int) $mailing_id).
",";
198 $sql .= (empty($targetarray[
'fk_contact']) ?
'0' : (int) $targetarray[
'fk_contact']).
",";
199 $sql .=
"'".$this->db->escape($targetarray[
'lastname']).
"',";
200 $sql .=
"'".$this->db->escape($targetarray[
'firstname']).
"',";
201 $sql .=
"'".$this->db->escape($targetarray[
'email']).
"',";
202 $sql .=
"'".$this->db->escape($targetarray[
'other']).
"',";
203 $sql .=
"'".$this->db->escape($targetarray[
'source_url']).
"',";
204 $sql .= (empty($targetarray[
'source_id']) ?
'null' :
"'".$this->db->escape($targetarray[
'source_id']).
"'").
",";
205 $sql .=
"'".$this->db->escape(
dol_hash($conf->file->instance_unique_id.
";".$targetarray[
'email'].
";".$targetarray[
'lastname'].
";".((
int) $mailing_id).
";".
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY'),
'md5')).
"',";
206 $sql .=
"'".$this->db->escape($targetarray[
'source_type']).
"')";
208 $result = $this->db->query($sql);
212 if ($this->db->errno() !=
'DB_ERROR_RECORD_ALREADY_EXISTS') {
214 dol_syslog($this->db->error().
' : '.$targetarray[
'email']);
215 $this->error = $this->db->error().
' : '.$targetarray[
'email'];
216 $this->db->rollback();
223 dol_syslog(__METHOD__.
": mailing ".$j.
" targets added");
243 if (empty($this->evenunsubscribe)) {
244 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
245 $sql .=
" SET mc.statut = 3";
246 $sql .=
" WHERE mc.fk_mailing = ".((int) $mailing_id);
247 $sql .=
" AND EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = mc.email and mu.entity = ".((int) $conf->entity).
")";
249 dol_syslog(__METHOD__.
":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG);
250 $result = $this->db->query($sql);
274 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
275 $sql .=
" WHERE fk_mailing = ".((int) $mailing_id);
277 if (!$this->db->query($sql)) {
Parent class of emailing target selectors modules.
__construct($db)
Constructor.
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.
dol_print_error($db='', $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')
Returns a hash (non reversible encryption) of a string.