dolibarr  19.0.0-dev
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 
28 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
29 
33 class 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').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
149  } elseif ($nb == 0) {
150  $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("NoNotificationsWillBeSent");
151  } elseif ($nb == 1) {
152  $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("ANotificationsWillBeSent");
153  } elseif ($nb >= 2) {
154  $texte = img_object($langs->trans("Notifications"), 'email').' '.$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  $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
553  $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $link, $user->getFullName($outputlangs));
554  $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
555  break;
556  case 'ORDER_SUPPLIER_APPROVE':
557  $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
558  $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
559  $object_type = 'order_supplier';
560  $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
561  $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $link, $user->getFullName($outputlangs));
562  $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
563  break;
564  case 'ORDER_SUPPLIER_REFUSE':
565  $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
566  $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
567  $object_type = 'order_supplier';
568  $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n";
569  $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $link, $user->getFullName($outputlangs));
570  $mesg .= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n";
571  break;
572  case 'SHIPPING_VALIDATE':
573  $link = '<a href="'.$urlwithroot.'/expedition/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
574  $dir_output = $conf->expedition->dir_output."/sending/".get_exdir(0, 0, 0, 1, $object, 'shipment');
575  $object_type = 'shipping';
576  $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated", $link);
577  break;
578  case 'EXPENSE_REPORT_VALIDATE':
579  $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
580  $dir_output = $conf->expensereport->dir_output;
581  $object_type = 'expensereport';
582  $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $link);
583  break;
584  case 'EXPENSE_REPORT_APPROVE':
585  $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
586  $dir_output = $conf->expensereport->dir_output;
587  $object_type = 'expensereport';
588  $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $link);
589  break;
590  case 'HOLIDAY_VALIDATE':
591  $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
592  $dir_output = $conf->holiday->dir_output;
593  $object_type = 'holiday';
594  $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated", $link);
595  break;
596  case 'HOLIDAY_APPROVE':
597  $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
598  $dir_output = $conf->holiday->dir_output;
599  $object_type = 'holiday';
600  $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved", $link);
601  break;
602  case 'ACTION_CREATE':
603  $link = '<a href="'.$urlwithroot.'/comm/action/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
604  $dir_output = $conf->agenda->dir_output;
605  $object_type = 'action';
606  $mesg = $outputlangs->transnoentitiesnoconv("EMailTextActionAdded", $link);
607  break;
608  default:
609  $object_type = $object->element;
610  $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object, $object_type);
611  $template = $notifcode.'_TEMPLATE';
612  $mesg = $outputlangs->transnoentitiesnoconv('Notify_'.$notifcode).' '.$newref.' '.$dir_output;
613  break;
614  }
615 
616  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
617  $formmail = new FormMail($this->db);
618  $arraydefaultmessage = null;
619 
620  $template = $notifcode.'_TEMPLATE';
621  $labeltouse = getDolGlobalString($template);
622  if (!empty($labeltouse)) {
623  $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.'_send', $user, $outputlangs, 0, 1, $labeltouse);
624  }
625  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
626  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
627  complete_substitutions_array($substitutionarray, $outputlangs, $object);
628  $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
629  $message = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
630  } else {
631  $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name)."\n";
632  $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n";
633  $message .= "\n";
634  $message .= $mesg;
635  }
636 
637  $ref = dol_sanitizeFileName($newref);
638  $pdf_path = $dir_output."/".$ref.".pdf";
639  if (!dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
640  // We can't add PDF as it is not generated yet.
641  $filepdf = '';
642  } else {
643  $filepdf = $pdf_path;
644  $filename_list[] = $filepdf;
645  $mimetype_list[] = mime_content_type($filepdf);
646  $mimefilename_list[] = $ref.".pdf";
647  }
648 
649  $labeltouse = !empty($labeltouse) ? $labeltouse : '';
650 
651  // Replace keyword __SUPERVISOREMAIL__
652  if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) {
653  $newval = '';
654  if ($user->fk_user > 0) {
655  $supervisoruser = new User($this->db);
656  $supervisoruser->fetch($user->fk_user);
657  if ($supervisoruser->email) {
658  $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
659  }
660  }
661  dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
662  $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
663  $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
664  $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string
665  $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string
666  }
667 
668  $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list, 'outputlangs'=>$outputlangs, 'labeltouse'=>$labeltouse);
669  if (!isset($action)) {
670  $action = '';
671  }
672 
673  $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
674  if (empty($reshook)) {
675  if (!empty($hookmanager->resArray['files'])) {
676  $filename_list = $hookmanager->resArray['files']['file'];
677  $mimetype_list = $hookmanager->resArray['files']['mimefile'];
678  $mimefilename_list = $hookmanager->resArray['files']['filename'];
679  }
680  if (!empty($hookmanager->resArray['subject'])) {
681  $subject .= $hookmanager->resArray['subject'];
682  }
683  if (!empty($hookmanager->resArray['message'])) {
684  $message .= $hookmanager->resArray['message'];
685  }
686  }
687 
688  $mailfile = new CMailFile(
689  $subject,
690  $sendto,
691  $replyto,
692  $message,
693  $filename_list,
694  $mimetype_list,
695  $mimefilename_list,
696  '',
697  '',
698  0,
699  -1,
700  '',
701  '',
702  $trackid,
703  '',
704  'notification'
705  );
706 
707  if ($mailfile->sendfile()) {
708  if ($obj->type_target == 'touserid') {
709  $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
710  $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)."')";
711  } else {
712  $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_contact, 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  }
715  if (!$this->db->query($sql)) {
716  dol_print_error($this->db);
717  }
718  } else {
719  $error++;
720  $this->errors[] = $mailfile->error;
721  }
722  } else {
723  dol_syslog("No notification sent for ".$sendto." because email is empty");
724  }
725  $i++;
726  }
727  } else {
728  dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ? '' : $object->socid));
729  }
730  } else {
731  $error++;
732  $this->errors[] = $this->db->lasterror();
733  dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
734  return -1;
735  }
736 
737  // Check notification using fixed email
738  // TODO Move vars NOTIFICATION_FIXEDEMAIL into table llx_notify_def and inclulde the case into previous loop of sql result
739  if (!$error) {
740  foreach ($conf->global as $key => $val) {
741  $reg = array();
742  if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
743  continue;
744  }
745 
746  $threshold = (float) $reg[1];
747  if (!empty($object->total_ht) && $object->total_ht <= $threshold) {
748  dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification");
749  continue;
750  }
751 
752  $param = 'NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1];
753 
754  $sendto = $conf->global->$param;
755  $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
756  if ($notifcodedefid <= 0) {
757  dol_print_error($this->db, 'Failed to get id from code');
758  }
759  $trackid = '';
760 
761  $object_type = '';
762  $link = '';
763  $num++;
764 
765  $subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification").($projtitle ? ' '.$projtitle : '');
766 
767  switch ($notifcode) {
768  case 'BILL_VALIDATE':
769  $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
770  $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
771  $object_type = 'facture';
772  $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $link);
773  break;
774  case 'BILL_PAYED':
775  $link = '<a href="'.$urlwithroot.'/compta/facture/card.php?facid='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
776  $dir_output = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
777  $object_type = 'facture';
778  $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed", $link);
779  break;
780  case 'ORDER_VALIDATE':
781  $link = '<a href="'.$urlwithroot.'/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
782  $dir_output = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
783  $object_type = 'order';
784  $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $link);
785  break;
786  case 'ORDER_CLOSE':
787  $link = '<a href="'.$urlwithroot.'/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
788  $dir_output = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
789  $object_type = 'order';
790  $mesg = $langs->transnoentitiesnoconv("EMailTextOrderClose", $link);
791  break;
792  case 'PROPAL_VALIDATE':
793  $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
794  $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
795  $object_type = 'propal';
796  $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $link);
797  break;
798  case 'PROPAL_CLOSE_SIGNED':
799  $link = '<a href="'.$urlwithroot.'/comm/propal/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
800  $dir_output = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
801  $object_type = 'propal';
802  $mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned", $link);
803  break;
804  case 'FICHINTER_ADD_CONTACT':
805  $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
806  $dir_output = $conf->ficheinter->dir_output;
807  $object_type = 'ficheinter';
808  $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link);
809  break;
810  case 'FICHINTER_VALIDATE':
811  $link = '<a href="'.$urlwithroot.'/fichinter/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
812  $dir_output = $conf->facture->dir_output;
813  $object_type = 'ficheinter';
814  $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $link);
815  break;
816  case 'ORDER_SUPPLIER_VALIDATE':
817  $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
818  $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
819  $object_type = 'order_supplier';
820  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
821  $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $link, $user->getFullName($langs));
822  $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
823  break;
824  case 'ORDER_SUPPLIER_APPROVE':
825  $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
826  $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
827  $object_type = 'order_supplier';
828  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
829  $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
830  $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
831  break;
832  case 'ORDER_SUPPLIER_APPROVE2':
833  $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
834  $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object);
835  $object_type = 'order_supplier';
836  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
837  $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
838  $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
839  break;
840  case 'ORDER_SUPPLIER_REFUSE':
841  $link = '<a href="'.$urlwithroot.'/fourn/commande/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
842  $dir_output = $conf->fournisseur->dir_output.'/commande/';
843  $object_type = 'order_supplier';
844  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
845  $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $link, $user->getFullName($langs));
846  $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
847  break;
848  case 'SHIPPING_VALIDATE':
849  $link = '<a href="'.$urlwithroot.'/expedition/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
850  $dir_output = $conf->expedition->dir_output."/sending/".get_exdir(0, 0, 0, 1, $object, 'shipment');
851  $object_type = 'order_supplier';
852  $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $link);
853  break;
854  case 'EXPENSE_REPORT_VALIDATE':
855  $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
856  $dir_output = $conf->expensereport->dir_output;
857  $object_type = 'expensereport';
858  $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $link);
859  break;
860  case 'EXPENSE_REPORT_APPROVE':
861  $link = '<a href="'.$urlwithroot.'/expensereport/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
862  $dir_output = $conf->expensereport->dir_output;
863  $object_type = 'expensereport';
864  $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $link);
865  break;
866  case 'HOLIDAY_VALIDATE':
867  $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
868  $dir_output = $conf->holiday->dir_output;
869  $object_type = 'holiday';
870  $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated", $link);
871  break;
872  case 'HOLIDAY_APPROVE':
873  $link = '<a href="'.$urlwithroot.'/holiday/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
874  $dir_output = $conf->holiday->dir_output;
875  $object_type = 'holiday';
876  $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved", $link);
877  break;
878  case 'ACTION_CREATE':
879  $link = '<a href="'.$urlwithroot.'/comm/action/card.php?id='.$object->id.'&entity='.$object->entity.'">'.$newref.'</a>';
880  $dir_output = $conf->agenda->dir_output;
881  $object_type = 'action';
882  $mesg = $langs->transnoentitiesnoconv("EMailTextActionAdded", $link);
883  break;
884  default:
885  $object_type = $object->element;
886  $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object, $object_type);
887  $mesg = $langs->transnoentitiesnoconv('Notify_'.$notifcode).' '.$newref;
888  break;
889  }
890  $ref = dol_sanitizeFileName($newref);
891  $pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
892  if (!dol_is_file($pdf_path)) {
893  // We can't add PDF as it is not generated yet.
894  $filepdf = '';
895  } else {
896  $filepdf = $pdf_path;
897  $filename_list[] = $pdf_path;
898  $mimetype_list[] = mime_content_type($filepdf);
899  $mimefilename_list[] = $ref.".pdf";
900  }
901 
902  $message = '';
903  $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n";
904  $message .= "\n";
905  $message .= $mesg;
906 
907  $message = nl2br($message);
908 
909  // Replace keyword __SUPERVISOREMAIL__
910  if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) {
911  $newval = '';
912  if ($user->fk_user > 0) {
913  $supervisoruser = new User($this->db);
914  $supervisoruser->fetch($user->fk_user);
915  if ($supervisoruser->email) {
916  $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
917  }
918  }
919  dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
920  $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
921  $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
922  $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string
923  $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string
924  }
925 
926  if ($sendto) {
927  $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
928  $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
929  if (empty($reshook)) {
930  if (!empty($hookmanager->resArray['files'])) {
931  $filename_list = $hookmanager->resArray['files']['file'];
932  $mimetype_list = $hookmanager->resArray['files']['mimefile'];
933  $mimefilename_list = $hookmanager->resArray['files']['filename'];
934  }
935  if (!empty($hookmanager->resArray['subject'])) {
936  $subject .= $hookmanager->resArray['subject'];
937  }
938  if (!empty($hookmanager->resArray['message'])) {
939  $message .= $hookmanager->resArray['message'];
940  }
941  }
942  $mailfile = new CMailFile(
943  $subject,
944  $sendto,
945  $replyto,
946  $message,
947  $filename_list,
948  $mimetype_list,
949  $mimefilename_list,
950  '',
951  '',
952  0,
953  1,
954  '',
955  $trackid,
956  '',
957  '',
958  'notification'
959  );
960 
961  if ($mailfile->sendfile()) {
962  $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
963  $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)."')";
964  if (!$this->db->query($sql)) {
965  dol_print_error($this->db);
966  }
967  } else {
968  $error++;
969  $this->errors[] = $mailfile->error;
970  }
971  }
972  }
973  }
974 
975  if (!$error) {
976  return $num;
977  } else {
978  return -1 * $error;
979  }
980  }
981 }
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.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:483
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.
div float
Buy price without taxes.
Definition: style.css.php:921