mailing.class.php 22 KB

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