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>';
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>';
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>';
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>';
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>';
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>';
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>';
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>';
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>';
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>';
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>';
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() :
'';
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>';
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;
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) {
955 if (method_exists(
$object,
'fetch_thirdparty') && empty(
$object->thirdparty)) {
960 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
961 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
963 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
964 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
970 $pdf_path = $dir_output.
"/".$ref.
".pdf";
971 if (!
dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
975 $filepdf = $pdf_path;
976 $filename_list[] = $filepdf;
977 $mimetype_list[] = mime_content_type($filepdf);
978 $mimefilename_list[] = $ref.
".pdf";
981 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
984 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
986 if ($user->fk_user > 0) {
987 $supervisoruser =
new User($this->db);
988 $supervisoruser->fetch($user->fk_user);
989 if ($supervisoruser->email) {
990 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
993 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
994 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
995 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
996 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
997 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1000 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'outputlangs' => $outputlangs,
'labeltouse' => $labeltouse);
1001 if (!isset($action)) {
1005 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1006 if (empty($reshook)) {
1007 if (!empty($hookmanager->resArray[
'files'])) {
1008 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1009 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1010 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1012 if (!empty($hookmanager->resArray[
'subject'])) {
1013 $subject .= $hookmanager->resArray[
'subject'];
1015 if (!empty($hookmanager->resArray[
'message'])) {
1016 $message .= $hookmanager->resArray[
'message'];
1039 if ($mailfile->sendfile()) {
1040 if ($obj->type_target ==
'touserid') {
1041 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, 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 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
1045 $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).
"')";
1047 if (!$this->db->query($sql)) {
1052 $this->errors[] = $mailfile->error;
1055 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
1060 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty(
$object->socid) ?
'' :
$object->socid));
1064 $this->errors[] = $this->db->lasterror();
1065 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
1072 foreach (
$conf->global as $key => $val) {
1074 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
1080 $threshold = (float) $reg[1];
1081 if (!empty(
$object->total_ht) &&
$object->total_ht <= $threshold) {
1082 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".
$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
1086 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
1087 if ($notifcodedefid <= 0) {
1096 $appli = $mysoc->name;
1098 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
1100 switch ($notifcode) {
1101 case 'BILL_VALIDATE':
1102 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1104 $object_type =
'facture';
1105 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
1108 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1110 $object_type =
'facture';
1111 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
1113 case 'ORDER_VALIDATE':
1114 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1116 $object_type =
'order';
1117 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
1120 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1122 $object_type =
'order';
1123 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
1125 case 'PROPAL_VALIDATE':
1126 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1128 $object_type =
'propal';
1129 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
1131 case 'PROPAL_CLOSE_SIGNED':
1132 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1134 $object_type =
'propal';
1135 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
1137 case 'FICHINTER_ADD_CONTACT':
1138 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1139 $dir_output =
$conf->ficheinter->dir_output;
1140 $object_type =
'ficheinter';
1141 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
1143 case 'FICHINTER_VALIDATE':
1144 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1145 $dir_output =
$conf->facture->dir_output;
1146 $object_type =
'ficheinter';
1147 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
1149 case 'FICHINTER_MODIFY':
1150 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1151 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1152 $dir_output =
$conf->ficheinter->dir_output;
1153 $object_type =
'ficheinter';
1154 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
1156 case 'FICHINTER_CLOSE':
1157 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1158 $dir_output =
$conf->facture->dir_output;
1159 $object_type =
'ficheinter';
1160 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
1162 case 'ORDER_SUPPLIER_CANCEL':
1163 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1165 $object_type =
'order_supplier';
1166 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1167 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs));
1168 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1170 case 'ORDER_SUPPLIER_VALIDATE':
1171 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1173 $object_type =
'order_supplier';
1174 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1175 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
1176 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1178 case 'ORDER_SUPPLIER_APPROVE':
1179 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1181 $object_type =
'order_supplier';
1182 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1183 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
1184 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1186 case 'ORDER_SUPPLIER_SUBMIT':
1187 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1189 $object_type =
'order_supplier';
1190 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1191 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
1192 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1194 case 'ORDER_SUPPLIER_REFUSE':
1195 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1197 $object_type =
'order_supplier';
1198 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1199 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
1200 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1202 case 'SHIPPING_MODIFY':
1203 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1204 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1206 $object_type =
'order_supplier';
1207 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionModified", $link, $context_info);
1209 case 'SHIPPING_VALIDATE':
1210 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1212 $object_type =
'order_supplier';
1213 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
1215 case 'EXPENSE_REPORT_VALIDATE':
1216 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1217 $dir_output =
$conf->expensereport->dir_output;
1218 $object_type =
'expensereport';
1219 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
1221 case 'EXPENSE_REPORT_APPROVE':
1222 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1223 $dir_output =
$conf->expensereport->dir_output;
1224 $object_type =
'expensereport';
1225 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
1227 case 'HOLIDAY_VALIDATE':
1228 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1229 $dir_output =
$conf->holiday->dir_output;
1230 $object_type =
'holiday';
1231 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
1233 case 'HOLIDAY_APPROVE':
1234 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1235 $dir_output =
$conf->holiday->dir_output;
1236 $object_type =
'holiday';
1237 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
1239 case 'ACTION_CREATE':
1240 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1241 $dir_output =
$conf->agenda->dir_output;
1242 $object_type =
'action';
1243 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
1245 case 'CONTRACT_MODIFY':
1246 $link =
'<a href="'.$urlwithroot.
'/contrat/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1247 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1248 $dir_output =
$conf->contract->multidir_output;
1249 $object_type =
'contrat';
1250 $mesg = $langs->transnoentitiesnoconv(
"EMailTextContractModified", $link, $context_info);
1253 $object_type =
$object->element;
1255 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
1259 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
1264 $filepdf = $pdf_path;
1265 $filename_list[] = $pdf_path;
1266 $mimetype_list[] = mime_content_type($filepdf);
1267 $mimefilename_list[] = $ref.
".pdf";
1271 $outputlangs = $langs;
1276 $emailTemplate =
null;
1277 if (!empty($mailTemplateLabel)) {
1278 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1279 $formmail =
new FormMail($this->db);
1280 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $mailTemplateLabel);
1282 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
1283 if (property_exists(
$object,
'thirdparty') &&
$object->thirdparty instanceof
Societe &&
$object->thirdparty->default_lang &&
$object->thirdparty->default_lang != $langs->defaultlang) {
1285 $outputlangs->setDefaultLang(
$object->thirdparty->default_lang);
1286 $outputlangs->loadLangs(array(
'main',
'other'));
1290 $subject =
make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs);
1291 $message =
make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs);
1294 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
1298 $message = nl2br($message);
1302 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
1304 if ($user->fk_user > 0) {
1305 $supervisoruser =
new User($this->db);
1306 $supervisoruser->fetch($user->fk_user);
1307 if ($supervisoruser->email) {
1308 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1311 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1312 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1313 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1314 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1315 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1319 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'subject' => &$subject,
'message' => &$message);
1320 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1321 if (empty($reshook)) {
1322 if (!empty($hookmanager->resArray[
'files'])) {
1323 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1324 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1325 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1327 if (!empty($hookmanager->resArray[
'subject'])) {
1328 $subject .= $hookmanager->resArray[
'subject'];
1330 if (!empty($hookmanager->resArray[
'message'])) {
1331 $message .= $hookmanager->resArray[
'message'];
1353 if ($mailfile->sendfile()) {
1354 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1355 $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).
"')";
1356 if (!$this->db->query($sql)) {
1361 $this->errors[] = $mailfile->error;