25require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'mailing_target';
41 public $table_element =
'mailing_cibles';
46 public $picto =
'contact';
97 public $statut_dest = array();
131 const STATUS_NOTSENT = 0;
132 const STATUS_SENT = 1;
133 const STATUS_READ = 2;
134 const STATUS_READANDUNSUBSCRIBED = 3;
135 const STATUS_ERROR = -1;
147 $this->labelStatus[0] =
'TargetStatusNotSent';
148 $this->labelStatus[1] =
'TargetStatusSent';
149 $this->labelStatus[2] =
'TargetStatusRead';
150 $this->labelStatus[3] =
'TargetStatusReadAndUnsubscribed';
151 $this->labelStatus[-1] =
'TargetStatusError';
153 $this->statut_dest[0] =
'TargetStatusNotSent';
154 $this->statut_dest[1] =
'TargetStatusSent';
155 $this->statut_dest[2] =
'TargetStatusRead';
156 $this->statut_dest[3] =
'TargetStatusReadAndUnsubscribed';
157 $this->statut_dest[-1] =
'TargetStatusError';
168 global $conf, $langs;
170 if (empty($this->fk_mailing)) {
171 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Mailing"));
175 if (0 == $this->fk_mailing) {
176 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Mailing"));
179 if (empty($this->
email)) {
180 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Email"));
183 if (empty($this->statut)) {
186 if (empty($this->
status)) {
189 if ($this->
status !== $this->statut) {
190 $this->error =
'Status='.$this->status.
' and Statut='.$this->statut.
' field must be identical';
193 if (empty($this->fk_contact)) {
205 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing_cibles";
206 $sql .=
" (fk_mailing, fk_contact, email, statut)";
207 $sql .=
" VALUES (".((int) $this->fk_mailing).
", ";
208 $sql .= ((int) $this->fk_contact).
", ";
209 $sql .=
"'".$this->db->escape($this->
email).
"', ";
210 $sql .= ((int) $conf->statut).
" )";
214 $resql = $this->db->query($sql);
216 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"mailing_cibles");
218 $result = $this->
update($user);
227 $this->db->rollback();
228 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
232 $this->error = $this->db->lasterror();
233 $this->db->rollback();
244 public function delete($user)
250 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
251 $sql .=
" WHERE rowid = " . ((int) $this->
id);
254 $resql = $this->db->query($sql);
260 $this->db->rollback();
261 $this->error = $this->db->lasterror();
275 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
276 $sql .=
" SET statut = ".((int) self::STATUS_NOTSENT).
", tms = '".$this->db->idate($now).
"'";
277 $sql .=
" WHERE rowid = ".((int) $this->
id);
280 if ($this->db->query($sql)) {
283 $this->error = $this->db->lasterror();
297 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
298 $sql .=
" SET statut = ".((int) self::STATUS_SENT).
", tms = '".$this->db->idate($now).
"'";
299 $sql .=
" WHERE rowid = ".((int) $this->
id);
302 if ($this->db->query($sql)) {
305 $this->error = $this->db->lasterror();
319 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
320 $sql .=
" SET statut = ".((int) self::STATUS_READ).
", tms = '".$this->db->idate($now).
"'";
321 $sql .=
" WHERE rowid = ".((int) $this->
id);
324 if ($this->db->query($sql)) {
327 $this->error = $this->db->lasterror();
341 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
342 $sql .=
" SET statut = ".((int) self::STATUS_READANDUNSUBSCRIBED).
", tms = '".$this->db->idate($now).
"'";
343 $sql .=
" WHERE rowid = ".((int) $this->
id);
346 if ($this->db->query($sql)) {
349 $this->error = $this->db->lasterror();
363 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles ";
364 $sql .=
" SET statut = ".((int) self::STATUS_ERROR).
", tms = '".$this->db->idate($now).
"'";
365 $sql .=
" WHERE rowid = ".((int) $this->
id);
368 if ($this->db->query($sql)) {
371 $this->error = $this->db->lasterror();
386 if (empty($this->fk_mailing)) {
390 if (empty($this->
email)) {
393 if (empty($this->statut)) {
396 if (empty($this->
status)) {
399 if ($this->
status !== $this->statut) {
402 if (empty($this->fk_contact)) {
410 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
411 $sql .=
" SET fk_mailing = '".((int) $this->fk_mailing).
"'";
412 $sql .=
", fk_contact = '".((int) $this->fk_contact).
"'";
413 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
414 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
415 $sql .=
", email = '".$this->db->escape($this->
email).
"'";
416 $sql .=
", other = '".$this->db->escape($this->other).
"'";
417 $sql .=
", tag = '".$this->db->escape($this->tag).
"'";
418 $sql .=
", statut = '".((int) $this->statut).
"'";
419 $sql .=
", source_url = '".$this->db->escape($this->source_url).
"'";
420 $sql .=
", source_id = '".((int) $this->source_id).
"'";
421 $sql .=
", source_type = '".$this->db->escape($this->source_type).
"'";
422 if ($this->date_envoi) {
423 $sql .=
", date_envoi = '".$this->db->idate($this->date_envoi).
"'";
425 $sql .=
", error_text = '".($this->error_text ? $this->db->escape($this->error_text) :
null).
"'";
426 $sql .=
" WHERE rowid = ".(int) $this->
id;
429 $resql = $this->db->query($sql);
435 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
436 $this->error = $langs->trans(
"ErrorRecordAlreadyExists", $this->
email);
438 $this->error = $this->db->lasterror();
440 $this->db->rollback();
453 $sql =
"SELECT t.rowid";
454 $sql .=
", t.fk_mailing";
455 $sql .=
", t.fk_contact";
456 $sql .=
", t.lastname";
457 $sql .=
", t.firstname";
461 $sql .=
", t.statut as status";
462 $sql .=
", t.source_url";
463 $sql .=
", t.source_id";
464 $sql .=
", t.source_type";
465 $sql .=
", t.date_envoi";
466 $sql .=
", t.tms as date_modification";
467 $sql .=
", t.error_text";
468 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as t";
469 $sql .=
" WHERE t.rowid = ".(int) $rowid;
471 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
472 $result = $this->db->query($sql);
474 if ($this->db->num_rows($result)) {
475 $obj = $this->db->fetch_object($result);
477 $this->
id = $obj->rowid;
478 $this->fk_mailing = $obj->fk_mailing;
479 $this->fk_contact = $obj->fk_contact;
480 $this->lastname = $obj->lastname;
481 $this->firstname = $obj->firstname;
482 $this->
email = $obj->email;
483 $this->other = $obj->other;
484 $this->tag = $obj->tag;
485 $this->statut = $obj->status;
486 $this->
status = $obj->status;
487 $this->source_url = $obj->source_url;
488 $this->source_id = $obj->source_id;
489 $this->source_type = $obj->source_type;
490 $this->date_envoi = $this->db->jdate($obj->date_envoi);
491 $this->date_modification = $this->db->jdate($obj->date_modification);
492 $this->tms = $this->db->jdate($obj->date_modification);
493 $this->error_text = $obj->error_text;
497 dol_syslog(get_class($this).
"::fetch Error -1");
501 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.