dolibarr 19.0.3
notify.class.php
Go to the documentation of this file.
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 * Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
30
34class Notify
35{
39 public $id;
40
44 public $db;
45
49 public $error = '';
50
54 public $errors = array();
55
56 public $author;
57 public $ref;
58 public $date;
59 public $duree;
60 public $note;
61
65 public $fk_project;
66
67 // This codes actions are defined into table llx_notify_def
68 public static $arrayofnotifsupported = array(
69 'BILL_VALIDATE',
70 'BILL_PAYED',
71 'ORDER_CREATE',
72 'ORDER_VALIDATE',
73 'ORDER_CLOSE',
74 'PROPAL_VALIDATE',
75 'PROPAL_CLOSE_SIGNED',
76 'PROPAL_CLOSE_REFUSED',
77 'FICHINTER_VALIDATE',
78 'FICHINTER_CLOSE',
79 'FICHINTER_ADD_CONTACT',
80 'ORDER_SUPPLIER_VALIDATE',
81 'ORDER_SUPPLIER_APPROVE',
82 'ORDER_SUPPLIER_SUBMIT',
83 'ORDER_SUPPLIER_REFUSE',
84 'SHIPPING_VALIDATE',
85 'EXPENSE_REPORT_VALIDATE',
86 'EXPENSE_REPORT_APPROVE',
87 'HOLIDAY_VALIDATE',
88 'HOLIDAY_APPROVE',
89 'ACTION_CREATE'
90 );
91
97 public function __construct($db)
98 {
99 $this->db = $db;
100 }
101
102
112 public function confirmMessage($action, $socid, $object)
113 {
114 global $conf, $langs;
115 $langs->load("mails");
116
117 // Get full list of all notifications subscribed for $action, $socid and $object
118 $listofnotiftodo = $this->getNotificationsArray($action, $socid, $object, 0);
119
120 if (getDolGlobalString('NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER')) {
121 foreach ($listofnotiftodo as $val) {
122 if ($val['type'] == 'touser') {
123 unset($listofnotiftodo[$val['email']]);
124 //$listofnotiftodo = array_merge($listofnotiftodo);
125 }
126 }
127 }
128 if (getDolGlobalString('NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT')) {
129 foreach ($listofnotiftodo as $val) {
130 if ($val['type'] == 'tocontact') {
131 unset($listofnotiftodo[$val['email']]);
132 //$listofnotiftodo = array_merge($listofnotiftodo);
133 }
134 }
135 }
136 if (getDolGlobalString('NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX')) {
137 foreach ($listofnotiftodo as $val) {
138 if ($val['type'] == 'tofixedemail') {
139 unset($listofnotiftodo[$val['email']]);
140 //$listofnotiftodo = array_merge($listofnotiftodo);
141 }
142 }
143 }
144
145 $texte = '';
146 $nb = -1;
147 if (is_array($listofnotiftodo)) {
148 $nb = count($listofnotiftodo);
149 }
150 if ($nb < 0) {
151 $texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
152 } elseif ($nb == 0) {
153 $texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("NoNotificationsWillBeSent");
154 } elseif ($nb == 1) {
155 $texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("ANotificationsWillBeSent");
156 } elseif ($nb >= 2) {
157 $texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("SomeNotificationsWillBeSent", $nb);
158 }
159
160 if (is_array($listofnotiftodo)) {
161 $i = 0;
162 foreach ($listofnotiftodo as $val) {
163 if ($i) {
164 $texte .= ', ';
165 } else {
166 $texte .= ' (';
167 }
168 if ($val['isemailvalid']) {
169 $texte .= $val['email'];
170 } else {
171 $texte .= $val['emaildesc'];
172 }
173 $i++;
174 }
175 if ($i) {
176 $texte .= ')';
177 }
178 }
179
180 return $texte;
181 }
182
193 public function getNotificationsArray($notifcode, $socid = 0, $object = null, $userid = 0, $scope = array('thirdparty', 'user', 'global'))
194 {
195 global $conf, $user;
196
197 $error = 0;
198 $resarray = array();
199
200 $valueforthreshold = 0;
201 if (is_object($object)) {
202 $valueforthreshold = $object->total_ht;
203 }
204
205 $sqlnotifcode = '';
206 if ($notifcode) {
207 if (is_numeric($notifcode)) {
208 $sqlnotifcode = " AND n.fk_action = ".((int) $notifcode); // Old usage
209 } else {
210 $sqlnotifcode = " AND a.code = '".$this->db->escape($notifcode)."'"; // New usage
211 }
212 }
213
214 if (!$error) {
215 if ($socid >= 0 && in_array('thirdparty', $scope)) {
216 $sql = "SELECT a.code, c.email, c.rowid, c.statut as status";
217 $sql .= " FROM ".$this->db->prefix()."notify_def as n,";
218 $sql .= " ".$this->db->prefix()."socpeople as c,";
219
220 $sql .= " ".$this->db->prefix()."c_action_trigger as a,";
221 $sql .= " ".$this->db->prefix()."societe as s";
222 $sql .= " WHERE n.fk_contact = c.rowid";
223 $sql .= " AND a.rowid = n.fk_action";
224 $sql .= " AND n.fk_soc = s.rowid";
225 $sql .= $sqlnotifcode;
226 $sql .= " AND s.entity IN (".getEntity('societe').")";
227 if ($socid > 0) {
228 $sql .= " AND s.rowid = ".((int) $socid);
229 }
230
231 dol_syslog(__METHOD__." ".$notifcode.", ".$socid, LOG_DEBUG);
232
233 $resql = $this->db->query($sql);
234 if ($resql) {
235 $num = $this->db->num_rows($resql);
236 $i = 0;
237 while ($i < $num) {
238 $obj = $this->db->fetch_object($resql);
239 // we want to notify only if contact is enable
240 if ($obj && $obj->status == 1) {
241 $newval2 = trim($obj->email);
242 $isvalid = isValidEmail($newval2);
243 if (empty($resarray[$newval2])) {
244 $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
245 }
246 }
247 $i++;
248 }
249 } else {
250 $error++;
251 $this->error = $this->db->lasterror();
252 }
253 }
254 }
255
256 if (!$error) {
257 if ($userid >= 0 && in_array('user', $scope)) {
258 $sql = "SELECT a.code, c.email, c.rowid";
259 $sql .= " FROM ".$this->db->prefix()."notify_def as n,";
260 $sql .= " ".$this->db->prefix()."user as c,";
261 $sql .= " ".$this->db->prefix()."c_action_trigger as a";
262 $sql .= " WHERE n.fk_user = c.rowid";
263 $sql .= " AND a.rowid = n.fk_action";
264 $sql .= $sqlnotifcode;
265 $sql .= " AND c.entity IN (".getEntity('user').")";
266 if ($userid > 0) {
267 $sql .= " AND c.rowid = ".((int) $userid);
268 }
269
270 dol_syslog(__METHOD__." ".$notifcode.", ".$socid, LOG_DEBUG);
271
272 $resql = $this->db->query($sql);
273 if ($resql) {
274 $num = $this->db->num_rows($resql);
275 $i = 0;
276 while ($i < $num) {
277 $obj = $this->db->fetch_object($resql);
278 if ($obj) {
279 $newval2 = trim($obj->email);
280 $isvalid = isValidEmail($newval2);
281 if (empty($resarray[$newval2])) {
282 $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
283 }
284 }
285 $i++;
286 }
287 } else {
288 $error++;
289 $this->error = $this->db->lasterror();
290 }
291 }
292 }
293
294 if (!$error) {
295 if (in_array('global', $scope)) {
296 // List of notifications enabled for fixed email
297 foreach ($conf->global as $key => $val) {
298 if ($notifcode) {
299 if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
300 continue;
301 }
302 } else {
303 if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
304 continue;
305 }
306 }
307
308 $threshold = (float) $reg[1];
309 if ($valueforthreshold < $threshold) {
310 continue;
311 }
312
313 $tmpemail = explode(',', $val);
314 foreach ($tmpemail as $key2 => $val2) {
315 $newval2 = trim($val2);
316 if ($newval2 == '__SUPERVISOREMAIL__') {
317 if ($user->fk_user > 0) {
318 $tmpuser = new User($this->db);
319 $tmpuser->fetch($user->fk_user);
320 if ($tmpuser->email) {
321 $newval2 = trim($tmpuser->email);
322 } else {
323 $newval2 = '';
324 }
325 } else {
326 $newval2 = '';
327 }
328 }
329 if ($newval2) {
330 $isvalid = isValidEmail($newval2, 0);
331 if (empty($resarray[$newval2])) {
332 $resarray[$newval2] = array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
333 }
334 }
335 }
336 }
337 }
338 }
339
340 if ($error) {
341 return -1;
342 }
343
344 //var_dump($resarray);
345 return $resarray;
346 }
347
359 public function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
360 {
361 global $user, $conf, $langs, $mysoc;
362 global $hookmanager;
363 global $dolibarr_main_url_root;
364 global $action;
365
366 // Complete the array Notify::$arrayofnotifsupported
367 if (!is_object($hookmanager)) {
368 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
369 $hookmanager = new HookManager($this->db);
370 }
371 $hookmanager->initHooks(array('notification'));
372
373 $parameters = array('notifcode' => $notifcode);
374 $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action);
375 if (empty($reshook)) {
376 if (!empty($hookmanager->resArray['arrayofnotifsupported'])) {
377 Notify::$arrayofnotifsupported = array_merge(Notify::$arrayofnotifsupported, $hookmanager->resArray['arrayofnotifsupported']);
378 }
379 }
380
381 // If the trigger code is not managed by the Notification module
382 if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
383 return 0;
384 }
385
386 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
387
388 dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object id=".$object->id);
389
390 $langs->load("other");
391
392 // Define $urlwithroot
393 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
394 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
395 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
396
397 // Define some vars
398 $application = 'Dolibarr';
399 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
400 $application = $conf->global->MAIN_APPLICATION_TITLE;
401 }
402 $replyto = $conf->notification->email_from;
403 $object_type = '';
404 $link = '';
405 $num = 0;
406 $error = 0;
407
408 $oldref = (empty($object->oldref) ? $object->ref : $object->oldref);
409 $newref = (empty($object->newref) ? $object->ref : $object->newref);
410
411 $sql = '';
412
413 // Check notification per third party
414 if (!empty($object->socid) && $object->socid > 0) {
415 $sql .= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
416 $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
417 $sql .= " FROM ".$this->db->prefix()."socpeople as c,";
418 $sql .= " ".$this->db->prefix()."c_action_trigger as a,";
419 $sql .= " ".$this->db->prefix()."notify_def as n,";
420 $sql .= " ".$this->db->prefix()."societe as s";
421 $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
422 $sql .= " AND n.fk_soc = s.rowid";
423 $sql .= " AND c.statut = 1";
424 if (is_numeric($notifcode)) {
425 $sql .= " AND n.fk_action = ".((int) $notifcode); // Old usage
426 } else {
427 $sql .= " AND a.code = '".$this->db->escape($notifcode)."'"; // New usage
428 }
429 $sql .= " AND s.rowid = ".((int) $object->socid);
430
431 $sql .= "\nUNION\n";
432 }
433
434 // Check notification per user
435 $sql .= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
436 $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
437 $sql .= " FROM ".$this->db->prefix()."user as c,";
438 $sql .= " ".$this->db->prefix()."c_action_trigger as a,";
439 $sql .= " ".$this->db->prefix()."notify_def as n";
440 $sql .= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
441 $sql .= " AND c.statut = 1";
442 if (is_numeric($notifcode)) {
443 $sql .= " AND n.fk_action = ".((int) $notifcode); // Old usage
444 } else {
445 $sql .= " AND a.code = '".$this->db->escape($notifcode)."'"; // New usage
446 }
447
448 // Check notification fixed
449 // TODO Move part found after, into a sql here
450
451
452 // Loop on all notifications enabled
453 $result = $this->db->query($sql);
454 if ($result) {
455 $num = $this->db->num_rows($result);
456 $projtitle = '';
457 if (is_object($object->project) || $object->fetch_project() > 0) {
458 $projtitle = '('.$object->project->title.')';
459 }
460
461 if ($num > 0) {
462 $i = 0;
463 while ($i < $num && !$error) { // For each notification couple defined (third party/actioncode)
464 $obj = $this->db->fetch_object($result);
465
466 $sendto = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">";
467 $notifcodedefid = $obj->adid;
468 $trackid = '';
469 if ($obj->type_target == 'tocontactid') {
470 $trackid = 'ctc'.$obj->cid;
471 }
472 if ($obj->type_target == 'touserid') {
473 $trackid = 'use'.$obj->cid;
474 }
475
476 if (dol_strlen($obj->email)) {
477 // Set output language
478 $outputlangs = $langs;
479 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
480 $outputlangs = new Translate('', $conf);
481 $outputlangs->setDefaultLang($obj->default_lang);
482 $outputlangs->loadLangs(array("main", "other"));
483 }
484
485 $appli = $mysoc->name;
486
487 $subject = '['.$appli.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification").($projtitle ? ' '.$projtitle : '');
488
489 switch ($notifcode) {
490 case 'BILL_VALIDATE':
491 $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
492 $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
493 $object_type = 'facture';
494 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceValidated", $link);
495 break;
496 case 'BILL_PAYED':
497 $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
498 $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
499 $object_type = 'facture';
500 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoicePayed", $link);
501 break;
502 case 'ORDER_VALIDATE':
503 $link = '<a href="'.$urlwithroot.'/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
504 $dir_output = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
505 $object_type = 'order';
506 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderValidated", $link);
507 break;
508 case 'ORDER_CLOSE':
509 $link = '<a href="'.$urlwithroot.'/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
510 $dir_output = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
511 $object_type = 'order';
512 $labeltouse = $conf->global->ORDER_CLOSE_TEMPLATE;
513 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderClose", $link);
514 break;
515 case 'PROPAL_VALIDATE':
516 $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
517 $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
518 $object_type = 'propal';
519 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalValidated", $link);
520 break;
521 case 'PROPAL_CLOSE_REFUSED':
522 $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
523 $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
524 $object_type = 'propal';
525 $labeltouse = $conf->global->PROPAL_CLOSE_REFUSED_TEMPLATE;
526 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedRefused", $link);
527 if (!empty($object->context['closedfromonlinesignature'])) {
528 $mesg .= ' - From online page';
529 }
530 break;
531 case 'PROPAL_CLOSE_SIGNED':
532 $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
533 $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
534 $object_type = 'propal';
535 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedSigned", $link);
536 if (!empty($object->context['closedfromonlinesignature'])) {
537 $mesg .= ' - From online page';
538 }
539 break;
540 case 'FICHINTER_ADD_CONTACT':
541 $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
542 $dir_output = $conf->ficheinter->dir_output;
543 $object_type = 'ficheinter';
544 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link);
545 break;
546 case 'FICHINTER_VALIDATE':
547 $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
548 $dir_output = $conf->ficheinter->dir_output;
549 $object_type = 'ficheinter';
550 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated", $link);
551 break;
552 case 'FICHINTER_CLOSE':
553 $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
554 $dir_output = $conf->ficheinter->dir_output;
555 $object_type = 'ficheinter';
556 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionClosed", $link);
557 break;
558 case 'ORDER_SUPPLIER_VALIDATE':
559 $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
560 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
561 $object_type = 'order_supplier';
562 $labeltouse = isset($conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE : '';
563 $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
564 $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs));
565 $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
566 break;
567 case 'ORDER_SUPPLIER_APPROVE':
568 $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
569 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
570 $object_type = 'order_supplier';
571 $labeltouse = isset($conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE : '';
572 $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
573 $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs));
574 $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
575 break;
576 case 'ORDER_SUPPLIER_SUBMIT':
577 $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
578 $dir_output = $conf->fournisseur->commande->dir_output;
579 $object_type = 'order_supplier';
580 $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
581 $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs));
582 $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
583 break;
584 case 'ORDER_SUPPLIER_REFUSE':
585 $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
586 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
587 $object_type = 'order_supplier';
588 $labeltouse = isset($conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE : '';
589 $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
590 $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs));
591 $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
592 break;
593 case 'SHIPPING_VALIDATE':
594 $link = '<a href="'.$urlwithroot.'/expedition/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
595 $dir_output = $conf->expedition->dir_output."/sending/".get_exdir(0, 0, 0, 1, $object, 'shipment');
596 $object_type = 'shipping';
597 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated", $link);
598 break;
599 case 'EXPENSE_REPORT_VALIDATE':
600 $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
601 $dir_output = $conf->expensereport->dir_output;
602 $object_type = 'expensereport';
603 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $link);
604 break;
605 case 'EXPENSE_REPORT_APPROVE':
606 $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
607 $dir_output = $conf->expensereport->dir_output;
608 $object_type = 'expensereport';
609 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $link);
610 break;
611 case 'HOLIDAY_VALIDATE':
612 $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
613 $dir_output = $conf->holiday->dir_output;
614 $object_type = 'holiday';
615 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated", $link);
616 break;
617 case 'HOLIDAY_APPROVE':
618 $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
619 $dir_output = $conf->holiday->dir_output;
620 $object_type = 'holiday';
621 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved", $link);
622 break;
623 case 'ACTION_CREATE':
624 $link = '<a href="'.$urlwithroot.'/comm/action/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
625 $dir_output = $conf->agenda->dir_output;
626 $object_type = 'action';
627 $mesg = $outputlangs->transnoentitiesnoconv("EMailTextActionAdded", $link);
628 break;
629 default:
630 $object_type = $object->element;
631 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object, $object_type);
632 $template = $notifcode.'_TEMPLATE';
633 $mesg = $outputlangs->transnoentitiesnoconv('Notify_'.$notifcode).' '.$newref.' '.$dir_output;
634 break;
635 }
636
637 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
638 $formmail = new FormMail($this->db);
639 $arraydefaultmessage = null;
640
641 $template = $notifcode.'_TEMPLATE';
642 $labeltouse = getDolGlobalString($template);
643 if (!empty($labeltouse)) {
644 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.'_send', $user, $outputlangs, 0, 1, $labeltouse);
645 }
646 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
647 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
648 complete_substitutions_array($substitutionarray, $outputlangs, $object);
649 $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
650 $message = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
651 } else {
652 $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name)."\n";
653 $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n";
654 $message .= "\n";
655 $message .= $mesg;
656 }
657
658 $ref = dol_sanitizeFileName($newref);
659 $pdf_path = $dir_output."/".$ref.".pdf";
660 if (!dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
661 // We can't add PDF as it is not generated yet.
662 $filepdf = '';
663 } else {
664 $filepdf = $pdf_path;
665 $filename_list[] = $filepdf;
666 $mimetype_list[] = mime_content_type($filepdf);
667 $mimefilename_list[] = $ref.".pdf";
668 }
669
670 $labeltouse = !empty($labeltouse) ? $labeltouse : '';
671
672 // Replace keyword __SUPERVISOREMAIL__
673 if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) {
674 $newval = '';
675 if ($user->fk_user > 0) {
676 $supervisoruser = new User($this->db);
677 $supervisoruser->fetch($user->fk_user);
678 if ($supervisoruser->email) {
679 $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
680 }
681 }
682 dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
683 $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
684 $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
685 $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string
686 $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string
687 }
688
689 $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list, 'outputlangs'=>$outputlangs, 'labeltouse'=>$labeltouse);
690 if (!isset($action)) {
691 $action = '';
692 }
693
694 $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
695 if (empty($reshook)) {
696 if (!empty($hookmanager->resArray['files'])) {
697 $filename_list = $hookmanager->resArray['files']['file'];
698 $mimetype_list = $hookmanager->resArray['files']['mimefile'];
699 $mimefilename_list = $hookmanager->resArray['files']['filename'];
700 }
701 if (!empty($hookmanager->resArray['subject'])) {
702 $subject .= $hookmanager->resArray['subject'];
703 }
704 if (!empty($hookmanager->resArray['message'])) {
705 $message .= $hookmanager->resArray['message'];
706 }
707 }
708
709 $mailfile = new CMailFile(
710 $subject,
711 $sendto,
712 $replyto,
713 $message,
714 $filename_list,
715 $mimetype_list,
716 $mimefilename_list,
717 '',
718 '',
719 0,
720 -1,
721 '',
722 '',
723 $trackid,
724 '',
725 'notification'
726 );
727
728 if ($mailfile->sendfile()) {
729 if ($obj->type_target == 'touserid') {
730 $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
731 $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)."')";
732 } else {
733 $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
734 $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)."')";
735 }
736 if (!$this->db->query($sql)) {
737 dol_print_error($this->db);
738 }
739 } else {
740 $error++;
741 $this->errors[] = $mailfile->error;
742 }
743 } else {
744 dol_syslog("No notification sent for ".$sendto." because email is empty");
745 }
746 $i++;
747 }
748 } else {
749 dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ? '' : $object->socid));
750 }
751 } else {
752 $error++;
753 $this->errors[] = $this->db->lasterror();
754 dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
755 return -1;
756 }
757
758 // Check notification using fixed email
759 // TODO Move vars NOTIFICATION_FIXEDEMAIL into table llx_notify_def and inclulde the case into previous loop of sql result
760 if (!$error) {
761 foreach ($conf->global as $key => $val) {
762 $reg = array();
763 if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
764 continue;
765 }
766
767 $sendto = $val;
768
769 $threshold = (float) $reg[1];
770 if (!empty($object->total_ht) && $object->total_ht <= $threshold) {
771 dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification");
772 continue;
773 }
774
775 $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
776 if ($notifcodedefid <= 0) {
777 dol_print_error($this->db, 'Failed to get id from code');
778 }
779 $trackid = '';
780
781 $object_type = '';
782 $link = '';
783 $num++;
784
785 $appli = $mysoc->name;
786
787 $subject = '['.$appli.'] '.$langs->transnoentitiesnoconv("DolibarrNotification").($projtitle ? ' '.$projtitle : '');
788
789 switch ($notifcode) {
790 case 'BILL_VALIDATE':
791 $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
792 $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
793 $object_type = 'facture';
794 $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $link);
795 break;
796 case 'BILL_PAYED':
797 $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
798 $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
799 $object_type = 'facture';
800 $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed", $link);
801 break;
802 case 'ORDER_VALIDATE':
803 $link = '<a href="'.$urlwithroot.'/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
804 $dir_output = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
805 $object_type = 'order';
806 $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $link);
807 break;
808 case 'ORDER_CLOSE':
809 $link = '<a href="'.$urlwithroot.'/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
810 $dir_output = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
811 $object_type = 'order';
812 $mesg = $langs->transnoentitiesnoconv("EMailTextOrderClose", $link);
813 break;
814 case 'PROPAL_VALIDATE':
815 $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
816 $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
817 $object_type = 'propal';
818 $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $link);
819 break;
820 case 'PROPAL_CLOSE_SIGNED':
821 $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
822 $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
823 $object_type = 'propal';
824 $mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned", $link);
825 break;
826 case 'FICHINTER_ADD_CONTACT':
827 $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
828 $dir_output = $conf->ficheinter->dir_output;
829 $object_type = 'ficheinter';
830 $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link);
831 break;
832 case 'FICHINTER_VALIDATE':
833 $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
834 $dir_output = $conf->facture->dir_output;
835 $object_type = 'ficheinter';
836 $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $link);
837 break;
838 case 'FICHINTER_CLOSE':
839 $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
840 $dir_output = $conf->facture->dir_output;
841 $object_type = 'ficheinter';
842 $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionClosed", $link);
843 break;
844 case 'ORDER_SUPPLIER_VALIDATE':
845 $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
846 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
847 $object_type = 'order_supplier';
848 $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
849 $mesg .= $langs->transnoentitiesnoconv("EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
850 $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
851 break;
852 case 'ORDER_SUPPLIER_APPROVE':
853 $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
854 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
855 $object_type = 'order_supplier';
856 $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
857 $mesg .= $langs->transnoentitiesnoconv("EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
858 $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
859 break;
860 case 'ORDER_SUPPLIER_SUBMIT':
861 $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
862 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
863 $object_type = 'order_supplier';
864 $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
865 $mesg .= $langs->transnoentitiesnoconv("EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
866 $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
867 break;
868 case 'ORDER_SUPPLIER_REFUSE':
869 $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
870 $dir_output = $conf->fournisseur->dir_output.'/commande/';
871 $object_type = 'order_supplier';
872 $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
873 $mesg .= $langs->transnoentitiesnoconv("EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
874 $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
875 break;
876 case 'SHIPPING_VALIDATE':
877 $link = '<a href="'.$urlwithroot.'/expedition/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
878 $dir_output = $conf->expedition->dir_output."/sending/".get_exdir(0, 0, 0, 1, $object, 'shipment');
879 $object_type = 'order_supplier';
880 $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $link);
881 break;
882 case 'EXPENSE_REPORT_VALIDATE':
883 $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
884 $dir_output = $conf->expensereport->dir_output;
885 $object_type = 'expensereport';
886 $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $link);
887 break;
888 case 'EXPENSE_REPORT_APPROVE':
889 $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
890 $dir_output = $conf->expensereport->dir_output;
891 $object_type = 'expensereport';
892 $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $link);
893 break;
894 case 'HOLIDAY_VALIDATE':
895 $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
896 $dir_output = $conf->holiday->dir_output;
897 $object_type = 'holiday';
898 $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated", $link);
899 break;
900 case 'HOLIDAY_APPROVE':
901 $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
902 $dir_output = $conf->holiday->dir_output;
903 $object_type = 'holiday';
904 $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved", $link);
905 break;
906 case 'ACTION_CREATE':
907 $link = '<a href="'.$urlwithroot.'/comm/action/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
908 $dir_output = $conf->agenda->dir_output;
909 $object_type = 'action';
910 $mesg = $langs->transnoentitiesnoconv("EMailTextActionAdded", $link);
911 break;
912 default:
913 $object_type = $object->element;
914 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object, $object_type);
915 $mesg = $langs->transnoentitiesnoconv('Notify_'.$notifcode).' '.$newref;
916 break;
917 }
918 $ref = dol_sanitizeFileName($newref);
919 $pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
920 if (!dol_is_file($pdf_path)) {
921 // We can't add PDF as it is not generated yet.
922 $filepdf = '';
923 } else {
924 $filepdf = $pdf_path;
925 $filename_list[] = $pdf_path;
926 $mimetype_list[] = mime_content_type($filepdf);
927 $mimefilename_list[] = $ref.".pdf";
928 }
929
930 // if an e-mail template is configured for this notification code (for instance
931 // 'SHIPPING_VALIDATE_TEMPLATE'), we fetch this template by its label. Otherwise, a default message
932 // content will be sent.
933 $mailTemplateLabel = isset($conf->global->{$notifcode.'_TEMPLATE'}) ? $conf->global->{$notifcode.'_TEMPLATE'} : '';
934 $emailTemplate = null;
935 if (!empty($mailTemplateLabel)) {
936 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
937 $formmail = new FormMail($this->db);
938 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.'_send', $user, $langs, 0, 1, $labeltouse);
939 }
940 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
941 $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
942 complete_substitutions_array($substitutionarray, $langs, $object);
943 $subject = make_substitutions($emailTemplate->topic, $substitutionarray, $langs);
944 $message = make_substitutions($emailTemplate->content, $substitutionarray, $langs);
945 } else {
946 $message = '';
947 $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n";
948 $message .= "\n";
949 $message .= $mesg;
950
951 $message = nl2br($message);
952 }
953
954 // Replace keyword __SUPERVISOREMAIL__
955 if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) {
956 $newval = '';
957 if ($user->fk_user > 0) {
958 $supervisoruser = new User($this->db);
959 $supervisoruser->fetch($user->fk_user);
960 if ($supervisoruser->email) {
961 $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
962 }
963 }
964 dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
965 $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
966 $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
967 $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string
968 $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string
969 }
970
971 if ($sendto) {
972 $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list, 'subject'=>&$subject, 'message'=>&$message);
973 $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
974 if (empty($reshook)) {
975 if (!empty($hookmanager->resArray['files'])) {
976 $filename_list = $hookmanager->resArray['files']['file'];
977 $mimetype_list = $hookmanager->resArray['files']['mimefile'];
978 $mimefilename_list = $hookmanager->resArray['files']['filename'];
979 }
980 if (!empty($hookmanager->resArray['subject'])) {
981 $subject .= $hookmanager->resArray['subject'];
982 }
983 if (!empty($hookmanager->resArray['message'])) {
984 $message .= $hookmanager->resArray['message'];
985 }
986 }
987 $mailfile = new CMailFile(
988 $subject,
989 $sendto,
990 $replyto,
991 $message,
992 $filename_list,
993 $mimetype_list,
994 $mimefilename_list,
995 '',
996 '',
997 0,
998 1,
999 '',
1000 $trackid,
1001 '',
1002 '',
1003 'notification'
1004 );
1005
1006 if ($mailfile->sendfile()) {
1007 $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1008 $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($sendto)."')";
1009 if (!$this->db->query($sql)) {
1010 dol_print_error($this->db);
1011 }
1012 } else {
1013 $error++;
1014 $this->errors[] = $mailfile->error;
1015 }
1016 }
1017 }
1018 }
1019
1020 if (!$error) {
1021 return $num;
1022 } else {
1023 return -1 * $error;
1024 }
1025 }
1026}
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Class to manage hooks.
Class to manage notifications.
confirmMessage($action, $socid, $object)
Return message that say how many notification (and to which email) will occurs on requested event.
getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global'))
Return number of notifications activated for action code (and third party)
send($notifcode, $object, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array())
Check if notification are active for couple action/company.
__construct($db)
Constructor.
Class to manage translations.
Class to manage Dolibarr users.
dol_is_file($pathoffile)
Return if path is a file.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.