dolibarr 23.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-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2025 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing_targets.class.php';
31
35class Mailing extends CommonObject
36{
40 public $element = 'mailing';
41
45 public $table_element = 'mailing';
46
50 public $picto = 'email';
51
55 public $messtype = 'email';
56
60 public $title;
61
65 public $sujet;
66
70 public $body;
71
75 public $evenunsubscribe;
76
80 public $note_public;
81
85 public $note_private;
86
90 public $nbemail;
91
95 public $bgcolor;
96
100 public $bgimage;
101
106 public $statut; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
107
111 public $status; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
112
116 public $email_from;
117
121 public $sendto;
122
126 public $email_replyto;
127
131 public $email_errorsto;
132
136 public $joined_file1;
137
141 public $joined_file2;
142
146 public $joined_file3;
147
151 public $joined_file4;
152
156 public $date_envoi;
157
161 public $extraparams = array();
162
166 public $statut_dest = array();
167
171 public $substitutionarray;
172
176 public $substitutionarrayfortest;
177
181 public $targets = array();
182
187 public $fk_project;
188
189 public $fields = array(
190 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
191 'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Fk project', 'enabled' => "isModEnabled('project')", 'visible' => -1, 'position' => 10),
192 );
193
194 const STATUS_DRAFT = 0;
195 const STATUS_VALIDATED = 1;
196 const STATUS_SENTPARTIALY = 2;
197 const STATUS_SENTCOMPLETELY = 3;
198
199
205 public function __construct($db)
206 {
207 $this->db = $db;
208
209 // List of language codes for status
210 $this->labelStatus[0] = 'MailingStatusDraft';
211 $this->labelStatus[1] = 'MailingStatusValidated';
212 $this->labelStatus[2] = 'MailingStatusSentPartialy';
213 $this->labelStatus[3] = 'MailingStatusSentCompletely';
214
215 $this->statut_dest[0] = 'MailingStatusNotSent';
216 $this->statut_dest[1] = 'MailingStatusSent';
217 $this->statut_dest[2] = 'MailingStatusRead';
218 $this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe'; // Read but ask to not be contacted anymore
219 $this->statut_dest[-1] = 'MailingStatusError';
220 }
221
229 public function create($user, $notrigger = 0)
230 {
231 global $conf, $langs;
232
233 // Check properties
234 if (preg_match('/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
235 $this->error = 'InvalidHTMLStringCantBeCleaned';
236 return -1;
237 }
238
239 $this->title = trim($this->title);
240 $this->email_from = trim($this->email_from);
241 if (empty($this->messtype)) {
242 $this->messtype = 'email';
243 }
244 if (!$this->email_from) {
245 if ($this->messtype !== 'sms') {
246 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailFrom"));
247 } else {
248 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PhoneFrom"));
249 }
250 return -1;
251 }
252
253 $error = 0;
254 $now = dol_now();
255
256 $this->db->begin();
257
258 $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing";
259 $sql .= " (messtype, date_creat, fk_user_creat, entity)";
260 $sql .= " VALUES ('".$this->db->escape($this->messtype)."', '".$this->db->idate($now)."', ".((int) $user->id).", ".((int) $conf->entity).")";
261
262 if (!$this->title) {
263 $this->title = $langs->trans("NoTitle");
264 }
265
266 dol_syslog(__METHOD__, LOG_DEBUG);
267
268 $resql = $this->db->query($sql);
269 if ($resql) {
270 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
271
272 $result = $this->update($user, 1);
273 if ($result < 0) {
274 $error++;
275 }
276
277 if (!$error && !$notrigger) {
278 // Call trigger
279 $result = $this->call_trigger('MAILING_CREATE', $user);
280 if ($result < 0) {
281 $error++;
282 }
283 // End call triggers
284 }
285
286 if (!$error) {
287 $this->db->commit();
288 return $this->id;
289 } else {
290 $this->db->rollback();
291 dol_syslog(__METHOD__ . ' ' . $this->error, LOG_ERR);
292 return -2;
293 }
294 } else {
295 $this->error = $this->db->lasterror();
296 $this->db->rollback();
297 return -1;
298 }
299 }
300
308 public function update($user, $notrigger = 0)
309 {
310 global $langs;
311
312 // Check properties
313 if (preg_match('/^InvalidHTMLStringCantBeCleaned/', $this->body)) {
314 $this->error = 'InvalidHTMLStringCantBeCleaned';
315 return -1;
316 }
317
318 if (empty($this->messtype)) {
319 $this->messtype = 'email';
320 }
321
322 $error = 0;
323 $this->db->begin();
324
325 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
326 $sql .= " SET titre = '".$this->db->escape($this->title)."'";
327 $sql .= ", messtype = '".$this->db->escape($this->messtype)."'";
328 $sql .= ", sujet = '".$this->db->escape($this->sujet)."'";
329 $sql .= ", body = '".$this->db->escape($this->body)."'";
330 $sql .= ", email_from = '".$this->db->escape($this->email_from)."'";
331 $sql .= ", email_replyto = '".$this->db->escape($this->email_replyto)."'";
332 $sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
333 $sql .= ", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) : null)."'";
334 $sql .= ", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) : null)."'";
335 $sql .= ", evenunsubscribe = ".((int) $this->evenunsubscribe);
336 $sql .= ", note_public = '".$this->db->escape($this->note_public)."'";
337 $sql .= ", note_private = '".$this->db->escape($this->note_private)."'";
338 $sql .= ", fk_project = '".((int) $this->fk_project)."'";
339 $sql .= " WHERE rowid = ".(int) $this->id;
340
341 dol_syslog(__METHOD__, LOG_DEBUG);
342 $resql = $this->db->query($sql);
343 if ($resql) {
344 if (!$error && !$notrigger) {
345 // Call trigger
346 $result = $this->call_trigger('MAILING_MODIFY', $user);
347 if ($result < 0) {
348 $error++;
349 }
350 // End call triggers
351 }
352
353 if (!$error) {
354 dol_syslog(__METHOD__ . ' success');
355 $this->db->commit();
356 return 1;
357 } else {
358 $this->db->rollback();
359 dol_syslog(__METHOD__ . ' ' . $this->error, LOG_ERR);
360 return -2;
361 }
362 } else {
363 if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
364 $this->error = $langs->trans("ErrorTitleAlreadyExists", $this->title);
365 } else {
366 $this->error = $this->db->lasterror();
367 }
368 $this->db->rollback();
369 return -1;
370 }
371 }
372
380 public function fetch($rowid, $ref = '')
381 {
382 $sql = "SELECT m.rowid, m.messtype, m.titre as title, m.entity, m.sujet, m.body, m.bgcolor, m.bgimage, m.evenunsubscribe";
383 $sql .= ", m.note_public, m.note_private";
384 $sql .= ", m.email_from, m.email_replyto, m.email_errorsto";
385 $sql .= ", m.statut as status, m.nbemail";
386 $sql .= ", m.fk_user_creat, m.fk_user_valid";
387 $sql .= ", m.tms as date_modification";
388 $sql .= ", m.date_creat";
389 $sql .= ", m.date_valid";
390 $sql .= ", m.date_envoi";
391 $sql .= ", m.extraparams";
392 $sql .= ", m.tag";
393 $sql .= ", m.name_from";
394 $sql .= ", m.fk_user_modif";
395 $sql .= ", m.fk_user_appro";
396 $sql .= ", m.date_appro";
397 $sql .= ", m.cible";
398 $sql .= ", m.joined_file1";
399 $sql .= ", m.joined_file2";
400 $sql .= ", m.joined_file3";
401 $sql .= ", m.joined_file4";
402 $sql .= ", m.fk_project";
403 $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
404 $sql .= " WHERE entity IN (".getEntity('mailing').")";
405 if ($ref) {
406 $sql .= " AND m.titre = '".$this->db->escape($ref)."'";
407 } else {
408 $sql .= " AND m.rowid = ".(int) $rowid;
409 }
410
411 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
412 $result = $this->db->query($sql);
413 if ($result) {
414 if ($this->db->num_rows($result)) {
415 $obj = $this->db->fetch_object($result);
416
417 $this->id = $obj->rowid;
418 $this->entity = $obj->entity;
419 $this->ref = $obj->rowid;
420 $this->title = $obj->title;
421 $this->messtype = $obj->messtype;
422
423 $this->statut = $obj->status; // deprecated
424 $this->status = $obj->status;
425
426 $this->nbemail = $obj->nbemail;
427
428 $this->sujet = $obj->sujet;
429 if (getDolGlobalString('FCKEDITOR_ENABLE_MAILING') && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5))) {
430 $this->body = dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5);
431 } else {
432 $this->body = $obj->body;
433 }
434
435 $this->bgcolor = $obj->bgcolor;
436 $this->bgimage = $obj->bgimage;
437 $this->evenunsubscribe = $obj->evenunsubscribe;
438 $this->note_public = $obj->note_public;
439 $this->note_private = $obj->note_private;
440
441 $this->email_from = $obj->email_from;
442 $this->email_replyto = $obj->email_replyto;
443 $this->email_errorsto = $obj->email_errorsto;
444
445 $this->user_creation_id = $obj->fk_user_creat;
446 $this->user_validation_id = $obj->fk_user_valid;
447
448 $this->date_creation = $this->db->jdate($obj->date_creat);
449 $this->date_validation = $this->db->jdate($obj->date_valid);
450 $this->date_envoi = $this->db->jdate($obj->date_envoi);
451 $this->date_modification = $this->db->jdate($obj->date_modification); // tms
452
453 $this->extraparams = (array) json_decode($obj->extraparams, true);
454
455 $this->tag = $obj->tag;
456 $this->name_from = $obj->name_from;
457 $this->fk_user_modif = $obj->fk_user_modif;
458 $this->fk_user_appro = $obj->fk_user_appro;
459 $this->date_appro = $obj->date_appro;
460 $this->cible = $obj->cible;
461 $this->joined_file1 = $obj->joined_file1;
462 $this->joined_file2 = $obj->joined_file2;
463 $this->joined_file3 = $obj->joined_file3;
464 $this->joined_file4 = $obj->joined_file4;
465 $this->fk_project = $obj->fk_project;
466
467 if ($this->messtype == 'sms') {
468 $this->picto = 'phone';
469 }
470
471 return 1;
472 } else {
473 dol_syslog(get_class($this)."::fetch Erreur -1");
474 return -1;
475 }
476 } else {
477 dol_syslog(get_class($this)."::fetch Erreur -2");
478 return -2;
479 }
480 }
481
482
493 public function createFromClone(User $user, $fromid, $option1, $option2, $notrigger = 0)
494 {
495 global $langs;
496
497 $error = 0;
498
499 $object = new Mailing($this->db);
500
501 $this->db->begin();
502
503 // Load source object
504 $object->fetch($fromid);
505 $object->id = 0;
506 $object->status = 0;
507 $object->statut = 0;
508
509 // Clear fields
510 $object->title = $langs->trans("CopyOf").' '.$object->title.' '.dol_print_date(dol_now());
511
512 // If no option copy content
513 if (empty($option1)) {
514 // Clear values
515 $object->nbemail = 0;
516 $object->sujet = '';
517 $object->body = '';
518 $object->bgcolor = '';
519 $object->bgimage = '';
520 $object->evenunsubscribe = 0;
521 $object->note_public = '';
522 $object->note_private = '';
523
524 //$object->email_from = ''; // We do not reset from email because it is a mandatory value
525 $object->email_replyto = '';
526 $object->email_errorsto = '';
527
528 $object->user_creation_id = $user->id;
529 $object->user_validation_id = null;
530
531 $object->date_envoi = null;
532 }
533
534 // Create clone
535 $object->context['createfromclone'] = 'createfromclone';
536 $result = $object->create($user, $notrigger);
537
538 // Other options
539 if ($result < 0) {
541 $error++;
542 }
543
544 if (!$error) {
545 // Clone recipient targets
546 if (!empty($option2)) {
547 require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
548
549 $mailing_target = new MailingTargets($this->db);
550
551 $target_array = array();
552
553 $sql = "SELECT fk_contact,";
554 $sql .= " lastname,";
555 $sql .= " firstname,";
556 $sql .= " email,";
557 $sql .= " other,";
558 $sql .= " source_url,";
559 $sql .= " source_id ,";
560 $sql .= " source_type";
561 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles";
562 $sql .= " WHERE fk_mailing = ".((int) $fromid);
563
564 $result = $this->db->query($sql);
565 if ($result) {
566 if ($this->db->num_rows($result)) {
567 while ($obj = $this->db->fetch_object($result)) {
568 $target_array[] = array(
569 'fk_contact' => $obj->fk_contact,
570 'lastname' => $obj->lastname,
571 'firstname' => $obj->firstname,
572 'email' => $obj->email,
573 'other' => $obj->other,
574 'source_url' => $obj->source_url,
575 'source_id' => $obj->source_id,
576 'source_type' => $obj->source_type
577 );
578 }
579 }
580 } else {
581 $this->error = $this->db->lasterror();
582 return -1;
583 }
584
585 $mailing_target->addTargetsToDatabase($object->id, $target_array);
586 }
587 }
588
589 unset($object->context['createfromclone']);
590
591 // End
592 if (!$error) {
593 $this->db->commit();
594 return $object->id;
595 } else {
596 $this->db->rollback();
597 return -1;
598 }
599 }
600
607 public function valid($user)
608 {
609 $now = dol_now();
610
611 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
612 $sql .= " SET statut = 1, date_valid = '".$this->db->idate($now)."', fk_user_valid=".$user->id;
613 $sql .= " WHERE rowid = ".((int) $this->id);
614
615 dol_syslog("Mailing::valid", LOG_DEBUG);
616 if ($this->db->query($sql)) {
617 return 1;
618 } else {
619 $this->error = $this->db->lasterror();
620 return -1;
621 }
622 }
623
630 public function setDraft($user)
631 {
632 $now = dol_now();
633
634 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
635 $sql .= " SET statut = 0, tms = '".$this->db->idate($now)."', fk_user_modif=".$user->id;
636 $sql .= " WHERE rowid = ".((int) $this->id);
637
638 dol_syslog("Mailing::valid", LOG_DEBUG);
639 if ($this->db->query($sql)) {
640 return 1;
641 } else {
642 $this->error = $this->db->lasterror();
643 return -1;
644 }
645 }
646
654 public function delete($user, $notrigger = 0)
655 {
656 $error = 0;
657
658 $this->db->begin();
659
660 if (!$notrigger) {
661 $result = $this->call_trigger('MAILING_DELETE', $user);
662 if ($result < 0) {
663 $error++;
664 }
665 }
666
667 if (!$error) {
668 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "mailing";
669 $sql .= " WHERE rowid = " . ((int) $this->id);
670
671 dol_syslog(__METHOD__, LOG_DEBUG);
672 $resql = $this->db->query($sql);
673 if ($resql) {
674 $res = $this->delete_targets();
675 if ($res <= 0) {
676 $error++;
677 }
678
679 if (!$error) {
680 dol_syslog(__METHOD__ . ' success');
681 $this->db->commit();
682 return 1;
683 } else {
684 $this->db->rollback();
685 dol_syslog(__METHOD__ . ' ' . $this->error, LOG_ERR);
686 return -2;
687 }
688 } else {
689 $this->db->rollback();
690 $this->error = $this->db->lasterror();
691 return -1;
692 }
693 } else {
694 $this->db->rollback();
695 return -1;
696 }
697 }
698
699 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
705 public function delete_targets()
706 {
707 // phpcs:enable
708 $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
709 $sql .= " WHERE fk_mailing = ".((int) $this->id);
710
711 dol_syslog("Mailing::delete_targets", LOG_DEBUG);
712 $resql = $this->db->query($sql);
713 if ($resql) {
714 $this->refreshNbOfTargets();
715
716 return 1;
717 } else {
718 $this->error = $this->db->lasterror();
719 return 0;
720 }
721 }
722
723
724 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
731 public function reset_targets_status($user)
732 {
733 // phpcs:enable
734 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
735 $sql .= " SET statut = 0";
736 $sql .= " WHERE fk_mailing = ".((int) $this->id);
737
738 dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
739 $resql = $this->db->query($sql);
740 if ($resql) {
741 return 1;
742 } else {
743 $this->error = $this->db->lasterror();
744 return -1;
745 }
746 }
747
755 public function resetTargetErrorStatus($user, $id)
756 {
757 // phpcs:enable
758 global $langs;
759
760 $sql = "SELECT email, statut FROM ".MAIN_DB_PREFIX."mailing_cibles";
761 $sql .= " WHERE fk_mailing = ".((int) $this->id);
762 $sql .= " AND rowid = ".((int) $id);
763 $resql = $this->db->query($sql);
764 if ($resql) {
765 $nb = $this->db->num_rows($resql);
766 $obj = $this->db->fetch_object($resql);
767 if ($obj->statut != -1) {
768 $langs->load("errors");
769 $this->error = $langs->trans('ErrorIsNotInError', $obj->email);
770 return 0;
771 }
772 } else {
773 $this->error = $this->db->lasterror();
774 }
775
776 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
777 $sql .= " SET statut = 0";
778 $sql .= " WHERE fk_mailing = ".((int) $this->id);
779 $sql .= " AND rowid = ".((int) $id);
780 $sql .= " AND statut = -1";
781
782 dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
783 $resql = $this->db->query($sql);
784 if ($resql) {
785 return 1;
786 } else {
787 $this->error = $this->db->lasterror();
788 return -1;
789 }
790 }
791
798 public function countNbOfTargets($mode)
799 {
800 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
801 $sql .= " WHERE fk_mailing = ".((int) $this->id);
802 if ($mode == 'alreadysent') {
803 $sql .= " AND statut <> 0";
804 } elseif ($mode == 'alreadysentok') {
805 $sql .= " AND statut > 0";
806 } elseif ($mode == 'alreadysentko') {
807 $sql .= " AND statut = -1";
808 } elseif ($mode == 'all') {
809 // just want to return all possible recipients
810 } else {
811 $this->error = 'BadValueForParameterMode';
812 return -2;
813 }
814
815 $resql = $this->db->query($sql);
816 if ($resql) {
817 $obj = $this->db->fetch_object($resql);
818 if ($obj) {
819 return $obj->nb;
820 }
821 } else {
822 $this->error = $this->db->lasterror();
823 return -1;
824 }
825 return 0;
826 }
827
834 public function refreshNbOfTargets()
835 {
836 $sql = "SELECT COUNT(rowid) as nb";
837 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles";
838 $sql .= " WHERE fk_mailing = ".((int) $this->id);
839
840 $resql = $this->db->query($sql);
841 if ($resql) {
842 $obj = $this->db->fetch_object($resql);
843 if ($obj) {
844 $nbforupdate = $obj->nb;
845
846 $sql = 'UPDATE '.MAIN_DB_PREFIX.'mailing SET nbemail = '.((int) $nbforupdate);
847 $sql .= ' WHERE rowid = '.((int) $this->id);
848
849 $resqlupdate = $this->db->query($sql);
850 if (! $resqlupdate) {
851 $this->error = $this->db->lasterror();
852 return -1;
853 } else {
854 $this->nbemail = (int) $nbforupdate;
855 }
856 }
857 } else {
858 $this->error = $this->db->lasterror();
859 return -1;
860 }
861
862 return 1;
863 }
864
871 public function getTooltipContentArray($params)
872 {
873 global $langs;
874
875 //$nofetch = !empty($params['nofetch']);
876 $langs->load('mails');
877
878 $datas = array();
879 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ShowEMailing").'</u>';
880 if (isset($this->status)) {
881 $datas['picto'] .= ' '.$this->getLibStatut(5);
882 }
883 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
884 if (isset($this->title)) {
885 $datas['title'] = '<br><b>'.$langs->trans('MailTitle').':</b> '.$this->title;
886 }
887 if (isset($this->sujet)) {
888 $datas['subject'] = '<br><b>'.$langs->trans('MailTopic').':</b> '.$this->sujet;
889 }
890
891 return $datas;
892 }
893
904 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
905 {
906 global $conf, $langs, $hookmanager;
907
908 if (!empty($conf->dol_no_mouse_hover)) {
909 $notooltip = 1; // Force disable tooltips
910 }
911
912 $result = '';
913 $params = [
914 'id' => $this->id,
915 'objecttype' => $this->element,
916 'option' => $option,
917 'nofetch' => 1,
918 ];
919 $classfortooltip = 'classfortooltip';
920 $dataparams = '';
921 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
922 $classfortooltip = 'classforajaxtooltip';
923 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
924 $label = '';
925 } else {
926 $label = implode($this->getTooltipContentArray($params));
927 }
928
929 $url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
930
931 if ($option != 'nolink') {
932 // Add param to save lastsearch_values or not
933 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
934 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
935 $add_save_lastsearch_values = 1;
936 }
937 if ($add_save_lastsearch_values) {
938 $url .= '&save_lastsearch_values=1';
939 }
940 }
941
942 $linkclose = '';
943 if (empty($notooltip)) {
944 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
945 $label = $langs->trans("ShowEMailing");
946 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
947 }
948 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
949 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
950 } else {
951 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
952 }
953
954 $linkstart = '<a href="'.$url.'"';
955 $linkstart .= $linkclose.'>';
956 $linkend = '</a>';
957
958 $result .= $linkstart;
959 if ($withpicto) {
960 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
961 }
962 if ($withpicto != 2) {
963 $result .= $this->ref;
964 }
965 $result .= $linkend;
966 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
967
968 global $action;
969 $hookmanager->initHooks(array('emailingdao'));
970 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
971 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
972 if ($reshook > 0) {
973 $result = $hookmanager->resPrint;
974 } else {
975 $result .= $hookmanager->resPrint;
976 }
977
978 return $result;
979 }
980
987 public function getLibStatut($mode = 0)
988 {
989 return $this->LibStatut($this->status, $mode);
990 }
991
992 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1000 public function LibStatut($status, $mode = 0)
1001 {
1002 // phpcs:enable
1003 global $langs;
1004 $langs->load("mailing");
1005
1006 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1007 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1008
1009 $statusType = 'status'.$status;
1010 if ($status == 2) {
1011 $statusType = 'status3';
1012 }
1013 if ($status == 3) {
1014 $statusType = 'status6';
1015 }
1016
1017 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1018 }
1019
1020
1030 public static function libStatutDest($status, $mode = 0, $desc = '')
1031 {
1032 global $langs;
1033 $langs->load("mails");
1034
1035 $labelStatus = array();
1036 $labelStatusShort = array();
1037
1038 $labelStatus[-1] = $langs->transnoentitiesnoconv('MailingStatusError');
1039 $labelStatus[0] = $langs->transnoentitiesnoconv('MailingStatusNotSent');
1040 $labelStatus[1] = $langs->transnoentitiesnoconv('MailingStatusSent');
1041 $labelStatus[2] = $langs->transnoentitiesnoconv('MailingStatusRead');
1042 $labelStatus[3] = $langs->transnoentitiesnoconv('MailingStatusNotContact');
1043 $labelStatusShort[-1] = $langs->transnoentitiesnoconv('MailingStatusError');
1044 $labelStatusShort[0] = $langs->transnoentitiesnoconv('MailingStatusNotSent');
1045 $labelStatusShort[1] = $langs->transnoentitiesnoconv('MailingStatusSent');
1046 $labelStatusShort[2] = $langs->transnoentitiesnoconv('MailingStatusRead');
1047 $labelStatusShort[3] = $langs->transnoentitiesnoconv('MailingStatusNotContact');
1048
1049 $statusType = 'status'.$status;
1050 if ($status == -1) {
1051 $statusType = 'status8';
1052 }
1053 if ($status == 1) {
1054 $statusType = 'status6';
1055 }
1056 if ($status == 2) {
1057 $statusType = 'status4';
1058 }
1059
1060 $param = array();
1061 if ($status == -1) {
1062 $param = array('badgeParams' => array('attr' => array('title' => $desc)));
1063 }
1064
1065 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode, '', $param);
1066 }
1067}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
setErrorsFromObject($object)
setErrorsFromObject
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.
setDraft($user)
SetDraft 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)
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.
createFromClone(User $user, $fromid, $option1, $option2, $notrigger=0)
Load an object from its id and create a new one in database.
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.
dol_now($mode='gmt')
Return date for now.
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)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.