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