28 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
53 public $errors = array();
67 static public $arrayofnotifsupported = array(
73 'PROPAL_CLOSE_SIGNED',
75 'FICHINTER_ADD_CONTACT',
76 'ORDER_SUPPLIER_VALIDATE',
77 'ORDER_SUPPLIER_APPROVE',
78 'ORDER_SUPPLIER_REFUSE',
80 'EXPENSE_REPORT_VALIDATE',
81 'EXPENSE_REPORT_APPROVE',
109 global $conf, $langs;
110 $langs->load(
"mails");
115 if (!empty($conf->global->NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER)) {
116 foreach ($listofnotiftodo as $val) {
117 if ($val[
'type'] ==
'touser') {
118 unset($listofnotiftodo[$val[
'email']]);
123 if (!empty($conf->global->NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT)) {
124 foreach ($listofnotiftodo as $val) {
125 if ($val[
'type'] ==
'tocontact') {
126 unset($listofnotiftodo[$val[
'email']]);
131 if (!empty($conf->global->NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX)) {
132 foreach ($listofnotiftodo as $val) {
133 if ($val[
'type'] ==
'tofixedemail') {
134 unset($listofnotiftodo[$val[
'email']]);
142 if (is_array($listofnotiftodo)) {
143 $nb = count($listofnotiftodo);
146 $texte =
img_object($langs->trans(
"Notifications"),
'email').
' '.$langs->trans(
"ErrorFailedToGetListOfNotificationsToSend");
147 } elseif ($nb == 0) {
148 $texte =
img_object($langs->trans(
"Notifications"),
'email').
' '.$langs->trans(
"NoNotificationsWillBeSent");
149 } elseif ($nb == 1) {
150 $texte =
img_object($langs->trans(
"Notifications"),
'email').
' '.$langs->trans(
"ANotificationsWillBeSent");
151 } elseif ($nb >= 2) {
152 $texte =
img_object($langs->trans(
"Notifications"),
'email').
' '.$langs->trans(
"SomeNotificationsWillBeSent", $nb);
155 if (is_array($listofnotiftodo)) {
157 foreach ($listofnotiftodo as $val) {
163 if ($val[
'isemailvalid']) {
164 $texte .= $val[
'email'];
166 $texte .= $val[
'emaildesc'];
188 public function getNotificationsArray($notifcode, $socid = 0, $object =
null, $userid = 0, $scope = array(
'thirdparty',
'user',
'global'))
195 $valueforthreshold = 0;
196 if (is_object($object)) {
197 $valueforthreshold = $object->total_ht;
202 if (is_numeric($notifcode)) {
203 $sqlnotifcode =
" AND n.fk_action = ".((int) $notifcode);
205 $sqlnotifcode =
" AND a.code = '".$this->db->escape($notifcode).
"'";
210 if ($socid >= 0 && in_array(
'thirdparty', $scope)) {
211 $sql =
"SELECT a.code, c.email, c.rowid";
212 $sql .=
" FROM ".$this->db->prefix().
"notify_def as n,";
213 $sql .=
" ".$this->db->prefix().
"socpeople as c,";
214 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
215 $sql .=
" ".$this->db->prefix().
"societe as s";
216 $sql .=
" WHERE n.fk_contact = c.rowid";
217 $sql .=
" AND a.rowid = n.fk_action";
218 $sql .=
" AND n.fk_soc = s.rowid";
219 $sql .= $sqlnotifcode;
220 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
222 $sql .=
" AND s.rowid = ".((int) $socid);
225 dol_syslog(__METHOD__.
" ".$notifcode.
", ".$socid.
"", LOG_DEBUG);
232 $obj = $this->
db->fetch_object(
$resql);
234 $newval2 = trim($obj->email);
236 if (empty($resarray[$newval2])) {
237 $resarray[$newval2] = array(
'type'=>
'tocontact',
'code'=>trim($obj->code),
'emaildesc'=>
'Contact id '.$obj->rowid,
'email'=>$newval2,
'contactid'=>$obj->rowid,
'isemailvalid'=>$isvalid);
244 $this->error = $this->
db->lasterror();
250 if ($userid >= 0 && in_array(
'user', $scope)) {
251 $sql =
"SELECT a.code, c.email, c.rowid";
252 $sql .=
" FROM ".$this->db->prefix().
"notify_def as n,";
253 $sql .=
" ".$this->db->prefix().
"user as c,";
254 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a";
255 $sql .=
" WHERE n.fk_user = c.rowid";
256 $sql .=
" AND a.rowid = n.fk_action";
257 $sql .= $sqlnotifcode;
258 $sql .=
" AND c.entity IN (".getEntity(
'user').
")";
260 $sql .=
" AND c.rowid = ".((int) $userid);
263 dol_syslog(__METHOD__.
" ".$notifcode.
", ".$socid.
"", LOG_DEBUG);
270 $obj = $this->
db->fetch_object(
$resql);
272 $newval2 = trim($obj->email);
274 if (empty($resarray[$newval2])) {
275 $resarray[$newval2] = array(
'type'=>
'touser',
'code'=>trim($obj->code),
'emaildesc'=>
'User id '.$obj->rowid,
'email'=>$newval2,
'userid'=>$obj->rowid,
'isemailvalid'=>$isvalid);
282 $this->error = $this->
db->lasterror();
288 if (in_array(
'global', $scope)) {
290 foreach ($conf->global as $key => $val) {
292 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
296 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
301 $threshold = (
float) $reg[1];
302 if ($valueforthreshold < $threshold) {
306 $tmpemail = explode(
',', $val);
307 foreach ($tmpemail as $key2 => $val2) {
308 $newval2 = trim($val2);
309 if ($newval2 ==
'__SUPERVISOREMAIL__') {
310 if ($user->fk_user > 0) {
311 $tmpuser =
new User($this->
db);
312 $tmpuser->fetch($user->fk_user);
313 if ($tmpuser->email) {
314 $newval2 = trim($tmpuser->email);
324 if (empty($resarray[$newval2])) {
325 $resarray[$newval2] = array(
'type'=>
'tofixedemail',
'code'=>trim($key),
'emaildesc'=>trim($val2),
'email'=>$newval2,
'isemailvalid'=>$isvalid);
352 public function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
354 global $user, $conf, $langs, $mysoc;
356 global $dolibarr_main_url_root;
359 if (!is_object($hookmanager)) {
360 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
363 $hookmanager->initHooks(array(
'notification'));
365 $parameters = array(
'notifcode' => $notifcode);
366 $reshook = $hookmanager->executeHooks(
'notifsupported', $parameters, $object, $action);
367 if (empty($reshook)) {
368 if (!empty($hookmanager->resArray[
'arrayofnotifsupported'])) {
369 Notify::$arrayofnotifsupported = array_merge(Notify::$arrayofnotifsupported, $hookmanager->resArray[
'arrayofnotifsupported']);
373 if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
377 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
379 dol_syslog(get_class($this).
"::send notifcode=".$notifcode.
", object=".$object->id);
381 $langs->load(
"other");
384 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
385 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
389 $application =
'Dolibarr';
390 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
391 $application = $conf->global->MAIN_APPLICATION_TITLE;
393 $replyto = $conf->notification->email_from;
399 $oldref = (empty($object->oldref) ? $object->ref : $object->oldref);
400 $newref = (empty($object->newref) ? $object->ref : $object->newref);
405 if (!empty($object->socid) && $object->socid > 0) {
406 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
407 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.type";
408 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
409 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
410 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
411 $sql .=
" ".$this->db->prefix().
"societe as s";
412 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
413 $sql .=
" AND n.fk_soc = s.rowid";
414 $sql .=
" AND c.statut = 1";
415 if (is_numeric($notifcode)) {
416 $sql .=
" AND n.fk_action = ".((int) $notifcode);
418 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
420 $sql .=
" AND s.rowid = ".((int) $object->socid);
426 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
427 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.type";
428 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
429 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
430 $sql .=
" ".$this->db->prefix().
"notify_def as n";
431 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
432 $sql .=
" AND c.statut = 1";
433 if (is_numeric($notifcode)) {
434 $sql .=
" AND n.fk_action = ".((int) $notifcode);
436 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
439 $result = $this->
db->query($sql);
441 $num = $this->
db->num_rows($result);
443 if (!empty($object->fk_project)) {
444 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
446 $proj->fetch($object->fk_project);
447 $projtitle =
'('.$proj->title.
')';
452 while ($i < $num && !$error) {
453 $obj = $this->
db->fetch_object($result);
456 $notifcodedefid = $obj->adid;
458 if ($obj->type_target ==
'tocontactid') {
459 $trackid =
'ctc'.$obj->cid;
461 if ($obj->type_target ==
'touserid') {
462 $trackid =
'use'.$obj->cid;
467 $outputlangs = $langs;
468 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
470 $outputlangs->setDefaultLang($obj->default_lang);
471 $outputlangs->loadLangs(array(
"main",
"other"));
474 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
476 switch ($notifcode) {
477 case 'BILL_VALIDATE':
478 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
479 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
480 $object_type =
'facture';
481 $labeltouse = $conf->global->BILL_VALIDATE_TEMPLATE;
482 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
485 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
486 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
487 $object_type =
'facture';
488 $labeltouse = $conf->global->BILL_PAYED_TEMPLATE;
489 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
491 case 'ORDER_VALIDATE':
492 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
493 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
494 $object_type =
'order';
495 $labeltouse = $conf->global->ORDER_VALIDATE_TEMPLATE;
496 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
498 case 'PROPAL_VALIDATE':
499 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
500 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
501 $object_type =
'propal';
502 $labeltouse = $conf->global->PROPAL_VALIDATE_TEMPLATE;
503 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
505 case 'PROPAL_CLOSE_SIGNED':
506 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
507 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
508 $object_type =
'propal';
509 $labeltouse = $conf->global->PROPAL_CLOSE_SIGNED_TEMPLATE;
510 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
512 case 'FICHINTER_ADD_CONTACT':
513 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
514 $dir_output = $conf->ficheinter->dir_output;
515 $object_type =
'ficheinter';
516 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
518 case 'FICHINTER_VALIDATE':
519 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
520 $dir_output = $conf->ficheinter->dir_output;
521 $object_type =
'ficheinter';
522 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
524 case 'ORDER_SUPPLIER_VALIDATE':
525 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
526 $dir_output = $conf->fournisseur->commande->dir_output;
527 $object_type =
'order_supplier';
528 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
529 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidatedBy", $link, $user->getFullName($outputlangs));
530 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
532 case 'ORDER_SUPPLIER_APPROVE':
533 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
534 $dir_output = $conf->fournisseur->commande->dir_output;
535 $object_type =
'order_supplier';
536 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
537 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($outputlangs));
538 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
540 case 'ORDER_SUPPLIER_REFUSE':
541 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
542 $dir_output = $conf->fournisseur->commande->dir_output;
543 $object_type =
'order_supplier';
544 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
545 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextOrderRefusedBy", $link, $user->getFullName($outputlangs));
546 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
548 case 'SHIPPING_VALIDATE':
549 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
550 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object,
'shipment');
551 $object_type =
'shipping';
552 $labeltouse = $conf->global->SHIPPING_VALIDATE_TEMPLATE;
553 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
555 case 'EXPENSE_REPORT_VALIDATE':
556 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
557 $dir_output = $conf->expensereport->dir_output;
558 $object_type =
'expensereport';
559 $labeltouse = $conf->global->EXPENSE_REPORT_VALIDATE_TEMPLATE;
560 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
562 case 'EXPENSE_REPORT_APPROVE':
563 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
564 $dir_output = $conf->expensereport->dir_output;
565 $object_type =
'expensereport';
566 $labeltouse = $conf->global->EXPENSE_REPORT_APPROVE_TEMPLATE;
567 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
569 case 'HOLIDAY_VALIDATE':
570 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
571 $dir_output = $conf->holiday->dir_output;
572 $object_type =
'holiday';
573 $labeltouse = $conf->global->HOLIDAY_VALIDATE_TEMPLATE;
574 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
576 case 'HOLIDAY_APPROVE':
577 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
578 $dir_output = $conf->holiday->dir_output;
579 $object_type =
'holiday';
580 $labeltouse = $conf->global->HOLIDAY_APPROVE_TEMPLATE;
581 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
583 case 'ACTION_CREATE':
584 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
585 $dir_output = $conf->agenda->dir_output;
586 $object_type =
'action';
587 $labeltouse = $conf->global->ACTION_CREATE_TEMPLATE;
588 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
591 $object_type = $object->element;
592 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
593 $template = $notifcode.
'_TEMPLATE';
594 $labeltouse = $conf->global->$template;
595 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
599 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
601 $arraydefaultmessage =
null;
603 if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($this->
db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
604 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
607 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
608 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
610 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
611 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
617 $pdf_path = $dir_output.
"/".$ref.
".pdf";
618 if (!
dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
622 $filepdf = $pdf_path;
623 $filename_list[] = $filepdf;
624 $mimetype_list[] = mime_content_type($filepdf);
625 $mimefilename_list[] = $ref.
".pdf";
628 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
630 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list,
'outputlangs'=>$outputlangs,
'labeltouse'=>$labeltouse);
631 if (!isset($action)) {
635 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
636 if (empty($reshook)) {
637 if (!empty($hookmanager->resArray[
'files'])) {
638 $filename_list = $hookmanager->resArray[
'files'][
'file'];
639 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
640 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
642 if (!empty($hookmanager->resArray[
'subject'])) {
643 $subject .= $hookmanager->resArray[
'subject'];
645 if (!empty($hookmanager->resArray[
'message'])) {
646 $message .= $hookmanager->resArray[
'message'];
669 if ($mailfile->sendfile()) {
670 if ($obj->type_target ==
'touserid') {
671 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
672 $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).
"')";
674 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
675 $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).
"')";
677 if (!$this->
db->query($sql)) {
682 $this->errors[] = $mailfile->error;
685 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
690 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ?
'' : $object->socid));
694 $this->errors[] = $this->
db->lasterror();
695 dol_syslog(
"Failed to get list of notification to send ".$this->
db->lasterror(), LOG_ERR);
701 foreach ($conf->global as $key => $val) {
703 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
707 $threshold = (
float) $reg[1];
708 if (!empty($object->total_ht) && $object->total_ht <= $threshold) {
709 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
713 $param =
'NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_'.$reg[1];
715 $sendto = $conf->global->$param;
716 $notifcodedefid =
dol_getIdFromCode($this->
db, $notifcode,
'c_action_trigger',
'code',
'rowid');
717 if ($notifcodedefid <= 0) {
726 $subject =
'['.$mysoc->name.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
728 switch ($notifcode) {
729 case 'BILL_VALIDATE':
730 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
731 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
732 $object_type =
'facture';
733 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
736 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
737 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
738 $object_type =
'facture';
739 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
741 case 'ORDER_VALIDATE':
742 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
743 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
744 $object_type =
'order';
745 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
747 case 'PROPAL_VALIDATE':
748 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
749 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
750 $object_type =
'propal';
751 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
753 case 'PROPAL_CLOSE_SIGNED':
754 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
755 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
756 $object_type =
'propal';
757 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
759 case 'FICHINTER_ADD_CONTACT':
760 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
761 $dir_output = $conf->ficheinter->dir_output;
762 $object_type =
'ficheinter';
763 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
765 case 'FICHINTER_VALIDATE':
766 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
767 $dir_output = $conf->facture->dir_output;
768 $object_type =
'ficheinter';
769 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
771 case 'ORDER_SUPPLIER_VALIDATE':
772 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
773 $dir_output = $conf->fournisseur->commande->dir_output;
774 $object_type =
'order_supplier';
775 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
776 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderValidatedBy", $link, $user->getFullName($langs));
777 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
779 case 'ORDER_SUPPLIER_APPROVE':
780 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
781 $dir_output = $conf->fournisseur->commande->dir_output;
782 $object_type =
'order_supplier';
783 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
784 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
785 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
787 case 'ORDER_SUPPLIER_APPROVE2':
788 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
789 $dir_output = $conf->fournisseur->commande->dir_output;
790 $object_type =
'order_supplier';
791 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
792 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
793 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
795 case 'ORDER_SUPPLIER_REFUSE':
796 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
797 $dir_output = $conf->fournisseur->dir_output.
'/commande/';
798 $object_type =
'order_supplier';
799 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
800 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderRefusedBy", $link, $user->getFullName($langs));
801 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
803 case 'SHIPPING_VALIDATE':
804 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
805 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object,
'shipment');
806 $object_type =
'order_supplier';
807 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
809 case 'EXPENSE_REPORT_VALIDATE':
810 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
811 $dir_output = $conf->expensereport->dir_output;
812 $object_type =
'expensereport';
813 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
815 case 'EXPENSE_REPORT_APPROVE':
816 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
817 $dir_output = $conf->expensereport->dir_output;
818 $object_type =
'expensereport';
819 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
821 case 'HOLIDAY_VALIDATE':
822 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
823 $dir_output = $conf->holiday->dir_output;
824 $object_type =
'holiday';
825 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
827 case 'HOLIDAY_APPROVE':
828 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
829 $dir_output = $conf->holiday->dir_output;
830 $object_type =
'holiday';
831 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
833 case 'ACTION_CREATE':
834 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
835 $dir_output = $conf->agenda->dir_output;
836 $object_type =
'action';
837 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
840 $object_type = $object->element;
841 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
842 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
846 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
851 $filepdf = $pdf_path;
852 $filename_list[] = $pdf_path;
853 $mimetype_list[] = mime_content_type($filepdf);
854 $mimefilename_list[] = $ref.
".pdf";
858 $message .= $langs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
862 $message = nl2br($message);
865 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
867 if ($user->fk_user > 0) {
868 $supervisoruser =
new User($this->
db);
869 $supervisoruser->fetch($user->fk_user);
870 if ($supervisoruser->email) {
871 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
874 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
875 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
876 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
877 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
878 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
882 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list);
883 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
884 if (empty($reshook)) {
885 if (!empty($hookmanager->resArray[
'files'])) {
886 $filename_list = $hookmanager->resArray[
'files'][
'file'];
887 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
888 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
890 if (!empty($hookmanager->resArray[
'subject'])) {
891 $subject .= $hookmanager->resArray[
'subject'];
893 if (!empty($hookmanager->resArray[
'message'])) {
894 $message .= $hookmanager->resArray[
'message'];
916 if ($mailfile->sendfile()) {
917 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
918 $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).
"')";
919 if (!$this->
db->query($sql)) {
924 $this->errors[] = $mailfile->error;