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';
224 global $conf, $langs;
227 if ($this->body ===
'InvalidHTMLString') {
228 $this->error =
'InvalidHTMLString';
234 $this->title = trim($this->title);
235 $this->email_from = trim($this->email_from);
237 if (!$this->email_from) {
238 $this->error = $langs->trans(
"ErrorMailFromRequired");
244 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing";
245 $sql .=
" (date_creat, fk_user_creat, entity)";
246 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $user->id).
", ".((int) $conf->entity).
")";
249 $this->title = $langs->trans(
"NoTitle");
253 $result = $this->
db->query($sql);
255 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"mailing");
257 if ($this->
update($user) > 0) {
260 $this->error = $this->
db->lasterror();
261 $this->
db->rollback();
267 $this->error = $this->
db->lasterror();
268 $this->
db->rollback();
282 if ($this->body ===
'InvalidHTMLString') {
283 $this->error =
'InvalidHTMLString';
287 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
288 $sql .=
" SET titre = '".$this->db->escape($this->title).
"'";
289 $sql .=
", sujet = '".$this->db->escape($this->sujet).
"'";
290 $sql .=
", body = '".$this->db->escape($this->body).
"'";
291 $sql .=
", email_from = '".$this->db->escape($this->email_from).
"'";
292 $sql .=
", email_replyto = '".$this->db->escape($this->email_replyto).
"'";
293 $sql .=
", email_errorsto = '".$this->db->escape($this->email_errorsto).
"'";
294 $sql .=
", bgcolor = '".($this->bgcolor ? $this->
db->escape($this->bgcolor) :
null).
"'";
295 $sql .=
", bgimage = '".($this->bgimage ? $this->
db->escape($this->bgimage) :
null).
"'";
296 $sql .=
" WHERE rowid = ".(int) $this->
id;
299 $result = $this->
db->query($sql);
303 $this->error = $this->
db->lasterror();
318 $sql =
"SELECT m.rowid, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage";
319 $sql .=
", m.email_from, m.email_replyto, m.email_errorsto";
320 $sql .=
", m.statut, m.nbemail";
321 $sql .=
", m.fk_user_creat, m.fk_user_valid";
322 $sql .=
", m.date_creat";
323 $sql .=
", m.date_valid";
324 $sql .=
", m.date_envoi";
325 $sql .=
", m.extraparams";
326 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing as m";
327 $sql .=
" WHERE m.rowid = ".(int) $rowid;
329 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
330 $result = $this->
db->query($sql);
332 if ($this->
db->num_rows($result)) {
333 $obj = $this->
db->fetch_object($result);
335 $this->
id = $obj->rowid;
336 $this->
ref = $obj->rowid;
337 $this->statut = $obj->statut;
338 $this->nbemail = $obj->nbemail;
339 $this->title = $obj->title;
341 $this->sujet = $obj->sujet;
345 $this->body = $obj->body;
348 $this->bgcolor = $obj->bgcolor;
349 $this->bgimage = $obj->bgimage;
351 $this->email_from = $obj->email_from;
352 $this->email_replyto = $obj->email_replyto;
353 $this->email_errorsto = $obj->email_errorsto;
355 $this->user_creat = $obj->fk_user_creat;
356 $this->user_creation = $obj->fk_user_creat;
357 $this->user_valid = $obj->fk_user_valid;
358 $this->user_validation = $obj->fk_user_valid;
360 $this->date_creat = $this->
db->jdate($obj->date_creat);
361 $this->date_creation = $this->
db->jdate($obj->date_creat);
362 $this->date_valid = $this->
db->jdate($obj->date_valid);
363 $this->date_validation = $this->
db->jdate($obj->date_valid);
364 $this->date_envoi = $this->
db->jdate($obj->date_envoi);
366 $this->extraparams = (array) json_decode($obj->extraparams,
true);
370 dol_syslog(get_class($this).
"::fetch Erreur -1");
374 dol_syslog(get_class($this).
"::fetch Erreur -2");
400 $object->fetch($fromid);
408 if (empty($option1)) {
410 $object->nbemail = 0;
413 $object->bgcolor =
'';
414 $object->bgimage =
'';
417 $object->email_replyto =
'';
418 $object->email_errorsto =
'';
420 $object->user_creat = $user->id;
421 $object->user_valid =
'';
423 $object->date_creat =
'';
424 $object->date_valid =
'';
425 $object->date_envoi =
'';
429 $object->context[
'createfromclone'] =
'createfromclone';
430 $result = $object->create($user);
434 $this->error = $object->error;
435 $this->errors = array_merge($this->errors, $object->errors);
441 if (!empty($option2)) {
442 require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
446 $target_array = array();
448 $sql =
"SELECT fk_contact,";
449 $sql .=
" lastname,";
450 $sql .=
" firstname,";
453 $sql .=
" source_url,";
454 $sql .=
" source_id ,";
455 $sql .=
" source_type";
456 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
457 $sql .=
" WHERE fk_mailing = ".((int) $fromid);
459 $result = $this->
db->query($sql);
461 if ($this->
db->num_rows($result)) {
462 while ($obj = $this->
db->fetch_object($result)) {
463 $target_array[] = array(
464 'fk_contact'=>$obj->fk_contact,
465 'lastname'=>$obj->lastname,
466 'firstname'=>$obj->firstname,
467 'email'=>$obj->email,
468 'other'=>$obj->other,
469 'source_url'=>$obj->source_url,
470 'source_id'=>$obj->source_id,
471 'source_type'=>$obj->source_type
476 $this->error = $this->
db->lasterror();
480 $mailing_target->addTargetsToDatabase($object->id, $target_array);
484 unset($object->context[
'createfromclone']);
491 $this->
db->rollback();
506 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
507 $sql .=
" SET statut = 1, date_valid = '".$this->db->idate($now).
"', fk_user_valid=".$user->id;
508 $sql .=
" WHERE rowid = ".((int) $this->
id);
511 if ($this->
db->query($sql)) {
514 $this->error = $this->
db->lasterror();
527 public function delete($rowid, $notrigger = 0)
533 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing";
534 $sql .=
" WHERE rowid = ".((int) $rowid);
541 $this->
db->rollback();
542 $this->error = $this->
db->lasterror();
546 $this->
db->rollback();
547 $this->error = $this->
db->lasterror();
554 $this->
db->rollback();
572 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
573 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
575 dol_syslog(
"Mailing::delete_targets", LOG_DEBUG);
582 $this->error = $this->
db->lasterror();
598 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
599 $sql .=
" SET statut = 0";
600 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
602 dol_syslog(
"Mailing::reset_targets_status", LOG_DEBUG);
607 $this->error = $this->
db->lasterror();
621 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
622 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
623 if ($mode ==
'alreadysent') {
624 $sql .=
" AND statut <> 0";
625 } elseif ($mode ==
'alreadysentok') {
626 $sql .=
" AND statut > 0";
627 } elseif ($mode ==
'alreadysentko') {
628 $sql .=
" AND statut = -1";
630 $this->error =
'BadValueForParameterMode';
636 $obj = $this->
db->fetch_object(
$resql);
641 $this->error = $this->
db->lasterror();
655 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
656 $sql .=
" WHERE fk_mailing = ".((int) $this->
id);
660 $obj = $this->
db->fetch_object(
$resql);
662 $nbforupdate = $obj->nb;
664 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'mailing SET nbemail = '.((int) $nbforupdate);
665 $sql .=
' WHERE rowid = '.((int) $this->
id);
667 $resqlupdate = $this->
db->query($sql);
668 if (! $resqlupdate) {
669 $this->error = $this->
db->lasterror();
672 $this->nbemail = (int) $nbforupdate;
676 $this->error = $this->
db->lasterror();
693 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
695 global $db, $conf, $langs, $hookmanager;
696 global $dolibarr_main_authentication, $dolibarr_main_demo;
699 if (!empty($conf->dol_no_mouse_hover)) {
706 $label =
'<u>'.$langs->trans(
"ShowEMailing").
'</u>';
708 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
710 $url = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$this->id;
712 if ($option !=
'nolink') {
714 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
715 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
716 $add_save_lastsearch_values = 1;
718 if ($add_save_lastsearch_values) {
719 $url .=
'&save_lastsearch_values=1';
724 if (empty($notooltip)) {
725 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
726 $label = $langs->trans(
"ShowEMailing");
727 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
729 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
730 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
732 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
735 $linkstart =
'<a href="'.$url.
'"';
736 $linkstart .= $linkclose.
'>';
739 $result .= $linkstart;
741 $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);
743 if ($withpicto != 2) {
744 $result .= $this->ref;
750 $hookmanager->initHooks(array(
'emailingdao'));
751 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
752 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
754 $result = $hookmanager->resPrint;
756 $result .= $hookmanager->resPrint;
770 return $this->
LibStatut($this->statut, $mode);
785 $langs->load(
"mailing");
787 $labelStatus = $langs->transnoentitiesnoconv($this->statuts[$status]);
788 $labelStatusShort = $langs->transnoentitiesnoconv($this->statuts[$status]);
790 $statusType =
'status'.$status;
792 $statusType =
'status3';
795 $statusType =
'status6';
798 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
814 $langs->load(
"mails");
816 $labelStatus = array();
817 $labelStatusShort = array();
819 $labelStatus[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
820 $labelStatus[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
821 $labelStatus[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
822 $labelStatus[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
823 $labelStatus[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
824 $labelStatusShort[-1] = $langs->transnoentitiesnoconv(
'MailingStatusError');
825 $labelStatusShort[0] = $langs->transnoentitiesnoconv(
'MailingStatusNotSent');
826 $labelStatusShort[1] = $langs->transnoentitiesnoconv(
'MailingStatusSent');
827 $labelStatusShort[2] = $langs->transnoentitiesnoconv(
'MailingStatusRead');
828 $labelStatusShort[3] = $langs->transnoentitiesnoconv(
'MailingStatusNotContact');
830 $statusType =
'status'.$status;
832 $statusType =
'status8';
835 $statusType =
'status6';
838 $statusType =
'status4';
842 if ($status == - 1) {
843 $param = array(
'badgeParams'=>array(
'attr'=>array(
'title'=>$desc)));
845 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.
create($user)
Create an EMailing.
static libStatutDest($status, $mode=0, $desc='')
Return the label of a given status of a recipient TODO Add class mailin_target.class....
update($user)
Update emailing record.
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.
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.