notify.class.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2018 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2021 Thibault FOUCART <support@ptibogxiv.net>
  7. * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/core/class/notify.class.php
  24. * \ingroup notification
  25. * \brief File of class to manage notifications
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  28. /**
  29. * Class to manage notifications
  30. */
  31. class Notify
  32. {
  33. /**
  34. * @var int ID
  35. */
  36. public $id;
  37. /**
  38. * @var DoliDB Database handler.
  39. */
  40. public $db;
  41. /**
  42. * @var string Error code (or message)
  43. */
  44. public $error = '';
  45. /**
  46. * @var string[] Error codes (or messages)
  47. */
  48. public $errors = array();
  49. public $author;
  50. public $ref;
  51. public $date;
  52. public $duree;
  53. public $note;
  54. /**
  55. * @var int Project ID
  56. */
  57. public $fk_project;
  58. // This codes actions are defined into table llx_notify_def
  59. static public $arrayofnotifsupported = array(
  60. 'BILL_VALIDATE',
  61. 'BILL_PAYED',
  62. 'ORDER_CREATE',
  63. 'ORDER_VALIDATE',
  64. 'PROPAL_VALIDATE',
  65. 'PROPAL_CLOSE_SIGNED',
  66. 'FICHINTER_VALIDATE',
  67. 'FICHINTER_ADD_CONTACT',
  68. 'ORDER_SUPPLIER_VALIDATE',
  69. 'ORDER_SUPPLIER_APPROVE',
  70. 'ORDER_SUPPLIER_REFUSE',
  71. 'SHIPPING_VALIDATE',
  72. 'EXPENSE_REPORT_VALIDATE',
  73. 'EXPENSE_REPORT_APPROVE',
  74. 'HOLIDAY_VALIDATE',
  75. 'HOLIDAY_APPROVE',
  76. 'ACTION_CREATE'
  77. );
  78. /**
  79. * Constructor
  80. *
  81. * @param DoliDB $db Database handler
  82. */
  83. public function __construct($db)
  84. {
  85. $this->db = $db;
  86. }
  87. /**
  88. * Return message that say how many notification (and to which email) will occurs on requested event.
  89. * This is to show confirmation messages before event is recorded.
  90. *
  91. * @param string $action Id of action in llx_c_action_trigger
  92. * @param int $socid Id of third party
  93. * @param Object $object Object the notification is about
  94. * @return string Message
  95. */
  96. public function confirmMessage($action, $socid, $object)
  97. {
  98. global $conf, $langs;
  99. $langs->load("mails");
  100. // Get full list of all notifications subscribed for $action, $socid and $object
  101. $listofnotiftodo = $this->getNotificationsArray($action, $socid, $object, 0);
  102. if (!empty($conf->global->NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER)) {
  103. foreach ($listofnotiftodo as $val) {
  104. if ($val['type'] == 'touser') {
  105. unset($listofnotiftodo[$val['email']]);
  106. //$listofnotiftodo = array_merge($listofnotiftodo);
  107. }
  108. }
  109. }
  110. if (!empty($conf->global->NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT)) {
  111. foreach ($listofnotiftodo as $val) {
  112. if ($val['type'] == 'tocontact') {
  113. unset($listofnotiftodo[$val['email']]);
  114. //$listofnotiftodo = array_merge($listofnotiftodo);
  115. }
  116. }
  117. }
  118. if (!empty($conf->global->NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX)) {
  119. foreach ($listofnotiftodo as $val) {
  120. if ($val['type'] == 'tofixedemail') {
  121. unset($listofnotiftodo[$val['email']]);
  122. //$listofnotiftodo = array_merge($listofnotiftodo);
  123. }
  124. }
  125. }
  126. $texte = '';
  127. $nb = -1;
  128. if (is_array($listofnotiftodo)) {
  129. $nb = count($listofnotiftodo);
  130. }
  131. if ($nb < 0) {
  132. $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
  133. } elseif ($nb == 0) {
  134. $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("NoNotificationsWillBeSent");
  135. } elseif ($nb == 1) {
  136. $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("ANotificationsWillBeSent");
  137. } elseif ($nb >= 2) {
  138. $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("SomeNotificationsWillBeSent", $nb);
  139. }
  140. if (is_array($listofnotiftodo)) {
  141. $i = 0;
  142. foreach ($listofnotiftodo as $val) {
  143. if ($i) {
  144. $texte .= ', ';
  145. } else {
  146. $texte .= ' (';
  147. }
  148. if ($val['isemailvalid']) {
  149. $texte .= $val['email'];
  150. } else {
  151. $texte .= $val['emaildesc'];
  152. }
  153. $i++;
  154. }
  155. if ($i) {
  156. $texte .= ')';
  157. }
  158. }
  159. return $texte;
  160. }
  161. /**
  162. * Return number of notifications activated for action code (and third party)
  163. *
  164. * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
  165. * @param int $socid Id of third party or 0 for all thirdparties or -1 for no thirdparties
  166. * @param Object $object Object the notification is about (need it to check threshold value of some notifications)
  167. * @param int $userid Id of user or 0 for all users or -1 for no users
  168. * @param array $scope Scope where to search
  169. * @return array|int <0 if KO, array of notifications to send if OK
  170. */
  171. public function getNotificationsArray($notifcode, $socid = 0, $object = null, $userid = 0, $scope = array('thirdparty', 'user', 'global'))
  172. {
  173. global $conf, $user;
  174. $error = 0;
  175. $resarray = array();
  176. $valueforthreshold = 0;
  177. if (is_object($object)) {
  178. $valueforthreshold = $object->total_ht;
  179. }
  180. $sqlnotifcode = '';
  181. if ($notifcode) {
  182. if (is_numeric($notifcode)) {
  183. $sqlnotifcode = " AND n.fk_action = ".((int) $notifcode); // Old usage
  184. } else {
  185. $sqlnotifcode = " AND a.code = '".$this->db->escape($notifcode)."'"; // New usage
  186. }
  187. }
  188. if (!$error) {
  189. if ($socid >= 0 && in_array('thirdparty', $scope)) {
  190. $sql = "SELECT a.code, c.email, c.rowid";
  191. $sql .= " FROM ".$this->db->prefix()."notify_def as n,";
  192. $sql .= " ".$this->db->prefix()."socpeople as c,";
  193. $sql .= " ".$this->db->prefix()."c_action_trigger as a,";
  194. $sql .= " ".$this->db->prefix()."societe as s";
  195. $sql .= " WHERE n.fk_contact = c.rowid";
  196. $sql .= " AND a.rowid = n.fk_action";
  197. $sql .= " AND n.fk_soc = s.rowid";
  198. $sql .= $sqlnotifcode;
  199. $sql .= " AND s.entity IN (".getEntity('societe').")";
  200. if ($socid > 0) {
  201. $sql .= " AND s.rowid = ".((int) $socid);
  202. }
  203. dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
  204. $resql = $this->db->query($sql);
  205. if ($resql) {
  206. $num = $this->db->num_rows($resql);
  207. $i = 0;
  208. while ($i < $num) {
  209. $obj = $this->db->fetch_object($resql);
  210. if ($obj) {
  211. $newval2 = trim($obj->email);
  212. $isvalid = isValidEmail($newval2);
  213. if (empty($resarray[$newval2])) {
  214. $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
  215. }
  216. }
  217. $i++;
  218. }
  219. } else {
  220. $error++;
  221. $this->error = $this->db->lasterror();
  222. }
  223. }
  224. }
  225. if (!$error) {
  226. if ($userid >= 0 && in_array('user', $scope)) {
  227. $sql = "SELECT a.code, c.email, c.rowid";
  228. $sql .= " FROM ".$this->db->prefix()."notify_def as n,";
  229. $sql .= " ".$this->db->prefix()."user as c,";
  230. $sql .= " ".$this->db->prefix()."c_action_trigger as a";
  231. $sql .= " WHERE n.fk_user = c.rowid";
  232. $sql .= " AND a.rowid = n.fk_action";
  233. $sql .= $sqlnotifcode;
  234. $sql .= " AND c.entity IN (".getEntity('user').")";
  235. if ($userid > 0) {
  236. $sql .= " AND c.rowid = ".((int) $userid);
  237. }
  238. dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
  239. $resql = $this->db->query($sql);
  240. if ($resql) {
  241. $num = $this->db->num_rows($resql);
  242. $i = 0;
  243. while ($i < $num) {
  244. $obj = $this->db->fetch_object($resql);
  245. if ($obj) {
  246. $newval2 = trim($obj->email);
  247. $isvalid = isValidEmail($newval2);
  248. if (empty($resarray[$newval2])) {
  249. $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
  250. }
  251. }
  252. $i++;
  253. }
  254. } else {
  255. $error++;
  256. $this->error = $this->db->lasterror();
  257. }
  258. }
  259. }
  260. if (!$error) {
  261. if (in_array('global', $scope)) {
  262. // List of notifications enabled for fixed email
  263. foreach ($conf->global as $key => $val) {
  264. if ($notifcode) {
  265. if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
  266. continue;
  267. }
  268. } else {
  269. if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
  270. continue;
  271. }
  272. }
  273. $threshold = (float) $reg[1];
  274. if ($valueforthreshold < $threshold) {
  275. continue;
  276. }
  277. $tmpemail = explode(',', $val);
  278. foreach ($tmpemail as $key2 => $val2) {
  279. $newval2 = trim($val2);
  280. if ($newval2 == '__SUPERVISOREMAIL__') {
  281. if ($user->fk_user > 0) {
  282. $tmpuser = new User($this->db);
  283. $tmpuser->fetch($user->fk_user);
  284. if ($tmpuser->email) {
  285. $newval2 = trim($tmpuser->email);
  286. } else {
  287. $newval2 = '';
  288. }
  289. } else {
  290. $newval2 = '';
  291. }
  292. }
  293. if ($newval2) {
  294. $isvalid = isValidEmail($newval2, 0);
  295. if (empty($resarray[$newval2])) {
  296. $resarray[$newval2] = array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
  297. }
  298. }
  299. }
  300. }
  301. }
  302. }
  303. if ($error) {
  304. return -1;
  305. }
  306. //var_dump($resarray);
  307. return $resarray;
  308. }
  309. /**
  310. * Check if notification are active for couple action/company.
  311. * If yes, send mail and save trace into llx_notify.
  312. *
  313. * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
  314. * @param Object $object Object the notification deals on
  315. * @param array $filename_list List of files to attach (full path of filename on file system)
  316. * @param array $mimetype_list List of MIME type of attached files
  317. * @param array $mimefilename_list List of attached file name in message
  318. * @return int <0 if KO, or number of changes if OK
  319. */
  320. public function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
  321. {
  322. global $user, $conf, $langs, $mysoc;
  323. global $hookmanager;
  324. global $dolibarr_main_url_root;
  325. global $action;
  326. if (!is_object($hookmanager)) {
  327. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  328. $hookmanager = new HookManager($this->db);
  329. }
  330. $hookmanager->initHooks(array('notification'));
  331. $parameters = array('notifcode' => $notifcode);
  332. $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action);
  333. if (empty($reshook)) {
  334. if (!empty($hookmanager->resArray['arrayofnotifsupported'])) {
  335. Notify::$arrayofnotifsupported = array_merge(Notify::$arrayofnotifsupported, $hookmanager->resArray['arrayofnotifsupported']);
  336. }
  337. }
  338. if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
  339. return 0;
  340. }
  341. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  342. dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id);
  343. $langs->load("other");
  344. // Define $urlwithroot
  345. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  346. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  347. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  348. // Define some vars
  349. $application = 'Dolibarr';
  350. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  351. $application = $conf->global->MAIN_APPLICATION_TITLE;
  352. }
  353. $replyto = $conf->notification->email_from;
  354. $object_type = '';
  355. $link = '';
  356. $num = 0;
  357. $error = 0;
  358. $oldref = (empty($object->oldref) ? $object->ref : $object->oldref);
  359. $newref = (empty($object->newref) ? $object->ref : $object->newref);
  360. $sql = '';
  361. // Check notification per third party
  362. if (!empty($object->socid) && $object->socid > 0) {
  363. $sql .= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
  364. $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
  365. $sql .= " FROM ".$this->db->prefix()."socpeople as c,";
  366. $sql .= " ".$this->db->prefix()."c_action_trigger as a,";
  367. $sql .= " ".$this->db->prefix()."notify_def as n,";
  368. $sql .= " ".$this->db->prefix()."societe as s";
  369. $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
  370. $sql .= " AND n.fk_soc = s.rowid";
  371. $sql .= " AND c.statut = 1";
  372. if (is_numeric($notifcode)) {
  373. $sql .= " AND n.fk_action = ".((int) $notifcode); // Old usage
  374. } else {
  375. $sql .= " AND a.code = '".$this->db->escape($notifcode)."'"; // New usage
  376. }
  377. $sql .= " AND s.rowid = ".((int) $object->socid);
  378. $sql .= "\nUNION\n";
  379. }
  380. // Check notification per user
  381. $sql .= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
  382. $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
  383. $sql .= " FROM ".$this->db->prefix()."user as c,";
  384. $sql .= " ".$this->db->prefix()."c_action_trigger as a,";
  385. $sql .= " ".$this->db->prefix()."notify_def as n";
  386. $sql .= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
  387. $sql .= " AND c.statut = 1";
  388. if (is_numeric($notifcode)) {
  389. $sql .= " AND n.fk_action = ".((int) $notifcode); // Old usage
  390. } else {
  391. $sql .= " AND a.code = '".$this->db->escape($notifcode)."'"; // New usage
  392. }
  393. $result = $this->db->query($sql);
  394. if ($result) {
  395. $num = $this->db->num_rows($result);
  396. $projtitle = '';
  397. if (!empty($object->fk_project)) {
  398. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  399. $proj = new Project($this->db);
  400. $proj->fetch($object->fk_project);
  401. $projtitle = '('.$proj->title.')';
  402. }
  403. if ($num > 0) {
  404. $i = 0;
  405. while ($i < $num && !$error) { // For each notification couple defined (third party/actioncode)
  406. $obj = $this->db->fetch_object($result);
  407. $sendto = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">";
  408. $notifcodedefid = $obj->adid;
  409. $trackid = '';
  410. if ($obj->type_target == 'tocontactid') {
  411. $trackid = 'con'.$obj->cid;
  412. }
  413. if ($obj->type_target == 'touserid') {
  414. $trackid = 'use'.$obj->cid;
  415. }
  416. if (dol_strlen($obj->email)) {
  417. // Set output language
  418. $outputlangs = $langs;
  419. if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
  420. $outputlangs = new Translate('', $conf);
  421. $outputlangs->setDefaultLang($obj->default_lang);
  422. $outputlangs->loadLangs(array("main", "other"));
  423. }
  424. $subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification").($projtitle ? ' '.$projtitle : '');
  425. switch ($notifcode) {
  426. case 'BILL_VALIDATE':
  427. $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  428. $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
  429. $object_type = 'facture';
  430. $labeltouse = $conf->global->BILL_VALIDATE_TEMPLATE;
  431. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceValidated", $link);
  432. break;
  433. case 'BILL_PAYED':
  434. $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  435. $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
  436. $object_type = 'facture';
  437. $labeltouse = $conf->global->BILL_PAYED_TEMPLATE;
  438. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoicePayed", $link);
  439. break;
  440. case 'ORDER_VALIDATE':
  441. $link = '<a href="'.$urlwithroot.'/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  442. $dir_output = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
  443. $object_type = 'order';
  444. $labeltouse = $conf->global->ORDER_VALIDATE_TEMPLATE;
  445. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderValidated", $link);
  446. break;
  447. case 'PROPAL_VALIDATE':
  448. $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  449. $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
  450. $object_type = 'propal';
  451. $labeltouse = $conf->global->PROPAL_VALIDATE_TEMPLATE;
  452. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalValidated", $link);
  453. break;
  454. case 'PROPAL_CLOSE_SIGNED':
  455. $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  456. $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
  457. $object_type = 'propal';
  458. $labeltouse = $conf->global->PROPAL_CLOSE_SIGNED_TEMPLATE;
  459. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedSigned", $link);
  460. break;
  461. case 'FICHINTER_ADD_CONTACT':
  462. $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  463. $dir_output = $conf->ficheinter->dir_output;
  464. $object_type = 'ficheinter';
  465. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link);
  466. break;
  467. case 'FICHINTER_VALIDATE':
  468. $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  469. $dir_output = $conf->ficheinter->dir_output;
  470. $object_type = 'ficheinter';
  471. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated", $link);
  472. break;
  473. case 'ORDER_SUPPLIER_VALIDATE':
  474. $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  475. $dir_output = $conf->fournisseur->commande->dir_output;
  476. $object_type = 'order_supplier';
  477. $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
  478. $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $link, $user->getFullName($outputlangs));
  479. $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
  480. break;
  481. case 'ORDER_SUPPLIER_APPROVE':
  482. $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  483. $dir_output = $conf->fournisseur->commande->dir_output;
  484. $object_type = 'order_supplier';
  485. $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
  486. $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $link, $user->getFullName($outputlangs));
  487. $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
  488. break;
  489. case 'ORDER_SUPPLIER_REFUSE':
  490. $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  491. $dir_output = $conf->fournisseur->commande->dir_output;
  492. $object_type = 'order_supplier';
  493. $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
  494. $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $link, $user->getFullName($outputlangs));
  495. $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
  496. break;
  497. case 'SHIPPING_VALIDATE':
  498. $link = '<a href="'.$urlwithroot.'/expedition/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  499. $dir_output = $conf->expedition->dir_output."/sending/".get_exdir(0, 0, 0, 1, $object, 'shipment');
  500. $object_type = 'shipping';
  501. $labeltouse = $conf->global->SHIPPING_VALIDATE_TEMPLATE;
  502. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated", $link);
  503. break;
  504. case 'EXPENSE_REPORT_VALIDATE':
  505. $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  506. $dir_output = $conf->expensereport->dir_output;
  507. $object_type = 'expensereport';
  508. $labeltouse = $conf->global->EXPENSE_REPORT_VALIDATE_TEMPLATE;
  509. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $link);
  510. break;
  511. case 'EXPENSE_REPORT_APPROVE':
  512. $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  513. $dir_output = $conf->expensereport->dir_output;
  514. $object_type = 'expensereport';
  515. $labeltouse = $conf->global->EXPENSE_REPORT_APPROVE_TEMPLATE;
  516. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $link);
  517. break;
  518. case 'HOLIDAY_VALIDATE':
  519. $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  520. $dir_output = $conf->holiday->dir_output;
  521. $object_type = 'holiday';
  522. $labeltouse = $conf->global->HOLIDAY_VALIDATE_TEMPLATE;
  523. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated", $link);
  524. break;
  525. case 'HOLIDAY_APPROVE':
  526. $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  527. $dir_output = $conf->holiday->dir_output;
  528. $object_type = 'holiday';
  529. $labeltouse = $conf->global->HOLIDAY_APPROVE_TEMPLATE;
  530. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved", $link);
  531. break;
  532. case 'ACTION_CREATE':
  533. $link = '<a href="'.$urlwithroot.'/comm/action/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  534. $dir_output = $conf->agenda->dir_output;
  535. $object_type = 'action';
  536. $labeltouse = $conf->global->ACTION_CREATE_TEMPLATE;
  537. $mesg = $outputlangs->transnoentitiesnoconv("EMailTextActionAdded", $link);
  538. break;
  539. default:
  540. $object_type = $object->element;
  541. $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object, $object_type);
  542. $template = $notifcode.'_TEMPLATE';
  543. $labeltouse = $conf->global->$template;
  544. $mesg = $outputlangs->transnoentitiesnoconv('Notify_'.$notifcode).' '.$newref.' '.$dir_output;
  545. break;
  546. }
  547. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  548. $formmail = new FormMail($this->db);
  549. $arraydefaultmessage = null;
  550. if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.'_send', $user, $outputlangs, 0, 1, $labeltouse);
  551. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  552. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  553. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  554. $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
  555. $message = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
  556. } else {
  557. $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name)."\n";
  558. $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n";
  559. $message .= "\n";
  560. $message .= $mesg;
  561. }
  562. $ref = dol_sanitizeFileName($newref);
  563. $pdf_path = $dir_output."/".$ref.".pdf";
  564. if (!dol_is_file($pdf_path)) {
  565. // We can't add PDF as it is not generated yet.
  566. $filepdf = '';
  567. } else {
  568. $filepdf = $pdf_path;
  569. $filename_list[] = $filepdf;
  570. $mimetype_list[] = mime_content_type($filepdf);
  571. $mimefilename_list[] = $ref.".pdf";
  572. }
  573. $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list, 'outputlangs'=>$outputlangs, 'labeltouse'=>$labeltouse);
  574. if (!isset($action)) {
  575. $action = '';
  576. }
  577. $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  578. if (empty($reshook)) {
  579. if (!empty($hookmanager->resArray['subject'])) {
  580. $subject .= $hookmanager->resArray['subject'];
  581. }
  582. if (!empty($hookmanager->resArray['message'])) {
  583. $message .= $hookmanager->resArray['message'];
  584. }
  585. }
  586. $mailfile = new CMailFile(
  587. $subject,
  588. $sendto,
  589. $replyto,
  590. $message,
  591. $filename_list,
  592. $mimetype_list,
  593. $mimefilename_list,
  594. '',
  595. '',
  596. 0,
  597. -1,
  598. '',
  599. '',
  600. $trackid,
  601. '',
  602. 'notification'
  603. );
  604. if ($mailfile->sendfile()) {
  605. if ($obj->type_target == 'touserid') {
  606. $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
  607. $sql .= " VALUES ('".$this->db->idate(dol_now())."', ".((int) $notifcodedefid).", ".($object->socid > 0 ? ((int) $object->socid) : 'null').", ".((int) $obj->cid).", '".$this->db->escape($obj->type)."', '".$this->db->escape($object_type)."', '".$this->db->escape($obj->type_target)."', ".((int) $object->id).", '".$this->db->escape($obj->email)."')";
  608. } else {
  609. $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
  610. $sql .= " VALUES ('".$this->db->idate(dol_now())."', ".((int) $notifcodedefid).", ".($object->socid > 0 ? ((int) $object->socid) : 'null').", ".((int) $obj->cid).", '".$this->db->escape($obj->type)."', '".$this->db->escape($object_type)."', '".$this->db->escape($obj->type_target)."', ".((int) $object->id).", '".$this->db->escape($obj->email)."')";
  611. }
  612. if (!$this->db->query($sql)) {
  613. dol_print_error($this->db);
  614. }
  615. } else {
  616. $error++;
  617. $this->errors[] = $mailfile->error;
  618. }
  619. } else {
  620. dol_syslog("No notification sent for ".$sendto." because email is empty");
  621. }
  622. $i++;
  623. }
  624. } else {
  625. dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ? '' : $object->socid));
  626. }
  627. } else {
  628. $error++;
  629. $this->errors[] = $this->db->lasterror();
  630. dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
  631. return -1;
  632. }
  633. // Check notification using fixed email
  634. if (!$error) {
  635. foreach ($conf->global as $key => $val) {
  636. $reg = array();
  637. if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
  638. continue;
  639. }
  640. $threshold = (float) $reg[1];
  641. if (!empty($object->total_ht) && $object->total_ht <= $threshold) {
  642. dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification");
  643. continue;
  644. }
  645. $param = 'NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1];
  646. $sendto = $conf->global->$param;
  647. $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
  648. if ($notifcodedefid <= 0) {
  649. dol_print_error($this->db, 'Failed to get id from code');
  650. }
  651. $trackid = '';
  652. $object_type = '';
  653. $link = '';
  654. $num++;
  655. $subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification").($projtitle ? ' '.$projtitle : '');
  656. switch ($notifcode) {
  657. case 'BILL_VALIDATE':
  658. $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  659. $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
  660. $object_type = 'facture';
  661. $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $link);
  662. break;
  663. case 'BILL_PAYED':
  664. $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  665. $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
  666. $object_type = 'facture';
  667. $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed", $link);
  668. break;
  669. case 'ORDER_VALIDATE':
  670. $link = '<a href="'.$urlwithroot.'/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  671. $dir_output = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
  672. $object_type = 'order';
  673. $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $link);
  674. break;
  675. case 'PROPAL_VALIDATE':
  676. $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  677. $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
  678. $object_type = 'propal';
  679. $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $link);
  680. break;
  681. case 'PROPAL_CLOSE_SIGNED':
  682. $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  683. $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
  684. $object_type = 'propal';
  685. $mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned", $link);
  686. break;
  687. case 'FICHINTER_ADD_CONTACT':
  688. $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  689. $dir_output = $conf->ficheinter->dir_output;
  690. $object_type = 'ficheinter';
  691. $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link);
  692. break;
  693. case 'FICHINTER_VALIDATE':
  694. $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  695. $dir_output = $conf->facture->dir_output;
  696. $object_type = 'ficheinter';
  697. $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $link);
  698. break;
  699. case 'ORDER_SUPPLIER_VALIDATE':
  700. $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  701. $dir_output = $conf->fournisseur->commande->dir_output;
  702. $object_type = 'order_supplier';
  703. $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
  704. $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $link, $user->getFullName($langs));
  705. $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
  706. break;
  707. case 'ORDER_SUPPLIER_APPROVE':
  708. $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  709. $dir_output = $conf->fournisseur->commande->dir_output;
  710. $object_type = 'order_supplier';
  711. $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
  712. $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
  713. $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
  714. break;
  715. case 'ORDER_SUPPLIER_APPROVE2':
  716. $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  717. $dir_output = $conf->fournisseur->commande->dir_output;
  718. $object_type = 'order_supplier';
  719. $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
  720. $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
  721. $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
  722. break;
  723. case 'ORDER_SUPPLIER_REFUSE':
  724. $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  725. $dir_output = $conf->fournisseur->dir_output.'/commande/';
  726. $object_type = 'order_supplier';
  727. $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
  728. $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $link, $user->getFullName($langs));
  729. $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
  730. break;
  731. case 'SHIPPING_VALIDATE':
  732. $link = '<a href="'.$urlwithroot.'/expedition/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  733. $dir_output = $conf->expedition->dir_output."/sending/".get_exdir(0, 0, 0, 1, $object, 'shipment');
  734. $object_type = 'order_supplier';
  735. $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $link);
  736. break;
  737. case 'EXPENSE_REPORT_VALIDATE':
  738. $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  739. $dir_output = $conf->expensereport->dir_output;
  740. $object_type = 'expensereport';
  741. $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $link);
  742. break;
  743. case 'EXPENSE_REPORT_APPROVE':
  744. $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  745. $dir_output = $conf->expensereport->dir_output;
  746. $object_type = 'expensereport';
  747. $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $link);
  748. break;
  749. case 'HOLIDAY_VALIDATE':
  750. $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  751. $dir_output = $conf->holiday->dir_output;
  752. $object_type = 'holiday';
  753. $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated", $link);
  754. break;
  755. case 'HOLIDAY_APPROVE':
  756. $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  757. $dir_output = $conf->holiday->dir_output;
  758. $object_type = 'holiday';
  759. $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved", $link);
  760. break;
  761. case 'ACTION_CREATE':
  762. $link = '<a href="'.$urlwithroot.'/comm/action/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
  763. $dir_output = $conf->agenda->dir_output;
  764. $object_type = 'action';
  765. $mesg = $langs->transnoentitiesnoconv("EMailTextActionAdded", $link);
  766. break;
  767. default:
  768. $object_type = $object->element;
  769. $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object, $object_type);
  770. $mesg = $langs->transnoentitiesnoconv('Notify_'.$notifcode).' '.$newref;
  771. break;
  772. }
  773. $ref = dol_sanitizeFileName($newref);
  774. $pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
  775. if (!dol_is_file($pdf_path)) {
  776. // We can't add PDF as it is not generated yet.
  777. $filepdf = '';
  778. } else {
  779. $filepdf = $pdf_path;
  780. $filename_list[] = $pdf_path;
  781. $mimetype_list[] = mime_content_type($filepdf);
  782. $mimefilename_list[] = $ref.".pdf";
  783. }
  784. $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n";
  785. $message .= "\n";
  786. $message .= $mesg;
  787. $message = nl2br($message);
  788. // Replace keyword __SUPERVISOREMAIL__
  789. if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) {
  790. $newval = '';
  791. if ($user->fk_user > 0) {
  792. $supervisoruser = new User($this->db);
  793. $supervisoruser->fetch($user->fk_user);
  794. if ($supervisoruser->email) {
  795. $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
  796. }
  797. }
  798. dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
  799. $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
  800. $sendto = preg_replace('/,\s*,/', ',', $sendto); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email, , othermail" and it's not valid
  801. $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string
  802. $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string
  803. }
  804. if ($sendto) {
  805. $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
  806. $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  807. if (empty($reshook)) {
  808. if (!empty($hookmanager->resArray['subject'])) {
  809. $subject .= $hookmanager->resArray['subject'];
  810. }
  811. if (!empty($hookmanager->resArray['message'])) {
  812. $message .= $hookmanager->resArray['message'];
  813. }
  814. }
  815. $mailfile = new CMailFile(
  816. $subject,
  817. $sendto,
  818. $replyto,
  819. $message,
  820. $filename_list,
  821. $mimetype_list,
  822. $mimefilename_list,
  823. '',
  824. '',
  825. 0,
  826. 1,
  827. '',
  828. $trackid,
  829. '',
  830. '',
  831. 'notification'
  832. );
  833. if ($mailfile->sendfile()) {
  834. $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
  835. $sql .= " VALUES ('".$this->db->idate(dol_now())."', ".((int) $notifcodedefid).", ".($object->socid > 0 ? ((int) $object->socid) : 'null').", null, 'email', 'tofixedemail', '".$this->db->escape($object_type)."', ".((int) $object->id).", '".$this->db->escape($conf->global->$param)."')";
  836. if (!$this->db->query($sql)) {
  837. dol_print_error($this->db);
  838. }
  839. } else {
  840. $error++;
  841. $this->errors[] = $mailfile->error;
  842. }
  843. }
  844. }
  845. }
  846. if (!$error) {
  847. return $num;
  848. } else {
  849. return -1 * $error;
  850. }
  851. }
  852. }