dolibarr  7.0.0-beta
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  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
25 require_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
26 
27 
31 class Notify
32 {
33  var $id;
34  var $db;
35  var $error;
36  var $errors=array();
37 
38  var $author;
39  var $ref;
40  var $date;
41  var $duree;
42  var $note;
43  var $fk_project;
44 
45  // Les codes actions sont definis dans la table llx_notify_def
46 
47  // codes actions supported are
48  public $arrayofnotifsupported = array(
49  'BILL_VALIDATE',
50  'BILL_PAYED',
51  'ORDER_VALIDATE',
52  'PROPAL_VALIDATE',
53  'PROPAL_CLOSE_SIGNED',
54  'FICHINTER_VALIDATE',
55  'FICHINTER_ADD_CONTACT',
56  'ORDER_SUPPLIER_VALIDATE',
57  'ORDER_SUPPLIER_APPROVE',
58  'ORDER_SUPPLIER_REFUSE',
59  'SHIPPING_VALIDATE'
60  );
61 
62 
68  function __construct($db)
69  {
70  $this->db = $db;
71  }
72 
73 
83  function confirmMessage($action,$socid,$object)
84  {
85  global $langs;
86  $langs->load("mails");
87 
88  $listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0);
89 
90  $nb=-1;
91  if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo);
92  if ($nb < 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
93  if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
94  if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
95  if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
96 
97  if (is_array($listofnotiftodo))
98  {
99  $i=0;
100  foreach ($listofnotiftodo as $key => $val)
101  {
102  if ($i) $texte.=', ';
103  else $texte.=' (';
104  if ($val['isemailvalid']) $texte.=$val['email'];
105  else $texte.=$val['emaildesc'];
106  $i++;
107  }
108  if ($i) $texte.=')';
109  }
110 
111  return $texte;
112  }
113 
124  function getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global'))
125  {
126  global $conf, $user;
127 
128  $error=0;
129  $resarray=array();
130 
131  $valueforthreshold = 0;
132  if (is_object($object)) $valueforthreshold = $object->total_ht;
133 
134  if (! $error)
135  {
136  if ($socid >= 0 && in_array('thirdparty', $scope))
137  {
138  $sql = "SELECT a.code, c.email, c.rowid";
139  $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
140  $sql.= " ".MAIN_DB_PREFIX."socpeople as c,";
141  $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
142  $sql.= " ".MAIN_DB_PREFIX."societe as s";
143  $sql.= " WHERE n.fk_contact = c.rowid";
144  $sql.= " AND a.rowid = n.fk_action";
145  $sql.= " AND n.fk_soc = s.rowid";
146  if ($notifcode)
147  {
148  if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage
149  else $sql.= " AND a.code = '".$notifcode."'"; // New usage
150  }
151  $sql.= " AND s.entity IN (".getEntity('societe').")";
152  if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
153 
154  dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
155 
156  $resql = $this->db->query($sql);
157  if ($resql)
158  {
159  $num = $this->db->num_rows($resql);
160  $i=0;
161  while ($i < $num)
162  {
163  $obj = $this->db->fetch_object($resql);
164  if ($obj)
165  {
166  $newval2=trim($obj->email);
167  $isvalid=isValidEmail($newval2);
168  if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
169  }
170  $i++;
171  }
172  }
173  else
174  {
175  $error++;
176  $this->error=$this->db->lasterror();
177  }
178  }
179  }
180 
181  if (! $error)
182  {
183  if ($userid >= 0 && in_array('user', $scope))
184  {
185  $sql = "SELECT a.code, c.email, c.rowid";
186  $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,";
187  $sql.= " ".MAIN_DB_PREFIX."user as c,";
188  $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a";
189  $sql.= " WHERE n.fk_user = c.rowid";
190  $sql.= " AND a.rowid = n.fk_action";
191  if ($notifcode)
192  {
193  if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage
194  else $sql.= " AND a.code = '".$notifcode."'"; // New usage
195  }
196  $sql.= " AND c.entity IN (".getEntity('user').")";
197  if ($userid > 0) $sql.= " AND c.rowid = ".$userid;
198 
199  dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
200 
201  $resql = $this->db->query($sql);
202  if ($resql)
203  {
204  $num = $this->db->num_rows($resql);
205  $i=0;
206  while ($i < $num)
207  {
208  $obj = $this->db->fetch_object($resql);
209  if ($obj)
210  {
211  $newval2=trim($obj->email);
212  $isvalid=isValidEmail($newval2);
213  if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
214  }
215  $i++;
216  }
217  }
218  else
219  {
220  $error++;
221  $this->error=$this->db->lasterror();
222  }
223  }
224  }
225 
226  if (! $error)
227  {
228  if (in_array('global', $scope))
229  {
230  // List of notifications enabled for fixed email
231  foreach($conf->global as $key => $val)
232  {
233  if ($notifcode)
234  {
235  if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
236  }
237  else
238  {
239  if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
240  }
241 
242  $threshold = (float) $reg[1];
243  if ($valueforthreshold < $threshold) continue;
244 
245  $tmpemail=explode(',',$val);
246  foreach($tmpemail as $key2 => $val2)
247  {
248  $newval2=trim($val2);
249  if ($newval2 == '__SUPERVISOREMAIL__')
250  {
251  if ($user->fk_user > 0)
252  {
253  $tmpuser=new User($this->db);
254  $tmpuser->fetch($user->fk_user);
255  if ($tmpuser->email) $newval2=trim($tmpuser->email);
256  else $newval2='';
257  }
258  else $newval2='';
259  }
260  if ($newval2)
261  {
262  $isvalid=isValidEmail($newval2, 0);
263  if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
264  }
265  }
266  }
267  }
268  }
269 
270  if ($error) return -1;
271 
272  //var_dump($resarray);
273  return $resarray;
274  }
275 
284  function send($notifcode, $object)
285  {
286  global $user,$conf,$langs,$mysoc;
287  global $hookmanager;
288  global $dolibarr_main_url_root;
289 
290  if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0;
291 
292  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
293  if (! is_object($hookmanager))
294  {
295  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
296  $hookmanager=new HookManager($this->db);
297  }
298  $hookmanager->initHooks(array('notification'));
299 
300  dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id);
301 
302  $langs->load("other");
303 
304  // Define $urlwithroot
305  $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
306  $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
307  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
308 
309  // Define some vars
310  $application = 'Dolibarr';
311  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
312  $replyto = $conf->notification->email_from;
313  $filename = basename($file);
314  $mimefile = dol_mimetype($file);
315  $object_type = '';
316  $link = '';
317  $num = 0;
318 
319  $oldref=(empty($object->oldref)?$object->ref:$object->oldref);
320  $newref=(empty($object->newref)?$object->ref:$object->newref);
321 
322  // Check notification per third party
323  $sql = "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
324  $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
325  $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,";
326  $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
327  $sql.= " ".MAIN_DB_PREFIX."notify_def as n,";
328  $sql.= " ".MAIN_DB_PREFIX."societe as s";
329  $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
330  $sql.= " AND n.fk_soc = s.rowid";
331  if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage
332  else $sql.= " AND a.code = '".$notifcode."'"; // New usage
333  $sql .= " AND s.rowid = ".$object->socid;
334 
335  // Check notification per user
336  $sql.= "\nUNION\n";
337 
338  $sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
339  $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
340  $sql.= " FROM ".MAIN_DB_PREFIX."user as c,";
341  $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
342  $sql.= " ".MAIN_DB_PREFIX."notify_def as n";
343  $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
344  if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage
345  else $sql.= " AND a.code = '".$notifcode."'"; // New usage
346 
347  $result = $this->db->query($sql);
348  if ($result)
349  {
350  $num = $this->db->num_rows($result);
351 
352  if ($num > 0)
353  {
354  $i = 0;
355  while ($i < $num && ! $error) // For each notification couple defined (third party/actioncode)
356  {
357  $obj = $this->db->fetch_object($result);
358 
359  $sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">";
360  $notifcodedefid = $obj->adid;
361 
362  if (dol_strlen($obj->email))
363  {
364  // Set output language
365  $outputlangs = $langs;
366  if ($obj->default_lang && $obj->default_lang != $langs->defaultlang)
367  {
368  $outputlangs = new Translate('', $conf);
369  $outputlangs->setDefaultLang($obj->default_lang);
370  }
371 
372  $subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification");
373 
374  switch ($notifcode) {
375  case 'BILL_VALIDATE':
376  $link='/compta/facture/card.php?facid='.$object->id;
377  $dir_output = $conf->facture->dir_output;
378  $object_type = 'facture';
379  $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref);
380  break;
381  case 'BILL_PAYED':
382  $link='/compta/facture/card.php?facid='.$object->id;
383  $dir_output = $conf->facture->dir_output;
384  $object_type = 'facture';
385  $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref);
386  break;
387  case 'ORDER_VALIDATE':
388  $link='/commande/card.php?id='.$object->id;
389  $dir_output = $conf->commande->dir_output;
390  $object_type = 'order';
391  $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$newref);
392  break;
393  case 'PROPAL_VALIDATE':
394  $link='/comm/propal/card.php?id='.$object->id;
395  $dir_output = $conf->propal->dir_output;
396  $object_type = 'propal';
397  $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$newref);
398  break;
399  case 'PROPAL_CLOSE_SIGNED':
400  $link='/comm/propal/card.php?id='.$object->id;
401  $dir_output = $conf->propal->dir_output;
402  $object_type = 'propal';
403  $mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$newref);
404  break;
405  case 'FICHINTER_ADD_CONTACT':
406  $link='/fichinter/card.php?id='.$object->id;
407  $dir_output = $conf->facture->dir_output;
408  $object_type = 'ficheinter';
409  $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$object->ref);
410  break;
411  case 'FICHINTER_VALIDATE':
412  $link='/fichinter/card.php?id='.$object->id;
413  $dir_output = $conf->facture->dir_output;
414  $object_type = 'ficheinter';
415  $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref);
416  break;
417  case 'ORDER_SUPPLIER_VALIDATE':
418  $link='/fourn/commande/card.php?id='.$object->id;
419  $dir_output = $conf->fournisseur->commande->dir_output;
420  $object_type = 'order_supplier';
421  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
422  $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$object->ref,$user->getFullName($langs));
423  $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
424  break;
425  case 'ORDER_SUPPLIER_APPROVE':
426  $link='/fourn/commande/card.php?id='.$object->id;
427  $dir_output = $conf->fournisseur->commande->dir_output;
428  $object_type = 'order_supplier';
429  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
430  $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
431  $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
432  break;
433  case 'ORDER_SUPPLIER_REFUSE':
434  $link='/fourn/commande/card.php?id='.$object->id;
435  $dir_output = $conf->fournisseur->commande->dir_output;
436  $object_type = 'order_supplier';
437  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
438  $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs));
439  $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
440  break;
441  case 'SHIPPING_VALIDATE':
442  $dir_output = $conf->expedition->dir_output.'/sending/';
443  $object_type = 'order_supplier';
444  $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref);
445  break;
446  }
447  $ref = dol_sanitizeFileName($newref);
448  $pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
449  if (! dol_is_file($pdf_path))
450  {
451  // We can't add PDF as it is not generated yet.
452  $filepdf = '';
453  }
454  else
455  {
456  $filepdf = $pdf_path;
457  }
458 
459  $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
460  $message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
461  $message.= "\n";
462  $message.= $mesg;
463  if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
464 
465  $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename);
466  $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
467  if (empty($reshook))
468  {
469  if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
470  if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
471  }
472 
473  $mailfile = new CMailFile(
474  $subject,
475  $sendto,
476  $replyto,
477  $message,
478  array($file),
479  array($mimefile),
480  array($filename[count($filename)-1]),
481  '',
482  '',
483  0,
484  -1
485  );
486 
487  if ($mailfile->sendfile())
488  {
489  if ($obj->type_target == 'touserid') {
490  $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
491  $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
492 
493  }
494  else {
495  $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
496  $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
497 
498  }
499  if (! $this->db->query($sql))
500  {
501  dol_print_error($this->db);
502  }
503  }
504  else
505  {
506  $error++;
507  $this->errors[]=$mailfile->error;
508  }
509  }
510  else
511  {
512  dol_syslog("No notification sent for ".$sendto." because email is empty");
513  }
514  $i++;
515  }
516  }
517  else
518  {
519  dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid);
520  }
521  }
522  else
523  {
524  $error++;
525  $this->errors[]=$this->db->lasterror();
526  dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
527  return -1;
528  }
529 
530  // Check notification using fixed email
531  if (! $error)
532  {
533  foreach($conf->global as $key => $val)
534  {
535  if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
536 
537  $threshold = (float) $reg[1];
538  if (!empty($object->total_ht) && $object->total_ht <= $threshold)
539  {
540  dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification");
541  continue;
542  }
543 
544  $param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1];
545 
546  $sendto = $conf->global->$param;
547  $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
548  if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code');
549 
550  $object_type = '';
551  $link = '';
552  $num++;
553 
554  $subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification");
555 
556  switch ($notifcode) {
557  case 'BILL_VALIDATE':
558  $link='/compta/facture/card.php?facid='.$object->id;
559  $dir_output = $conf->facture->dir_output;
560  $object_type = 'facture';
561  $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref);
562  break;
563  case 'BILL_PAYED':
564  $link='/compta/facture/card.php?facid='.$object->id;
565  $dir_output = $conf->facture->dir_output;
566  $object_type = 'facture';
567  $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref);
568  break;
569  case 'ORDER_VALIDATE':
570  $link='/commande/card.php?id='.$object->id;
571  $dir_output = $conf->commande->dir_output;
572  $object_type = 'order';
573  $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$newref);
574  break;
575  case 'PROPAL_VALIDATE':
576  $link='/comm/propal/card.php?id='.$object->id;
577  $dir_output = $conf->propal->dir_output;
578  $object_type = 'propal';
579  $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$newref);
580  break;
581  case 'PROPAL_CLOSE_SIGNED':
582  $link='/comm/propal/card.php?id='.$object->id;
583  $dir_output = $conf->propal->dir_output;
584  $object_type = 'propal';
585  $mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$newref);
586  break;
587  case 'FICHINTER_ADD_CONTACT':
588  $link='/fichinter/card.php?id='.$object->id;
589  $dir_output = $conf->facture->dir_output;
590  $object_type = 'ficheinter';
591  $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref);
592  break;
593  case 'FICHINTER_VALIDATE':
594  $link='/fichinter/card.php?id='.$object->id;
595  $dir_output = $conf->facture->dir_output;
596  $object_type = 'ficheinter';
597  $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref);
598  break;
599  case 'ORDER_SUPPLIER_VALIDATE':
600  $link='/fourn/commande/card.php?id='.$object->id;
601  $dir_output = $conf->fournisseur->commande->dir_output;
602  $object_type = 'order_supplier';
603  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
604  $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs));
605  $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
606  break;
607  case 'ORDER_SUPPLIER_APPROVE':
608  $link='/fourn/commande/card.php?id='.$object->id;
609  $dir_output = $conf->fournisseur->commande->dir_output;
610  $object_type = 'order_supplier';
611  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
612  $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
613  $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
614  break;
615  case 'ORDER_SUPPLIER_APPROVE2':
616  $link='/fourn/commande/card.php?id='.$object->id;
617  $dir_output = $conf->fournisseur->commande->dir_output;
618  $object_type = 'order_supplier';
619  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
620  $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
621  $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
622  break;
623  case 'ORDER_SUPPLIER_REFUSE':
624  $link='/fourn/commande/card.php?id='.$object->id;
625  $dir_output = $conf->fournisseur->dir_output.'/commande/';
626  $object_type = 'order_supplier';
627  $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
628  $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs));
629  $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
630  break;
631  case 'SHIPPING_VALIDATE':
632  $dir_output = $conf->expedition->dir_output.'/sending/';
633  $object_type = 'order_supplier';
634  $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref);
635  break;
636  }
637  $ref = dol_sanitizeFileName($newref);
638  $pdf_path = $dir_output."/".$ref."/".$ref.".pdf";
639  if (! dol_is_file($pdf_path))
640  {
641  // We can't add PDF as it is not generated yet.
642  $filepdf = '';
643  }
644  else
645  {
646  $filepdf = $pdf_path;
647  }
648 
649  $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
650  $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
651  $message.= "\n";
652  $message.= $mesg;
653  if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
654 
655  // Replace keyword __SUPERVISOREMAIL__
656  if (preg_match('/__SUPERVISOREMAIL__/', $sendto))
657  {
658  $newval='';
659  if ($user->fk_user > 0)
660  {
661  $supervisoruser=new User($this->db);
662  $supervisoruser->fetch($user->fk_user);
663  if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
664  }
665  dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
666  $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
667  $sendto = preg_replace('/^[\s,]+/','',$sendto); // Clean start of string
668  $sendto = preg_replace('/[\s,]+$/','',$sendto); // Clean end of string
669  }
670 
671  if ($sendto)
672  {
673  $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename);
674  $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
675  if (empty($reshook))
676  {
677  if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
678  if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
679  }
680 
681  $mailfile = new CMailFile(
682  $subject,
683  $sendto,
684  $replyto,
685  $message,
686  array($file),
687  array($mimefile),
688  array($filename[count($filename)-1]),
689  '',
690  '',
691  0,
692  -1
693  );
694 
695  if ($mailfile->sendfile())
696  {
697  $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
698  $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')";
699  if (! $this->db->query($sql))
700  {
701  dol_print_error($this->db);
702  }
703  }
704  else
705  {
706  $error++;
707  $this->errors[]=$mailfile->error;
708  }
709  }
710  }
711  }
712 
713  if (! $error) return $num;
714  else return -1 * $error;
715  }
716 
717 }
718 
send($notifcode, $object)
Check if notification are active for couple action/company.
Class to manage notifications.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return mime type of a file.
Class to manage Dolibarr users.
Definition: user.class.php:39
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0)
Return an id or code from a code or id.
getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global'))
Return number of notifications activated for action code (and third party)
confirmMessage($action, $socid, $object)
Return message that say how many notification (and to which email) will occurs on requested event...
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_concatdesc($text1, $text2, $forxml=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Class to manage hooks.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext); $mailfile->sendfile();.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage translations.
dol_now($mode='gmt')
Return date for now.
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:427
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
__construct($db)
Constructor.
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
div float
Buy price without taxes.
Definition: style.css.php:525
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.