26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'mailing';
42 public $table_element =
'mailing';
47 public $picto =
'email';
97 public $email_replyto;
102 public $email_errorsto;
107 public $joined_file1;
112 public $joined_file2;
117 public $joined_file3;
122 public $joined_file4;
127 public $user_creation;
138 public $user_validation;
155 public $date_creation;
166 public $date_validation;
171 public $extraparams = array();
176 public $statut_dest = array();
181 public $statuts = array();
186 public $substitutionarray;
191 public $substitutionarrayfortest;
204 $this->statuts[0] =
'MailingStatusDraft';
205 $this->statuts[1] =
'MailingStatusValidated';
206 $this->statuts[2] =
'MailingStatusSentPartialy';
207 $this->statuts[3] =
'MailingStatusSentCompletely';
209 $this->statut_dest[-1] =
'MailingStatusError';
210 $this->statut_dest[0] =
'MailingStatusNotSent';
211 $this->statut_dest[1] =
'MailingStatusSent';
212 $this->statut_dest[2] =
'MailingStatusRead';
213 $this->statut_dest[3] =
'MailingStatusReadAndUnsubscribe';
223 public function create($user, $notrigger = 0)
225 global $conf, $langs;
228 if ($this->body ===
'InvalidHTMLString') {
229 $this->error =
'InvalidHTMLString';
233 $this->title = trim($this->title);
234 $this->email_from = trim($this->email_from);
236 if (!$this->email_from) {
237 $this->error = $langs->trans(
"ErrorMailFromRequired");
245 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing";
246 $sql .=
" (date_creat, fk_user_creat, entity)";
247 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $user->id).
", ".((int) $conf->entity).
")";
250 $this->title = $langs->trans(
"NoTitle");
256 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"mailing");
258 $result = $this->
update($user, 1);
263 if (!$error && !$notrigger) {
276 $this->
db->rollback();
277 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
281 $this->error = $this->
db->lasterror();
282 $this->
db->rollback();
294 public function update($user, $notrigger = 0)
297 if ($this->body ===
'InvalidHTMLString') {
298 $this->error =
'InvalidHTMLString';
305 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
306 $sql .=
" SET titre = '".$this->db->escape($this->title).
"'";
307 $sql .=
", sujet = '".$this->db->escape($this->sujet).
"'";
308 $sql .=
", body = '".$this->db->escape($this->body).
"'";
309 $sql .=
", email_from = '".$this->db->escape($this->email_from).
"'";
310 $sql .=
", email_replyto = '".$this->db->escape($this->email_replyto).
"'";
311 $sql .=
", email_errorsto = '".$this->db->escape($this->email_errorsto).
"'";
312 $sql .=
", bgcolor = '".($this->bgcolor ? $this->
db->escape($this->bgcolor) :
null).
"'";
313 $sql .=
", bgimage = '".($this->bgimage ? $this->
db->escape($this->bgimage) :
null).
"'";
314 $sql .=
" WHERE rowid = ".(int) $this->
id;
319 if (!$error && !$notrigger) {
333 $this->
db->rollback();
334 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_ERR);
338 $this->error = $this->
db->lasterror();
339 $this->
db->rollback();
354 $sql =
"SELECT m.rowid, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage";
355 $sql .=
", m.email_from, m.email_replyto, m.email_errorsto";
356 $sql .=
", m.statut, m.nbemail";
357 $sql .=
", m.fk_user_creat, m.fk_user_valid";
358 $sql .=
", m.date_creat";
359 $sql .=
", m.date_valid";
360 $sql .=
", m.date_envoi";
361 $sql .=
", m.extraparams";
362 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing as m";
363 $sql .=
" WHERE m.rowid = ".(int) $rowid;
365 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
366 $result = $this->
db->query($sql);
368 if ($this->
db->num_rows($result)) {
369 $obj = $this->
db->fetch_object($result);
371 $this->
id = $obj->rowid;
372 $this->
ref = $obj->rowid;
373 $this->statut = $obj->statut;
374 $this->nbemail = $obj->nbemail;
375 $this->title = $obj->title;
377 $this->sujet = $obj->sujet;
381 $this->body = $obj->body;
384 $this->bgcolor = $obj->bgcolor;
385 $this->bgimage = $obj->bgimage;
387 $this->email_from = $obj->email_from;
388 $this->email_replyto = $obj->email_replyto;
389 $this->email_errorsto = $obj->email_errorsto;
391 $this->user_creat = $obj->fk_user_creat;
392 $this->user_creation = $obj->fk_user_creat;
393 $this->user_valid = $obj->fk_user_valid;
394 $this->user_validation = $obj->fk_user_valid;
396 $this->date_creat = $this->
db->jdate($obj->date_creat);
397 $this->date_creation = $this->
db->jdate($obj->date_creat);
398 $this->date_valid = $this->
db->jdate($obj->date_valid);
399 $this->date_validation = $this->
db->jdate($obj->date_valid);
400 $this->date_envoi = $this->
db->jdate($obj->date_envoi);
402 $this->extraparams = (array) json_decode($obj->extraparams,
true);
406 dol_syslog(get_class($this).
"::fetch Erreur -1");
410 dol_syslog(get_class($this).
"::fetch Erreur -2");
436 $object->fetch($fromid);
444 if (empty($option1)) {
446 $object->nbemail = 0;
449 $object->bgcolor =
'';
450 $object->bgimage =
'';
453 $object->email_replyto =
'';
454 $object->email_errorsto =
'';
456 $object->user_creat = $user->id;
457 $object->user_valid =
'';
459 $object->date_creat =
'';
460 $object->date_valid =
'';
461 $object->date_envoi =
'';
465 $object->context[
'createfromclone'] =
'createfromclone';
466 $result = $object->create($user);
470 $this->error = $object->error;
471 $this->errors = array_merge($this->errors, $object->errors);
477 if (!empty($option2)) {
478 require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
482 $target_array = array();
484 $sql =
"SELECT fk_contact,";
485 $sql .=
" lastname,";
486 $sql .=
" firstname,";
489 $sql .=
" source_url,";
490 $sql .=
" source_id ,";
491 $sql .=
" source_type";
492 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
493 $sql .=
" WHERE fk_mailing = ".((int) $fromid);
495 $result = $this->
db->query($sql);
497 if ($this->
db->num_rows($result)) {
498 while ($obj = $this->
db->fetch_object($result)) {
499 $target_array[] = array(
500 'fk_contact'=>$obj->fk_contact,
501 'lastname'=>$obj->lastname,
502 'firstname'=>$obj->firstname,
503 'email'=>$obj->email,
504 'other'=>$obj->other,
505 'source_url'=>$obj->source_url,
506 'source_id'=>$obj->source_id,
507 'source_type'=>$obj->source_type
512 $this->error = $this->
db->lasterror();
516 $mailing_target->addTargetsToDatabase($object->id, $target_array);
520 unset($object->context[
'createfromclone']);
527 $this->
db->rollback();
542 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
543 $sql .=
" SET statut = 1, date_valid = '".$this->db->idate($now).
"', fk_user_valid=".$user->id;
544 $sql .=
" WHERE rowid = ".((int) $this->
id);
547 if ($this->
db->query($sql)) {
550 $this->error = $this->
db->lasterror();
563 public function delete($rowid, $notrigger = 0)
578 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"mailing";
579 $sql .=
" WHERE rowid = " . ((int) $rowid);
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);
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);
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';
682 $obj = $this->
db->fetch_object(
$resql);
687 $this->error = $this->
db->lasterror();
701 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
702 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
706 $obj = $this->
db->fetch_object(
$resql);
708 $nbforupdate = $obj->nb;
710 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'mailing SET nbemail = '.((int) $nbforupdate);
711 $sql .=
' WHERE rowid = '.((int) $this->
id);
713 $resqlupdate = $this->
db->query($sql);
714 if (! $resqlupdate) {
715 $this->error = $this->
db->lasterror();
718 $this->nbemail = (int) $nbforupdate;
722 $this->error = $this->
db->lasterror();
739 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
741 global $db, $conf, $langs, $hookmanager;
742 global $dolibarr_main_authentication, $dolibarr_main_demo;
745 if (!empty($conf->dol_no_mouse_hover)) {
752 $label =
'<u>'.$langs->trans(
"ShowEMailing").
'</u>';
754 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
756 $url = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$this->id;
758 if ($option !=
'nolink') {
760 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
761 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
762 $add_save_lastsearch_values = 1;
764 if ($add_save_lastsearch_values) {
765 $url .=
'&save_lastsearch_values=1';
770 if (empty($notooltip)) {
771 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
772 $label = $langs->trans(
"ShowEMailing");
773 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
775 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
776 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
778 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
781 $linkstart =
'<a href="'.$url.
'"';
782 $linkstart .= $linkclose.
'>';
785 $result .= $linkstart;
787 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
789 if ($withpicto != 2) {
790 $result .= $this->ref;
796 $hookmanager->initHooks(array(
'emailingdao'));
797 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
798 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
800 $result = $hookmanager->resPrint;
802 $result .= $hookmanager->resPrint;
816 return $this->
LibStatut($this->statut, $mode);
831 $langs->load(
"mailing");
833 $labelStatus = $langs->transnoentitiesnoconv($this->statuts[$status]);
834 $labelStatusShort = $langs->transnoentitiesnoconv($this->statuts[$status]);
836 $statusType =
'status'.$status;
838 $statusType =
'status3';
841 $statusType =
'status6';
844 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
860 $langs->load(
"mails");
862 $labelStatus = array();
863 $labelStatusShort = array();
865 $labelStatus[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
866 $labelStatus[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
867 $labelStatus[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
868 $labelStatus[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
869 $labelStatus[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
870 $labelStatusShort[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
871 $labelStatusShort[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
872 $labelStatusShort[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
873 $labelStatusShort[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
874 $labelStatusShort[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
876 $statusType =
'status'.$status;
878 $statusType =
'status8';
881 $statusType =
'status6';
884 $statusType =
'status4';
888 if ($status == - 1) {
889 $param = array(
'badgeParams'=>array(
'attr'=>array(
'title'=>$desc)));
891 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'', $statusType, $mode,
'', $param);
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.
__construct($db)
Constructor.
fetch($rowid)
Get object from database.
update($user, $notrigger=0)
Update emailing record.
create($user, $notrigger=0)
Create an EMailing.
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.