mailing.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/comm/mailing/class/mailing.class.php
  21. * \ingroup mailing
  22. * \brief File of class to manage emailings module
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  25. /**
  26. * Class to manage emailings module
  27. */
  28. class Mailing extends CommonObject
  29. {
  30. /**
  31. * @var string ID to identify managed object
  32. */
  33. public $element = 'mailing';
  34. /**
  35. * @var string Name of table without prefix where object is stored
  36. */
  37. public $table_element = 'mailing';
  38. /**
  39. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  40. */
  41. public $picto = 'email';
  42. public $titre;
  43. public $sujet;
  44. public $body;
  45. public $nbemail;
  46. public $bgcolor;
  47. public $bgimage;
  48. public $statut; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
  49. public $email_from;
  50. public $email_replyto;
  51. public $email_errorsto;
  52. public $joined_file1;
  53. public $joined_file2;
  54. public $joined_file3;
  55. public $joined_file4;
  56. public $user_creat;
  57. public $user_valid;
  58. /**
  59. * @var integer|string date_creation
  60. */
  61. public $date_creat;
  62. public $date_valid;
  63. public $extraparams = array();
  64. public $statut_dest = array();
  65. public $statuts = array();
  66. /**
  67. * Constructor
  68. *
  69. * @param DoliDb $db Database handler
  70. */
  71. public function __construct($db)
  72. {
  73. $this->db = $db;
  74. // List of language codes for status
  75. $this->statuts[0] = 'MailingStatusDraft';
  76. $this->statuts[1] = 'MailingStatusValidated';
  77. $this->statuts[2] = 'MailingStatusSentPartialy';
  78. $this->statuts[3] = 'MailingStatusSentCompletely';
  79. $this->statut_dest[-1] = 'MailingStatusError';
  80. $this->statut_dest[0] = 'MailingStatusNotSent';
  81. $this->statut_dest[1] = 'MailingStatusSent';
  82. $this->statut_dest[2] = 'MailingStatusRead';
  83. $this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe'; // Read but ask to not be contacted anymore
  84. }
  85. /**
  86. * Create an EMailing
  87. *
  88. * @param User $user Object of user making creation
  89. * @return int -1 if error, Id of created object if OK
  90. */
  91. public function create($user)
  92. {
  93. global $conf, $langs;
  94. $this->db->begin();
  95. $this->titre = trim($this->titre);
  96. $this->email_from = trim($this->email_from);
  97. if (!$this->email_from)
  98. {
  99. $this->error = $langs->trans("ErrorMailFromRequired");
  100. return -1;
  101. }
  102. $now = dol_now();
  103. $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing";
  104. $sql .= " (date_creat, fk_user_creat, entity)";
  105. $sql .= " VALUES ('".$this->db->idate($now)."', ".$user->id.", ".$conf->entity.")";
  106. if (!$this->titre)
  107. {
  108. $this->titre = $langs->trans("NoTitle");
  109. }
  110. dol_syslog("Mailing::Create", LOG_DEBUG);
  111. $result = $this->db->query($sql);
  112. if ($result)
  113. {
  114. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
  115. if ($this->update($user) > 0)
  116. {
  117. $this->db->commit();
  118. }
  119. else
  120. {
  121. $this->error = $this->db->lasterror();
  122. $this->db->rollback();
  123. return -1;
  124. }
  125. return $this->id;
  126. }
  127. else
  128. {
  129. $this->error = $this->db->lasterror();
  130. $this->db->rollback();
  131. return -1;
  132. }
  133. }
  134. /**
  135. * Update emailing record
  136. *
  137. * @param User $user Object of user making change
  138. * @return int < 0 if KO, > 0 if OK
  139. */
  140. public function update($user)
  141. {
  142. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
  143. $sql .= " SET titre = '".$this->db->escape($this->titre)."'";
  144. $sql .= ", sujet = '".$this->db->escape($this->sujet)."'";
  145. $sql .= ", body = '".$this->db->escape($this->body)."'";
  146. $sql .= ", email_from = '".$this->db->escape($this->email_from)."'";
  147. $sql .= ", email_replyto = '".$this->db->escape($this->email_replyto)."'";
  148. $sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
  149. $sql .= ", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) : null)."'";
  150. $sql .= ", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) : null)."'";
  151. $sql .= " WHERE rowid = ".$this->id;
  152. dol_syslog("Mailing::Update", LOG_DEBUG);
  153. $result = $this->db->query($sql);
  154. if ($result)
  155. {
  156. return 1;
  157. }
  158. else
  159. {
  160. $this->error = $this->db->lasterror();
  161. return -1;
  162. }
  163. }
  164. /**
  165. * Get object from database
  166. *
  167. * @param int $rowid Id of emailing
  168. * @return int <0 if KO, >0 if OK
  169. */
  170. public function fetch($rowid)
  171. {
  172. global $conf;
  173. $sql = "SELECT m.rowid, m.titre, m.sujet, m.body, m.bgcolor, m.bgimage";
  174. $sql .= ", m.email_from, m.email_replyto, m.email_errorsto";
  175. $sql .= ", m.statut, m.nbemail";
  176. $sql .= ", m.fk_user_creat, m.fk_user_valid";
  177. $sql .= ", m.date_creat";
  178. $sql .= ", m.date_valid";
  179. $sql .= ", m.date_envoi";
  180. $sql .= ", m.extraparams";
  181. $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
  182. $sql .= " WHERE m.rowid = ".(int) $rowid;
  183. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  184. $result = $this->db->query($sql);
  185. if ($result)
  186. {
  187. if ($this->db->num_rows($result))
  188. {
  189. $obj = $this->db->fetch_object($result);
  190. $this->id = $obj->rowid;
  191. $this->ref = $obj->rowid;
  192. $this->statut = $obj->statut;
  193. $this->nbemail = $obj->nbemail;
  194. $this->titre = $obj->titre;
  195. $this->sujet = $obj->sujet;
  196. if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401))) {
  197. $this->body = dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401);
  198. } else {
  199. $this->body = $obj->body;
  200. }
  201. $this->bgcolor = $obj->bgcolor;
  202. $this->bgimage = $obj->bgimage;
  203. $this->email_from = $obj->email_from;
  204. $this->email_replyto = $obj->email_replyto;
  205. $this->email_errorsto = $obj->email_errorsto;
  206. $this->user_creat = $obj->fk_user_creat;
  207. $this->user_valid = $obj->fk_user_valid;
  208. $this->date_creat = $this->db->jdate($obj->date_creat);
  209. $this->date_valid = $this->db->jdate($obj->date_valid);
  210. $this->date_envoi = $this->db->jdate($obj->date_envoi);
  211. $this->extraparams = (array) json_decode($obj->extraparams, true);
  212. return 1;
  213. }
  214. else
  215. {
  216. dol_syslog(get_class($this)."::fetch Erreur -1");
  217. return -1;
  218. }
  219. }
  220. else
  221. {
  222. dol_syslog(get_class($this)."::fetch Erreur -2");
  223. return -2;
  224. }
  225. }
  226. /**
  227. * Load an object from its id and create a new one in database
  228. *
  229. * @param User $user User making the clone
  230. * @param int $fromid Id of object to clone
  231. * @param int $option1 1=Clone content, 0=Forget content
  232. * @param int $option2 1=Clone recipients
  233. * @return int New id of clone
  234. */
  235. public function createFromClone(User $user, $fromid, $option1, $option2)
  236. {
  237. global $langs;
  238. $error = 0;
  239. $object = new Mailing($this->db);
  240. $this->db->begin();
  241. // Load source object
  242. $object->fetch($fromid);
  243. $object->id = 0;
  244. $object->statut = 0;
  245. // Clear fields
  246. $object->titre = $langs->trans("CopyOf").' '.$object->titre.' '.dol_print_date(dol_now());
  247. // If no option copy content
  248. if (empty($option1))
  249. {
  250. // Clear values
  251. $object->nbemail = 0;
  252. $object->sujet = '';
  253. $object->body = '';
  254. $object->bgcolor = '';
  255. $object->bgimage = '';
  256. //$object->email_from = ''; // We do not reset from email because it is a mandatory value
  257. $object->email_replyto = '';
  258. $object->email_errorsto = '';
  259. $object->user_creat = $user->id;
  260. $object->user_valid = '';
  261. $object->date_creat = '';
  262. $object->date_valid = '';
  263. $object->date_envoi = '';
  264. }
  265. // Create clone
  266. $object->context['createfromclone'] = 'createfromclone';
  267. $result = $object->create($user);
  268. // Other options
  269. if ($result < 0)
  270. {
  271. $this->error = $object->error;
  272. $this->errors = array_merge($this->errors, $object->errors);
  273. $error++;
  274. }
  275. if (!$error)
  276. {
  277. // Clone recipient targets
  278. if (!empty($option2)) {
  279. require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
  280. $mailing_target = new MailingTargets($this->db);
  281. $target_array = array();
  282. $sql = "SELECT fk_contact,";
  283. $sql .= " lastname,";
  284. $sql .= " firstname,";
  285. $sql .= " email,";
  286. $sql .= " other,";
  287. $sql .= " source_url,";
  288. $sql .= " source_id ,";
  289. $sql .= " source_type";
  290. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles";
  291. $sql .= " WHERE fk_mailing = ".$fromid;
  292. $result = $this->db->query($sql);
  293. if ($result)
  294. {
  295. if ($this->db->num_rows($result))
  296. {
  297. while ($obj = $this->db->fetch_object($result)) {
  298. $target_array[] = array(
  299. 'fk_contact'=>$obj->fk_contact,
  300. 'lastname'=>$obj->lastname,
  301. 'firstname'=>$obj->firstname,
  302. 'email'=>$obj->email,
  303. 'other'=>$obj->other,
  304. 'source_url'=>$obj->source_url,
  305. 'source_id'=>$obj->source_id,
  306. 'source_type'=>$obj->source_type
  307. );
  308. }
  309. }
  310. }
  311. else
  312. {
  313. $this->error = $this->db->lasterror();
  314. return -1;
  315. }
  316. $mailing_target->addTargetsToDatabase($object->id, $target_array);
  317. }
  318. }
  319. unset($object->context['createfromclone']);
  320. // End
  321. if (!$error)
  322. {
  323. $this->db->commit();
  324. return $object->id;
  325. }
  326. else
  327. {
  328. $this->db->rollback();
  329. return -1;
  330. }
  331. }
  332. /**
  333. * Validate emailing
  334. *
  335. * @param User $user Objet user qui valide
  336. * @return int <0 if KO, >0 if OK
  337. */
  338. public function valid($user)
  339. {
  340. $now = dol_now();
  341. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
  342. $sql .= " SET statut = 1, date_valid = '".$this->db->idate($now)."', fk_user_valid=".$user->id;
  343. $sql .= " WHERE rowid = ".$this->id;
  344. dol_syslog("Mailing::valid", LOG_DEBUG);
  345. if ($this->db->query($sql))
  346. {
  347. return 1;
  348. }
  349. else
  350. {
  351. $this->error = $this->db->lasterror();
  352. return -1;
  353. }
  354. }
  355. /**
  356. * Delete emailing
  357. *
  358. * @param int $rowid id du mailing a supprimer
  359. * @return int 1 en cas de succes
  360. */
  361. public function delete($rowid, $notrigger = 0)
  362. {
  363. global $user;
  364. $this->db->begin();
  365. $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing";
  366. $sql .= " WHERE rowid = ".$rowid;
  367. dol_syslog("Mailing::delete", LOG_DEBUG);
  368. $resql = $this->db->query($sql);
  369. if ($resql)
  370. {
  371. $res = $this->delete_targets();
  372. if(empty($res)){
  373. $this->db->rollback();
  374. $this->error = $this->db->lasterror();
  375. return -1;
  376. }
  377. }
  378. else
  379. {
  380. $this->db->rollback();
  381. $this->error = $this->db->lasterror();
  382. return -1;
  383. }
  384. if(!$notrigger){
  385. $result = $this->call_trigger('MAILING_DELETE', $user);
  386. if ($result < 0)
  387. {
  388. $this->db->rollback();
  389. return -1;
  390. }
  391. }
  392. $this->db->commit();
  393. return 1;
  394. }
  395. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  396. /**
  397. * Delete targets emailing
  398. *
  399. * @return int 1 if OK, 0 if error
  400. */
  401. public function delete_targets()
  402. {
  403. // phpcs:enable
  404. $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
  405. $sql .= " WHERE fk_mailing = ".$this->id;
  406. dol_syslog("Mailing::delete_targets", LOG_DEBUG);
  407. $resql = $this->db->query($sql);
  408. if ($resql)
  409. {
  410. $this->refreshNbOfTargets();
  411. return 1;
  412. }
  413. else
  414. {
  415. $this->error = $this->db->lasterror();
  416. return 0;
  417. }
  418. }
  419. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  420. /**
  421. * Change status of each recipient
  422. *
  423. * @param User $user Objet user qui valide
  424. * @return int <0 if KO, >0 if OK
  425. */
  426. public function reset_targets_status($user)
  427. {
  428. // phpcs:enable
  429. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
  430. $sql .= " SET statut = 0";
  431. $sql .= " WHERE fk_mailing = ".$this->id;
  432. dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
  433. $resql = $this->db->query($sql);
  434. if ($resql)
  435. {
  436. return 1;
  437. }
  438. else
  439. {
  440. $this->error = $this->db->lasterror();
  441. return -1;
  442. }
  443. }
  444. /**
  445. * Count number of target with status
  446. *
  447. * @param string $mode Mode ('alreadysent' = Sent success or error, 'alreadysentok' = Sent success, 'alreadysentko' = Sent error)
  448. * @return int Nb of target with status
  449. */
  450. public function countNbOfTargets($mode)
  451. {
  452. $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
  453. $sql .= " WHERE fk_mailing = ".$this->id;
  454. if ($mode == 'alreadysent') $sql .= " AND statut <> 0";
  455. elseif ($mode == 'alreadysentok') $sql .= " AND statut > 0";
  456. elseif ($mode == 'alreadysentko') $sql .= " AND statut = -1";
  457. else
  458. {
  459. $this->error = 'BadValueForParameterMode';
  460. return -2;
  461. }
  462. $resql = $this->db->query($sql);
  463. if ($resql)
  464. {
  465. $obj = $this->db->fetch_object($resql);
  466. if ($obj) return $obj->nb;
  467. }
  468. else
  469. {
  470. $this->error = $this->db->lasterror();
  471. return -1;
  472. }
  473. return 0;
  474. }
  475. /**
  476. * Refresh denormalized value ->nbemail into emailing record
  477. * Note: There is also the method update_nb into modules_mailings that is used for this.
  478. *
  479. * @return int <0 if KO, >0 if OK
  480. */
  481. public function refreshNbOfTargets()
  482. {
  483. $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
  484. $sql .= " WHERE fk_mailing = ".$this->id;
  485. $resql = $this->db->query($sql);
  486. if ($resql) {
  487. $obj = $this->db->fetch_object($resql);
  488. if ($obj) {
  489. $nbforupdate = $obj->nb;
  490. $sql = 'UPDATE '.MAIN_DB_PREFIX.'mailing SET nbemail = '.((int) $nbforupdate);
  491. $sql .= ' WHERE rowid = '.$this->id;
  492. $resqlupdate = $this->db->query($sql);
  493. if (! $resqlupdate) {
  494. $this->error = $this->db->lasterror();
  495. return -1;
  496. }
  497. }
  498. } else {
  499. $this->error = $this->db->lasterror();
  500. return -1;
  501. }
  502. return 1;
  503. }
  504. /**
  505. * Return a link to the object card (with optionally the picto)
  506. *
  507. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  508. * @param string $option On what the link point to ('nolink', ...)
  509. * @param int $notooltip 1=Disable tooltip
  510. * @param string $morecss Add more css on link
  511. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  512. * @return string String with URL
  513. */
  514. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  515. {
  516. global $db, $conf, $langs, $hookmanager;
  517. global $dolibarr_main_authentication, $dolibarr_main_demo;
  518. global $menumanager;
  519. if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
  520. $result = '';
  521. $companylink = '';
  522. $label = '<u>'.$langs->trans("ShowEMailing").'</u>';
  523. $label .= '<br>';
  524. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  525. $url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
  526. if ($option != 'nolink')
  527. {
  528. // Add param to save lastsearch_values or not
  529. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  530. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
  531. if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
  532. }
  533. $linkclose = '';
  534. if (empty($notooltip))
  535. {
  536. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  537. {
  538. $label = $langs->trans("ShowEMailing");
  539. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  540. }
  541. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  542. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  543. /*
  544. $hookmanager->initHooks(array('myobjectdao'));
  545. $parameters=array('id'=>$this->id);
  546. $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
  547. if ($reshook > 0) $linkclose = $hookmanager->resPrint;
  548. */
  549. }
  550. else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  551. $linkstart = '<a href="'.$url.'"';
  552. $linkstart .= $linkclose.'>';
  553. $linkend = '</a>';
  554. $result .= $linkstart;
  555. if ($withpicto) $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);
  556. if ($withpicto != 2) $result .= $this->ref;
  557. $result .= $linkend;
  558. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  559. global $action;
  560. $hookmanager->initHooks(array('emailingdao'));
  561. $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
  562. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  563. if ($reshook > 0) $result = $hookmanager->resPrint;
  564. else $result .= $hookmanager->resPrint;
  565. return $result;
  566. }
  567. /**
  568. * Return label of status of emailing (draft, validated, ...)
  569. *
  570. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
  571. * @return string Label
  572. */
  573. public function getLibStatut($mode = 0)
  574. {
  575. return $this->LibStatut($this->statut, $mode);
  576. }
  577. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  578. /**
  579. * Renvoi le libelle d'un statut donne
  580. *
  581. * @param int $status Id status
  582. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  583. * @return string Label
  584. */
  585. public function LibStatut($status, $mode = 0)
  586. {
  587. // phpcs:enable
  588. global $langs;
  589. $langs->load("mailing");
  590. $labelStatus = $langs->trans($this->statuts[$status]);
  591. $labelStatusShort = $langs->trans($this->statuts[$status]);
  592. $statusType = 'status'.$status;
  593. if ($status == 2) $statusType = 'status3';
  594. if ($status == 3) $statusType = 'status6';
  595. return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
  596. }
  597. /**
  598. * Renvoi le libelle d'un statut donne
  599. * TODO Add class mailin_target.class.php
  600. *
  601. * @param int $status Id status
  602. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  603. * @param string $desc Desc error
  604. * @return string Label
  605. */
  606. public static function libStatutDest($status, $mode = 0, $desc = '')
  607. {
  608. global $langs;
  609. $langs->load("mails");
  610. $labelStatus = array();
  611. $labelStatusShort = array();
  612. $labelStatus[-1] = $langs->trans('MailingStatusError');
  613. $labelStatus[0] = $langs->trans('MailingStatusNotSent');
  614. $labelStatus[1] = $langs->trans('MailingStatusSent');
  615. $labelStatus[2] = $langs->trans('MailingStatusRead');
  616. $labelStatus[3] = $langs->trans('MailingStatusNotContact');
  617. $labelStatusShort[-1] = $langs->trans('MailingStatusError');
  618. $labelStatusShort[0] = $langs->trans('MailingStatusNotSent');
  619. $labelStatusShort[1] = $langs->trans('MailingStatusSent');
  620. $labelStatusShort[2] = $langs->trans('MailingStatusRead');
  621. $labelStatusShort[3] = $langs->trans('MailingStatusNotContact');
  622. $statusType = 'status'.$status;
  623. if ($status == -1) $statusType = 'status8';
  624. if ($status == 1) $statusType = 'status6';
  625. if ($status == 2) $statusType = 'status4';
  626. $param = array();
  627. if ($status == - 1) {
  628. $param = array('badgeParams'=>array('attr'=>array('title'=>$desc)));
  629. }
  630. return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode, '', $param);
  631. }
  632. }