26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'mailing';
42 public $table_element =
'mailing';
47 public $picto =
'email';
92 public $email_replyto;
97 public $email_errorsto;
102 public $joined_file1;
107 public $joined_file2;
112 public $joined_file3;
117 public $joined_file4;
123 public $user_creation;
134 public $user_validation;
154 public $extraparams = array();
159 public $statut_dest = array();
164 public $statuts = array();
177 $this->statuts[0] =
'MailingStatusDraft';
178 $this->statuts[1] =
'MailingStatusValidated';
179 $this->statuts[2] =
'MailingStatusSentPartialy';
180 $this->statuts[3] =
'MailingStatusSentCompletely';
182 $this->statut_dest[-1] =
'MailingStatusError';
183 $this->statut_dest[0] =
'MailingStatusNotSent';
184 $this->statut_dest[1] =
'MailingStatusSent';
185 $this->statut_dest[2] =
'MailingStatusRead';
186 $this->statut_dest[3] =
'MailingStatusReadAndUnsubscribe';
197 global $conf, $langs;
201 $this->title = trim($this->title);
202 $this->email_from = trim($this->email_from);
204 if (!$this->email_from) {
205 $this->error = $langs->trans(
"ErrorMailFromRequired");
211 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"mailing";
212 $sql .=
" (date_creat, fk_user_creat, entity)";
213 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".$user->id.
", ".$conf->entity.
")";
216 $this->title = $langs->trans(
"NoTitle");
220 $result = $this->
db->query($sql);
222 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"mailing");
224 if ($this->
update($user) > 0) {
227 $this->error = $this->
db->lasterror();
228 $this->
db->rollback();
234 $this->error = $this->
db->lasterror();
235 $this->
db->rollback();
248 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
249 $sql .=
" SET titre = '".$this->db->escape($this->title).
"'";
250 $sql .=
", sujet = '".$this->db->escape($this->sujet).
"'";
251 $sql .=
", body = '".$this->db->escape($this->body).
"'";
252 $sql .=
", email_from = '".$this->db->escape($this->email_from).
"'";
253 $sql .=
", email_replyto = '".$this->db->escape($this->email_replyto).
"'";
254 $sql .=
", email_errorsto = '".$this->db->escape($this->email_errorsto).
"'";
255 $sql .=
", bgcolor = '".($this->bgcolor ? $this->
db->escape($this->bgcolor) : null).
"'";
256 $sql .=
", bgimage = '".($this->bgimage ? $this->
db->escape($this->bgimage) : null).
"'";
257 $sql .=
" WHERE rowid = ".(int) $this->
id;
260 $result = $this->
db->query($sql);
264 $this->error = $this->
db->lasterror();
279 $sql =
"SELECT m.rowid, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage";
280 $sql .=
", m.email_from, m.email_replyto, m.email_errorsto";
281 $sql .=
", m.statut, m.nbemail";
282 $sql .=
", m.fk_user_creat, m.fk_user_valid";
283 $sql .=
", m.date_creat";
284 $sql .=
", m.date_valid";
285 $sql .=
", m.date_envoi";
286 $sql .=
", m.extraparams";
287 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing as m";
288 $sql .=
" WHERE m.rowid = ".(int) $rowid;
290 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
291 $result = $this->
db->query($sql);
293 if ($this->
db->num_rows($result)) {
294 $obj = $this->
db->fetch_object($result);
296 $this->
id = $obj->rowid;
297 $this->ref = $obj->rowid;
298 $this->
statut = $obj->statut;
299 $this->nbemail = $obj->nbemail;
300 $this->title = $obj->title;
302 $this->sujet = $obj->sujet;
306 $this->body = $obj->body;
309 $this->bgcolor = $obj->bgcolor;
310 $this->bgimage = $obj->bgimage;
312 $this->email_from = $obj->email_from;
313 $this->email_replyto = $obj->email_replyto;
314 $this->email_errorsto = $obj->email_errorsto;
316 $this->user_creat = $obj->fk_user_creat;
317 $this->user_valid = $obj->fk_user_valid;
319 $this->date_creat = $this->
db->jdate($obj->date_creat);
320 $this->date_valid = $this->
db->jdate($obj->date_valid);
321 $this->date_envoi = $this->
db->jdate($obj->date_envoi);
323 $this->extraparams = (array) json_decode($obj->extraparams,
true);
327 dol_syslog(get_class($this).
"::fetch Erreur -1");
331 dol_syslog(get_class($this).
"::fetch Erreur -2");
357 $object->fetch($fromid);
365 if (empty($option1)) {
367 $object->nbemail = 0;
370 $object->bgcolor =
'';
371 $object->bgimage =
'';
374 $object->email_replyto =
'';
375 $object->email_errorsto =
'';
377 $object->user_creat = $user->id;
378 $object->user_valid =
'';
380 $object->date_creat =
'';
381 $object->date_valid =
'';
382 $object->date_envoi =
'';
386 $object->context[
'createfromclone'] =
'createfromclone';
387 $result = $object->create($user);
391 $this->error = $object->error;
392 $this->errors = array_merge($this->errors, $object->errors);
398 if (!empty($option2)) {
399 require_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
403 $target_array = array();
405 $sql =
"SELECT fk_contact,";
406 $sql .=
" lastname,";
407 $sql .=
" firstname,";
410 $sql .=
" source_url,";
411 $sql .=
" source_id ,";
412 $sql .=
" source_type";
413 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
414 $sql .=
" WHERE fk_mailing = ".$fromid;
416 $result = $this->
db->query($sql);
418 if ($this->
db->num_rows($result)) {
419 while ($obj = $this->
db->fetch_object($result)) {
420 $target_array[] = array(
421 'fk_contact'=>$obj->fk_contact,
422 'lastname'=>$obj->lastname,
423 'firstname'=>$obj->firstname,
424 'email'=>$obj->email,
425 'other'=>$obj->other,
426 'source_url'=>$obj->source_url,
427 'source_id'=>$obj->source_id,
428 'source_type'=>$obj->source_type
433 $this->error = $this->
db->lasterror();
437 $mailing_target->addTargetsToDatabase($object->id, $target_array);
441 unset($object->context[
'createfromclone']);
448 $this->
db->rollback();
463 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing ";
464 $sql .=
" SET statut = 1, date_valid = '".$this->db->idate($now).
"', fk_user_valid=".$user->id;
465 $sql .=
" WHERE rowid = ".$this->id;
468 if ($this->
db->query($sql)) {
471 $this->error = $this->
db->lasterror();
483 public function delete($rowid)
485 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing";
486 $sql .=
" WHERE rowid = ".$rowid;
493 $this->error = $this->
db->lasterror();
507 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
508 $sql .=
" WHERE fk_mailing = ".$this->id;
510 dol_syslog(
"Mailing::delete_targets", LOG_DEBUG);
517 $this->error = $this->
db->lasterror();
533 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"mailing_cibles";
534 $sql .=
" SET statut = 0";
535 $sql .=
" WHERE fk_mailing = ".$this->id;
537 dol_syslog(
"Mailing::reset_targets_status", LOG_DEBUG);
542 $this->error = $this->
db->lasterror();
556 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
557 $sql .=
" WHERE fk_mailing = ".$this->id;
558 if ($mode ==
'alreadysent') {
559 $sql .=
" AND statut <> 0";
560 } elseif ($mode ==
'alreadysentok') {
561 $sql .=
" AND statut > 0";
562 } elseif ($mode ==
'alreadysentko') {
563 $sql .=
" AND statut = -1";
565 $this->error =
'BadValueForParameterMode';
571 $obj = $this->
db->fetch_object(
$resql);
576 $this->error = $this->
db->lasterror();
590 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_cibles";
591 $sql .=
" WHERE fk_mailing = ".$this->id;
595 $obj = $this->
db->fetch_object(
$resql);
597 $nbforupdate = $obj->nb;
599 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'mailing SET nbemail = '.((int) $nbforupdate);
600 $sql .=
' WHERE rowid = '.$this->id;
602 $resqlupdate = $this->
db->query($sql);
603 if (! $resqlupdate) {
604 $this->error = $this->
db->lasterror();
607 $this->nbemail = (int) $nbforupdate;
611 $this->error = $this->
db->lasterror();
628 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
630 global $db, $conf, $langs, $hookmanager;
631 global $dolibarr_main_authentication, $dolibarr_main_demo;
634 if (!empty($conf->dol_no_mouse_hover)) {
641 $label =
'<u>'.$langs->trans(
"ShowEMailing").
'</u>';
643 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
645 $url = DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$this->id;
647 if ($option !=
'nolink') {
649 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
650 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) {
651 $add_save_lastsearch_values = 1;
653 if ($add_save_lastsearch_values) {
654 $url .=
'&save_lastsearch_values=1';
659 if (empty($notooltip)) {
660 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
661 $label = $langs->trans(
"ShowEMailing");
662 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
664 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
665 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
674 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
677 $linkstart =
'<a href="'.$url.
'"';
678 $linkstart .= $linkclose.
'>';
681 $result .= $linkstart;
683 $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);
685 if ($withpicto != 2) {
686 $result .= $this->ref;
692 $hookmanager->initHooks(array(
'emailingdao'));
693 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
694 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
696 $result = $hookmanager->resPrint;
698 $result .= $hookmanager->resPrint;
727 $langs->load(
"mailing");
729 $labelStatus = $langs->trans($this->statuts[$status]);
730 $labelStatusShort = $langs->trans($this->statuts[$status]);
732 $statusType =
'status'.$status;
734 $statusType =
'status3';
737 $statusType =
'status6';
740 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
756 $langs->load(
"mails");
758 $labelStatus = array();
759 $labelStatusShort = array();
761 $labelStatus[-1] = $langs->trans(
'MailingStatusError');
762 $labelStatus[0] = $langs->trans(
'MailingStatusNotSent');
763 $labelStatus[1] = $langs->trans(
'MailingStatusSent');
764 $labelStatus[2] = $langs->trans(
'MailingStatusRead');
765 $labelStatus[3] = $langs->trans(
'MailingStatusNotContact');
766 $labelStatusShort[-1] = $langs->trans(
'MailingStatusError');
767 $labelStatusShort[0] = $langs->trans(
'MailingStatusNotSent');
768 $labelStatusShort[1] = $langs->trans(
'MailingStatusSent');
769 $labelStatusShort[2] = $langs->trans(
'MailingStatusRead');
770 $labelStatusShort[3] = $langs->trans(
'MailingStatusNotContact');
772 $statusType =
'status'.$status;
774 $statusType =
'status8';
777 $statusType =
'status6';
780 $statusType =
'status4';
784 if ($status == - 1) {
785 $param = array(
'badgeParams'=>array(
'attr'=>array(
'title'=>$desc)));
787 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'', $statusType, $mode,
'', $param);
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
getLibStatut($mode=0)
Return label of status of emailing (draft, validated, ...)
createFromClone(User $user, $fromid, $option1, $option2)
Load an object from its id and create a new one in database.
update($user)
Update emailing record.
delete_targets()
Delete targets emailing.
dol_html_entity_decode($a, $b, $c= 'UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
$conf db
API class for accounts.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
countNbOfTargets($mode)
Count number of target with status.
valid($user)
Validate emailing.
refreshNbOfTargets()
Refresh denormalized value ->nbemail into emailing record Note: There is also the method update_nb in...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage emailings module.
reset_targets_status($user)
Change status of each recipient.
fetch($rowid)
Get object from database.
__construct($db)
Constructor.
print $_SERVER["PHP_SELF"]
Edit parameters.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
create($user)
Create an EMailing.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
static libStatutDest($status, $mode=0, $desc= '')
Renvoi le libelle d'un statut donne TODO Add class mailin_target.class.php.
Parent class of emailing target selectors modules.
dol_textishtml($msg, $option=0)
Return if a text is a html content.