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 $labeltouse = isset($conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
529 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
530 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidatedBy", $link, $user->getFullName($outputlangs));
531 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
533 case 'ORDER_SUPPLIER_APPROVE':
534 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
535 $dir_output = $conf->fournisseur->commande->dir_output;
536 $object_type =
'order_supplier';
537 $labeltouse = isset($conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
538 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
539 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($outputlangs));
540 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
542 case 'ORDER_SUPPLIER_REFUSE':
543 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
544 $dir_output = $conf->fournisseur->commande->dir_output;
545 $object_type =
'order_supplier';
546 $labeltouse = isset($conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
547 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
548 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextOrderRefusedBy", $link, $user->getFullName($outputlangs));
549 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
551 case 'SHIPPING_VALIDATE':
552 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
553 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object,
'shipment');
554 $object_type =
'shipping';
555 $labeltouse = $conf->global->SHIPPING_VALIDATE_TEMPLATE;
556 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
558 case 'EXPENSE_REPORT_VALIDATE':
559 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
560 $dir_output = $conf->expensereport->dir_output;
561 $object_type =
'expensereport';
562 $labeltouse = $conf->global->EXPENSE_REPORT_VALIDATE_TEMPLATE;
563 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
565 case 'EXPENSE_REPORT_APPROVE':
566 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
567 $dir_output = $conf->expensereport->dir_output;
568 $object_type =
'expensereport';
569 $labeltouse = $conf->global->EXPENSE_REPORT_APPROVE_TEMPLATE;
570 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
572 case 'HOLIDAY_VALIDATE':
573 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
574 $dir_output = $conf->holiday->dir_output;
575 $object_type =
'holiday';
576 $labeltouse = $conf->global->HOLIDAY_VALIDATE_TEMPLATE;
577 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
579 case 'HOLIDAY_APPROVE':
580 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
581 $dir_output = $conf->holiday->dir_output;
582 $object_type =
'holiday';
583 $labeltouse = $conf->global->HOLIDAY_APPROVE_TEMPLATE;
584 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
586 case 'ACTION_CREATE':
587 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
588 $dir_output = $conf->agenda->dir_output;
589 $object_type =
'action';
590 $labeltouse = $conf->global->ACTION_CREATE_TEMPLATE;
591 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
594 $object_type = $object->element;
595 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
596 $template = $notifcode.
'_TEMPLATE';
597 $labeltouse = $conf->global->$template;
598 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
602 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
604 $arraydefaultmessage =
null;
606 if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($this->
db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
607 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
610 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
611 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
613 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
614 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
620 $pdf_path = $dir_output.
"/".$ref.
".pdf";
621 if (!
dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
625 $filepdf = $pdf_path;
626 $filename_list[] = $filepdf;
627 $mimetype_list[] = mime_content_type($filepdf);
628 $mimefilename_list[] = $ref.
".pdf";
631 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
633 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list,
'outputlangs'=>$outputlangs,
'labeltouse'=>$labeltouse);
634 if (!isset($action)) {
638 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
639 if (empty($reshook)) {
640 if (!empty($hookmanager->resArray[
'files'])) {
641 $filename_list = $hookmanager->resArray[
'files'][
'file'];
642 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
643 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
645 if (!empty($hookmanager->resArray[
'subject'])) {
646 $subject .= $hookmanager->resArray[
'subject'];
648 if (!empty($hookmanager->resArray[
'message'])) {
649 $message .= $hookmanager->resArray[
'message'];
672 if ($mailfile->sendfile()) {
673 if ($obj->type_target ==
'touserid') {
674 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, 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 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
678 $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).
"')";
680 if (!$this->
db->query($sql)) {
685 $this->errors[] = $mailfile->error;
688 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
693 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ?
'' : $object->socid));
697 $this->errors[] = $this->
db->lasterror();
698 dol_syslog(
"Failed to get list of notification to send ".$this->
db->lasterror(), LOG_ERR);
704 foreach ($conf->global as $key => $val) {
706 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
710 $threshold = (
float) $reg[1];
711 if (!empty($object->total_ht) && $object->total_ht <= $threshold) {
712 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
716 $param =
'NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_'.$reg[1];
718 $sendto = $conf->global->$param;
719 $notifcodedefid =
dol_getIdFromCode($this->
db, $notifcode,
'c_action_trigger',
'code',
'rowid');
720 if ($notifcodedefid <= 0) {
729 $subject =
'['.$mysoc->name.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
731 switch ($notifcode) {
732 case 'BILL_VALIDATE':
733 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
734 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
735 $object_type =
'facture';
736 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
739 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
740 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
741 $object_type =
'facture';
742 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
744 case 'ORDER_VALIDATE':
745 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
746 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
747 $object_type =
'order';
748 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
750 case 'PROPAL_VALIDATE':
751 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
752 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
753 $object_type =
'propal';
754 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
756 case 'PROPAL_CLOSE_SIGNED':
757 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
758 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
759 $object_type =
'propal';
760 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
762 case 'FICHINTER_ADD_CONTACT':
763 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
764 $dir_output = $conf->ficheinter->dir_output;
765 $object_type =
'ficheinter';
766 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
768 case 'FICHINTER_VALIDATE':
769 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
770 $dir_output = $conf->facture->dir_output;
771 $object_type =
'ficheinter';
772 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
774 case 'ORDER_SUPPLIER_VALIDATE':
775 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
776 $dir_output = $conf->fournisseur->commande->dir_output;
777 $object_type =
'order_supplier';
778 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
779 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderValidatedBy", $link, $user->getFullName($langs));
780 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
782 case 'ORDER_SUPPLIER_APPROVE':
783 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
784 $dir_output = $conf->fournisseur->commande->dir_output;
785 $object_type =
'order_supplier';
786 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
787 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
788 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
790 case 'ORDER_SUPPLIER_APPROVE2':
791 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
792 $dir_output = $conf->fournisseur->commande->dir_output;
793 $object_type =
'order_supplier';
794 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
795 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
796 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
798 case 'ORDER_SUPPLIER_REFUSE':
799 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
800 $dir_output = $conf->fournisseur->dir_output.
'/commande/';
801 $object_type =
'order_supplier';
802 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
803 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderRefusedBy", $link, $user->getFullName($langs));
804 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
806 case 'SHIPPING_VALIDATE':
807 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
808 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object,
'shipment');
809 $object_type =
'order_supplier';
810 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
812 case 'EXPENSE_REPORT_VALIDATE':
813 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
814 $dir_output = $conf->expensereport->dir_output;
815 $object_type =
'expensereport';
816 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
818 case 'EXPENSE_REPORT_APPROVE':
819 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
820 $dir_output = $conf->expensereport->dir_output;
821 $object_type =
'expensereport';
822 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
824 case 'HOLIDAY_VALIDATE':
825 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
826 $dir_output = $conf->holiday->dir_output;
827 $object_type =
'holiday';
828 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
830 case 'HOLIDAY_APPROVE':
831 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
832 $dir_output = $conf->holiday->dir_output;
833 $object_type =
'holiday';
834 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
836 case 'ACTION_CREATE':
837 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
838 $dir_output = $conf->agenda->dir_output;
839 $object_type =
'action';
840 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
843 $object_type = $object->element;
844 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
845 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
849 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
854 $filepdf = $pdf_path;
855 $filename_list[] = $pdf_path;
856 $mimetype_list[] = mime_content_type($filepdf);
857 $mimefilename_list[] = $ref.
".pdf";
861 $message .= $langs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
865 $message = nl2br($message);
868 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
870 if ($user->fk_user > 0) {
871 $supervisoruser =
new User($this->
db);
872 $supervisoruser->fetch($user->fk_user);
873 if ($supervisoruser->email) {
874 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
877 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
878 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
879 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
880 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
881 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
885 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list);
886 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
887 if (empty($reshook)) {
888 if (!empty($hookmanager->resArray[
'files'])) {
889 $filename_list = $hookmanager->resArray[
'files'][
'file'];
890 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
891 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
893 if (!empty($hookmanager->resArray[
'subject'])) {
894 $subject .= $hookmanager->resArray[
'subject'];
896 if (!empty($hookmanager->resArray[
'message'])) {
897 $message .= $hookmanager->resArray[
'message'];
919 if ($mailfile->sendfile()) {
920 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
921 $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).
"')";
922 if (!$this->
db->query($sql)) {
927 $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.