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 = constant(
'DOL_APPLICATION_TITLE');
667 if ($applicationcustom) {
668 $application = (preg_match(
'/^\+/', $applicationcustom) ? $application :
'').$applicationcustom;
685 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
686 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
687 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
688 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
689 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
690 $sql .=
" ".$this->db->prefix().
"societe as s";
691 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
692 $sql .=
" AND n.fk_soc = s.rowid";
693 $sql .=
" AND c.statut = 1";
694 if (is_numeric($notifcode)) {
695 $sql .=
" AND n.fk_action = ".((int) $notifcode);
697 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
699 $sql .=
" AND s.rowid = ".((int)
$object->socid);
705 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
706 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
707 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
708 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
709 $sql .=
" ".$this->db->prefix().
"notify_def as n";
710 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
711 $sql .=
" AND c.statut = 1";
712 if (is_numeric($notifcode)) {
713 $sql .=
" AND n.fk_action = ".((int) $notifcode);
715 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
723 $result = $this->db->query($sql);
725 $num = $this->db->num_rows($result);
728 $projtitle =
'('.$object->project->title.
')';
733 while ($i < $num && !$error) {
734 $obj = $this->db->fetch_object($result);
737 $notifcodedefid = $obj->adid;
739 if ($obj->type_target ==
'tocontactid') {
740 $trackid =
'ctc'.$obj->cid;
742 if ($obj->type_target ==
'touserid') {
743 $trackid =
'use'.$obj->cid;
748 $outputlangs = $langs;
749 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
751 $outputlangs->setDefaultLang($obj->default_lang);
752 $outputlangs->loadLangs(array(
"main",
"other"));
755 $appli = $mysoc->name;
757 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
759 switch ($notifcode) {
761 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
763 $object_type =
'facture';
764 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceCanceled", $link);
766 case 'BILL_VALIDATE':
767 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
769 $object_type =
'facture';
770 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
773 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
775 $object_type =
'facture';
776 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
779 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
781 $object_type =
'order';
782 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderCanceled", $link);
784 case 'ORDER_VALIDATE':
785 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
787 $object_type =
'order';
788 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
791 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
793 $object_type =
'order';
795 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
797 case 'PROPAL_VALIDATE':
798 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
800 $object_type =
'propal';
801 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
803 case 'PROPAL_CLOSE_REFUSED':
804 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
806 $object_type =
'propal';
808 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
809 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
810 $mesg .=
' - From online page';
813 case 'PROPAL_CLOSE_SIGNED':
814 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
816 $object_type =
'propal';
817 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
818 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
819 $mesg .=
' - From online page';
822 case 'FICHINTER_ADD_CONTACT':
823 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
824 $dir_output =
$conf->ficheinter->dir_output;
825 $object_type =
'ficheinter';
826 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
828 case 'FICHINTER_VALIDATE':
829 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
830 $dir_output =
$conf->ficheinter->dir_output;
831 $object_type =
'ficheinter';
832 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
834 case 'FICHINTER_MODIFY':
835 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
836 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
837 $dir_output =
$conf->ficheinter->dir_output;
838 $object_type =
'ficheinter';
839 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
841 case 'FICHINTER_CLOSE':
842 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
843 $dir_output =
$conf->ficheinter->dir_output;
844 $object_type =
'ficheinter';
845 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
847 case 'ORDER_SUPPLIER_VALIDATE':
848 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
850 $object_type =
'order_supplier';
851 $labeltouse = isset(
$conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ?
$conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
852 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
853 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs));
854 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
856 case 'ORDER_SUPPLIER_CANCEL':
857 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
859 $object_type =
'order_supplier';
860 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
861 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($outputlangs));
862 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
864 case 'ORDER_SUPPLIER_APPROVE':
865 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
867 $object_type =
'order_supplier';
868 $labeltouse = isset(
$conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ?
$conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
869 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
870 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs));
871 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
873 case 'ORDER_SUPPLIER_SUBMIT':
874 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
876 $object_type =
'order_supplier';
877 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
878 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs));
879 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
881 case 'ORDER_SUPPLIER_REFUSE':
882 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
884 $object_type =
'order_supplier';
885 $labeltouse = isset(
$conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ?
$conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
886 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
887 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs));
888 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
890 case 'SHIPPING_MODIFY':
891 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
892 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
894 $object_type =
'shipping';
895 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionModified", $link, $context_info);
897 case 'SHIPPING_VALIDATE':
898 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
900 $object_type =
'shipping';
901 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
903 case 'EXPENSE_REPORT_VALIDATE':
904 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
905 $dir_output =
$conf->expensereport->dir_output;
906 $object_type =
'expensereport';
907 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
909 case 'EXPENSE_REPORT_APPROVE':
910 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
911 $dir_output =
$conf->expensereport->dir_output;
912 $object_type =
'expensereport';
913 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
915 case 'HOLIDAY_VALIDATE':
916 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
917 $dir_output =
$conf->holiday->dir_output;
918 $object_type =
'holiday';
919 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
921 case 'HOLIDAY_APPROVE':
922 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
923 $dir_output =
$conf->holiday->dir_output;
924 $object_type =
'holiday';
925 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
927 case 'ACTION_CREATE':
928 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
929 $dir_output =
$conf->agenda->dir_output;
930 $object_type =
'action';
931 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
933 case 'CONTRACT_MODIFY':
934 $link =
'<a href="'.$urlwithroot.
'/contrat/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
935 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
936 $dir_output =
$conf->contract->multidir_output;
937 $object_type =
'contract';
938 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextContractModified", $link, $context_info);
941 $object_type =
$object->element;
943 $template = $notifcode.
'_TEMPLATE';
944 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
948 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
949 $formmail =
new FormMail($this->db);
950 $arraydefaultmessage =
null;
952 $template = $notifcode.
'_TEMPLATE';
954 if (!empty($labeltouse)) {
955 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
957 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
958 if (method_exists(
$object,
'fetch_thirdparty') && empty(
$object->thirdparty)) {
964 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
965 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
967 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
968 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
974 $pdf_path = $dir_output.
"/".$ref.
".pdf";
975 if (!
dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
979 $filepdf = $pdf_path;
980 $filename_list[] = $filepdf;
981 $mimetype_list[] = mime_content_type($filepdf);
982 $mimefilename_list[] = $ref.
".pdf";
985 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
988 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
990 if ($user->fk_user > 0) {
991 $supervisoruser =
new User($this->db);
992 $supervisoruser->fetch($user->fk_user);
993 if ($supervisoruser->email) {
994 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
997 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
998 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
999 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1000 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1001 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1004 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'outputlangs' => $outputlangs,
'labeltouse' => $labeltouse);
1005 if (!isset($action)) {
1009 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1010 if (empty($reshook)) {
1011 if (!empty($hookmanager->resArray[
'files'])) {
1012 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1013 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1014 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1016 if (!empty($hookmanager->resArray[
'subject'])) {
1017 $subject .= $hookmanager->resArray[
'subject'];
1019 if (!empty($hookmanager->resArray[
'message'])) {
1020 $message .= $hookmanager->resArray[
'message'];
1043 if (! empty($mailfile->error) || ! empty($mailfile->errors)) {
1044 $this->error = $mailfile->error;
1045 $this->errors = $mailfile->errors;
1049 if ($mailfile->sendfile()) {
1050 if ($obj->type_target ==
'touserid') {
1051 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
1052 $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).
"')";
1054 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
1055 $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).
"')";
1057 if (!$this->db->query($sql)) {
1062 $this->errors[] = $mailfile->error;
1065 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
1070 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty(
$object->socid) ?
'' :
$object->socid));
1074 $this->errors[] = $this->db->lasterror();
1075 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
1082 foreach (
$conf->global as $key => $val) {
1084 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
1090 $threshold = (float) $reg[1];
1091 if (!empty(
$object->total_ht) &&
$object->total_ht <= $threshold) {
1092 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".
$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
1096 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
1097 if ($notifcodedefid <= 0) {
1106 $appli = $mysoc->name;
1108 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
1110 switch ($notifcode) {
1111 case 'BILL_VALIDATE':
1112 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1114 $object_type =
'facture';
1115 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
1118 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1120 $object_type =
'facture';
1121 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
1123 case 'ORDER_VALIDATE':
1124 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1126 $object_type =
'order';
1127 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
1130 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1132 $object_type =
'order';
1133 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
1135 case 'PROPAL_VALIDATE':
1136 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1138 $object_type =
'propal';
1139 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
1141 case 'PROPAL_CLOSE_SIGNED':
1142 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1144 $object_type =
'propal';
1145 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
1147 case 'FICHINTER_ADD_CONTACT':
1148 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1149 $dir_output =
$conf->ficheinter->dir_output;
1150 $object_type =
'ficheinter';
1151 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
1153 case 'FICHINTER_VALIDATE':
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(
"EMailTextInterventionValidated", $link);
1159 case 'FICHINTER_MODIFY':
1160 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1161 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1162 $dir_output =
$conf->ficheinter->dir_output;
1163 $object_type =
'ficheinter';
1164 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
1166 case 'FICHINTER_CLOSE':
1167 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1168 $dir_output =
$conf->facture->dir_output;
1169 $object_type =
'ficheinter';
1170 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
1172 case 'ORDER_SUPPLIER_CANCEL':
1173 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1175 $object_type =
'order_supplier';
1176 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1177 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs));
1178 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1180 case 'ORDER_SUPPLIER_VALIDATE':
1181 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1183 $object_type =
'order_supplier';
1184 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1185 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
1186 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1188 case 'ORDER_SUPPLIER_APPROVE':
1189 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1191 $object_type =
'order_supplier';
1192 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1193 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
1194 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1196 case 'ORDER_SUPPLIER_SUBMIT':
1197 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1199 $object_type =
'order_supplier';
1200 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1201 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
1202 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1204 case 'ORDER_SUPPLIER_REFUSE':
1205 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1207 $object_type =
'order_supplier';
1208 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1209 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
1210 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1212 case 'SHIPPING_MODIFY':
1213 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1214 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1216 $object_type =
'order_supplier';
1217 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionModified", $link, $context_info);
1219 case 'SHIPPING_VALIDATE':
1220 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1222 $object_type =
'order_supplier';
1223 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
1225 case 'EXPENSE_REPORT_VALIDATE':
1226 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1227 $dir_output =
$conf->expensereport->dir_output;
1228 $object_type =
'expensereport';
1229 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
1231 case 'EXPENSE_REPORT_APPROVE':
1232 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1233 $dir_output =
$conf->expensereport->dir_output;
1234 $object_type =
'expensereport';
1235 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
1237 case 'HOLIDAY_VALIDATE':
1238 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1239 $dir_output =
$conf->holiday->dir_output;
1240 $object_type =
'holiday';
1241 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
1243 case 'HOLIDAY_APPROVE':
1244 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1245 $dir_output =
$conf->holiday->dir_output;
1246 $object_type =
'holiday';
1247 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
1249 case 'ACTION_CREATE':
1250 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1251 $dir_output =
$conf->agenda->dir_output;
1252 $object_type =
'action';
1253 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
1255 case 'CONTRACT_MODIFY':
1256 $link =
'<a href="'.$urlwithroot.
'/contrat/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1257 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1258 $dir_output =
$conf->contract->multidir_output;
1259 $object_type =
'contrat';
1260 $mesg = $langs->transnoentitiesnoconv(
"EMailTextContractModified", $link, $context_info);
1263 $object_type =
$object->element;
1265 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
1269 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
1274 $filepdf = $pdf_path;
1275 $filename_list[] = $pdf_path;
1276 $mimetype_list[] = mime_content_type($filepdf);
1277 $mimefilename_list[] = $ref.
".pdf";
1281 $outputlangs = $langs;
1286 $emailTemplate =
null;
1287 if (!empty($mailTemplateLabel)) {
1288 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1289 $formmail =
new FormMail($this->db);
1290 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $mailTemplateLabel);
1292 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
1293 if (property_exists(
$object,
'thirdparty')) {
1298 if (
$object->thirdparty instanceof
Societe &&
$object->thirdparty->default_lang &&
$object->thirdparty->default_lang != $langs->defaultlang) {
1300 $outputlangs->setDefaultLang(
$object->thirdparty->default_lang);
1301 $outputlangs->loadLangs(array(
'main',
'other'));
1307 $subject =
make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs);
1308 $message =
make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs);
1311 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
1315 $message = nl2br($message);
1319 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
1321 if ($user->fk_user > 0) {
1322 $supervisoruser =
new User($this->db);
1323 $supervisoruser->fetch($user->fk_user);
1324 if ($supervisoruser->email) {
1325 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1328 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1329 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1330 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1331 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1332 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1336 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'subject' => &$subject,
'message' => &$message);
1337 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1338 if (empty($reshook)) {
1339 if (!empty($hookmanager->resArray[
'files'])) {
1340 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1341 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1342 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1344 if (!empty($hookmanager->resArray[
'subject'])) {
1345 $subject .= $hookmanager->resArray[
'subject'];
1347 if (!empty($hookmanager->resArray[
'message'])) {
1348 $message .= $hookmanager->resArray[
'message'];
1370 if (! empty($mailfile->error) || ! empty($mailfile->errors)) {
1371 $this->error = $mailfile->error;
1372 $this->errors = $mailfile->errors;
1376 if ($mailfile->sendfile()) {
1377 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1378 $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).
"')";
1379 if (!$this->db->query($sql)) {
1384 $this->errors[] = $mailfile->error;