mailing.class.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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. /**
  43. * @var string title
  44. */
  45. public $title;
  46. /**
  47. * @var string subject
  48. */
  49. public $sujet;
  50. /**
  51. * @var string body
  52. */
  53. public $body;
  54. /**
  55. * @var int number of email
  56. */
  57. public $nbemail;
  58. /**
  59. * @var string background color
  60. */
  61. public $bgcolor;
  62. /**
  63. * @var string background image
  64. */
  65. public $bgimage;
  66. /**
  67. * @var int status
  68. */
  69. public $statut; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
  70. /**
  71. * @var string email from
  72. */
  73. public $email_from;
  74. /**
  75. * @var string email to
  76. */
  77. public $sendto;
  78. /**
  79. * @var string email reply to
  80. */
  81. public $email_replyto;
  82. /**
  83. * @var string email errors to
  84. */
  85. public $email_errorsto;
  86. /**
  87. * @var string first joined file
  88. */
  89. public $joined_file1;
  90. /**
  91. * @var string second joined file
  92. */
  93. public $joined_file2;
  94. /**
  95. * @var string third joined file
  96. */
  97. public $joined_file3;
  98. /**
  99. * @var string fourth joined file
  100. */
  101. public $joined_file4;
  102. /**
  103. * @var int id of user create
  104. */
  105. public $user_creation;
  106. /**
  107. * @var int id of user create
  108. * @deprecated
  109. */
  110. public $user_creat;
  111. /**
  112. * @var int id of user validate
  113. */
  114. public $user_validation;
  115. /**
  116. * @var int id of user validate
  117. * @deprecated
  118. */
  119. public $user_valid;
  120. /**
  121. * @var integer|string date_creation
  122. * @deprecated
  123. */
  124. public $date_creat;
  125. /**
  126. * @var integer|string date_creation
  127. */
  128. public $date_creation;
  129. /**
  130. * @var int date validate
  131. * @deprecated
  132. */
  133. public $date_valid;
  134. /**
  135. * @var int date validate
  136. */
  137. public $date_validation;
  138. /**
  139. * @var array extraparams
  140. */
  141. public $extraparams = array();
  142. /**
  143. * @var array statut dest
  144. */
  145. public $statut_dest = array();
  146. /**
  147. * @var array statuts
  148. */
  149. public $statuts = array();
  150. /**
  151. * @var array substitutionarray
  152. */
  153. public $substitutionarray;
  154. /**
  155. * @var array substitutionarrayfortest
  156. */
  157. public $substitutionarrayfortest;
  158. /**
  159. * Constructor
  160. *
  161. * @param DoliDb $db Database handler
  162. */
  163. public function __construct($db)
  164. {
  165. $this->db = $db;
  166. // List of language codes for status
  167. $this->statuts[0] = 'MailingStatusDraft';
  168. $this->statuts[1] = 'MailingStatusValidated';
  169. $this->statuts[2] = 'MailingStatusSentPartialy';
  170. $this->statuts[3] = 'MailingStatusSentCompletely';
  171. $this->statut_dest[-1] = 'MailingStatusError';
  172. $this->statut_dest[0] = 'MailingStatusNotSent';
  173. $this->statut_dest[1] = 'MailingStatusSent';
  174. $this->statut_dest[2] = 'MailingStatusRead';
  175. $this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe'; // Read but ask to not be contacted anymore
  176. }
  177. /**
  178. * Create an EMailing
  179. *
  180. * @param User $user Object of user making creation
  181. * @return int -1 if error, Id of created object if OK
  182. */
  183. public function create($user)
  184. {
  185. global $conf, $langs;
  186. // Check properties
  187. if ($this->body === 'InvalidHTMLString') {
  188. $this->error = 'InvalidHTMLString';
  189. return -1;
  190. }
  191. $this->db->begin();
  192. $this->title = trim($this->title);
  193. $this->email_from = trim($this->email_from);
  194. if (!$this->email_from) {
  195. $this->error = $langs->trans("ErrorMailFromRequired");
  196. return -1;
  197. }
  198. $now = dol_now();
  199. $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing";
  200. $sql .= " (date_creat, fk_user_creat, entity)";
  201. $sql .= " VALUES ('".$this->db->idate($now)."', ".((int) $user->id).", ".((int) $conf->entity).")";
  202. if (!$this->title) {
  203. $this->title = $langs->trans("NoTitle");
  204. }
  205. dol_syslog("Mailing::Create", LOG_DEBUG);
  206. $result = $this->db->query($sql);
  207. if ($result) {
  208. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
  209. if ($this->update($user) > 0) {
  210. $this->db->commit();
  211. } else {
  212. $this->error = $this->db->lasterror();
  213. $this->db->rollback();
  214. return -1;
  215. }
  216. return $this->id;
  217. } else {
  218. $this->error = $this->db->lasterror();
  219. $this->db->rollback();
  220. return -1;
  221. }
  222. }
  223. /**
  224. * Update emailing record
  225. *
  226. * @param User $user Object of user making change
  227. * @return int < 0 if KO, > 0 if OK
  228. */
  229. public function update($user)
  230. {
  231. // Check properties
  232. if ($this->body === 'InvalidHTMLString') {
  233. $this->error = 'InvalidHTMLString';
  234. return -1;
  235. }
  236. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
  237. $sql .= " SET titre = '".$this->db->escape($this->title)."'";
  238. $sql .= ", sujet = '".$this->db->escape($this->sujet)."'";
  239. $sql .= ", body = '".$this->db->escape($this->body)."'";
  240. $sql .= ", email_from = '".$this->db->escape($this->email_from)."'";
  241. $sql .= ", email_replyto = '".$this->db->escape($this->email_replyto)."'";
  242. $sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
  243. $sql .= ", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) : null)."'";
  244. $sql .= ", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) : null)."'";
  245. $sql .= " WHERE rowid = ".(int) $this->id;
  246. dol_syslog("Mailing::Update", LOG_DEBUG);
  247. $result = $this->db->query($sql);
  248. if ($result) {
  249. return 1;
  250. } else {
  251. $this->error = $this->db->lasterror();
  252. return -1;
  253. }
  254. }
  255. /**
  256. * Get object from database
  257. *
  258. * @param int $rowid Id of emailing
  259. * @return int <0 if KO, >0 if OK
  260. */
  261. public function fetch($rowid)
  262. {
  263. global $conf;
  264. $sql = "SELECT m.rowid, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage";
  265. $sql .= ", m.email_from, m.email_replyto, m.email_errorsto";
  266. $sql .= ", m.statut, m.nbemail";
  267. $sql .= ", m.fk_user_creat, m.fk_user_valid";
  268. $sql .= ", m.date_creat";
  269. $sql .= ", m.date_valid";
  270. $sql .= ", m.date_envoi";
  271. $sql .= ", m.extraparams";
  272. $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
  273. $sql .= " WHERE m.rowid = ".(int) $rowid;
  274. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  275. $result = $this->db->query($sql);
  276. if ($result) {
  277. if ($this->db->num_rows($result)) {
  278. $obj = $this->db->fetch_object($result);
  279. $this->id = $obj->rowid;
  280. $this->ref = $obj->rowid;
  281. $this->statut = $obj->statut;
  282. $this->nbemail = $obj->nbemail;
  283. $this->title = $obj->title;
  284. $this->sujet = $obj->sujet;
  285. if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5))) {
  286. $this->body = dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5);
  287. } else {
  288. $this->body = $obj->body;
  289. }
  290. $this->bgcolor = $obj->bgcolor;
  291. $this->bgimage = $obj->bgimage;
  292. $this->email_from = $obj->email_from;
  293. $this->email_replyto = $obj->email_replyto;
  294. $this->email_errorsto = $obj->email_errorsto;
  295. $this->user_creat = $obj->fk_user_creat;
  296. $this->user_creation = $obj->fk_user_creat;
  297. $this->user_valid = $obj->fk_user_valid;
  298. $this->user_validation = $obj->fk_user_valid;
  299. $this->date_creat = $this->db->jdate($obj->date_creat);
  300. $this->date_creation = $this->db->jdate($obj->date_creat);
  301. $this->date_valid = $this->db->jdate($obj->date_valid);
  302. $this->date_validation = $this->db->jdate($obj->date_valid);
  303. $this->date_envoi = $this->db->jdate($obj->date_envoi);
  304. $this->extraparams = (array) json_decode($obj->extraparams, true);
  305. return 1;
  306. } else {
  307. dol_syslog(get_class($this)."::fetch Erreur -1");
  308. return -1;
  309. }
  310. } else {
  311. dol_syslog(get_class($this)."::fetch Erreur -2");
  312. return -2;
  313. }
  314. }
  315. /**
  316. * Load an object from its id and create a new one in database
  317. *
  318. * @param User $user User making the clone
  319. * @param int $fromid Id of object to clone
  320. * @param int $option1 1=Clone content, 0=Forget content
  321. * @param int $option2 1=Clone recipients
  322. * @return int New id of clone
  323. */
  324. public function createFromClone(User $user, $fromid, $option1, $option2)
  325. {
  326. global $langs;
  327. $error = 0;
  328. $object = new Mailing($this->db);
  329. $this->db->begin();
  330. // Load source object
  331. $object->fetch($fromid);
  332. $object->id = 0;
  333. $object->statut = 0;
  334. // Clear fields
  335. $object->title = $langs->trans("CopyOf").' '.$object->title.' '.dol_print_date(dol_now());
  336. // If no option copy content
  337. if (empty($option1)) {
  338. // Clear values
  339. $object->nbemail = 0;
  340. $object->sujet = '';
  341. $object->body = '';
  342. $object->bgcolor = '';
  343. $object->bgimage = '';
  344. //$object->email_from = ''; // We do not reset from email because it is a mandatory value
  345. $object->email_replyto = '';
  346. $object->email_errorsto = '';
  347. $object->user_creat = $user->id;
  348. $object->user_valid = '';
  349. $object->date_creat = '';
  350. $object->date_valid = '';
  351. $object->date_envoi = '';
  352. }
  353. // Create clone
  354. $object->context['createfromclone'] = 'createfromclone';
  355. $result = $object->create($user);
  356. // Other options
  357. if ($result < 0) {
  358. $this->error = $object->error;
  359. $this->errors = array_merge($this->errors, $object->errors);
  360. $error++;
  361. }
  362. if (!$error) {
  363. // Clone recipient targets
  364. if (!empty($option2)) {
  365. require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
  366. $mailing_target = new MailingTargets($this->db);
  367. $target_array = array();
  368. $sql = "SELECT fk_contact,";
  369. $sql .= " lastname,";
  370. $sql .= " firstname,";
  371. $sql .= " email,";
  372. $sql .= " other,";
  373. $sql .= " source_url,";
  374. $sql .= " source_id ,";
  375. $sql .= " source_type";
  376. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles";
  377. $sql .= " WHERE fk_mailing = ".((int) $fromid);
  378. $result = $this->db->query($sql);
  379. if ($result) {
  380. if ($this->db->num_rows($result)) {
  381. while ($obj = $this->db->fetch_object($result)) {
  382. $target_array[] = array(
  383. 'fk_contact'=>$obj->fk_contact,
  384. 'lastname'=>$obj->lastname,
  385. 'firstname'=>$obj->firstname,
  386. 'email'=>$obj->email,
  387. 'other'=>$obj->other,
  388. 'source_url'=>$obj->source_url,
  389. 'source_id'=>$obj->source_id,
  390. 'source_type'=>$obj->source_type
  391. );
  392. }
  393. }
  394. } else {
  395. $this->error = $this->db->lasterror();
  396. return -1;
  397. }
  398. $mailing_target->addTargetsToDatabase($object->id, $target_array);
  399. }
  400. }
  401. unset($object->context['createfromclone']);
  402. // End
  403. if (!$error) {
  404. $this->db->commit();
  405. return $object->id;
  406. } else {
  407. $this->db->rollback();
  408. return -1;
  409. }
  410. }
  411. /**
  412. * Validate emailing
  413. *
  414. * @param User $user Objet user qui valide
  415. * @return int <0 if KO, >0 if OK
  416. */
  417. public function valid($user)
  418. {
  419. $now = dol_now();
  420. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
  421. $sql .= " SET statut = 1, date_valid = '".$this->db->idate($now)."', fk_user_valid=".$user->id;
  422. $sql .= " WHERE rowid = ".((int) $this->id);
  423. dol_syslog("Mailing::valid", LOG_DEBUG);
  424. if ($this->db->query($sql)) {
  425. return 1;
  426. } else {
  427. $this->error = $this->db->lasterror();
  428. return -1;
  429. }
  430. }
  431. /**
  432. * Delete emailing
  433. *
  434. * @param int $rowid Id if emailing to delete
  435. * @param int $notrigger Disable triggers
  436. * @return int >0 if OK, <0 if KO
  437. */
  438. public function delete($rowid, $notrigger = 0)
  439. {
  440. global $user;
  441. $this->db->begin();
  442. $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing";
  443. $sql .= " WHERE rowid = ".((int) $rowid);
  444. dol_syslog("Mailing::delete", LOG_DEBUG);
  445. $resql = $this->db->query($sql);
  446. if ($resql) {
  447. $res = $this->delete_targets();
  448. if ($res <= 0) {
  449. $this->db->rollback();
  450. $this->error = $this->db->lasterror();
  451. return -1;
  452. }
  453. } else {
  454. $this->db->rollback();
  455. $this->error = $this->db->lasterror();
  456. return -1;
  457. }
  458. if (!$notrigger) {
  459. $result = $this->call_trigger('MAILING_DELETE', $user);
  460. if ($result < 0) {
  461. $this->db->rollback();
  462. return -1;
  463. }
  464. }
  465. $this->db->commit();
  466. return 1;
  467. }
  468. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  469. /**
  470. * Delete targets emailing
  471. *
  472. * @return int 1 if OK, 0 if error
  473. */
  474. public function delete_targets()
  475. {
  476. // phpcs:enable
  477. $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
  478. $sql .= " WHERE fk_mailing = ".((int) $this->id);
  479. dol_syslog("Mailing::delete_targets", LOG_DEBUG);
  480. $resql = $this->db->query($sql);
  481. if ($resql) {
  482. $this->refreshNbOfTargets();
  483. return 1;
  484. } else {
  485. $this->error = $this->db->lasterror();
  486. return 0;
  487. }
  488. }
  489. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  490. /**
  491. * Change status of each recipient
  492. *
  493. * @param User $user Objet user qui valide
  494. * @return int <0 if KO, >0 if OK
  495. */
  496. public function reset_targets_status($user)
  497. {
  498. // phpcs:enable
  499. $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
  500. $sql .= " SET statut = 0";
  501. $sql .= " WHERE fk_mailing = ".((int) $this->id);
  502. dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
  503. $resql = $this->db->query($sql);
  504. if ($resql) {
  505. return 1;
  506. } else {
  507. $this->error = $this->db->lasterror();
  508. return -1;
  509. }
  510. }
  511. /**
  512. * Count number of target with status
  513. *
  514. * @param string $mode Mode ('alreadysent' = Sent success or error, 'alreadysentok' = Sent success, 'alreadysentko' = Sent error)
  515. * @return int Nb of target with status
  516. */
  517. public function countNbOfTargets($mode)
  518. {
  519. $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
  520. $sql .= " WHERE fk_mailing = ".((int) $this->id);
  521. if ($mode == 'alreadysent') {
  522. $sql .= " AND statut <> 0";
  523. } elseif ($mode == 'alreadysentok') {
  524. $sql .= " AND statut > 0";
  525. } elseif ($mode == 'alreadysentko') {
  526. $sql .= " AND statut = -1";
  527. } else {
  528. $this->error = 'BadValueForParameterMode';
  529. return -2;
  530. }
  531. $resql = $this->db->query($sql);
  532. if ($resql) {
  533. $obj = $this->db->fetch_object($resql);
  534. if ($obj) {
  535. return $obj->nb;
  536. }
  537. } else {
  538. $this->error = $this->db->lasterror();
  539. return -1;
  540. }
  541. return 0;
  542. }
  543. /**
  544. * Refresh denormalized value ->nbemail into emailing record
  545. * Note: There is also the method update_nb into modules_mailings that is used for this.
  546. *
  547. * @return int <0 if KO, >0 if OK
  548. */
  549. public function refreshNbOfTargets()
  550. {
  551. $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
  552. $sql .= " WHERE fk_mailing = ".((int) $this->id);
  553. $resql = $this->db->query($sql);
  554. if ($resql) {
  555. $obj = $this->db->fetch_object($resql);
  556. if ($obj) {
  557. $nbforupdate = $obj->nb;
  558. $sql = 'UPDATE '.MAIN_DB_PREFIX.'mailing SET nbemail = '.((int) $nbforupdate);
  559. $sql .= ' WHERE rowid = '.((int) $this->id);
  560. $resqlupdate = $this->db->query($sql);
  561. if (! $resqlupdate) {
  562. $this->error = $this->db->lasterror();
  563. return -1;
  564. } else {
  565. $this->nbemail = (int) $nbforupdate;
  566. }
  567. }
  568. } else {
  569. $this->error = $this->db->lasterror();
  570. return -1;
  571. }
  572. return 1;
  573. }
  574. /**
  575. * Return a link to the object card (with optionally the picto)
  576. *
  577. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  578. * @param string $option On what the link point to ('nolink', ...)
  579. * @param int $notooltip 1=Disable tooltip
  580. * @param string $morecss Add more css on link
  581. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  582. * @return string String with URL
  583. */
  584. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  585. {
  586. global $db, $conf, $langs, $hookmanager;
  587. global $dolibarr_main_authentication, $dolibarr_main_demo;
  588. global $menumanager;
  589. if (!empty($conf->dol_no_mouse_hover)) {
  590. $notooltip = 1; // Force disable tooltips
  591. }
  592. $result = '';
  593. $companylink = '';
  594. $label = '<u>'.$langs->trans("ShowEMailing").'</u>';
  595. $label .= '<br>';
  596. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  597. $url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
  598. if ($option != 'nolink') {
  599. // Add param to save lastsearch_values or not
  600. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  601. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  602. $add_save_lastsearch_values = 1;
  603. }
  604. if ($add_save_lastsearch_values) {
  605. $url .= '&save_lastsearch_values=1';
  606. }
  607. }
  608. $linkclose = '';
  609. if (empty($notooltip)) {
  610. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  611. $label = $langs->trans("ShowEMailing");
  612. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  613. }
  614. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  615. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  616. } else {
  617. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  618. }
  619. $linkstart = '<a href="'.$url.'"';
  620. $linkstart .= $linkclose.'>';
  621. $linkend = '</a>';
  622. $result .= $linkstart;
  623. if ($withpicto) {
  624. $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);
  625. }
  626. if ($withpicto != 2) {
  627. $result .= $this->ref;
  628. }
  629. $result .= $linkend;
  630. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  631. global $action;
  632. $hookmanager->initHooks(array('emailingdao'));
  633. $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
  634. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  635. if ($reshook > 0) {
  636. $result = $hookmanager->resPrint;
  637. } else {
  638. $result .= $hookmanager->resPrint;
  639. }
  640. return $result;
  641. }
  642. /**
  643. * Return label of status of emailing (draft, validated, ...)
  644. *
  645. * @param int $mode 0=Long label, 1=Short label, 2=Picto+Short label, 3=Picto, 4=Picto+Short label, 5=Short label+Picto, 6=Picto+Long label, 7=Very short label+Picto
  646. * @return string Label
  647. */
  648. public function getLibStatut($mode = 0)
  649. {
  650. return $this->LibStatut($this->statut, $mode);
  651. }
  652. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  653. /**
  654. * Return the label of a given status
  655. *
  656. * @param int $status Id status
  657. * @param int $mode 0=Long label, 1=Short label, 2=Picto+Short label, 3=Picto, 4=Picto+Short label, 5=Short label+Picto, 6=Picto+Long label, 7=Very short label+Picto
  658. * @return string Label
  659. */
  660. public function LibStatut($status, $mode = 0)
  661. {
  662. // phpcs:enable
  663. global $langs;
  664. $langs->load("mailing");
  665. $labelStatus = $langs->transnoentitiesnoconv($this->statuts[$status]);
  666. $labelStatusShort = $langs->transnoentitiesnoconv($this->statuts[$status]);
  667. $statusType = 'status'.$status;
  668. if ($status == 2) {
  669. $statusType = 'status3';
  670. }
  671. if ($status == 3) {
  672. $statusType = 'status6';
  673. }
  674. return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
  675. }
  676. /**
  677. * Return the label of a given status of a recipient
  678. * TODO Add class mailin_target.class.php
  679. *
  680. * @param int $status Id status
  681. * @param int $mode 0=Long label, 1=Short label, 2=Picto+Short label, 3=Picto, 4=Picto+Short label, 5=Short label+Picto, 6=Picto+Long label, 7=Very short label+Picto
  682. * @param string $desc Desc error
  683. * @return string Label
  684. */
  685. public static function libStatutDest($status, $mode = 0, $desc = '')
  686. {
  687. global $langs;
  688. $langs->load("mails");
  689. $labelStatus = array();
  690. $labelStatusShort = array();
  691. $labelStatus[-1] = $langs->transnoentitiesnoconv('MailingStatusError');
  692. $labelStatus[0] = $langs->transnoentitiesnoconv('MailingStatusNotSent');
  693. $labelStatus[1] = $langs->transnoentitiesnoconv('MailingStatusSent');
  694. $labelStatus[2] = $langs->transnoentitiesnoconv('MailingStatusRead');
  695. $labelStatus[3] = $langs->transnoentitiesnoconv('MailingStatusNotContact');
  696. $labelStatusShort[-1] = $langs->transnoentitiesnoconv('MailingStatusError');
  697. $labelStatusShort[0] = $langs->transnoentitiesnoconv('MailingStatusNotSent');
  698. $labelStatusShort[1] = $langs->transnoentitiesnoconv('MailingStatusSent');
  699. $labelStatusShort[2] = $langs->transnoentitiesnoconv('MailingStatusRead');
  700. $labelStatusShort[3] = $langs->transnoentitiesnoconv('MailingStatusNotContact');
  701. $statusType = 'status'.$status;
  702. if ($status == -1) {
  703. $statusType = 'status8';
  704. }
  705. if ($status == 1) {
  706. $statusType = 'status6';
  707. }
  708. if ($status == 2) {
  709. $statusType = 'status4';
  710. }
  711. $param = array();
  712. if ($status == - 1) {
  713. $param = array('badgeParams'=>array('attr'=>array('title'=>$desc)));
  714. }
  715. return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode, '', $param);
  716. }
  717. }