626 public function send($notifcode,
$object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
628 global $user, $conf, $langs, $mysoc;
630 global $dolibarr_main_url_root;
634 if (!is_object($hookmanager)) {
635 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
638 $hookmanager->initHooks(array(
'notification'));
640 $parameters = array(
'notifcode' => $notifcode);
641 $reshook = $hookmanager->executeHooks(
'notifsupported', $parameters,
$object, $action);
642 if (empty($reshook)) {
643 if (!empty($hookmanager->resArray[
'arrayofnotifsupported'])) {
644 Notify::$arrayofnotifsupported = array_merge(Notify::$arrayofnotifsupported, $hookmanager->resArray[
'arrayofnotifsupported']);
649 if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
653 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
655 dol_syslog(get_class($this).
"::send notifcode=".$notifcode.
", object id=".
$object->id);
657 $langs->load(
"other");
660 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
661 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
665 $application =
'Dolibarr';
682 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
683 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
684 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
685 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
686 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
687 $sql .=
" ".$this->db->prefix().
"societe as s";
688 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
689 $sql .=
" AND n.fk_soc = s.rowid";
690 $sql .=
" AND c.statut = 1";
691 if (is_numeric($notifcode)) {
692 $sql .=
" AND n.fk_action = ".((int) $notifcode);
694 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
696 $sql .=
" AND s.rowid = ".((int)
$object->socid);
702 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
703 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
704 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
705 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
706 $sql .=
" ".$this->db->prefix().
"notify_def as n";
707 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
708 $sql .=
" AND c.statut = 1";
709 if (is_numeric($notifcode)) {
710 $sql .=
" AND n.fk_action = ".((int) $notifcode);
712 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
720 $result = $this->db->query($sql);
722 $num = $this->db->num_rows($result);
725 $projtitle =
'('.$object->project->title.
')';
730 while ($i < $num && !$error) {
731 $obj = $this->db->fetch_object($result);
734 $notifcodedefid = $obj->adid;
736 if ($obj->type_target ==
'tocontactid') {
737 $trackid =
'ctc'.$obj->cid;
739 if ($obj->type_target ==
'touserid') {
740 $trackid =
'use'.$obj->cid;
745 $outputlangs = $langs;
746 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
748 $outputlangs->setDefaultLang($obj->default_lang);
749 $outputlangs->loadLangs(array(
"main",
"other"));
752 $appli = $mysoc->name;
754 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
756 switch ($notifcode) {
758 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
759 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
760 $object_type =
'facture';
761 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceCanceled", $link);
763 case 'BILL_VALIDATE':
764 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
765 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
766 $object_type =
'facture';
767 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
770 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
771 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
772 $object_type =
'facture';
773 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
776 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
777 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
778 $object_type =
'order';
779 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderCanceled", $link);
781 case 'ORDER_VALIDATE':
782 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
783 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
784 $object_type =
'order';
785 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
788 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
789 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
790 $object_type =
'order';
792 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
794 case 'PROPAL_VALIDATE':
795 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
797 $object_type =
'propal';
798 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
800 case 'PROPAL_CLOSE_REFUSED':
801 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
803 $object_type =
'propal';
805 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
806 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
807 $mesg .=
' - From online page';
810 case 'PROPAL_CLOSE_SIGNED':
811 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
813 $object_type =
'propal';
814 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
815 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
816 $mesg .=
' - From online page';
819 case 'FICHINTER_ADD_CONTACT':
820 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
821 $dir_output = $conf->ficheinter->dir_output;
822 $object_type =
'ficheinter';
823 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
825 case 'FICHINTER_VALIDATE':
826 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
827 $dir_output = $conf->ficheinter->dir_output;
828 $object_type =
'ficheinter';
829 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
831 case 'FICHINTER_MODIFY':
832 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
833 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
834 $dir_output = $conf->ficheinter->dir_output;
835 $object_type =
'ficheinter';
836 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
838 case 'FICHINTER_CLOSE':
839 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
840 $dir_output = $conf->ficheinter->dir_output;
841 $object_type =
'ficheinter';
842 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
844 case 'ORDER_SUPPLIER_VALIDATE':
845 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
846 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
847 $object_type =
'order_supplier';
848 $labeltouse = isset($conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
849 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
850 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs));
851 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
853 case 'ORDER_SUPPLIER_CANCEL':
854 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
855 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
856 $object_type =
'order_supplier';
857 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
858 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($outputlangs));
859 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
861 case 'ORDER_SUPPLIER_APPROVE':
862 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
863 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
864 $object_type =
'order_supplier';
865 $labeltouse = isset($conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
866 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
867 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs));
868 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
870 case 'ORDER_SUPPLIER_SUBMIT':
871 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
872 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
873 $object_type =
'order_supplier';
874 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
875 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs));
876 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
878 case 'ORDER_SUPPLIER_REFUSE':
879 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
880 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
881 $object_type =
'order_supplier';
882 $labeltouse = isset($conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
883 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
884 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs));
885 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
887 case 'SHIPPING_MODIFY':
888 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
889 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
890 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
891 $object_type =
'shipping';
892 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionModified", $link, $context_info);
894 case 'SHIPPING_VALIDATE':
895 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
896 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
897 $object_type =
'shipping';
898 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
900 case 'EXPENSE_REPORT_VALIDATE':
901 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
902 $dir_output = $conf->expensereport->dir_output;
903 $object_type =
'expensereport';
904 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
906 case 'EXPENSE_REPORT_APPROVE':
907 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
908 $dir_output = $conf->expensereport->dir_output;
909 $object_type =
'expensereport';
910 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
912 case 'HOLIDAY_VALIDATE':
913 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
914 $dir_output = $conf->holiday->dir_output;
915 $object_type =
'holiday';
916 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
918 case 'HOLIDAY_APPROVE':
919 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
920 $dir_output = $conf->holiday->dir_output;
921 $object_type =
'holiday';
922 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
924 case 'ACTION_CREATE':
925 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
926 $dir_output = $conf->agenda->dir_output;
927 $object_type =
'action';
928 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
930 case 'CONTRACT_MODIFY':
931 $link =
'<a href="'.$urlwithroot.
'/contrat/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
932 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
933 $dir_output = $conf->contract->multidir_output;
934 $object_type =
'contract';
935 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextContractModified", $link, $context_info);
938 $object_type =
$object->element;
939 $dir_output = $conf->$object_type->multidir_output[
$object->entity ?
$object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1,
$object, $object_type);
940 $template = $notifcode.
'_TEMPLATE';
941 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
945 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
946 $formmail =
new FormMail($this->db);
947 $arraydefaultmessage =
null;
949 $template = $notifcode.
'_TEMPLATE';
951 if (!empty($labeltouse)) {
952 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
954 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
957 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
958 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
960 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
961 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
967 $pdf_path = $dir_output.
"/".$ref.
".pdf";
968 if (!
dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
972 $filepdf = $pdf_path;
973 $filename_list[] = $filepdf;
974 $mimetype_list[] = mime_content_type($filepdf);
975 $mimefilename_list[] = $ref.
".pdf";
978 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
981 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
983 if ($user->fk_user > 0) {
984 $supervisoruser =
new User($this->db);
985 $supervisoruser->fetch($user->fk_user);
986 if ($supervisoruser->email) {
987 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
990 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
991 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
992 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
993 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
994 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
997 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'outputlangs' => $outputlangs,
'labeltouse' => $labeltouse);
998 if (!isset($action)) {
1002 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1003 if (empty($reshook)) {
1004 if (!empty($hookmanager->resArray[
'files'])) {
1005 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1006 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1007 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1009 if (!empty($hookmanager->resArray[
'subject'])) {
1010 $subject .= $hookmanager->resArray[
'subject'];
1012 if (!empty($hookmanager->resArray[
'message'])) {
1013 $message .= $hookmanager->resArray[
'message'];
1036 if ($mailfile->sendfile()) {
1037 if ($obj->type_target ==
'touserid') {
1038 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
1039 $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).
"')";
1041 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
1042 $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).
"')";
1044 if (!$this->db->query($sql)) {
1049 $this->errors[] = $mailfile->error;
1052 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
1057 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty(
$object->socid) ?
'' :
$object->socid));
1061 $this->errors[] = $this->db->lasterror();
1062 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
1069 foreach ($conf->global as $key => $val) {
1071 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
1077 $threshold = (float) $reg[1];
1078 if (!empty(
$object->total_ht) &&
$object->total_ht <= $threshold) {
1079 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".
$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
1083 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
1084 if ($notifcodedefid <= 0) {
1093 $appli = $mysoc->name;
1095 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
1097 switch ($notifcode) {
1098 case 'BILL_VALIDATE':
1099 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1100 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1101 $object_type =
'facture';
1102 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
1105 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1106 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1107 $object_type =
'facture';
1108 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
1110 case 'ORDER_VALIDATE':
1111 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1112 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1113 $object_type =
'order';
1114 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
1117 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1118 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1119 $object_type =
'order';
1120 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
1122 case 'PROPAL_VALIDATE':
1123 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1125 $object_type =
'propal';
1126 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
1128 case 'PROPAL_CLOSE_SIGNED':
1129 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1131 $object_type =
'propal';
1132 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
1134 case 'FICHINTER_ADD_CONTACT':
1135 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1136 $dir_output = $conf->ficheinter->dir_output;
1137 $object_type =
'ficheinter';
1138 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
1140 case 'FICHINTER_VALIDATE':
1141 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1142 $dir_output = $conf->facture->dir_output;
1143 $object_type =
'ficheinter';
1144 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
1146 case 'FICHINTER_MODIFY':
1147 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1148 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1149 $dir_output = $conf->ficheinter->dir_output;
1150 $object_type =
'ficheinter';
1151 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
1153 case 'FICHINTER_CLOSE':
1154 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1155 $dir_output = $conf->facture->dir_output;
1156 $object_type =
'ficheinter';
1157 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
1159 case 'ORDER_SUPPLIER_CANCEL':
1160 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1161 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1162 $object_type =
'order_supplier';
1163 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1164 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs));
1165 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1167 case 'ORDER_SUPPLIER_VALIDATE':
1168 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1169 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1170 $object_type =
'order_supplier';
1171 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1172 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
1173 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1175 case 'ORDER_SUPPLIER_APPROVE':
1176 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1177 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1178 $object_type =
'order_supplier';
1179 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1180 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
1181 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1183 case 'ORDER_SUPPLIER_SUBMIT':
1184 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1185 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1186 $object_type =
'order_supplier';
1187 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1188 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
1189 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1191 case 'ORDER_SUPPLIER_REFUSE':
1192 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1193 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1194 $object_type =
'order_supplier';
1195 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1196 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
1197 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1199 case 'SHIPPING_MODIFY':
1200 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1201 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1202 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
1203 $object_type =
'order_supplier';
1204 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionModified", $link, $context_info);
1206 case 'SHIPPING_VALIDATE':
1207 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1208 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
1209 $object_type =
'order_supplier';
1210 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
1212 case 'EXPENSE_REPORT_VALIDATE':
1213 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1214 $dir_output = $conf->expensereport->dir_output;
1215 $object_type =
'expensereport';
1216 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
1218 case 'EXPENSE_REPORT_APPROVE':
1219 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1220 $dir_output = $conf->expensereport->dir_output;
1221 $object_type =
'expensereport';
1222 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
1224 case 'HOLIDAY_VALIDATE':
1225 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1226 $dir_output = $conf->holiday->dir_output;
1227 $object_type =
'holiday';
1228 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
1230 case 'HOLIDAY_APPROVE':
1231 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1232 $dir_output = $conf->holiday->dir_output;
1233 $object_type =
'holiday';
1234 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
1236 case 'ACTION_CREATE':
1237 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1238 $dir_output = $conf->agenda->dir_output;
1239 $object_type =
'action';
1240 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
1242 case 'CONTRACT_MODIFY':
1243 $link =
'<a href="'.$urlwithroot.
'/contrat/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1244 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1245 $dir_output = $conf->contract->multidir_output;
1246 $object_type =
'contrat';
1247 $mesg = $langs->transnoentitiesnoconv(
"EMailTextContractModified", $link, $context_info);
1250 $object_type =
$object->element;
1251 $dir_output = $conf->$object_type->multidir_output[
$object->entity ?
$object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1,
$object, $object_type);
1252 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
1256 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
1261 $filepdf = $pdf_path;
1262 $filename_list[] = $pdf_path;
1263 $mimetype_list[] = mime_content_type($filepdf);
1264 $mimefilename_list[] = $ref.
".pdf";
1268 $outputlangs = $langs;
1273 $emailTemplate =
null;
1274 if (!empty($mailTemplateLabel)) {
1275 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1276 $formmail =
new FormMail($this->db);
1277 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $mailTemplateLabel);
1279 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
1280 if (property_exists(
$object,
'thirdparty') &&
$object->thirdparty instanceof
Societe &&
$object->thirdparty->default_lang &&
$object->thirdparty->default_lang != $langs->defaultlang) {
1281 $outputlangs =
new Translate(
'', $conf);
1282 $outputlangs->setDefaultLang(
$object->thirdparty->default_lang);
1283 $outputlangs->loadLangs(array(
'main',
'other'));
1287 $subject =
make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs);
1288 $message =
make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs);
1291 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
1295 $message = nl2br($message);
1299 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
1301 if ($user->fk_user > 0) {
1302 $supervisoruser =
new User($this->db);
1303 $supervisoruser->fetch($user->fk_user);
1304 if ($supervisoruser->email) {
1305 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1308 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1309 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1310 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1311 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1312 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1316 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'subject' => &$subject,
'message' => &$message);
1317 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1318 if (empty($reshook)) {
1319 if (!empty($hookmanager->resArray[
'files'])) {
1320 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1321 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1322 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1324 if (!empty($hookmanager->resArray[
'subject'])) {
1325 $subject .= $hookmanager->resArray[
'subject'];
1327 if (!empty($hookmanager->resArray[
'message'])) {
1328 $message .= $hookmanager->resArray[
'message'];
1350 if ($mailfile->sendfile()) {
1351 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1352 $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($sendto).
"')";
1353 if (!$this->db->query($sql)) {
1358 $this->errors[] = $mailfile->error;