dolibarr 22.0.5
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 = 'email';
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 if (empty($this->messtype)) {
225 $this->messtype = 'email';
226 }
227 if (!$this->email_from) {
228 if ($this->messtype !== 'sms') {
229 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailFrom"));
230 } else {
231 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PhoneFrom"));
232 }
233 return -1;
234 }
235
236 $error = 0;
237 $now = dol_now();
238
239 $this->db->begin();
240
241 $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing";
242 $sql .= " (messtype, date_creat, fk_user_creat, entity)";
243 $sql .= " VALUES ('".$this->db->escape($this->messtype)."', '".$this->db->idate($now)."', ".((int) $user->id).", ".((int) $conf->entity).")";
244
245 if (!$this->title) {
246 $this->title = $langs->trans("NoTitle");
247 }
248
249 dol_syslog(__METHOD__, LOG_DEBUG);
250
251 $resql = $this->db->query($sql);
252 if ($resql) {
253 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
254
255 $result = $this->update($user, 1);
256 if ($result < 0) {
257 $error++;
258 }
259
260 if (!$error && !$notrigger) {
261 // Call trigger
262 $result = $this->call_trigger('MAILING_CREATE', $user);
263 if ($result < 0) {
264 $error++;
265 }
266 // End call triggers
267 }
268
269 if (!$error) {
270 $this->db->commit();
271 return $this->id;
272 } else {
273 $this->db->rollback();
274 dol_syslog(__METHOD__ . ' ' . $this->error, LOG_ERR);
275 return -2;
276 }
277 } else {
278 $this->error = $this->db->lasterror();
279 $this->db->rollback();
280 return -1;
281 }
282 }
283
291 public function update($user, $notrigger = 0)
292 {
293 global $langs;
294
295 // Check properties
296 if (preg_match('/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
297 $this->error = 'InvalidHTMLStringCantBeCleaned';
298 return -1;
299 }
300
301 if (empty($this->messtype)) {
302 $this->messtype = 'email';
303 }
304
305 $error = 0;
306 $this->db->begin();
307
308 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
309 $sql .= " SET titre = '".$this->db->escape($this->title)."'";
310 $sql .= ", messtype = '".$this->db->escape($this->messtype)."'";
311 $sql .= ", sujet = '".$this->db->escape($this->sujet)."'";
312 $sql .= ", body = '".$this->db->escape($this->body)."'";
313 $sql .= ", email_from = '".$this->db->escape($this->email_from)."'";
314 $sql .= ", email_replyto = '".$this->db->escape($this->email_replyto)."'";
315 $sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
316 $sql .= ", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) : null)."'";
317 $sql .= ", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) : null)."'";
318 $sql .= ", evenunsubscribe = ".((int) $this->evenunsubscribe);
319 $sql .= ", note_public = '".$this->db->escape($this->note_public)."'";
320 $sql .= ", note_private = '".$this->db->escape($this->note_private)."'";
321 $sql .= " WHERE rowid = ".(int) $this->id;
322
323 dol_syslog(__METHOD__, LOG_DEBUG);
324 $resql = $this->db->query($sql);
325 if ($resql) {
326 if (!$error && !$notrigger) {
327 // Call trigger
328 $result = $this->call_trigger('MAILING_MODIFY', $user);
329 if ($result < 0) {
330 $error++;
331 }
332 // End call triggers
333 }
334
335 if (!$error) {
336 dol_syslog(__METHOD__ . ' success');
337 $this->db->commit();
338 return 1;
339 } else {
340 $this->db->rollback();
341 dol_syslog(__METHOD__ . ' ' . $this->error, LOG_ERR);
342 return -2;
343 }
344 } else {
345 if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
346 $this->error = $langs->trans("ErrorTitleAlreadyExists", $this->title);
347 } else {
348 $this->error = $this->db->lasterror();
349 }
350 $this->db->rollback();
351 return -1;
352 }
353 }
354
362 public function fetch($rowid, $ref = '')
363 {
364 $sql = "SELECT m.rowid, m.messtype, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe";
365 $sql .= ", m.note_public, m.note_private";
366 $sql .= ", m.email_from, m.email_replyto, m.email_errorsto";
367 $sql .= ", m.statut as status, m.nbemail";
368 $sql .= ", m.fk_user_creat, m.fk_user_valid";
369 $sql .= ", m.date_creat";
370 $sql .= ", m.date_valid";
371 $sql .= ", m.date_envoi";
372 $sql .= ", m.extraparams";
373 $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
374 $sql .= " WHERE entity IN (".getEntity('mailing').")";
375 if ($ref) {
376 $sql .= " AND m.titre = '".$this->db->escape($ref)."'";
377 } else {
378 $sql .= " AND m.rowid = ".(int) $rowid;
379 }
380
381 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
382 $result = $this->db->query($sql);
383 if ($result) {
384 if ($this->db->num_rows($result)) {
385 $obj = $this->db->fetch_object($result);
386
387 $this->id = $obj->rowid;
388 $this->ref = $obj->rowid;
389 $this->title = $obj->title;
390 $this->messtype = $obj->messtype;
391
392 $this->statut = $obj->status; // deprecated
393 $this->status = $obj->status;
394
395 $this->nbemail = $obj->nbemail;
396
397 $this->sujet = $obj->sujet;
398 if (getDolGlobalString('FCKEDITOR_ENABLE_MAILING') && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5))) {
399 $this->body = dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5);
400 } else {
401 $this->body = $obj->body;
402 }
403
404 $this->bgcolor = $obj->bgcolor;
405 $this->bgimage = $obj->bgimage;
406 $this->evenunsubscribe = $obj->evenunsubscribe;
407 $this->note_public = $obj->note_public;
408 $this->note_private = $obj->note_private;
409
410 $this->email_from = $obj->email_from;
411 $this->email_replyto = $obj->email_replyto;
412 $this->email_errorsto = $obj->email_errorsto;
413
414 $this->user_creation_id = $obj->fk_user_creat;
415 $this->user_validation_id = $obj->fk_user_valid;
416
417 $this->date_creation = $this->db->jdate($obj->date_creat);
418 $this->date_validation = $this->db->jdate($obj->date_valid);
419 $this->date_envoi = $this->db->jdate($obj->date_envoi);
420
421 $this->extraparams = (array) json_decode($obj->extraparams, true);
422
423 if ($this->messtype == 'sms') {
424 $this->picto = 'phone';
425 }
426
427 return 1;
428 } else {
429 dol_syslog(get_class($this)."::fetch Erreur -1");
430 return -1;
431 }
432 } else {
433 dol_syslog(get_class($this)."::fetch Erreur -2");
434 return -2;
435 }
436 }
437
438
448 public function createFromClone(User $user, $fromid, $option1, $option2)
449 {
450 global $langs;
451
452 $error = 0;
453
454 $object = new Mailing($this->db);
455
456 $this->db->begin();
457
458 // Load source object
459 $object->fetch($fromid);
460 $object->id = 0;
461 $object->status = 0;
462 $object->statut = 0;
463
464 // Clear fields
465 $object->title = $langs->trans("CopyOf").' '.$object->title.' '.dol_print_date(dol_now());
466
467 // If no option copy content
468 if (empty($option1)) {
469 // Clear values
470 $object->nbemail = 0;
471 $object->sujet = '';
472 $object->body = '';
473 $object->bgcolor = '';
474 $object->bgimage = '';
475 $object->evenunsubscribe = 0;
476 $object->note_public = '';
477 $object->note_private = '';
478
479 //$object->email_from = ''; // We do not reset from email because it is a mandatory value
480 $object->email_replyto = '';
481 $object->email_errorsto = '';
482
483 $object->user_creation_id = $user->id;
484 $object->user_validation_id = null;
485
486 $object->date_envoi = null;
487 }
488
489 // Create clone
490 $object->context['createfromclone'] = 'createfromclone';
491 $result = $object->create($user);
492
493 // Other options
494 if ($result < 0) {
495 $this->error = $object->error;
496 $this->errors = array_merge($this->errors, $object->errors);
497 $error++;
498 }
499
500 if (!$error) {
501 // Clone recipient targets
502 if (!empty($option2)) {
503 require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
504
505 $mailing_target = new MailingTargets($this->db);
506
507 $target_array = array();
508
509 $sql = "SELECT fk_contact,";
510 $sql .= " lastname,";
511 $sql .= " firstname,";
512 $sql .= " email,";
513 $sql .= " other,";
514 $sql .= " source_url,";
515 $sql .= " source_id ,";
516 $sql .= " source_type";
517 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles";
518 $sql .= " WHERE fk_mailing = ".((int) $fromid);
519
520 $result = $this->db->query($sql);
521 if ($result) {
522 if ($this->db->num_rows($result)) {
523 while ($obj = $this->db->fetch_object($result)) {
524 $target_array[] = array(
525 'fk_contact' => $obj->fk_contact,
526 'lastname' => $obj->lastname,
527 'firstname' => $obj->firstname,
528 'email' => $obj->email,
529 'other' => $obj->other,
530 'source_url' => $obj->source_url,
531 'source_id' => $obj->source_id,
532 'source_type' => $obj->source_type
533 );
534 }
535 }
536 } else {
537 $this->error = $this->db->lasterror();
538 return -1;
539 }
540
541 $mailing_target->addTargetsToDatabase($object->id, $target_array);
542 }
543 }
544
545 unset($object->context['createfromclone']);
546
547 // End
548 if (!$error) {
549 $this->db->commit();
550 return $object->id;
551 } else {
552 $this->db->rollback();
553 return -1;
554 }
555 }
556
563 public function valid($user)
564 {
565 $now = dol_now();
566
567 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
568 $sql .= " SET statut = 1, date_valid = '".$this->db->idate($now)."', fk_user_valid=".$user->id;
569 $sql .= " WHERE rowid = ".((int) $this->id);
570
571 dol_syslog("Mailing::valid", LOG_DEBUG);
572 if ($this->db->query($sql)) {
573 return 1;
574 } else {
575 $this->error = $this->db->lasterror();
576 return -1;
577 }
578 }
579
580
588 public function delete($user, $notrigger = 0)
589 {
590 $error = 0;
591
592 $this->db->begin();
593
594 if (!$notrigger) {
595 $result = $this->call_trigger('MAILING_DELETE', $user);
596 if ($result < 0) {
597 $error++;
598 }
599 }
600
601 if (!$error) {
602 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "mailing";
603 $sql .= " WHERE rowid = " . ((int) $this->id);
604
605 dol_syslog(__METHOD__, LOG_DEBUG);
606 $resql = $this->db->query($sql);
607 if ($resql) {
608 $res = $this->delete_targets();
609 if ($res <= 0) {
610 $error++;
611 }
612
613 if (!$error) {
614 dol_syslog(__METHOD__ . ' success');
615 $this->db->commit();
616 return 1;
617 } else {
618 $this->db->rollback();
619 dol_syslog(__METHOD__ . ' ' . $this->error, LOG_ERR);
620 return -2;
621 }
622 } else {
623 $this->db->rollback();
624 $this->error = $this->db->lasterror();
625 return -1;
626 }
627 } else {
628 $this->db->rollback();
629 return -1;
630 }
631 }
632
633 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
639 public function delete_targets()
640 {
641 // phpcs:enable
642 $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
643 $sql .= " WHERE fk_mailing = ".((int) $this->id);
644
645 dol_syslog("Mailing::delete_targets", LOG_DEBUG);
646 $resql = $this->db->query($sql);
647 if ($resql) {
648 $this->refreshNbOfTargets();
649
650 return 1;
651 } else {
652 $this->error = $this->db->lasterror();
653 return 0;
654 }
655 }
656
657
658 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
665 public function reset_targets_status($user)
666 {
667 // phpcs:enable
668 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
669 $sql .= " SET statut = 0";
670 $sql .= " WHERE fk_mailing = ".((int) $this->id);
671
672 dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
673 $resql = $this->db->query($sql);
674 if ($resql) {
675 return 1;
676 } else {
677 $this->error = $this->db->lasterror();
678 return -1;
679 }
680 }
681
689 public function resetTargetErrorStatus($user, $id)
690 {
691 // phpcs:enable
692 global $langs;
693
694 $sql = "SELECT email, statut FROM ".MAIN_DB_PREFIX."mailing_cibles";
695 $sql .= " WHERE fk_mailing = ".((int) $this->id);
696 $sql .= " AND rowid = ".((int) $id);
697 $resql = $this->db->query($sql);
698 if ($resql) {
699 $nb = $this->db->num_rows($resql);
700 $obj = $this->db->fetch_object($resql);
701 if ($obj->statut != -1) {
702 $langs->load("errors");
703 $this->error = $langs->trans('ErrorIsNotInError', $obj->email);
704 return 0;
705 }
706 } else {
707 $this->error = $this->db->lasterror();
708 }
709
710 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
711 $sql .= " SET statut = 0";
712 $sql .= " WHERE fk_mailing = ".((int) $this->id);
713 $sql .= " AND rowid = ".((int) $id);
714 $sql .= " AND statut = -1";
715
716 dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
717 $resql = $this->db->query($sql);
718 if ($resql) {
719 return 1;
720 } else {
721 $this->error = $this->db->lasterror();
722 return -1;
723 }
724 }
725
732 public function countNbOfTargets($mode)
733 {
734 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
735 $sql .= " WHERE fk_mailing = ".((int) $this->id);
736 if ($mode == 'alreadysent') {
737 $sql .= " AND statut <> 0";
738 } elseif ($mode == 'alreadysentok') {
739 $sql .= " AND statut > 0";
740 } elseif ($mode == 'alreadysentko') {
741 $sql .= " AND statut = -1";
742 } else {
743 $this->error = 'BadValueForParameterMode';
744 return -2;
745 }
746
747 $resql = $this->db->query($sql);
748 if ($resql) {
749 $obj = $this->db->fetch_object($resql);
750 if ($obj) {
751 return $obj->nb;
752 }
753 } else {
754 $this->error = $this->db->lasterror();
755 return -1;
756 }
757 return 0;
758 }
759
766 public function refreshNbOfTargets()
767 {
768 $sql = "SELECT COUNT(rowid) as nb";
769 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles";
770 $sql .= " WHERE fk_mailing = ".((int) $this->id);
771
772 $resql = $this->db->query($sql);
773 if ($resql) {
774 $obj = $this->db->fetch_object($resql);
775 if ($obj) {
776 $nbforupdate = $obj->nb;
777
778 $sql = 'UPDATE '.MAIN_DB_PREFIX.'mailing SET nbemail = '.((int) $nbforupdate);
779 $sql .= ' WHERE rowid = '.((int) $this->id);
780
781 $resqlupdate = $this->db->query($sql);
782 if (! $resqlupdate) {
783 $this->error = $this->db->lasterror();
784 return -1;
785 } else {
786 $this->nbemail = (int) $nbforupdate;
787 }
788 }
789 } else {
790 $this->error = $this->db->lasterror();
791 return -1;
792 }
793
794 return 1;
795 }
796
803 public function getTooltipContentArray($params)
804 {
805 global $langs;
806
807 //$nofetch = !empty($params['nofetch']);
808 $langs->load('mails');
809
810 $datas = array();
811 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ShowEMailing").'</u>';
812 if (isset($this->status)) {
813 $datas['picto'] .= ' '.$this->getLibStatut(5);
814 }
815 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
816 if (isset($this->title)) {
817 $datas['title'] = '<br><b>'.$langs->trans('MailTitle').':</b> '.$this->title;
818 }
819 if (isset($this->sujet)) {
820 $datas['subject'] = '<br><b>'.$langs->trans('MailTopic').':</b> '.$this->sujet;
821 }
822
823 return $datas;
824 }
825
836 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
837 {
838 global $conf, $langs, $hookmanager;
839
840 if (!empty($conf->dol_no_mouse_hover)) {
841 $notooltip = 1; // Force disable tooltips
842 }
843
844 $result = '';
845 $params = [
846 'id' => $this->id,
847 'objecttype' => $this->element,
848 'option' => $option,
849 'nofetch' => 1,
850 ];
851 $classfortooltip = 'classfortooltip';
852 $dataparams = '';
853 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
854 $classfortooltip = 'classforajaxtooltip';
855 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
856 $label = '';
857 } else {
858 $label = implode($this->getTooltipContentArray($params));
859 }
860
861 $url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
862
863 if ($option != 'nolink') {
864 // Add param to save lastsearch_values or not
865 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
866 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
867 $add_save_lastsearch_values = 1;
868 }
869 if ($add_save_lastsearch_values) {
870 $url .= '&save_lastsearch_values=1';
871 }
872 }
873
874 $linkclose = '';
875 if (empty($notooltip)) {
876 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
877 $label = $langs->trans("ShowEMailing");
878 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
879 }
880 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
881 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
882 } else {
883 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
884 }
885
886 $linkstart = '<a href="'.$url.'"';
887 $linkstart .= $linkclose.'>';
888 $linkend = '</a>';
889
890 $result .= $linkstart;
891 if ($withpicto) {
892 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
893 }
894 if ($withpicto != 2) {
895 $result .= $this->ref;
896 }
897 $result .= $linkend;
898 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
899
900 global $action;
901 $hookmanager->initHooks(array('emailingdao'));
902 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
903 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
904 if ($reshook > 0) {
905 $result = $hookmanager->resPrint;
906 } else {
907 $result .= $hookmanager->resPrint;
908 }
909
910 return $result;
911 }
912
919 public function getLibStatut($mode = 0)
920 {
921 return $this->LibStatut($this->status, $mode);
922 }
923
924 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
932 public function LibStatut($status, $mode = 0)
933 {
934 // phpcs:enable
935 global $langs;
936 $langs->load("mailing");
937
938 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
939 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
940
941 $statusType = 'status'.$status;
942 if ($status == 2) {
943 $statusType = 'status3';
944 }
945 if ($status == 3) {
946 $statusType = 'status6';
947 }
948
949 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
950 }
951
952
962 public static function libStatutDest($status, $mode = 0, $desc = '')
963 {
964 global $langs;
965 $langs->load("mails");
966
967 $labelStatus = array();
968 $labelStatusShort = array();
969
970 $labelStatus[-1] = $langs->transnoentitiesnoconv('MailingStatusError');
971 $labelStatus[0] = $langs->transnoentitiesnoconv('MailingStatusNotSent');
972 $labelStatus[1] = $langs->transnoentitiesnoconv('MailingStatusSent');
973 $labelStatus[2] = $langs->transnoentitiesnoconv('MailingStatusRead');
974 $labelStatus[3] = $langs->transnoentitiesnoconv('MailingStatusNotContact');
975 $labelStatusShort[-1] = $langs->transnoentitiesnoconv('MailingStatusError');
976 $labelStatusShort[0] = $langs->transnoentitiesnoconv('MailingStatusNotSent');
977 $labelStatusShort[1] = $langs->transnoentitiesnoconv('MailingStatusSent');
978 $labelStatusShort[2] = $langs->transnoentitiesnoconv('MailingStatusRead');
979 $labelStatusShort[3] = $langs->transnoentitiesnoconv('MailingStatusNotContact');
980
981 $statusType = 'status'.$status;
982 if ($status == -1) {
983 $statusType = 'status8';
984 }
985 if ($status == 1) {
986 $statusType = 'status6';
987 }
988 if ($status == 2) {
989 $statusType = 'status4';
990 }
991
992 $param = array();
993 if ($status == -1) {
994 $param = array('badgeParams' => array('attr' => array('title' => $desc)));
995 }
996
997 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode, '', $param);
998 }
999}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
$object ref
Definition info.php:90
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