mailing.class.php 22 KB

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