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;
688 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
689 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
690 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
691 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
692 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
693 $sql .=
" ".$this->db->prefix().
"societe as s";
694 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
695 $sql .=
" AND n.fk_soc = s.rowid";
696 $sql .=
" AND c.statut = 1";
697 if (is_numeric($notifcode)) {
698 $sql .=
" AND n.fk_action = ".((int) $notifcode);
700 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
702 $sql .=
" AND s.rowid = ".((int)
$object->socid);
708 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
709 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
710 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
711 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
712 $sql .=
" ".$this->db->prefix().
"notify_def as n";
713 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
714 $sql .=
" AND c.statut = 1";
715 if (is_numeric($notifcode)) {
716 $sql .=
" AND n.fk_action = ".((int) $notifcode);
718 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
726 $result = $this->db->query($sql);
728 $num = $this->db->num_rows($result);
731 $projtitle =
'('.$object->project->title.
')';
736 while ($i < $num && !$error) {
737 $obj = $this->db->fetch_object($result);
740 $notifcodedefid = $obj->adid;
742 if ($obj->type_target ==
'tocontactid') {
743 $trackid =
'ctc'.$obj->cid;
745 if ($obj->type_target ==
'touserid') {
746 $trackid =
'use'.$obj->cid;
751 $outputlangs = $langs;
752 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
754 $outputlangs->setDefaultLang($obj->default_lang);
755 $outputlangs->loadLangs(array(
"main",
"other"));
758 $appli = $mysoc->name;
760 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
762 switch ($notifcode) {
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(
"EMailTextInvoiceCanceled", $link);
769 case 'BILL_VALIDATE':
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(
"EMailTextInvoiceValidated", $link);
776 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
778 $object_type =
'facture';
779 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
782 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
784 $object_type =
'order';
785 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderCanceled", $link);
787 case 'ORDER_VALIDATE':
788 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
790 $object_type =
'order';
791 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
794 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
796 $object_type =
'order';
798 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
800 case 'PROPAL_VALIDATE':
801 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
803 $object_type =
'propal';
804 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
806 case 'PROPAL_CLOSE_REFUSED':
807 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
809 $object_type =
'propal';
811 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
812 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
813 $mesg .=
' - From online page';
816 case 'PROPAL_CLOSE_SIGNED':
817 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
819 $object_type =
'propal';
820 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
821 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
822 $mesg .=
' - From online page';
825 case 'FICHINTER_ADD_CONTACT':
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(
"EMailTextInterventionAddedContact", $link);
831 case 'FICHINTER_VALIDATE':
832 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
833 $dir_output =
$conf->ficheinter->dir_output;
834 $object_type =
'ficheinter';
835 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
837 case 'FICHINTER_MODIFY':
838 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
839 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
840 $dir_output =
$conf->ficheinter->dir_output;
841 $object_type =
'ficheinter';
842 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
844 case 'FICHINTER_CLOSE':
845 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
846 $dir_output =
$conf->ficheinter->dir_output;
847 $object_type =
'ficheinter';
848 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
850 case 'ORDER_SUPPLIER_VALIDATE':
851 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
853 $object_type =
'order_supplier';
854 $labeltouse = isset(
$conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ?
$conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
855 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
856 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs));
857 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
859 case 'ORDER_SUPPLIER_CANCEL':
860 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
862 $object_type =
'order_supplier';
863 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
864 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($outputlangs));
865 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
867 case 'ORDER_SUPPLIER_APPROVE':
868 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
870 $object_type =
'order_supplier';
871 $labeltouse = isset(
$conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ?
$conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
872 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
873 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs));
874 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
876 case 'ORDER_SUPPLIER_SUBMIT':
877 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
879 $object_type =
'order_supplier';
880 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
881 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs));
882 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
884 case 'ORDER_SUPPLIER_REFUSE':
885 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
887 $object_type =
'order_supplier';
888 $labeltouse = isset(
$conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ?
$conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
889 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
890 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs));
891 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
893 case 'SHIPPING_MODIFY':
894 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
895 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
897 $object_type =
'shipping';
898 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionModified", $link, $context_info);
900 case 'SHIPPING_VALIDATE':
901 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
903 $object_type =
'shipping';
904 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
906 case 'EXPENSE_REPORT_VALIDATE':
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(
"EMailTextExpenseReportValidated", $link);
912 case 'EXPENSE_REPORT_APPROVE':
913 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
914 $dir_output =
$conf->expensereport->dir_output;
915 $object_type =
'expensereport';
916 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
918 case 'HOLIDAY_VALIDATE':
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(
"EMailTextHolidayValidated", $link);
924 case 'HOLIDAY_APPROVE':
925 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
926 $dir_output =
$conf->holiday->dir_output;
927 $object_type =
'holiday';
928 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
930 case 'ACTION_CREATE':
931 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
932 $dir_output =
$conf->agenda->dir_output;
933 $object_type =
'action';
934 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
936 case 'CONTRACT_MODIFY':
937 $link =
'<a href="'.$urlwithroot.
'/contrat/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
938 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
939 $dir_output =
$conf->contract->multidir_output;
940 $object_type =
'contract';
941 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextContractModified", $link, $context_info);
944 $object_type =
$object->element;
946 $template = $notifcode.
'_TEMPLATE';
947 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
951 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
952 $formmail =
new FormMail($this->db);
953 $arraydefaultmessage =
null;
955 $template = $notifcode.
'_TEMPLATE';
957 if (!empty($labeltouse)) {
958 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
960 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
961 if (method_exists(
$object,
'fetch_thirdparty') && empty(
$object->thirdparty)) {
967 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
968 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
970 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
971 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
977 $pdf_path = $dir_output.
"/".$ref.
".pdf";
978 if (!
dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
982 $filepdf = $pdf_path;
983 $filename_list[] = $filepdf;
984 $mimetype_list[] = mime_content_type($filepdf);
985 $mimefilename_list[] = $ref.
".pdf";
988 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
991 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
993 if ($user->fk_user > 0) {
994 $supervisoruser =
new User($this->db);
995 $supervisoruser->fetch($user->fk_user);
996 if ($supervisoruser->email) {
997 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1000 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1001 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1002 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1003 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1004 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1007 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'outputlangs' => $outputlangs,
'labeltouse' => $labeltouse);
1008 if (!isset($action)) {
1012 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1013 if (empty($reshook)) {
1014 if (!empty($hookmanager->resArray[
'files'])) {
1015 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1016 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1017 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1019 if (!empty($hookmanager->resArray[
'subject'])) {
1020 $subject .= $hookmanager->resArray[
'subject'];
1022 if (!empty($hookmanager->resArray[
'message'])) {
1023 $message .= $hookmanager->resArray[
'message'];
1046 if (! empty($mailfile->error) || ! empty($mailfile->errors)) {
1047 $this->error = $mailfile->error;
1048 $this->errors = $mailfile->errors;
1052 if ($mailfile->sendfile()) {
1053 if ($obj->type_target ==
'touserid') {
1054 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, 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 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
1058 $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).
"')";
1060 if (!$this->db->query($sql)) {
1065 $this->errors[] = $mailfile->error;
1068 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
1073 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty(
$object->socid) ?
'' :
$object->socid));
1077 $this->errors[] = $this->db->lasterror();
1078 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
1085 foreach (
$conf->global as $key => $val) {
1087 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
1093 $threshold = (float) $reg[1];
1094 if (!empty(
$object->total_ht) &&
$object->total_ht <= $threshold) {
1095 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".
$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
1099 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
1100 if ($notifcodedefid <= 0) {
1109 $appli = $mysoc->name;
1111 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
1113 switch ($notifcode) {
1114 case 'BILL_VALIDATE':
1115 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1117 $object_type =
'facture';
1118 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
1121 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1123 $object_type =
'facture';
1124 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
1126 case 'ORDER_VALIDATE':
1127 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1129 $object_type =
'order';
1130 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
1133 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1135 $object_type =
'order';
1136 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
1138 case 'PROPAL_VALIDATE':
1139 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1141 $object_type =
'propal';
1142 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
1144 case 'PROPAL_CLOSE_SIGNED':
1145 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1147 $object_type =
'propal';
1148 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
1150 case 'FICHINTER_ADD_CONTACT':
1151 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1152 $dir_output =
$conf->ficheinter->dir_output;
1153 $object_type =
'ficheinter';
1154 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
1156 case 'FICHINTER_VALIDATE':
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(
"EMailTextInterventionValidated", $link);
1162 case 'FICHINTER_MODIFY':
1163 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1164 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1165 $dir_output =
$conf->ficheinter->dir_output;
1166 $object_type =
'ficheinter';
1167 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
1169 case 'FICHINTER_CLOSE':
1170 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1171 $dir_output =
$conf->facture->dir_output;
1172 $object_type =
'ficheinter';
1173 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
1175 case 'ORDER_SUPPLIER_CANCEL':
1176 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1178 $object_type =
'order_supplier';
1179 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1180 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs));
1181 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1183 case 'ORDER_SUPPLIER_VALIDATE':
1184 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1186 $object_type =
'order_supplier';
1187 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1188 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
1189 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1191 case 'ORDER_SUPPLIER_APPROVE':
1192 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1194 $object_type =
'order_supplier';
1195 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1196 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
1197 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1199 case 'ORDER_SUPPLIER_SUBMIT':
1200 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1202 $object_type =
'order_supplier';
1203 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1204 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
1205 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1207 case 'ORDER_SUPPLIER_REFUSE':
1208 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1210 $object_type =
'order_supplier';
1211 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1212 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
1213 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1215 case 'SHIPPING_MODIFY':
1216 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1217 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1219 $object_type =
'order_supplier';
1220 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionModified", $link, $context_info);
1222 case 'SHIPPING_VALIDATE':
1223 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1225 $object_type =
'order_supplier';
1226 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
1228 case 'EXPENSE_REPORT_VALIDATE':
1229 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1230 $dir_output =
$conf->expensereport->dir_output;
1231 $object_type =
'expensereport';
1232 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
1234 case 'EXPENSE_REPORT_APPROVE':
1235 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1236 $dir_output =
$conf->expensereport->dir_output;
1237 $object_type =
'expensereport';
1238 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
1240 case 'HOLIDAY_VALIDATE':
1241 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1242 $dir_output =
$conf->holiday->dir_output;
1243 $object_type =
'holiday';
1244 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
1246 case 'HOLIDAY_APPROVE':
1247 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1248 $dir_output =
$conf->holiday->dir_output;
1249 $object_type =
'holiday';
1250 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
1252 case 'ACTION_CREATE':
1253 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1254 $dir_output =
$conf->agenda->dir_output;
1255 $object_type =
'action';
1256 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
1258 case 'CONTRACT_MODIFY':
1259 $link =
'<a href="'.$urlwithroot.
'/contrat/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1260 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1261 $dir_output =
$conf->contract->multidir_output;
1262 $object_type =
'contrat';
1263 $mesg = $langs->transnoentitiesnoconv(
"EMailTextContractModified", $link, $context_info);
1266 $object_type =
$object->element;
1268 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
1272 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
1277 $filepdf = $pdf_path;
1278 $filename_list[] = $pdf_path;
1279 $mimetype_list[] = mime_content_type($filepdf);
1280 $mimefilename_list[] = $ref.
".pdf";
1284 $outputlangs = $langs;
1289 $emailTemplate =
null;
1290 if (!empty($mailTemplateLabel)) {
1291 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1292 $formmail =
new FormMail($this->db);
1293 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $mailTemplateLabel);
1295 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
1296 if (property_exists(
$object,
'thirdparty')) {
1301 if (
$object->thirdparty instanceof
Societe &&
$object->thirdparty->default_lang &&
$object->thirdparty->default_lang != $langs->defaultlang) {
1303 $outputlangs->setDefaultLang(
$object->thirdparty->default_lang);
1304 $outputlangs->loadLangs(array(
'main',
'other'));
1310 $subject =
make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs);
1311 $message =
make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs);
1314 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
1318 $message = nl2br($message);
1322 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
1324 if ($user->fk_user > 0) {
1325 $supervisoruser =
new User($this->db);
1326 $supervisoruser->fetch($user->fk_user);
1327 if ($supervisoruser->email) {
1328 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1331 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1332 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1333 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1334 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1335 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1339 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'subject' => &$subject,
'message' => &$message);
1340 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1341 if (empty($reshook)) {
1342 if (!empty($hookmanager->resArray[
'files'])) {
1343 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1344 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1345 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1347 if (!empty($hookmanager->resArray[
'subject'])) {
1348 $subject .= $hookmanager->resArray[
'subject'];
1350 if (!empty($hookmanager->resArray[
'message'])) {
1351 $message .= $hookmanager->resArray[
'message'];
1373 if (! empty($mailfile->error) || ! empty($mailfile->errors)) {
1374 $this->error = $mailfile->error;
1375 $this->errors = $mailfile->errors;
1379 if ($mailfile->sendfile()) {
1380 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1381 $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).
"')";
1382 if (!$this->db->query($sql)) {
1387 $this->errors[] = $mailfile->error;