27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'mailing';
43 public $table_element =
'mailing';
48 public $picto =
'email';
73 public $evenunsubscribe;
114 public $email_replyto;
119 public $email_errorsto;
124 public $joined_file1;
129 public $joined_file2;
134 public $joined_file3;
139 public $joined_file4;
149 public $extraparams = array();
154 public $statut_dest = array();
159 public $substitutionarray;
164 public $substitutionarrayfortest;
166 const STATUS_DRAFT = 0;
167 const STATUS_VALIDATED = 1;
168 const STATUS_SENTPARTIALY = 2;
169 const STATUS_SENTCOMPLETELY = 3;
182 $this->labelStatus[0] =
'MailingStatusDraft';
183 $this->labelStatus[1] =
'MailingStatusValidated';
184 $this->labelStatus[2] =
'MailingStatusSentPartialy';
185 $this->labelStatus[3] =
'MailingStatusSentCompletely';
187 $this->statut_dest[0] =
'MailingStatusNotSent';
188 $this->statut_dest[1] =
'MailingStatusSent';
189 $this->statut_dest[2] =
'MailingStatusRead';
190 $this->statut_dest[3] =
'MailingStatusReadAndUnsubscribe';
191 $this->statut_dest[-1] =
'MailingStatusError';
201 public function create($user, $notrigger = 0)
203 global $conf, $langs;
206 if (preg_match(
'/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
207 $this->error =
'InvalidHTMLStringCantBeCleaned';
211 $this->title = trim($this->title);
212 $this->email_from = trim($this->email_from);
214 if (!$this->email_from) {
215 if ($this->messtype !==
'sms') {
216 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailFrom"));
218 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PhoneFrom"));
228 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing";
229 $sql .=
" (date_creat, fk_user_creat, entity)";
230 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $user->id).
", ".((int) $conf->entity).
")";
233 $this->title = $langs->trans(
"NoTitle");
238 $resql = $this->db->query($sql);
240 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"mailing");
242 $result = $this->
update($user, 1);
247 if (!$error && !$notrigger) {
260 $this->db->rollback();
261 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
265 $this->error = $this->db->lasterror();
266 $this->db->rollback();
278 public function update($user, $notrigger = 0)
283 if (preg_match(
'/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
284 $this->error =
'InvalidHTMLStringCantBeCleaned';
291 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
292 $sql .=
" SET titre = '".$this->db->escape($this->title).
"'";
293 $sql .=
", messtype = '".$this->db->escape($this->messtype).
"'";
294 $sql .=
", sujet = '".$this->db->escape($this->sujet).
"'";
295 $sql .=
", body = '".$this->db->escape($this->body).
"'";
296 $sql .=
", email_from = '".$this->db->escape($this->email_from).
"'";
297 $sql .=
", email_replyto = '".$this->db->escape($this->email_replyto).
"'";
298 $sql .=
", email_errorsto = '".$this->db->escape($this->email_errorsto).
"'";
299 $sql .=
", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) :
null).
"'";
300 $sql .=
", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) :
null).
"'";
301 $sql .=
", evenunsubscribe = ".((int) $this->evenunsubscribe);
302 $sql .=
" WHERE rowid = ".(int) $this->
id;
305 $resql = $this->db->query($sql);
307 if (!$error && !$notrigger) {
321 $this->db->rollback();
322 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
326 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
327 $this->error = $langs->trans(
"ErrorTitleAlreadyExists", $this->title);
329 $this->error = $this->db->lasterror();
331 $this->db->rollback();
343 public function fetch($rowid, $ref =
'')
345 $sql =
"SELECT m.rowid, m.messtype, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe";
346 $sql .=
", m.email_from, m.email_replyto, m.email_errorsto";
347 $sql .=
", m.statut as status, m.nbemail";
348 $sql .=
", m.fk_user_creat, m.fk_user_valid";
349 $sql .=
", m.date_creat";
350 $sql .=
", m.date_valid";
351 $sql .=
", m.date_envoi";
352 $sql .=
", m.extraparams";
353 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing as m";
354 $sql .=
" WHERE entity IN (".getEntity(
'mailing').
")";
356 $sql .=
" AND m.titre = '".$this->db->escape($ref).
"'";
358 $sql .=
" AND m.rowid = ".(int) $rowid;
361 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
362 $result = $this->db->query($sql);
364 if ($this->db->num_rows($result)) {
365 $obj = $this->db->fetch_object($result);
367 $this->
id = $obj->rowid;
368 $this->
ref = $obj->rowid;
369 $this->title = $obj->title;
370 $this->messtype = $obj->messtype;
372 $this->
statut = $obj->status;
373 $this->
status = $obj->status;
375 $this->nbemail = $obj->nbemail;
377 $this->sujet = $obj->sujet;
381 $this->body = $obj->body;
384 $this->bgcolor = $obj->bgcolor;
385 $this->bgimage = $obj->bgimage;
386 $this->evenunsubscribe = $obj->evenunsubscribe;
388 $this->email_from = $obj->email_from;
389 $this->email_replyto = $obj->email_replyto;
390 $this->email_errorsto = $obj->email_errorsto;
392 $this->user_creation_id = $obj->fk_user_creat;
393 $this->user_validation_id = $obj->fk_user_valid;
395 $this->date_creation = $this->db->jdate($obj->date_creat);
396 $this->date_validation = $this->db->jdate($obj->date_valid);
397 $this->date_envoi = $this->db->jdate($obj->date_envoi);
399 $this->extraparams = (array) json_decode($obj->extraparams,
true);
401 if ($this->messtype ==
'sms') {
402 $this->picto =
'phone';
407 dol_syslog(get_class($this).
"::fetch Erreur -1");
411 dol_syslog(get_class($this).
"::fetch Erreur -2");
446 if (empty($option1)) {
459 $object->user_creation_id = $user->id;
460 $object->user_validation_id =
null;
466 $object->context[
'createfromclone'] =
'createfromclone';
467 $result =
$object->create($user);
472 $this->errors = array_merge($this->errors,
$object->errors);
478 if (!empty($option2)) {
479 require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
483 $target_array = array();
485 $sql =
"SELECT fk_contact,";
486 $sql .=
" lastname,";
487 $sql .=
" firstname,";
490 $sql .=
" source_url,";
491 $sql .=
" source_id ,";
492 $sql .=
" source_type";
493 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
494 $sql .=
" WHERE fk_mailing = ".((int) $fromid);
496 $result = $this->db->query($sql);
498 if ($this->db->num_rows($result)) {
499 while ($obj = $this->db->fetch_object($result)) {
500 $target_array[] = array(
501 'fk_contact'=>$obj->fk_contact,
502 'lastname'=>$obj->lastname,
503 'firstname'=>$obj->firstname,
504 'email'=>$obj->email,
505 'other'=>$obj->other,
506 'source_url'=>$obj->source_url,
507 'source_id'=>$obj->source_id,
508 'source_type'=>$obj->source_type
513 $this->error = $this->db->lasterror();
517 $mailing_target->addTargetsToDatabase(
$object->id, $target_array);
521 unset(
$object->context[
'createfromclone']);
528 $this->db->rollback();
543 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
544 $sql .=
" SET statut = 1, date_valid = '".$this->db->idate($now).
"', fk_user_valid=".$user->id;
545 $sql .=
" WHERE rowid = ".((int) $this->
id);
548 if ($this->db->query($sql)) {
551 $this->error = $this->db->lasterror();
564 public function delete($user, $notrigger = 0)
578 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"mailing";
579 $sql .=
" WHERE rowid = " . ((int) $this->
id);
582 $resql = $this->db->query($sql);
594 $this->db->rollback();
595 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
599 $this->db->rollback();
600 $this->error = $this->db->lasterror();
604 $this->db->rollback();
618 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
619 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
621 dol_syslog(
"Mailing::delete_targets", LOG_DEBUG);
622 $resql = $this->db->query($sql);
628 $this->error = $this->db->lasterror();
644 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
645 $sql .=
" SET statut = 0";
646 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
648 dol_syslog(
"Mailing::reset_targets_status", LOG_DEBUG);
649 $resql = $this->db->query($sql);
653 $this->error = $this->db->lasterror();
667 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
668 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
669 if ($mode ==
'alreadysent') {
670 $sql .=
" AND statut <> 0";
671 } elseif ($mode ==
'alreadysentok') {
672 $sql .=
" AND statut > 0";
673 } elseif ($mode ==
'alreadysentko') {
674 $sql .=
" AND statut = -1";
676 $this->error =
'BadValueForParameterMode';
680 $resql = $this->db->query($sql);
682 $obj = $this->db->fetch_object($resql);
687 $this->error = $this->db->lasterror();
701 $sql =
"SELECT COUNT(rowid) as nb";
702 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
703 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
705 $resql = $this->db->query($sql);
707 $obj = $this->db->fetch_object($resql);
709 $nbforupdate = $obj->nb;
711 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'mailing SET nbemail = '.((int) $nbforupdate);
712 $sql .=
' WHERE rowid = '.((int) $this->
id);
714 $resqlupdate = $this->db->query($sql);
715 if (! $resqlupdate) {
716 $this->error = $this->db->lasterror();
719 $this->nbemail = (int) $nbforupdate;
723 $this->error = $this->db->lasterror();
742 $langs->load(
'mails');
745 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ShowEMailing").
'</u>';
746 if (isset($this->
status)) {
747 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
749 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
750 if (isset($this->title)) {
751 $datas[
'title'] =
'<br><b>'.$langs->trans(
'MailTitle').
':</b> '.$this->title;
753 if (isset($this->sujet)) {
754 $datas[
'subject'] =
'<br><b>'.$langs->trans(
'MailTopic').
':</b> '.$this->sujet;
770 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
772 global $conf, $langs, $hookmanager;
774 if (!empty($conf->dol_no_mouse_hover)) {
781 'objecttype' => $this->element,
785 $classfortooltip =
'classfortooltip';
788 $classfortooltip =
'classforajaxtooltip';
789 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
795 $url = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$this->id;
797 if ($option !=
'nolink') {
799 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
800 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
801 $add_save_lastsearch_values = 1;
803 if ($add_save_lastsearch_values) {
804 $url .=
'&save_lastsearch_values=1';
809 if (empty($notooltip)) {
811 $label = $langs->trans(
"ShowEMailing");
812 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
814 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
815 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
817 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
820 $linkstart =
'<a href="'.$url.
'"';
821 $linkstart .= $linkclose.
'>';
824 $result .= $linkstart;
826 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
828 if ($withpicto != 2) {
829 $result .= $this->ref;
835 $hookmanager->initHooks(array(
'emailingdao'));
836 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
837 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
839 $result = $hookmanager->resPrint;
841 $result .= $hookmanager->resPrint;
870 $langs->load(
"mailing");
872 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
873 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
875 $statusType =
'status'.$status;
877 $statusType =
'status3';
880 $statusType =
'status6';
883 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
899 $langs->load(
"mails");
901 $labelStatus = array();
902 $labelStatusShort = array();
904 $labelStatus[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
905 $labelStatus[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
906 $labelStatus[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
907 $labelStatus[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
908 $labelStatus[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
909 $labelStatusShort[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
910 $labelStatusShort[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
911 $labelStatusShort[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
912 $labelStatusShort[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
913 $labelStatusShort[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
915 $statusType =
'status'.$status;
917 $statusType =
'status8';
920 $statusType =
'status6';
923 $statusType =
'status4';
928 $param = array(
'badgeParams' => array(
'attr' => array(
'title' => $desc)));
931 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'', $statusType, $mode,
'', $param);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage emailings module.
static libStatutDest($status, $mode=0, $desc='')
Return the label of a given status of a recipient TODO Add class mailin_target.class....
getLibStatut($mode=0)
Return label of status of emailing (draft, validated, ...)
delete_targets()
Delete targets emailing.
valid($user)
Validate emailing.
countNbOfTargets($mode)
Count number of target with status.
create($user, $notrigger=0)
Create an EMailing.
fetch($rowid, $ref='')
Get object from database.
getTooltipContentArray($params)
getTooltipContentArray
__construct($db)
Constructor.
update($user, $notrigger=0)
Update emailing record.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
createFromClone(User $user, $fromid, $option1, $option2)
Load an object from its id and create a new one in database.
refreshNbOfTargets()
Refresh denormalized value ->nbemail into emailing record Note: There is also the method update_nb in...
reset_targets_status($user)
Change status of each recipient.
LibStatut($status, $mode=0)
Return the label of a given status.
Parent class of emailing target selectors modules.
Class to manage Dolibarr users.
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_textishtml($msg, $option=0)
Return if a text is a html content.
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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut