28 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
53 public $errors = array();
67 static public $arrayofnotifsupported = array(
73 'PROPAL_CLOSE_SIGNED',
74 'PROPAL_CLOSE_SIGNED_WEB',
75 'PROPAL_CLOSE_REFUSED',
76 'PROPAL_CLOSE_REFUSED_WEB',
78 'FICHINTER_ADD_CONTACT',
79 'ORDER_SUPPLIER_VALIDATE',
80 'ORDER_SUPPLIER_APPROVE',
81 'ORDER_SUPPLIER_REFUSE',
83 'EXPENSE_REPORT_VALIDATE',
84 'EXPENSE_REPORT_APPROVE',
112 global $conf, $langs;
113 $langs->load(
"mails");
118 if (!empty($conf->global->NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER)) {
119 foreach ($listofnotiftodo as $val) {
120 if ($val[
'type'] ==
'touser') {
121 unset($listofnotiftodo[$val[
'email']]);
126 if (!empty($conf->global->NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT)) {
127 foreach ($listofnotiftodo as $val) {
128 if ($val[
'type'] ==
'tocontact') {
129 unset($listofnotiftodo[$val[
'email']]);
134 if (!empty($conf->global->NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX)) {
135 foreach ($listofnotiftodo as $val) {
136 if ($val[
'type'] ==
'tofixedemail') {
137 unset($listofnotiftodo[$val[
'email']]);
145 if (is_array($listofnotiftodo)) {
146 $nb = count($listofnotiftodo);
149 $texte =
img_object($langs->trans(
"Notifications"),
'email').
' '.$langs->trans(
"ErrorFailedToGetListOfNotificationsToSend");
150 } elseif ($nb == 0) {
151 $texte =
img_object($langs->trans(
"Notifications"),
'email').
' '.$langs->trans(
"NoNotificationsWillBeSent");
152 } elseif ($nb == 1) {
153 $texte =
img_object($langs->trans(
"Notifications"),
'email').
' '.$langs->trans(
"ANotificationsWillBeSent");
154 } elseif ($nb >= 2) {
155 $texte =
img_object($langs->trans(
"Notifications"),
'email').
' '.$langs->trans(
"SomeNotificationsWillBeSent", $nb);
158 if (is_array($listofnotiftodo)) {
160 foreach ($listofnotiftodo as $val) {
166 if ($val[
'isemailvalid']) {
167 $texte .= $val[
'email'];
169 $texte .= $val[
'emaildesc'];
191 public function getNotificationsArray($notifcode, $socid = 0, $object =
null, $userid = 0, $scope = array(
'thirdparty',
'user',
'global'))
198 $valueforthreshold = 0;
199 if (is_object($object)) {
200 $valueforthreshold = $object->total_ht;
205 if (is_numeric($notifcode)) {
206 $sqlnotifcode =
" AND n.fk_action = ".((int) $notifcode);
208 $sqlnotifcode =
" AND a.code = '".$this->db->escape($notifcode).
"'";
213 if ($socid >= 0 && in_array(
'thirdparty', $scope)) {
214 $sql =
"SELECT a.code, c.email, c.rowid";
215 $sql .=
" FROM ".$this->db->prefix().
"notify_def as n,";
216 $sql .=
" ".$this->db->prefix().
"socpeople as c,";
217 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
218 $sql .=
" ".$this->db->prefix().
"societe as s";
219 $sql .=
" WHERE n.fk_contact = c.rowid";
220 $sql .=
" AND a.rowid = n.fk_action";
221 $sql .=
" AND n.fk_soc = s.rowid";
222 $sql .= $sqlnotifcode;
223 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
225 $sql .=
" AND s.rowid = ".((int) $socid);
228 dol_syslog(__METHOD__.
" ".$notifcode.
", ".$socid, LOG_DEBUG);
235 $obj = $this->
db->fetch_object(
$resql);
237 $newval2 = trim($obj->email);
239 if (empty($resarray[$newval2])) {
240 $resarray[$newval2] = array(
'type'=>
'tocontact',
'code'=>trim($obj->code),
'emaildesc'=>
'Contact id '.$obj->rowid,
'email'=>$newval2,
'contactid'=>$obj->rowid,
'isemailvalid'=>$isvalid);
247 $this->error = $this->
db->lasterror();
253 if ($userid >= 0 && in_array(
'user', $scope)) {
254 $sql =
"SELECT a.code, c.email, c.rowid";
255 $sql .=
" FROM ".$this->db->prefix().
"notify_def as n,";
256 $sql .=
" ".$this->db->prefix().
"user as c,";
257 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a";
258 $sql .=
" WHERE n.fk_user = c.rowid";
259 $sql .=
" AND a.rowid = n.fk_action";
260 $sql .= $sqlnotifcode;
261 $sql .=
" AND c.entity IN (".getEntity(
'user').
")";
263 $sql .=
" AND c.rowid = ".((int) $userid);
266 dol_syslog(__METHOD__.
" ".$notifcode.
", ".$socid, LOG_DEBUG);
273 $obj = $this->
db->fetch_object(
$resql);
275 $newval2 = trim($obj->email);
277 if (empty($resarray[$newval2])) {
278 $resarray[$newval2] = array(
'type'=>
'touser',
'code'=>trim($obj->code),
'emaildesc'=>
'User id '.$obj->rowid,
'email'=>$newval2,
'userid'=>$obj->rowid,
'isemailvalid'=>$isvalid);
285 $this->error = $this->
db->lasterror();
291 if (in_array(
'global', $scope)) {
293 foreach ($conf->global as $key => $val) {
295 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
299 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
304 $threshold = (
float) $reg[1];
305 if ($valueforthreshold < $threshold) {
309 $tmpemail = explode(
',', $val);
310 foreach ($tmpemail as $key2 => $val2) {
311 $newval2 = trim($val2);
312 if ($newval2 ==
'__SUPERVISOREMAIL__') {
313 if ($user->fk_user > 0) {
314 $tmpuser =
new User($this->
db);
315 $tmpuser->fetch($user->fk_user);
316 if ($tmpuser->email) {
317 $newval2 = trim($tmpuser->email);
327 if (empty($resarray[$newval2])) {
328 $resarray[$newval2] = array(
'type'=>
'tofixedemail',
'code'=>trim($key),
'emaildesc'=>trim($val2),
'email'=>$newval2,
'isemailvalid'=>$isvalid);
355 public function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
357 global $user, $conf, $langs, $mysoc;
359 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']);
376 if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
380 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
382 dol_syslog(get_class($this).
"::send notifcode=".$notifcode.
", object=".$object->id);
384 $langs->load(
"other");
387 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
388 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
392 $application =
'Dolibarr';
393 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
394 $application = $conf->global->MAIN_APPLICATION_TITLE;
396 $replyto = $conf->notification->email_from;
402 $oldref = (empty($object->oldref) ? $object->ref : $object->oldref);
403 $newref = (empty($object->newref) ? $object->ref : $object->newref);
408 if (!empty($object->socid) && $object->socid > 0) {
409 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
410 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.type";
411 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
412 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
413 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
414 $sql .=
" ".$this->db->prefix().
"societe as s";
415 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
416 $sql .=
" AND n.fk_soc = s.rowid";
417 $sql .=
" AND c.statut = 1";
418 if (is_numeric($notifcode)) {
419 $sql .=
" AND n.fk_action = ".((int) $notifcode);
421 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
423 $sql .=
" AND s.rowid = ".((int) $object->socid);
429 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
430 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.type";
431 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
432 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
433 $sql .=
" ".$this->db->prefix().
"notify_def as n";
434 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
435 $sql .=
" AND c.statut = 1";
436 if (is_numeric($notifcode)) {
437 $sql .=
" AND n.fk_action = ".((int) $notifcode);
439 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
442 $result = $this->
db->query($sql);
444 $num = $this->
db->num_rows($result);
446 if (!empty($object->fk_project)) {
447 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
449 $proj->fetch($object->fk_project);
450 $projtitle =
'('.$proj->title.
')';
455 while ($i < $num && !$error) {
456 $obj = $this->
db->fetch_object($result);
459 $notifcodedefid = $obj->adid;
461 if ($obj->type_target ==
'tocontactid') {
462 $trackid =
'ctc'.$obj->cid;
464 if ($obj->type_target ==
'touserid') {
465 $trackid =
'use'.$obj->cid;
470 $outputlangs = $langs;
471 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
473 $outputlangs->setDefaultLang($obj->default_lang);
474 $outputlangs->loadLangs(array(
"main",
"other"));
477 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
479 switch ($notifcode) {
480 case 'BILL_VALIDATE':
481 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
482 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
483 $object_type =
'facture';
484 $labeltouse = $conf->global->BILL_VALIDATE_TEMPLATE;
485 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
488 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
489 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
490 $object_type =
'facture';
491 $labeltouse = $conf->global->BILL_PAYED_TEMPLATE;
492 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
494 case 'ORDER_VALIDATE':
495 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
496 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
497 $object_type =
'order';
498 $labeltouse = $conf->global->ORDER_VALIDATE_TEMPLATE;
499 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
501 case 'PROPAL_VALIDATE':
502 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
503 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
504 $object_type =
'propal';
505 $labeltouse = $conf->global->PROPAL_VALIDATE_TEMPLATE;
506 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
508 case 'PROPAL_CLOSE_REFUSED':
509 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
510 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
511 $object_type =
'propal';
512 $labeltouse = $conf->global->PROPAL_CLOSE_REFUSED_TEMPLATE;
513 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
515 case 'PROPAL_CLOSE_REFUSED_WEB':
516 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
517 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
518 $object_type =
'propal';
519 $labeltouse = $conf->global->PROPAL_CLOSE_REFUSED_TEMPLATE;
520 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefusedWeb", $link);
522 case 'PROPAL_CLOSE_SIGNED':
523 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
524 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
525 $object_type =
'propal';
526 $labeltouse = $conf->global->PROPAL_CLOSE_SIGNED_TEMPLATE;
527 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
529 case 'PROPAL_CLOSE_SIGNED_WEB':
530 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
531 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
532 $object_type =
'propal';
533 $labeltouse = $conf->global->PROPAL_CLOSE_SIGNED_TEMPLATE;
534 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
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->dir_output;
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->dir_output;
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->dir_output;
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 $labeltouse = $conf->global->SHIPPING_VALIDATE_TEMPLATE;
577 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
579 case 'EXPENSE_REPORT_VALIDATE':
580 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
581 $dir_output = $conf->expensereport->dir_output;
582 $object_type =
'expensereport';
583 $labeltouse = $conf->global->EXPENSE_REPORT_VALIDATE_TEMPLATE;
584 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
586 case 'EXPENSE_REPORT_APPROVE':
587 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
588 $dir_output = $conf->expensereport->dir_output;
589 $object_type =
'expensereport';
590 $labeltouse = $conf->global->EXPENSE_REPORT_APPROVE_TEMPLATE;
591 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
593 case 'HOLIDAY_VALIDATE':
594 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
595 $dir_output = $conf->holiday->dir_output;
596 $object_type =
'holiday';
597 $labeltouse = $conf->global->HOLIDAY_VALIDATE_TEMPLATE;
598 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
600 case 'HOLIDAY_APPROVE':
601 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
602 $dir_output = $conf->holiday->dir_output;
603 $object_type =
'holiday';
604 $labeltouse = $conf->global->HOLIDAY_APPROVE_TEMPLATE;
605 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
607 case 'ACTION_CREATE':
608 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
609 $dir_output = $conf->agenda->dir_output;
610 $object_type =
'action';
611 $labeltouse = $conf->global->ACTION_CREATE_TEMPLATE;
612 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
615 $object_type = $object->element;
616 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
617 $template = $notifcode.
'_TEMPLATE';
618 $labeltouse = $conf->global->$template;
619 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
623 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
625 $arraydefaultmessage =
null;
627 if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($this->
db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
628 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
631 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
632 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
634 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
635 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
641 $pdf_path = $dir_output.
"/".$ref.
".pdf";
642 if (!
dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
646 $filepdf = $pdf_path;
647 $filename_list[] = $filepdf;
648 $mimetype_list[] = mime_content_type($filepdf);
649 $mimefilename_list[] = $ref.
".pdf";
652 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
654 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list,
'outputlangs'=>$outputlangs,
'labeltouse'=>$labeltouse);
655 if (!isset($action)) {
659 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
660 if (empty($reshook)) {
661 if (!empty($hookmanager->resArray[
'files'])) {
662 $filename_list = $hookmanager->resArray[
'files'][
'file'];
663 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
664 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
666 if (!empty($hookmanager->resArray[
'subject'])) {
667 $subject .= $hookmanager->resArray[
'subject'];
669 if (!empty($hookmanager->resArray[
'message'])) {
670 $message .= $hookmanager->resArray[
'message'];
693 if ($mailfile->sendfile()) {
694 if ($obj->type_target ==
'touserid') {
695 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
696 $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).
"')";
698 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
699 $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).
"')";
701 if (!$this->
db->query($sql)) {
706 $this->errors[] = $mailfile->error;
709 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
714 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ?
'' : $object->socid));
718 $this->errors[] = $this->
db->lasterror();
719 dol_syslog(
"Failed to get list of notification to send ".$this->
db->lasterror(), LOG_ERR);
725 foreach ($conf->global as $key => $val) {
727 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
731 $threshold = (
float) $reg[1];
732 if (!empty($object->total_ht) && $object->total_ht <= $threshold) {
733 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
737 $param =
'NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_'.$reg[1];
739 $sendto = $conf->global->$param;
740 $notifcodedefid =
dol_getIdFromCode($this->
db, $notifcode,
'c_action_trigger',
'code',
'rowid');
741 if ($notifcodedefid <= 0) {
750 $subject =
'['.$mysoc->name.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
752 switch ($notifcode) {
753 case 'BILL_VALIDATE':
754 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
755 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
756 $object_type =
'facture';
757 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
760 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
761 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
762 $object_type =
'facture';
763 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
765 case 'ORDER_VALIDATE':
766 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
767 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
768 $object_type =
'order';
769 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
771 case 'PROPAL_VALIDATE':
772 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
773 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
774 $object_type =
'propal';
775 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
777 case 'PROPAL_CLOSE_SIGNED':
778 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
779 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
780 $object_type =
'propal';
781 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
783 case 'FICHINTER_ADD_CONTACT':
784 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
785 $dir_output = $conf->ficheinter->dir_output;
786 $object_type =
'ficheinter';
787 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
789 case 'FICHINTER_VALIDATE':
790 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
791 $dir_output = $conf->facture->dir_output;
792 $object_type =
'ficheinter';
793 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
795 case 'ORDER_SUPPLIER_VALIDATE':
796 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
797 $dir_output = $conf->fournisseur->commande->dir_output;
798 $object_type =
'order_supplier';
799 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
800 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderValidatedBy", $link, $user->getFullName($langs));
801 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
803 case 'ORDER_SUPPLIER_APPROVE':
804 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
805 $dir_output = $conf->fournisseur->commande->dir_output;
806 $object_type =
'order_supplier';
807 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
808 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
809 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
811 case 'ORDER_SUPPLIER_APPROVE2':
812 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
813 $dir_output = $conf->fournisseur->commande->dir_output;
814 $object_type =
'order_supplier';
815 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
816 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
817 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
819 case 'ORDER_SUPPLIER_REFUSE':
820 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
821 $dir_output = $conf->fournisseur->dir_output.
'/commande/';
822 $object_type =
'order_supplier';
823 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
824 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderRefusedBy", $link, $user->getFullName($langs));
825 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
827 case 'SHIPPING_VALIDATE':
828 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
829 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object,
'shipment');
830 $object_type =
'order_supplier';
831 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
833 case 'EXPENSE_REPORT_VALIDATE':
834 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
835 $dir_output = $conf->expensereport->dir_output;
836 $object_type =
'expensereport';
837 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
839 case 'EXPENSE_REPORT_APPROVE':
840 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
841 $dir_output = $conf->expensereport->dir_output;
842 $object_type =
'expensereport';
843 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
845 case 'HOLIDAY_VALIDATE':
846 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
847 $dir_output = $conf->holiday->dir_output;
848 $object_type =
'holiday';
849 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
851 case 'HOLIDAY_APPROVE':
852 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
853 $dir_output = $conf->holiday->dir_output;
854 $object_type =
'holiday';
855 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
857 case 'ACTION_CREATE':
858 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
859 $dir_output = $conf->agenda->dir_output;
860 $object_type =
'action';
861 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
864 $object_type = $object->element;
865 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
866 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
870 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
875 $filepdf = $pdf_path;
876 $filename_list[] = $pdf_path;
877 $mimetype_list[] = mime_content_type($filepdf);
878 $mimefilename_list[] = $ref.
".pdf";
882 $message .= $langs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
886 $message = nl2br($message);
889 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
891 if ($user->fk_user > 0) {
892 $supervisoruser =
new User($this->
db);
893 $supervisoruser->fetch($user->fk_user);
894 if ($supervisoruser->email) {
895 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
898 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
899 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
900 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
901 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
902 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
906 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list);
907 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
908 if (empty($reshook)) {
909 if (!empty($hookmanager->resArray[
'files'])) {
910 $filename_list = $hookmanager->resArray[
'files'][
'file'];
911 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
912 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
914 if (!empty($hookmanager->resArray[
'subject'])) {
915 $subject .= $hookmanager->resArray[
'subject'];
917 if (!empty($hookmanager->resArray[
'message'])) {
918 $message .= $hookmanager->resArray[
'message'];
940 if ($mailfile->sendfile()) {
941 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
942 $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).
"')";
943 if (!$this->
db->query($sql)) {
948 $this->errors[] = $mailfile->error;
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
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.
if(isModEnabled('facture') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
dol_is_file($pathoffile)
Return if path is a file.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
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.
$conf db
API class for accounts.