28 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
53 public $errors = array();
67 static public $arrayofnotifsupported = array(
74 'PROPAL_CLOSE_SIGNED',
75 'PROPAL_CLOSE_REFUSED',
77 'FICHINTER_ADD_CONTACT',
78 'ORDER_SUPPLIER_VALIDATE',
79 'ORDER_SUPPLIER_APPROVE',
80 'ORDER_SUPPLIER_REFUSE',
82 'EXPENSE_REPORT_VALIDATE',
83 'EXPENSE_REPORT_APPROVE',
111 global $conf, $langs;
112 $langs->load(
"mails");
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']]);
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']]);
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']]);
144 if (is_array($listofnotiftodo)) {
145 $nb = count($listofnotiftodo);
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);
157 if (is_array($listofnotiftodo)) {
159 foreach ($listofnotiftodo as $val) {
165 if ($val[
'isemailvalid']) {
166 $texte .= $val[
'email'];
168 $texte .= $val[
'emaildesc'];
190 public function getNotificationsArray($notifcode, $socid = 0, $object =
null, $userid = 0, $scope = array(
'thirdparty',
'user',
'global'))
197 $valueforthreshold = 0;
198 if (is_object($object)) {
199 $valueforthreshold = $object->total_ht;
204 if (is_numeric($notifcode)) {
205 $sqlnotifcode =
" AND n.fk_action = ".((int) $notifcode);
207 $sqlnotifcode =
" AND a.code = '".$this->db->escape($notifcode).
"'";
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').
")";
224 $sql .=
" AND s.rowid = ".((int) $socid);
227 dol_syslog(__METHOD__.
" ".$notifcode.
", ".$socid, LOG_DEBUG);
229 $resql = $this->db->query(
$sql);
231 $num = $this->db->num_rows($resql);
234 $obj = $this->db->fetch_object($resql);
236 $newval2 = trim($obj->email);
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);
246 $this->error = $this->db->lasterror();
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').
")";
262 $sql .=
" AND c.rowid = ".((int) $userid);
265 dol_syslog(__METHOD__.
" ".$notifcode.
", ".$socid, LOG_DEBUG);
267 $resql = $this->db->query(
$sql);
269 $num = $this->db->num_rows($resql);
272 $obj = $this->db->fetch_object($resql);
274 $newval2 = trim($obj->email);
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);
284 $this->error = $this->db->lasterror();
290 if (in_array(
'global', $scope)) {
292 foreach ($conf->global as $key => $val) {
294 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
298 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
303 $threshold = (
float) $reg[1];
304 if ($valueforthreshold < $threshold) {
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);
326 if (empty($resarray[$newval2])) {
327 $resarray[$newval2] = array(
'type'=>
'tofixedemail',
'code'=>trim($key),
'emaildesc'=>trim($val2),
'email'=>$newval2,
'isemailvalid'=>$isvalid);
354 public function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
356 global $user, $conf, $langs, $mysoc;
358 global $dolibarr_main_url_root;
362 if (!is_object($hookmanager)) {
363 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
366 $hookmanager->initHooks(array(
'notification'));
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']);
377 if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
381 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
383 dol_syslog(get_class($this).
"::send notifcode=".$notifcode.
", object id=".$object->id);
385 $langs->load(
"other");
388 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
389 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
393 $application =
'Dolibarr';
394 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
395 $application = $conf->global->MAIN_APPLICATION_TITLE;
397 $replyto = $conf->notification->email_from;
403 $oldref = (empty($object->oldref) ? $object->ref : $object->oldref);
404 $newref = (empty($object->newref) ? $object->ref : $object->newref);
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);
422 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
424 $sql .=
" AND s.rowid = ".((int) $object->socid);
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);
440 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
448 $result = $this->db->query(
$sql);
450 $num = $this->db->num_rows($result);
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.
')';
461 while ($i < $num && !$error) {
462 $obj = $this->db->fetch_object($result);
465 $notifcodedefid = $obj->adid;
467 if ($obj->type_target ==
'tocontactid') {
468 $trackid =
'ctc'.$obj->cid;
470 if ($obj->type_target ==
'touserid') {
471 $trackid =
'use'.$obj->cid;
476 $outputlangs = $langs;
477 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
479 $outputlangs->setDefaultLang($obj->default_lang);
480 $outputlangs->loadLangs(array(
"main",
"other"));
483 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
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);
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);
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);
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);
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);
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';
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';
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);
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);
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";
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";
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";
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);
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);
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);
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);
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);
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);
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;
616 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
617 $formmail =
new FormMail($this->db);
618 $arraydefaultmessage =
null;
620 $template = $notifcode.
'_TEMPLATE';
622 if (!empty($labeltouse)) {
623 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
625 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
628 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
629 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
631 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
632 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
638 $pdf_path = $dir_output.
"/".$ref.
".pdf";
639 if (!
dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
643 $filepdf = $pdf_path;
644 $filename_list[] = $filepdf;
645 $mimetype_list[] = mime_content_type($filepdf);
646 $mimefilename_list[] = $ref.
".pdf";
649 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
652 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
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.
'>');
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);
664 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
665 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
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)) {
673 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
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'];
680 if (!empty($hookmanager->resArray[
'subject'])) {
681 $subject .= $hookmanager->resArray[
'subject'];
683 if (!empty($hookmanager->resArray[
'message'])) {
684 $message .= $hookmanager->resArray[
'message'];
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).
"')";
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).
"')";
715 if (!$this->db->query(
$sql)) {
720 $this->errors[] = $mailfile->error;
723 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
728 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ?
'' : $object->socid));
732 $this->errors[] = $this->db->lasterror();
733 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
740 foreach ($conf->global as $key => $val) {
742 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
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");
752 $param =
'NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_'.$reg[1];
754 $sendto = $conf->global->$param;
755 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
756 if ($notifcodedefid <= 0) {
765 $subject =
'['.$mysoc->name.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
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);
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);
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);
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);
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);
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);
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);
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);
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";
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";
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";
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";
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);
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);
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);
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);
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);
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);
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;
891 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
896 $filepdf = $pdf_path;
897 $filename_list[] = $pdf_path;
898 $mimetype_list[] = mime_content_type($filepdf);
899 $mimefilename_list[] = $ref.
".pdf";
903 $message .= $langs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
907 $message = nl2br($message);
910 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
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.
'>');
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);
922 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
923 $sendto = preg_replace(
'/[\s,]+$/',
'', $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);
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'];
935 if (!empty($hookmanager->resArray[
'subject'])) {
936 $subject .= $hookmanager->resArray[
'subject'];
938 if (!empty($hookmanager->resArray[
'message'])) {
939 $message .= $hookmanager->resArray[
'message'];
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)) {
969 $this->errors[] = $mailfile->error;