26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'mailing_target';
42 public $table_element =
'mailing_cibles';
47 public $picto =
'contact';
98 public $statut_dest = array();
132 const STATUS_NOTSENT = 0;
133 const STATUS_SENT = 1;
134 const STATUS_READ = 2;
135 const STATUS_READANDUNSUBSCRIBED = 3;
136 const STATUS_ERROR = -1;
148 $this->labelStatus[0] =
'TargetStatusNotSent';
149 $this->labelStatus[1] =
'TargetStatusSent';
150 $this->labelStatus[2] =
'TargetStatusRead';
151 $this->labelStatus[3] =
'TargetStatusReadAndUnsubscribed';
152 $this->labelStatus[-1] =
'TargetStatusError';
154 $this->statut_dest[0] =
'TargetStatusNotSent';
155 $this->statut_dest[1] =
'TargetStatusSent';
156 $this->statut_dest[2] =
'TargetStatusRead';
157 $this->statut_dest[3] =
'TargetStatusReadAndUnsubscribed';
158 $this->statut_dest[-1] =
'TargetStatusError';
169 global
$conf, $langs;
171 if (empty($this->fk_mailing)) {
172 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Mailing"));
176 if (0 == $this->fk_mailing) {
177 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Mailing"));
180 if (empty($this->
email)) {
181 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Email"));
184 if (empty($this->statut)) {
187 if (empty($this->
status)) {
190 if ($this->
status !== $this->statut) {
191 $this->error =
'Status='.$this->status.
' and Statut='.$this->statut.
' field must be identical';
194 if (empty($this->fk_contact)) {
206 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_cibles";
207 $sql .=
" (fk_mailing, fk_contact, email, statut)";
208 $sql .=
" VALUES (".((int) $this->fk_mailing).
", ";
209 $sql .= ((int) $this->fk_contact).
", ";
210 $sql .=
"'".$this->db->escape($this->
email).
"', ";
211 $sql .= ((int)
$conf->statut).
" )";
215 $resql = $this->db->query($sql);
217 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"mailing_cibles");
219 $result = $this->
update($user);
228 $this->db->rollback();
229 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
233 $this->error = $this->db->lasterror();
234 $this->db->rollback();
245 public function delete($user)
251 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
252 $sql .=
" WHERE rowid = " . ((int) $this->
id);
255 $resql = $this->db->query($sql);
261 $this->db->rollback();
262 $this->error = $this->db->lasterror();
276 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
277 $sql .=
" SET statut = ".((int) self::STATUS_NOTSENT).
", tms = '".$this->db->idate($now).
"'";
278 $sql .=
" WHERE rowid = ".((int) $this->
id);
281 if ($this->db->query($sql)) {
284 $this->error = $this->db->lasterror();
298 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
299 $sql .=
" SET statut = ".((int) self::STATUS_SENT).
", tms = '".$this->db->idate($now).
"'";
300 $sql .=
" WHERE rowid = ".((int) $this->
id);
303 if ($this->db->query($sql)) {
306 $this->error = $this->db->lasterror();
320 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
321 $sql .=
" SET statut = ".((int) self::STATUS_READ).
", tms = '".$this->db->idate($now).
"'";
322 $sql .=
" WHERE rowid = ".((int) $this->
id);
325 if ($this->db->query($sql)) {
328 $this->error = $this->db->lasterror();
342 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
343 $sql .=
" SET statut = ".((int) self::STATUS_READANDUNSUBSCRIBED).
", tms = '".$this->db->idate($now).
"'";
344 $sql .=
" WHERE rowid = ".((int) $this->
id);
347 if ($this->db->query($sql)) {
350 $this->error = $this->db->lasterror();
364 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
365 $sql .=
" SET statut = ".((int) self::STATUS_ERROR).
", tms = '".$this->db->idate($now).
"'";
366 $sql .=
" WHERE rowid = ".((int) $this->
id);
369 if ($this->db->query($sql)) {
372 $this->error = $this->db->lasterror();
387 if (empty($this->fk_mailing)) {
391 if (empty($this->
email)) {
394 if (empty($this->statut)) {
397 if (empty($this->
status)) {
400 if ($this->
status !== $this->statut) {
403 if (empty($this->fk_contact)) {
411 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
412 $sql .=
" SET fk_mailing = ".((int) $this->fk_mailing);
413 $sql .=
", fk_contact = ".((int) $this->fk_contact);
414 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
415 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
416 $sql .=
", email = '".$this->db->escape($this->
email).
"'";
417 $sql .=
", other = '".$this->db->escape($this->other).
"'";
418 $sql .=
", tag = '".$this->db->escape($this->tag).
"'";
419 $sql .=
", statut = ".((int) $this->statut);
420 $sql .=
", source_url = '".$this->db->escape($this->source_url).
"'";
421 $sql .=
", source_id = ".((int) $this->source_id);
422 $sql .=
", source_type = '".$this->db->escape($this->source_type).
"'";
423 if ($this->date_envoi) {
424 $sql .=
", date_envoi = '".$this->db->idate($this->date_envoi).
"'";
426 $sql .=
", error_text = '".($this->error_text ? $this->db->escape($this->error_text) :
null).
"'";
427 $sql .=
" WHERE rowid = ".(int) $this->
id;
430 $resql = $this->db->query($sql);
436 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
437 $this->error = $langs->trans(
"ErrorRecordAlreadyExists", $this->
email);
439 $this->error = $this->db->lasterror();
441 $this->db->rollback();
454 $sql =
"SELECT t.rowid";
455 $sql .=
", t.fk_mailing";
456 $sql .=
", t.fk_contact";
457 $sql .=
", t.lastname";
458 $sql .=
", t.firstname";
462 $sql .=
", t.statut as status";
463 $sql .=
", t.source_url";
464 $sql .=
", t.source_id";
465 $sql .=
", t.source_type";
466 $sql .=
", t.date_envoi";
467 $sql .=
", t.tms as date_modification";
468 $sql .=
", t.error_text";
469 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as t";
470 $sql .=
" WHERE t.rowid = ".(int) $rowid;
472 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
473 $result = $this->db->query($sql);
475 if ($this->db->num_rows($result)) {
476 $obj = $this->db->fetch_object($result);
478 $this->
id = $obj->rowid;
479 $this->fk_mailing = $obj->fk_mailing;
480 $this->fk_contact = $obj->fk_contact;
481 $this->lastname = $obj->lastname;
482 $this->firstname = $obj->firstname;
483 $this->
email = $obj->email;
484 $this->other = $obj->other;
485 $this->tag = $obj->tag;
486 $this->statut = $obj->status;
487 $this->
status = $obj->status;
488 $this->source_url = $obj->source_url;
489 $this->source_id = $obj->source_id;
490 $this->source_type = $obj->source_type;
491 $this->date_envoi = $this->db->jdate($obj->date_envoi);
492 $this->date_modification = $this->db->jdate($obj->date_modification);
493 $this->tms = $this->db->jdate($obj->date_modification);
494 $this->error_text = $obj->error_text;
498 dol_syslog(get_class($this).
"::fetch Error -1");
502 dol_syslog(get_class($this).
"::fetch Error -2");
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage emailings module.
fetch($rowid)
Get object from database.
setRead()
Set read mailing target.
setReadAndUnsubscribed()
Set read and unsubscribed mailing target.
setSent()
Set sent mailing target.
create($user)
Create an Mailing Target.
setError()
Set error mailing target.
update($user)
Update an Mailing Target.
setNotSent()
Set notsent mailing target.
__construct($db)
Constructor.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_now($mode='gmt')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.