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;
144 public $date_creation;
149 public $date_validation;
159 public $extraparams = array();
164 public $statut_dest = array();
169 public $substitutionarray;
174 public $substitutionarrayfortest;
176 const STATUS_DRAFT = 0;
177 const STATUS_VALIDATED = 1;
178 const STATUS_SENTPARTIALY = 2;
179 const STATUS_SENTCOMPLETELY = 3;
192 $this->labelStatus[0] =
'MailingStatusDraft';
193 $this->labelStatus[1] =
'MailingStatusValidated';
194 $this->labelStatus[2] =
'MailingStatusSentPartialy';
195 $this->labelStatus[3] =
'MailingStatusSentCompletely';
197 $this->statut_dest[0] =
'MailingStatusNotSent';
198 $this->statut_dest[1] =
'MailingStatusSent';
199 $this->statut_dest[2] =
'MailingStatusRead';
200 $this->statut_dest[3] =
'MailingStatusReadAndUnsubscribe';
201 $this->statut_dest[-1] =
'MailingStatusError';
211 public function create($user, $notrigger = 0)
213 global $conf, $langs;
216 if (preg_match(
'/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
217 $this->error =
'InvalidHTMLStringCantBeCleaned';
221 $this->title = trim($this->title);
222 $this->email_from = trim($this->email_from);
224 if (!$this->email_from) {
225 if ($this->messtype !==
'sms') {
226 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailFrom"));
228 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PhoneFrom"));
238 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing";
239 $sql .=
" (date_creat, fk_user_creat, entity)";
240 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $user->id).
", ".((int) $conf->entity).
")";
243 $this->title = $langs->trans(
"NoTitle");
248 $resql = $this->db->query($sql);
250 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"mailing");
252 $result = $this->
update($user, 1);
257 if (!$error && !$notrigger) {
270 $this->db->rollback();
271 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
275 $this->error = $this->db->lasterror();
276 $this->db->rollback();
288 public function update($user, $notrigger = 0)
293 if (preg_match(
'/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
294 $this->error =
'InvalidHTMLStringCantBeCleaned';
301 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
302 $sql .=
" SET titre = '".$this->db->escape($this->title).
"'";
303 $sql .=
", messtype = '".$this->db->escape($this->messtype).
"'";
304 $sql .=
", sujet = '".$this->db->escape($this->sujet).
"'";
305 $sql .=
", body = '".$this->db->escape($this->body).
"'";
306 $sql .=
", email_from = '".$this->db->escape($this->email_from).
"'";
307 $sql .=
", email_replyto = '".$this->db->escape($this->email_replyto).
"'";
308 $sql .=
", email_errorsto = '".$this->db->escape($this->email_errorsto).
"'";
309 $sql .=
", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) :
null).
"'";
310 $sql .=
", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) :
null).
"'";
311 $sql .=
", evenunsubscribe = ".((int) $this->evenunsubscribe);
312 $sql .=
" WHERE rowid = ".(int) $this->
id;
315 $resql = $this->db->query($sql);
317 if (!$error && !$notrigger) {
331 $this->db->rollback();
332 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
336 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
337 $this->error = $langs->trans(
"ErrorTitleAlreadyExists", $this->title);
339 $this->error = $this->db->lasterror();
341 $this->db->rollback();
353 public function fetch($rowid, $ref =
'')
355 $sql =
"SELECT m.rowid, m.messtype, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe";
356 $sql .=
", m.email_from, m.email_replyto, m.email_errorsto";
357 $sql .=
", m.statut as status, m.nbemail";
358 $sql .=
", m.fk_user_creat, m.fk_user_valid";
359 $sql .=
", m.date_creat";
360 $sql .=
", m.date_valid";
361 $sql .=
", m.date_envoi";
362 $sql .=
", m.extraparams";
363 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing as m";
364 $sql .=
" WHERE entity IN (".getEntity(
'mailing').
")";
366 $sql .=
" AND m.titre = '".$this->db->escape($ref).
"'";
368 $sql .=
" AND m.rowid = ".(int) $rowid;
371 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
372 $result = $this->db->query($sql);
374 if ($this->db->num_rows($result)) {
375 $obj = $this->db->fetch_object($result);
377 $this->
id = $obj->rowid;
378 $this->
ref = $obj->rowid;
379 $this->title = $obj->title;
380 $this->messtype = $obj->messtype;
382 $this->
statut = $obj->status;
383 $this->
status = $obj->status;
385 $this->nbemail = $obj->nbemail;
387 $this->sujet = $obj->sujet;
391 $this->body = $obj->body;
394 $this->bgcolor = $obj->bgcolor;
395 $this->bgimage = $obj->bgimage;
396 $this->evenunsubscribe = $obj->evenunsubscribe;
398 $this->email_from = $obj->email_from;
399 $this->email_replyto = $obj->email_replyto;
400 $this->email_errorsto = $obj->email_errorsto;
402 $this->user_creation_id = $obj->fk_user_creat;
403 $this->user_validation_id = $obj->fk_user_valid;
405 $this->date_creation = $this->db->jdate($obj->date_creat);
406 $this->date_validation = $this->db->jdate($obj->date_valid);
407 $this->date_envoi = $this->db->jdate($obj->date_envoi);
409 $this->extraparams = (array) json_decode($obj->extraparams,
true);
411 if ($this->messtype ==
'sms') {
412 $this->picto =
'phone';
417 dol_syslog(get_class($this).
"::fetch Erreur -1");
421 dol_syslog(get_class($this).
"::fetch Erreur -2");
456 if (empty($option1)) {
469 $object->user_creation_id = $user->id;
470 $object->user_validation_id =
null;
476 $object->context[
'createfromclone'] =
'createfromclone';
477 $result =
$object->create($user);
482 $this->errors = array_merge($this->errors,
$object->errors);
488 if (!empty($option2)) {
489 require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
493 $target_array = array();
495 $sql =
"SELECT fk_contact,";
496 $sql .=
" lastname,";
497 $sql .=
" firstname,";
500 $sql .=
" source_url,";
501 $sql .=
" source_id ,";
502 $sql .=
" source_type";
503 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
504 $sql .=
" WHERE fk_mailing = ".((int) $fromid);
506 $result = $this->db->query($sql);
508 if ($this->db->num_rows($result)) {
509 while ($obj = $this->db->fetch_object($result)) {
510 $target_array[] = array(
511 'fk_contact'=>$obj->fk_contact,
512 'lastname'=>$obj->lastname,
513 'firstname'=>$obj->firstname,
514 'email'=>$obj->email,
515 'other'=>$obj->other,
516 'source_url'=>$obj->source_url,
517 'source_id'=>$obj->source_id,
518 'source_type'=>$obj->source_type
523 $this->error = $this->db->lasterror();
527 $mailing_target->addTargetsToDatabase(
$object->id, $target_array);
531 unset(
$object->context[
'createfromclone']);
538 $this->db->rollback();
553 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
554 $sql .=
" SET statut = 1, date_valid = '".$this->db->idate($now).
"', fk_user_valid=".$user->id;
555 $sql .=
" WHERE rowid = ".((int) $this->
id);
558 if ($this->db->query($sql)) {
561 $this->error = $this->db->lasterror();
574 public function delete($user, $notrigger = 0)
588 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"mailing";
589 $sql .=
" WHERE rowid = " . ((int) $this->
id);
592 $resql = $this->db->query($sql);
604 $this->db->rollback();
605 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
609 $this->db->rollback();
610 $this->error = $this->db->lasterror();
614 $this->db->rollback();
628 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
629 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
631 dol_syslog(
"Mailing::delete_targets", LOG_DEBUG);
632 $resql = $this->db->query($sql);
638 $this->error = $this->db->lasterror();
654 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
655 $sql .=
" SET statut = 0";
656 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
658 dol_syslog(
"Mailing::reset_targets_status", LOG_DEBUG);
659 $resql = $this->db->query($sql);
663 $this->error = $this->db->lasterror();
677 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
678 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
679 if ($mode ==
'alreadysent') {
680 $sql .=
" AND statut <> 0";
681 } elseif ($mode ==
'alreadysentok') {
682 $sql .=
" AND statut > 0";
683 } elseif ($mode ==
'alreadysentko') {
684 $sql .=
" AND statut = -1";
686 $this->error =
'BadValueForParameterMode';
690 $resql = $this->db->query($sql);
692 $obj = $this->db->fetch_object($resql);
697 $this->error = $this->db->lasterror();
711 $sql =
"SELECT COUNT(rowid) as nb";
712 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
713 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
715 $resql = $this->db->query($sql);
717 $obj = $this->db->fetch_object($resql);
719 $nbforupdate = $obj->nb;
721 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'mailing SET nbemail = '.((int) $nbforupdate);
722 $sql .=
' WHERE rowid = '.((int) $this->
id);
724 $resqlupdate = $this->db->query($sql);
725 if (! $resqlupdate) {
726 $this->error = $this->db->lasterror();
729 $this->nbemail = (int) $nbforupdate;
733 $this->error = $this->db->lasterror();
752 $langs->load(
'mails');
755 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ShowEMailing").
'</u>';
756 if (isset($this->
status)) {
757 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
759 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
760 if (isset($this->title)) {
761 $datas[
'title'] =
'<br><b>'.$langs->trans(
'MailTitle').
':</b> '.$this->title;
763 if (isset($this->sujet)) {
764 $datas[
'subject'] =
'<br><b>'.$langs->trans(
'MailTopic').
':</b> '.$this->sujet;
780 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
782 global $conf, $langs, $hookmanager;
784 if (!empty($conf->dol_no_mouse_hover)) {
791 'objecttype' => $this->element,
795 $classfortooltip =
'classfortooltip';
798 $classfortooltip =
'classforajaxtooltip';
799 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
805 $url = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$this->id;
807 if ($option !=
'nolink') {
809 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
810 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
811 $add_save_lastsearch_values = 1;
813 if ($add_save_lastsearch_values) {
814 $url .=
'&save_lastsearch_values=1';
819 if (empty($notooltip)) {
821 $label = $langs->trans(
"ShowEMailing");
822 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
824 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
825 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
827 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
830 $linkstart =
'<a href="'.$url.
'"';
831 $linkstart .= $linkclose.
'>';
834 $result .= $linkstart;
836 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
838 if ($withpicto != 2) {
839 $result .= $this->ref;
845 $hookmanager->initHooks(array(
'emailingdao'));
846 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
847 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
849 $result = $hookmanager->resPrint;
851 $result .= $hookmanager->resPrint;
880 $langs->load(
"mailing");
882 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
883 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
885 $statusType =
'status'.$status;
887 $statusType =
'status3';
890 $statusType =
'status6';
893 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
909 $langs->load(
"mails");
911 $labelStatus = array();
912 $labelStatusShort = array();
914 $labelStatus[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
915 $labelStatus[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
916 $labelStatus[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
917 $labelStatus[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
918 $labelStatus[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
919 $labelStatusShort[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
920 $labelStatusShort[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
921 $labelStatusShort[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
922 $labelStatusShort[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
923 $labelStatusShort[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
925 $statusType =
'status'.$status;
927 $statusType =
'status8';
930 $statusType =
'status6';
933 $statusType =
'status4';
938 $param = array(
'badgeParams' => array(
'attr' => array(
'title' => $desc)));
941 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