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;
124 public $email_replyto;
129 public $email_errorsto;
134 public $joined_file1;
139 public $joined_file2;
144 public $joined_file3;
149 public $joined_file4;
154 public $date_creation;
159 public $date_validation;
169 public $extraparams = array();
174 public $statut_dest = array();
179 public $substitutionarray;
184 public $substitutionarrayfortest;
186 const STATUS_DRAFT = 0;
187 const STATUS_VALIDATED = 1;
188 const STATUS_SENTPARTIALY = 2;
189 const STATUS_SENTCOMPLETELY = 3;
202 $this->labelStatus[0] =
'MailingStatusDraft';
203 $this->labelStatus[1] =
'MailingStatusValidated';
204 $this->labelStatus[2] =
'MailingStatusSentPartialy';
205 $this->labelStatus[3] =
'MailingStatusSentCompletely';
207 $this->statut_dest[0] =
'MailingStatusNotSent';
208 $this->statut_dest[1] =
'MailingStatusSent';
209 $this->statut_dest[2] =
'MailingStatusRead';
210 $this->statut_dest[3] =
'MailingStatusReadAndUnsubscribe';
211 $this->statut_dest[-1] =
'MailingStatusError';
221 public function create($user, $notrigger = 0)
223 global $conf, $langs;
226 if (preg_match(
'/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
227 $this->error =
'InvalidHTMLStringCantBeCleaned';
231 $this->title = trim($this->title);
232 $this->email_from = trim($this->email_from);
234 if (!$this->email_from) {
235 if ($this->messtype !==
'sms') {
236 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailFrom"));
238 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PhoneFrom"));
248 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing";
249 $sql .=
" (date_creat, fk_user_creat, entity)";
250 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $user->id).
", ".((int) $conf->entity).
")";
253 $this->title = $langs->trans(
"NoTitle");
258 $resql = $this->db->query($sql);
260 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"mailing");
262 $result = $this->
update($user, 1);
267 if (!$error && !$notrigger) {
280 $this->db->rollback();
281 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
285 $this->error = $this->db->lasterror();
286 $this->db->rollback();
298 public function update($user, $notrigger = 0)
303 if (preg_match(
'/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
304 $this->error =
'InvalidHTMLStringCantBeCleaned';
311 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
312 $sql .=
" SET titre = '".$this->db->escape($this->title).
"'";
313 $sql .=
", messtype = '".$this->db->escape($this->messtype).
"'";
314 $sql .=
", sujet = '".$this->db->escape($this->sujet).
"'";
315 $sql .=
", body = '".$this->db->escape($this->body).
"'";
316 $sql .=
", email_from = '".$this->db->escape($this->email_from).
"'";
317 $sql .=
", email_replyto = '".$this->db->escape($this->email_replyto).
"'";
318 $sql .=
", email_errorsto = '".$this->db->escape($this->email_errorsto).
"'";
319 $sql .=
", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) :
null).
"'";
320 $sql .=
", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) :
null).
"'";
321 $sql .=
", evenunsubscribe = ".((int) $this->evenunsubscribe);
322 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
323 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
324 $sql .=
" WHERE rowid = ".(int) $this->
id;
327 $resql = $this->db->query($sql);
329 if (!$error && !$notrigger) {
343 $this->db->rollback();
344 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
348 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
349 $this->error = $langs->trans(
"ErrorTitleAlreadyExists", $this->title);
351 $this->error = $this->db->lasterror();
353 $this->db->rollback();
365 public function fetch($rowid, $ref =
'')
367 $sql =
"SELECT m.rowid, m.messtype, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe";
368 $sql .=
", m.note_public, m.note_private";
369 $sql .=
", m.email_from, m.email_replyto, m.email_errorsto";
370 $sql .=
", m.statut as status, m.nbemail";
371 $sql .=
", m.fk_user_creat, m.fk_user_valid";
372 $sql .=
", m.date_creat";
373 $sql .=
", m.date_valid";
374 $sql .=
", m.date_envoi";
375 $sql .=
", m.extraparams";
376 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing as m";
377 $sql .=
" WHERE entity IN (".getEntity(
'mailing').
")";
379 $sql .=
" AND m.titre = '".$this->db->escape($ref).
"'";
381 $sql .=
" AND m.rowid = ".(int) $rowid;
384 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
385 $result = $this->db->query($sql);
387 if ($this->db->num_rows($result)) {
388 $obj = $this->db->fetch_object($result);
390 $this->
id = $obj->rowid;
391 $this->
ref = $obj->rowid;
392 $this->title = $obj->title;
393 $this->messtype = $obj->messtype;
395 $this->
statut = $obj->status;
396 $this->
status = $obj->status;
398 $this->nbemail = $obj->nbemail;
400 $this->sujet = $obj->sujet;
404 $this->body = $obj->body;
407 $this->bgcolor = $obj->bgcolor;
408 $this->bgimage = $obj->bgimage;
409 $this->evenunsubscribe = $obj->evenunsubscribe;
410 $this->note_public = $obj->note_public;
411 $this->note_private = $obj->note_private;
413 $this->email_from = $obj->email_from;
414 $this->email_replyto = $obj->email_replyto;
415 $this->email_errorsto = $obj->email_errorsto;
417 $this->user_creation_id = $obj->fk_user_creat;
418 $this->user_validation_id = $obj->fk_user_valid;
420 $this->date_creation = $this->db->jdate($obj->date_creat);
421 $this->date_validation = $this->db->jdate($obj->date_valid);
422 $this->date_envoi = $this->db->jdate($obj->date_envoi);
424 $this->extraparams = (array) json_decode($obj->extraparams,
true);
426 if ($this->messtype ==
'sms') {
427 $this->picto =
'phone';
432 dol_syslog(get_class($this).
"::fetch Erreur -1");
436 dol_syslog(get_class($this).
"::fetch Erreur -2");
471 if (empty($option1)) {
486 $object->user_creation_id = $user->id;
487 $object->user_validation_id =
null;
493 $object->context[
'createfromclone'] =
'createfromclone';
494 $result =
$object->create($user);
499 $this->errors = array_merge($this->errors,
$object->errors);
505 if (!empty($option2)) {
506 require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
510 $target_array = array();
512 $sql =
"SELECT fk_contact,";
513 $sql .=
" lastname,";
514 $sql .=
" firstname,";
517 $sql .=
" source_url,";
518 $sql .=
" source_id ,";
519 $sql .=
" source_type";
520 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
521 $sql .=
" WHERE fk_mailing = ".((int) $fromid);
523 $result = $this->db->query($sql);
525 if ($this->db->num_rows($result)) {
526 while ($obj = $this->db->fetch_object($result)) {
527 $target_array[] = array(
528 'fk_contact'=>$obj->fk_contact,
529 'lastname'=>$obj->lastname,
530 'firstname'=>$obj->firstname,
531 'email'=>$obj->email,
532 'other'=>$obj->other,
533 'source_url'=>$obj->source_url,
534 'source_id'=>$obj->source_id,
535 'source_type'=>$obj->source_type
540 $this->error = $this->db->lasterror();
544 $mailing_target->addTargetsToDatabase(
$object->id, $target_array);
548 unset(
$object->context[
'createfromclone']);
555 $this->db->rollback();
570 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
571 $sql .=
" SET statut = 1, date_valid = '".$this->db->idate($now).
"', fk_user_valid=".$user->id;
572 $sql .=
" WHERE rowid = ".((int) $this->
id);
575 if ($this->db->query($sql)) {
578 $this->error = $this->db->lasterror();
591 public function delete($user, $notrigger = 0)
605 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"mailing";
606 $sql .=
" WHERE rowid = " . ((int) $this->
id);
609 $resql = $this->db->query($sql);
621 $this->db->rollback();
622 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
626 $this->db->rollback();
627 $this->error = $this->db->lasterror();
631 $this->db->rollback();
645 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
646 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
648 dol_syslog(
"Mailing::delete_targets", LOG_DEBUG);
649 $resql = $this->db->query($sql);
655 $this->error = $this->db->lasterror();
671 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
672 $sql .=
" SET statut = 0";
673 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
675 dol_syslog(
"Mailing::reset_targets_status", LOG_DEBUG);
676 $resql = $this->db->query($sql);
680 $this->error = $this->db->lasterror();
694 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
695 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
696 if ($mode ==
'alreadysent') {
697 $sql .=
" AND statut <> 0";
698 } elseif ($mode ==
'alreadysentok') {
699 $sql .=
" AND statut > 0";
700 } elseif ($mode ==
'alreadysentko') {
701 $sql .=
" AND statut = -1";
703 $this->error =
'BadValueForParameterMode';
707 $resql = $this->db->query($sql);
709 $obj = $this->db->fetch_object($resql);
714 $this->error = $this->db->lasterror();
728 $sql =
"SELECT COUNT(rowid) as nb";
729 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
730 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
732 $resql = $this->db->query($sql);
734 $obj = $this->db->fetch_object($resql);
736 $nbforupdate = $obj->nb;
738 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'mailing SET nbemail = '.((int) $nbforupdate);
739 $sql .=
' WHERE rowid = '.((int) $this->
id);
741 $resqlupdate = $this->db->query($sql);
742 if (! $resqlupdate) {
743 $this->error = $this->db->lasterror();
746 $this->nbemail = (int) $nbforupdate;
750 $this->error = $this->db->lasterror();
769 $langs->load(
'mails');
772 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ShowEMailing").
'</u>';
773 if (isset($this->
status)) {
774 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
776 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
777 if (isset($this->title)) {
778 $datas[
'title'] =
'<br><b>'.$langs->trans(
'MailTitle').
':</b> '.$this->title;
780 if (isset($this->sujet)) {
781 $datas[
'subject'] =
'<br><b>'.$langs->trans(
'MailTopic').
':</b> '.$this->sujet;
797 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
799 global $conf, $langs, $hookmanager;
801 if (!empty($conf->dol_no_mouse_hover)) {
808 'objecttype' => $this->element,
812 $classfortooltip =
'classfortooltip';
815 $classfortooltip =
'classforajaxtooltip';
816 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
822 $url = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$this->id;
824 if ($option !=
'nolink') {
826 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
827 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
828 $add_save_lastsearch_values = 1;
830 if ($add_save_lastsearch_values) {
831 $url .=
'&save_lastsearch_values=1';
836 if (empty($notooltip)) {
838 $label = $langs->trans(
"ShowEMailing");
839 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
841 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
842 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
844 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
847 $linkstart =
'<a href="'.$url.
'"';
848 $linkstart .= $linkclose.
'>';
851 $result .= $linkstart;
853 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
855 if ($withpicto != 2) {
856 $result .= $this->ref;
862 $hookmanager->initHooks(array(
'emailingdao'));
863 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
864 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
866 $result = $hookmanager->resPrint;
868 $result .= $hookmanager->resPrint;
897 $langs->load(
"mailing");
899 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
900 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
902 $statusType =
'status'.$status;
904 $statusType =
'status3';
907 $statusType =
'status6';
910 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
926 $langs->load(
"mails");
928 $labelStatus = array();
929 $labelStatusShort = array();
931 $labelStatus[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
932 $labelStatus[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
933 $labelStatus[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
934 $labelStatus[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
935 $labelStatus[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
936 $labelStatusShort[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
937 $labelStatusShort[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
938 $labelStatusShort[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
939 $labelStatusShort[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
940 $labelStatusShort[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
942 $statusType =
'status'.$status;
944 $statusType =
'status8';
947 $statusType =
'status6';
950 $statusType =
'status4';
955 $param = array(
'badgeParams' => array(
'attr' => array(
'title' => $desc)));
958 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