354 public function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
356 global $user, $conf, $langs, $mysoc;
358 global $dolibarr_main_url_root;
362 if (!is_object($hookmanager)) {
363 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
366 $hookmanager->initHooks(array(
'notification'));
368 $parameters = array(
'notifcode' => $notifcode);
369 $reshook = $hookmanager->executeHooks(
'notifsupported', $parameters, $object, $action);
370 if (empty($reshook)) {
371 if (!empty($hookmanager->resArray[
'arrayofnotifsupported'])) {
372 Notify::$arrayofnotifsupported = array_merge(Notify::$arrayofnotifsupported, $hookmanager->resArray[
'arrayofnotifsupported']);
377 if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
381 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
383 dol_syslog(get_class($this).
"::send notifcode=".$notifcode.
", object id=".$object->id);
385 $langs->load(
"other");
388 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
389 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
393 $application =
'Dolibarr';
394 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
395 $application = $conf->global->MAIN_APPLICATION_TITLE;
397 $replyto = $conf->notification->email_from;
403 $oldref = (empty($object->oldref) ? $object->ref : $object->oldref);
404 $newref = (empty($object->newref) ? $object->ref : $object->newref);
409 if (!empty($object->socid) && $object->socid > 0) {
410 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
411 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
412 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
413 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
414 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
415 $sql .=
" ".$this->db->prefix().
"societe as s";
416 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
417 $sql .=
" AND n.fk_soc = s.rowid";
418 $sql .=
" AND c.statut = 1";
419 if (is_numeric($notifcode)) {
420 $sql .=
" AND n.fk_action = ".((int) $notifcode);
422 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
424 $sql .=
" AND s.rowid = ".((int) $object->socid);
430 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
431 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
432 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
433 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
434 $sql .=
" ".$this->db->prefix().
"notify_def as n";
435 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
436 $sql .=
" AND c.statut = 1";
437 if (is_numeric($notifcode)) {
438 $sql .=
" AND n.fk_action = ".((int) $notifcode);
440 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
448 $result = $this->db->query($sql);
450 $num = $this->db->num_rows($result);
452 if (!empty($object->fk_project)) {
453 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
454 $proj =
new Project($this->db);
455 $proj->fetch($object->fk_project);
456 $projtitle =
'('.$proj->title.
')';
461 while ($i < $num && !$error) {
462 $obj = $this->db->fetch_object($result);
465 $notifcodedefid = $obj->adid;
467 if ($obj->type_target ==
'tocontactid') {
468 $trackid =
'ctc'.$obj->cid;
470 if ($obj->type_target ==
'touserid') {
471 $trackid =
'use'.$obj->cid;
476 $outputlangs = $langs;
477 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
479 $outputlangs->setDefaultLang($obj->default_lang);
480 $outputlangs->loadLangs(array(
"main",
"other"));
483 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
485 switch ($notifcode) {
486 case 'BILL_VALIDATE':
487 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
488 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
489 $object_type =
'facture';
490 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
493 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
494 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
495 $object_type =
'facture';
496 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
498 case 'ORDER_VALIDATE':
499 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
500 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
501 $object_type =
'order';
502 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
505 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
506 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
507 $object_type =
'order';
508 $labeltouse = $conf->global->ORDER_CLOSE_TEMPLATE;
509 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
511 case 'PROPAL_VALIDATE':
512 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
513 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
514 $object_type =
'propal';
515 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
517 case 'PROPAL_CLOSE_REFUSED':
518 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
519 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
520 $object_type =
'propal';
521 $labeltouse = $conf->global->PROPAL_CLOSE_REFUSED_TEMPLATE;
522 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
523 if (!empty($object->context[
'closedfromonlinesignature'])) {
524 $mesg .=
' - From online page';
527 case 'PROPAL_CLOSE_SIGNED':
528 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
529 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
530 $object_type =
'propal';
531 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
532 if (!empty($object->context[
'closedfromonlinesignature'])) {
533 $mesg .=
' - From online page';
536 case 'FICHINTER_ADD_CONTACT':
537 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
538 $dir_output = $conf->ficheinter->dir_output;
539 $object_type =
'ficheinter';
540 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
542 case 'FICHINTER_VALIDATE':
543 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
544 $dir_output = $conf->ficheinter->dir_output;
545 $object_type =
'ficheinter';
546 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
548 case 'ORDER_SUPPLIER_VALIDATE':
549 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
550 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
551 $object_type =
'order_supplier';
552 $labeltouse = isset($conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
553 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
554 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidatedBy", $link, $user->getFullName($outputlangs));
555 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
557 case 'ORDER_SUPPLIER_APPROVE':
558 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
559 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
560 $object_type =
'order_supplier';
561 $labeltouse = isset($conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
562 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
563 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($outputlangs));
564 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
566 case 'ORDER_SUPPLIER_REFUSE':
567 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
568 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
569 $object_type =
'order_supplier';
570 $labeltouse = isset($conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
571 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
572 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextOrderRefusedBy", $link, $user->getFullName($outputlangs));
573 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
575 case 'SHIPPING_VALIDATE':
576 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
577 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object,
'shipment');
578 $object_type =
'shipping';
579 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
581 case 'EXPENSE_REPORT_VALIDATE':
582 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
583 $dir_output = $conf->expensereport->dir_output;
584 $object_type =
'expensereport';
585 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
587 case 'EXPENSE_REPORT_APPROVE':
588 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
589 $dir_output = $conf->expensereport->dir_output;
590 $object_type =
'expensereport';
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 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
599 case 'HOLIDAY_APPROVE':
600 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
601 $dir_output = $conf->holiday->dir_output;
602 $object_type =
'holiday';
603 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
605 case 'ACTION_CREATE':
606 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
607 $dir_output = $conf->agenda->dir_output;
608 $object_type =
'action';
609 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
612 $object_type = $object->element;
613 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
614 $template = $notifcode.
'_TEMPLATE';
615 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
619 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
620 $formmail =
new FormMail($this->db);
621 $arraydefaultmessage =
null;
623 $template = $notifcode.
'_TEMPLATE';
625 if (!empty($labeltouse)) {
626 $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 :
'';
655 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
657 if ($user->fk_user > 0) {
658 $supervisoruser =
new User($this->db);
659 $supervisoruser->fetch($user->fk_user);
660 if ($supervisoruser->email) {
661 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
664 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
665 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
666 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
667 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
668 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
671 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list,
'outputlangs'=>$outputlangs,
'labeltouse'=>$labeltouse);
672 if (!isset($action)) {
676 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
677 if (empty($reshook)) {
678 if (!empty($hookmanager->resArray[
'files'])) {
679 $filename_list = $hookmanager->resArray[
'files'][
'file'];
680 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
681 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
683 if (!empty($hookmanager->resArray[
'subject'])) {
684 $subject .= $hookmanager->resArray[
'subject'];
686 if (!empty($hookmanager->resArray[
'message'])) {
687 $message .= $hookmanager->resArray[
'message'];
710 if ($mailfile->sendfile()) {
711 if ($obj->type_target ==
'touserid') {
712 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
713 $sql .=
" VALUES ('".$this->db->idate(
dol_now()).
"', ".((int) $notifcodedefid).
", ".($object->socid > 0 ? ((int) $object->socid) :
'null').
", ".((
int) $obj->cid).
", '".$this->db->escape($obj->type).
"', '".$this->db->escape($object_type).
"', '".$this->db->escape($obj->type_target).
"', ".((int) $object->id).
", '".$this->db->escape($obj->email).
"')";
715 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
716 $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).
"')";
718 if (!$this->db->query($sql)) {
723 $this->errors[] = $mailfile->error;
726 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
731 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty($object->socid) ?
'' : $object->socid));
735 $this->errors[] = $this->db->lasterror();
736 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
743 foreach ($conf->global as $key => $val) {
745 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
749 $threshold = (float) $reg[1];
750 if (!empty($object->total_ht) && $object->total_ht <= $threshold) {
751 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
755 $param =
'NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_'.$reg[1];
757 $sendto = $conf->global->$param;
758 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
759 if ($notifcodedefid <= 0) {
768 $subject =
'['.$mysoc->name.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
770 switch ($notifcode) {
771 case 'BILL_VALIDATE':
772 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
773 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
774 $object_type =
'facture';
775 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
778 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
779 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'invoice');
780 $object_type =
'facture';
781 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
783 case 'ORDER_VALIDATE':
784 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
785 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
786 $object_type =
'order';
787 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
790 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
791 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1, $object,
'commande');
792 $object_type =
'order';
793 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
795 case 'PROPAL_VALIDATE':
796 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
797 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
798 $object_type =
'propal';
799 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
801 case 'PROPAL_CLOSE_SIGNED':
802 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
803 $dir_output = $conf->propal->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object,
'propal');
804 $object_type =
'propal';
805 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
807 case 'FICHINTER_ADD_CONTACT':
808 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
809 $dir_output = $conf->ficheinter->dir_output;
810 $object_type =
'ficheinter';
811 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
813 case 'FICHINTER_VALIDATE':
814 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
815 $dir_output = $conf->facture->dir_output;
816 $object_type =
'ficheinter';
817 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
819 case 'ORDER_SUPPLIER_VALIDATE':
820 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
821 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
822 $object_type =
'order_supplier';
823 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
824 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderValidatedBy", $link, $user->getFullName($langs));
825 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
827 case 'ORDER_SUPPLIER_APPROVE':
828 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
829 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
830 $object_type =
'order_supplier';
831 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
832 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
833 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
835 case 'ORDER_SUPPLIER_APPROVE2':
836 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
837 $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity].
"/".
get_exdir(0, 0, 0, 1, $object);
838 $object_type =
'order_supplier';
839 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
840 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderApprovedBy", $link, $user->getFullName($langs));
841 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
843 case 'ORDER_SUPPLIER_REFUSE':
844 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
845 $dir_output = $conf->fournisseur->dir_output.
'/commande/';
846 $object_type =
'order_supplier';
847 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
848 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextOrderRefusedBy", $link, $user->getFullName($langs));
849 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
851 case 'SHIPPING_VALIDATE':
852 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
853 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1, $object,
'shipment');
854 $object_type =
'order_supplier';
855 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
857 case 'EXPENSE_REPORT_VALIDATE':
858 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
859 $dir_output = $conf->expensereport->dir_output;
860 $object_type =
'expensereport';
861 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
863 case 'EXPENSE_REPORT_APPROVE':
864 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
865 $dir_output = $conf->expensereport->dir_output;
866 $object_type =
'expensereport';
867 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
869 case 'HOLIDAY_VALIDATE':
870 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
871 $dir_output = $conf->holiday->dir_output;
872 $object_type =
'holiday';
873 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
875 case 'HOLIDAY_APPROVE':
876 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
877 $dir_output = $conf->holiday->dir_output;
878 $object_type =
'holiday';
879 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
881 case 'ACTION_CREATE':
882 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.$object->id.
'&entity='.$object->entity.
'">'.$newref.
'</a>';
883 $dir_output = $conf->agenda->dir_output;
884 $object_type =
'action';
885 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
888 $object_type = $object->element;
889 $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1, $object, $object_type);
890 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
894 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
899 $filepdf = $pdf_path;
900 $filename_list[] = $pdf_path;
901 $mimetype_list[] = mime_content_type($filepdf);
902 $mimefilename_list[] = $ref.
".pdf";
908 $mailTemplateLabel = isset($conf->global->{$notifcode.
'_TEMPLATE'}) ? $conf->global->{$notifcode.
'_TEMPLATE'} :
'';
909 $emailTemplate =
null;
910 if (!empty($mailTemplateLabel)) {
911 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
912 $formmail =
new FormMail($this->db);
913 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $langs, 0, 1, $labeltouse);
915 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
922 $message .= $langs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
926 $message = nl2br($message);
930 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
932 if ($user->fk_user > 0) {
933 $supervisoruser =
new User($this->db);
934 $supervisoruser->fetch($user->fk_user);
935 if ($supervisoruser->email) {
936 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
939 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
940 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
941 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
942 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
943 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
947 $parameters = array(
'notifcode'=>$notifcode,
'sendto'=>$sendto,
'replyto'=>$replyto,
'file'=>$filename_list,
'mimefile'=>$mimetype_list,
'filename'=>$mimefilename_list);
948 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters, $object, $action);
949 if (empty($reshook)) {
950 if (!empty($hookmanager->resArray[
'files'])) {
951 $filename_list = $hookmanager->resArray[
'files'][
'file'];
952 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
953 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
955 if (!empty($hookmanager->resArray[
'subject'])) {
956 $subject .= $hookmanager->resArray[
'subject'];
958 if (!empty($hookmanager->resArray[
'message'])) {
959 $message .= $hookmanager->resArray[
'message'];
981 if ($mailfile->sendfile()) {
982 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
983 $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).
"')";
984 if (!$this->db->query($sql)) {
989 $this->errors[] = $mailfile->error;