dolibarr 21.0.3
mailing.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29
30
34class Mailing extends CommonObject
35{
39 public $element = 'mailing';
40
44 public $table_element = 'mailing';
45
49 public $picto = 'email';
50
54 public $messtype;
55
59 public $title;
60
64 public $sujet;
65
69 public $body;
70
74 public $evenunsubscribe;
75
79 public $note_public;
80
84 public $note_private;
85
89 public $nbemail;
90
94 public $bgcolor;
95
99 public $bgimage;
100
105 public $statut; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
106
110 public $status; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
111
115 public $email_from;
116
120 public $sendto;
121
125 public $email_replyto;
126
130 public $email_errorsto;
131
135 public $joined_file1;
136
140 public $joined_file2;
141
145 public $joined_file3;
146
150 public $joined_file4;
151
155 public $date_envoi;
156
160 public $extraparams = array();
161
165 public $statut_dest = array();
166
170 public $substitutionarray;
171
175 public $substitutionarrayfortest;
176
177 const STATUS_DRAFT = 0;
178 const STATUS_VALIDATED = 1;
179 const STATUS_SENTPARTIALY = 2;
180 const STATUS_SENTCOMPLETELY = 3;
181
182
188 public function __construct($db)
189 {
190 $this->db = $db;
191
192 // List of language codes for status
193 $this->labelStatus[0] = 'MailingStatusDraft';
194 $this->labelStatus[1] = 'MailingStatusValidated';
195 $this->labelStatus[2] = 'MailingStatusSentPartialy';
196 $this->labelStatus[3] = 'MailingStatusSentCompletely';
197
198 $this->statut_dest[0] = 'MailingStatusNotSent';
199 $this->statut_dest[1] = 'MailingStatusSent';
200 $this->statut_dest[2] = 'MailingStatusRead';
201 $this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe'; // Read but ask to not be contacted anymore
202 $this->statut_dest[-1] = 'MailingStatusError';
203 }
204
212 public function create($user, $notrigger = 0)
213 {
214 global $conf, $langs;
215
216 // Check properties
217 if (preg_match('/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
218 $this->error = 'InvalidHTMLStringCantBeCleaned';
219 return -1;
220 }
221
222 $this->title = trim($this->title);
223 $this->email_from = trim($this->email_from);
224
225 if (!$this->email_from) {
226 if ($this->messtype !== 'sms') {
227 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailFrom"));
228 } else {
229 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PhoneFrom"));
230 }
231 return -1;
232 }
233
234 $error = 0;
235 $now = dol_now();
236
237 $this->db->begin();
238
239 $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing";
240 $sql .= " (date_creat, fk_user_creat, entity)";
241 $sql .= " VALUES ('".$this->db->idate($now)."', ".((int) $user->id).", ".((int) $conf->entity).")";
242
243 if (!$this->title) {
244 $this->title = $langs->trans("NoTitle");
245 }
246
247 dol_syslog(__METHOD__, LOG_DEBUG);
248
249 $resql = $this->db->query($sql);
250 if ($resql) {
251 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
252
253 $result = $this->update($user, 1);
254 if ($result < 0) {
255 $error++;
256 }
257
258 if (!$error && !$notrigger) {
259 // Call trigger
260 $result = $this->call_trigger('MAILING_CREATE', $user);
261 if ($result < 0) {
262 $error++;
263 }
264 // End call triggers
265 }
266
267 if (!$error) {
268 $this->db->commit();
269 return $this->id;
270 } else {
271 $this->db->rollback();
272 dol_syslog(__METHOD__ . ' ' . $this->error, LOG_ERR);
273 return -2;
274 }
275 } else {
276 $this->error = $this->db->lasterror();
277 $this->db->rollback();
278 return -1;
279 }
280 }
281
289 public function update($user, $notrigger = 0)
290 {
291 global $langs;
292
293 // Check properties
294 if (preg_match('/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
295 $this->error = 'InvalidHTMLStringCantBeCleaned';
296 return -1;
297 }
298
299 $error = 0;
300 $this->db->begin();
301
302 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
303 $sql .= " SET titre = '".$this->db->escape($this->title)."'";
304 $sql .= ", messtype = '".$this->db->escape($this->messtype)."'";
305 $sql .= ", sujet = '".$this->db->escape($this->sujet)."'";
306 $sql .= ", body = '".$this->db->escape($this->body)."'";
307 $sql .= ", email_from = '".$this->db->escape($this->email_from)."'";
308 $sql .= ", email_replyto = '".$this->db->escape($this->email_replyto)."'";
309 $sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
310 $sql .= ", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) : null)."'";
311 $sql .= ", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) : null)."'";
312 $sql .= ", evenunsubscribe = ".((int) $this->evenunsubscribe);
313 $sql .= ", note_public = '".$this->db->escape($this->note_public)."'";
314 $sql .= ", note_private = '".$this->db->escape($this->note_private)."'";
315 $sql .= " WHERE rowid = ".(int) $this->id;
316
317 dol_syslog(__METHOD__, LOG_DEBUG);
318 $resql = $this->db->query($sql);
319 if ($resql) {
320 if (!$error && !$notrigger) {
321 // Call trigger
322 $result = $this->call_trigger('MAILING_MODIFY', $user);
323 if ($result < 0) {
324 $error++;
325 }
326 // End call triggers
327 }
328
329 if (!$error) {
330 dol_syslog(__METHOD__ . ' success');
331 $this->db->commit();
332 return 1;
333 } else {
334 $this->db->rollback();
335 dol_syslog(__METHOD__ . ' ' . $this->error, LOG_ERR);
336 return -2;
337 }
338 } else {
339 if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
340 $this->error = $langs->trans("ErrorTitleAlreadyExists", $this->title);
341 } else {
342 $this->error = $this->db->lasterror();
343 }
344 $this->db->rollback();
345 return -1;
346 }
347 }
348
356 public function fetch($rowid, $ref = '')
357 {
358 $sql = "SELECT m.rowid, m.messtype, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe";
359 $sql .= ", m.note_public, m.note_private";
360 $sql .= ", m.email_from, m.email_replyto, m.email_errorsto";
361 $sql .= ", m.statut as status, m.nbemail";
362 $sql .= ", m.fk_user_creat, m.fk_user_valid";
363 $sql .= ", m.date_creat";
364 $sql .= ", m.date_valid";
365 $sql .= ", m.date_envoi";
366 $sql .= ", m.extraparams";
367 $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
368 $sql .= " WHERE entity IN (".getEntity('mailing').")";
369 if ($ref) {
370 $sql .= " AND m.titre = '".$this->db->escape($ref)."'";
371 } else {
372 $sql .= " AND m.rowid = ".(int) $rowid;
373 }
374
375 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
376 $result = $this->db->query($sql);
377 if ($result) {
378 if ($this->db->num_rows($result)) {
379 $obj = $this->db->fetch_object($result);
380
381 $this->id = $obj->rowid;
382 $this->ref = $obj->rowid;
383 $this->title = $obj->title;
384 $this->messtype = $obj->messtype;
385
386 $this->statut = $obj->status; // deprecated
387 $this->status = $obj->status;
388
389 $this->nbemail = $obj->nbemail;
390
391 $this->sujet = $obj->sujet;
392 if (getDolGlobalString('FCKEDITOR_ENABLE_MAILING') && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5))) {
393 $this->body = dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5);
394 } else {
395 $this->body = $obj->body;
396 }
397
398 $this->bgcolor = $obj->bgcolor;
399 $this->bgimage = $obj->bgimage;
400 $this->evenunsubscribe = $obj->evenunsubscribe;
401 $this->note_public = $obj->note_public;
402 $this->note_private = $obj->note_private;
403
404 $this->email_from = $obj->email_from;
405 $this->email_replyto = $obj->email_replyto;
406 $this->email_errorsto = $obj->email_errorsto;
407
408 $this->user_creation_id = $obj->fk_user_creat;
409 $this->user_validation_id = $obj->fk_user_valid;
410
411 $this->date_creation = $this->db->jdate($obj->date_creat);
412 $this->date_validation = $this->db->jdate($obj->date_valid);
413 $this->date_envoi = $this->db->jdate($obj->date_envoi);
414
415 $this->extraparams = (array) json_decode($obj->extraparams, true);
416
417 if ($this->messtype == 'sms') {
418 $this->picto = 'phone';
419 }
420
421 return 1;
422 } else {
423 dol_syslog(get_class($this)."::fetch Erreur -1");
424 return -1;
425 }
426 } else {
427 dol_syslog(get_class($this)."::fetch Erreur -2");
428 return -2;
429 }
430 }
431
432
442 public function createFromClone(User $user, $fromid, $option1, $option2)
443 {
444 global $langs;
445
446 $error = 0;
447
448 $object = new Mailing($this->db);
449
450 $this->db->begin();
451
452 // Load source object
453 $object->fetch($fromid);
454 $object->id = 0;
455 $object->status = 0;
456 $object->statut = 0;
457
458 // Clear fields
459 $object->title = $langs->trans("CopyOf").' '.$object->title.' '.dol_print_date(dol_now());
460
461 // If no option copy content
462 if (empty($option1)) {
463 // Clear values
464 $object->nbemail = 0;
465 $object->sujet = '';
466 $object->body = '';
467 $object->bgcolor = '';
468 $object->bgimage = '';
469 $object->evenunsubscribe = 0;
470 $object->note_public = '';
471 $object->note_private = '';
472
473 //$object->email_from = ''; // We do not reset from email because it is a mandatory value
474 $object->email_replyto = '';
475 $object->email_errorsto = '';
476
477 $object->user_creation_id = $user->id;
478 $object->user_validation_id = null;
479
480 $object->date_envoi = null;
481 }
482
483 // Create clone
484 $object->context['createfromclone'] = 'createfromclone';
485 $result = $object->create($user);
486
487 // Other options
488 if ($result < 0) {
489 $this->error = $object->error;
490 $this->errors = array_merge($this->errors, $object->errors);
491 $error++;
492 }
493
494 if (!$error) {
495 // Clone recipient targets
496 if (!empty($option2)) {
497 require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
498
499 $mailing_target = new MailingTargets($this->db);
500
501 $target_array = array();
502
503 $sql = "SELECT fk_contact,";
504 $sql .= " lastname,";
505 $sql .= " firstname,";
506 $sql .= " email,";
507 $sql .= " other,";
508 $sql .= " source_url,";
509 $sql .= " source_id ,";
510 $sql .= " source_type";
511 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles";
512 $sql .= " WHERE fk_mailing = ".((int) $fromid);
513
514 $result = $this->db->query($sql);
515 if ($result) {
516 if ($this->db->num_rows($result)) {
517 while ($obj = $this->db->fetch_object($result)) {
518 $target_array[] = array(
519 'fk_contact' => $obj->fk_contact,
520 'lastname' => $obj->lastname,
521 'firstname' => $obj->firstname,
522 'email' => $obj->email,
523 'other' => $obj->other,
524 'source_url' => $obj->source_url,
525 'source_id' => $obj->source_id,
526 'source_type' => $obj->source_type
527 );
528 }
529 }
530 } else {
531 $this->error = $this->db->lasterror();
532 return -1;
533 }
534
535 $mailing_target->addTargetsToDatabase($object->id, $target_array);
536 }
537 }
538
539 unset($object->context['createfromclone']);
540
541 // End
542 if (!$error) {
543 $this->db->commit();
544 return $object->id;
545 } else {
546 $this->db->rollback();
547 return -1;
548 }
549 }
550
557 public function valid($user)
558 {
559 $now = dol_now();
560
561 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
562 $sql .= " SET statut = 1, date_valid = '".$this->db->idate($now)."', fk_user_valid=".$user->id;
563 $sql .= " WHERE rowid = ".((int) $this->id);
564
565 dol_syslog("Mailing::valid", LOG_DEBUG);
566 if ($this->db->query($sql)) {
567 return 1;
568 } else {
569 $this->error = $this->db->lasterror();
570 return -1;
571 }
572 }
573
574
582 public function delete($user, $notrigger = 0)
583 {
584 $error = 0;
585
586 $this->db->begin();
587
588 if (!$notrigger) {
589 $result = $this->call_trigger('MAILING_DELETE', $user);
590 if ($result < 0) {
591 $error++;
592 }
593 }
594
595 if (!$error) {
596 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "mailing";
597 $sql .= " WHERE rowid = " . ((int) $this->id);
598
599 dol_syslog(__METHOD__, LOG_DEBUG);
600 $resql = $this->db->query($sql);
601 if ($resql) {
602 $res = $this->delete_targets();
603 if ($res <= 0) {
604 $error++;
605 }
606
607 if (!$error) {
608 dol_syslog(__METHOD__ . ' success');
609 $this->db->commit();
610 return 1;
611 } else {
612 $this->db->rollback();
613 dol_syslog(__METHOD__ . ' ' . $this->error, LOG_ERR);
614 return -2;
615 }
616 } else {
617 $this->db->rollback();
618 $this->error = $this->db->lasterror();
619 return -1;
620 }
621 } else {
622 $this->db->rollback();
623 return -1;
624 }
625 }
626
627 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
633 public function delete_targets()
634 {
635 // phpcs:enable
636 $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
637 $sql .= " WHERE fk_mailing = ".((int) $this->id);
638
639 dol_syslog("Mailing::delete_targets", LOG_DEBUG);
640 $resql = $this->db->query($sql);
641 if ($resql) {
642 $this->refreshNbOfTargets();
643
644 return 1;
645 } else {
646 $this->error = $this->db->lasterror();
647 return 0;
648 }
649 }
650
651
652 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
659 public function reset_targets_status($user)
660 {
661 // phpcs:enable
662 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
663 $sql .= " SET statut = 0";
664 $sql .= " WHERE fk_mailing = ".((int) $this->id);
665
666 dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
667 $resql = $this->db->query($sql);
668 if ($resql) {
669 return 1;
670 } else {
671 $this->error = $this->db->lasterror();
672 return -1;
673 }
674 }
675
683 public function resetTargetErrorStatus($user, $id)
684 {
685 // phpcs:enable
686 global $langs;
687
688 $sql = "SELECT email, statut FROM ".MAIN_DB_PREFIX."mailing_cibles";
689 $sql .= " WHERE fk_mailing = ".((int) $this->id);
690 $sql .= " AND rowid = ".((int) $id);
691 $resql = $this->db->query($sql);
692 if ($resql) {
693 $nb = $this->db->num_rows($resql);
694 $obj = $this->db->fetch_object($resql);
695 if ($obj->statut != -1) {
696 $langs->load("errors");
697 $this->error = $langs->trans('ErrorIsNotInError', $obj->email);
698 return 0;
699 }
700 } else {
701 $this->error = $this->db->lasterror();
702 }
703
704 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
705 $sql .= " SET statut = 0";
706 $sql .= " WHERE fk_mailing = ".((int) $this->id);
707 $sql .= " AND rowid = ".((int) $id);
708 $sql .= " AND statut = -1";
709
710 dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
711 $resql = $this->db->query($sql);
712 if ($resql) {
713 return 1;
714 } else {
715 $this->error = $this->db->lasterror();
716 return -1;
717 }
718 }
719
726 public function countNbOfTargets($mode)
727 {
728 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
729 $sql .= " WHERE fk_mailing = ".((int) $this->id);
730 if ($mode == 'alreadysent') {
731 $sql .= " AND statut <> 0";
732 } elseif ($mode == 'alreadysentok') {
733 $sql .= " AND statut > 0";
734 } elseif ($mode == 'alreadysentko') {
735 $sql .= " AND statut = -1";
736 } else {
737 $this->error = 'BadValueForParameterMode';
738 return -2;
739 }
740
741 $resql = $this->db->query($sql);
742 if ($resql) {
743 $obj = $this->db->fetch_object($resql);
744 if ($obj) {
745 return $obj->nb;
746 }
747 } else {
748 $this->error = $this->db->lasterror();
749 return -1;
750 }
751 return 0;
752 }
753
760 public function refreshNbOfTargets()
761 {
762 $sql = "SELECT COUNT(rowid) as nb";
763 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles";
764 $sql .= " WHERE fk_mailing = ".((int) $this->id);
765
766 $resql = $this->db->query($sql);
767 if ($resql) {
768 $obj = $this->db->fetch_object($resql);
769 if ($obj) {
770 $nbforupdate = $obj->nb;
771
772 $sql = 'UPDATE '.MAIN_DB_PREFIX.'mailing SET nbemail = '.((int) $nbforupdate);
773 $sql .= ' WHERE rowid = '.((int) $this->id);
774
775 $resqlupdate = $this->db->query($sql);
776 if (! $resqlupdate) {
777 $this->error = $this->db->lasterror();
778 return -1;
779 } else {
780 $this->nbemail = (int) $nbforupdate;
781 }
782 }
783 } else {
784 $this->error = $this->db->lasterror();
785 return -1;
786 }
787
788 return 1;
789 }
790
797 public function getTooltipContentArray($params)
798 {
799 global $langs;
800
801 //$nofetch = !empty($params['nofetch']);
802 $langs->load('mails');
803
804 $datas = array();
805 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ShowEMailing").'</u>';
806 if (isset($this->status)) {
807 $datas['picto'] .= ' '.$this->getLibStatut(5);
808 }
809 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
810 if (isset($this->title)) {
811 $datas['title'] = '<br><b>'.$langs->trans('MailTitle').':</b> '.$this->title;
812 }
813 if (isset($this->sujet)) {
814 $datas['subject'] = '<br><b>'.$langs->trans('MailTopic').':</b> '.$this->sujet;
815 }
816
817 return $datas;
818 }
819
830 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
831 {
832 global $conf, $langs, $hookmanager;
833
834 if (!empty($conf->dol_no_mouse_hover)) {
835 $notooltip = 1; // Force disable tooltips
836 }
837
838 $result = '';
839 $params = [
840 'id' => $this->id,
841 'objecttype' => $this->element,
842 'option' => $option,
843 'nofetch' => 1,
844 ];
845 $classfortooltip = 'classfortooltip';
846 $dataparams = '';
847 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
848 $classfortooltip = 'classforajaxtooltip';
849 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
850 $label = '';
851 } else {
852 $label = implode($this->getTooltipContentArray($params));
853 }
854
855 $url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
856
857 if ($option != 'nolink') {
858 // Add param to save lastsearch_values or not
859 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
860 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
861 $add_save_lastsearch_values = 1;
862 }
863 if ($add_save_lastsearch_values) {
864 $url .= '&save_lastsearch_values=1';
865 }
866 }
867
868 $linkclose = '';
869 if (empty($notooltip)) {
870 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
871 $label = $langs->trans("ShowEMailing");
872 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
873 }
874 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
875 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
876 } else {
877 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
878 }
879
880 $linkstart = '<a href="'.$url.'"';
881 $linkstart .= $linkclose.'>';
882 $linkend = '</a>';
883
884 $result .= $linkstart;
885 if ($withpicto) {
886 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
887 }
888 if ($withpicto != 2) {
889 $result .= $this->ref;
890 }
891 $result .= $linkend;
892 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
893
894 global $action;
895 $hookmanager->initHooks(array('emailingdao'));
896 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
897 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
898 if ($reshook > 0) {
899 $result = $hookmanager->resPrint;
900 } else {
901 $result .= $hookmanager->resPrint;
902 }
903
904 return $result;
905 }
906
913 public function getLibStatut($mode = 0)
914 {
915 return $this->LibStatut($this->status, $mode);
916 }
917
918 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
926 public function LibStatut($status, $mode = 0)
927 {
928 // phpcs:enable
929 global $langs;
930 $langs->load("mailing");
931
932 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
933 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
934
935 $statusType = 'status'.$status;
936 if ($status == 2) {
937 $statusType = 'status3';
938 }
939 if ($status == 3) {
940 $statusType = 'status6';
941 }
942
943 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
944 }
945
946
956 public static function libStatutDest($status, $mode = 0, $desc = '')
957 {
958 global $langs;
959 $langs->load("mails");
960
961 $labelStatus = array();
962 $labelStatusShort = array();
963
964 $labelStatus[-1] = $langs->transnoentitiesnoconv('MailingStatusError');
965 $labelStatus[0] = $langs->transnoentitiesnoconv('MailingStatusNotSent');
966 $labelStatus[1] = $langs->transnoentitiesnoconv('MailingStatusSent');
967 $labelStatus[2] = $langs->transnoentitiesnoconv('MailingStatusRead');
968 $labelStatus[3] = $langs->transnoentitiesnoconv('MailingStatusNotContact');
969 $labelStatusShort[-1] = $langs->transnoentitiesnoconv('MailingStatusError');
970 $labelStatusShort[0] = $langs->transnoentitiesnoconv('MailingStatusNotSent');
971 $labelStatusShort[1] = $langs->transnoentitiesnoconv('MailingStatusSent');
972 $labelStatusShort[2] = $langs->transnoentitiesnoconv('MailingStatusRead');
973 $labelStatusShort[3] = $langs->transnoentitiesnoconv('MailingStatusNotContact');
974
975 $statusType = 'status'.$status;
976 if ($status == -1) {
977 $statusType = 'status8';
978 }
979 if ($status == 1) {
980 $statusType = 'status6';
981 }
982 if ($status == 2) {
983 $statusType = 'status4';
984 }
985
986 $param = array();
987 if ($status == -1) {
988 $param = array('badgeParams' => array('attr' => array('title' => $desc)));
989 }
990
991 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode, '', $param);
992 }
993}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
$object ref
Definition info.php:89
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.
resetTargetErrorStatus($user, $id)
Reset status of a specific recipient in error.
LibStatut($status, $mode=0)
Return the label of a given status.
Parent class of emailing target selectors modules.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (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).
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79