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)) {
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', $nosalt=0)
Returns a hash (non reversible encryption) of a string.