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;
684 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
685 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
686 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
687 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
688 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
689 $sql .=
" ".$this->db->prefix().
"societe as s";
690 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
691 $sql .=
" AND n.fk_soc = s.rowid";
692 $sql .=
" AND c.statut = 1";
693 if (is_numeric($notifcode)) {
694 $sql .=
" AND n.fk_action = ".((int) $notifcode);
696 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
698 $sql .=
" AND s.rowid = ".((int)
$object->socid);
704 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
705 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
706 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
707 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
708 $sql .=
" ".$this->db->prefix().
"notify_def as n";
709 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
710 $sql .=
" AND c.statut = 1";
711 if (is_numeric($notifcode)) {
712 $sql .=
" AND n.fk_action = ".((int) $notifcode);
714 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
722 $result = $this->db->query($sql);
724 $num = $this->db->num_rows($result);
727 $projtitle =
'('.$object->project->title.
')';
732 while ($i < $num && !$error) {
733 $obj = $this->db->fetch_object($result);
736 $notifcodedefid = $obj->adid;
738 if ($obj->type_target ==
'tocontactid') {
739 $trackid =
'ctc'.$obj->cid;
741 if ($obj->type_target ==
'touserid') {
742 $trackid =
'use'.$obj->cid;
747 $outputlangs = $langs;
748 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
750 $outputlangs->setDefaultLang($obj->default_lang);
751 $outputlangs->loadLangs(array(
"main",
"other"));
754 $appli = $mysoc->name;
756 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
758 switch ($notifcode) {
760 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
762 $object_type =
'facture';
763 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceCanceled", $link);
765 case 'BILL_VALIDATE':
766 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
768 $object_type =
'facture';
769 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
772 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
774 $object_type =
'facture';
775 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
778 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
780 $object_type =
'order';
781 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderCanceled", $link);
783 case 'ORDER_VALIDATE':
784 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
786 $object_type =
'order';
787 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
790 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
792 $object_type =
'order';
794 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
796 case 'PROPAL_VALIDATE':
797 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
799 $object_type =
'propal';
800 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
802 case 'PROPAL_CLOSE_REFUSED':
803 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
805 $object_type =
'propal';
807 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
808 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
809 $mesg .=
' - From online page';
812 case 'PROPAL_CLOSE_SIGNED':
813 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
815 $object_type =
'propal';
816 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
817 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
818 $mesg .=
' - From online page';
821 case 'FICHINTER_ADD_CONTACT':
822 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
823 $dir_output =
$conf->ficheinter->dir_output;
824 $object_type =
'ficheinter';
825 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
827 case 'FICHINTER_VALIDATE':
828 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
829 $dir_output =
$conf->ficheinter->dir_output;
830 $object_type =
'ficheinter';
831 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
833 case 'FICHINTER_MODIFY':
834 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
835 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
836 $dir_output =
$conf->ficheinter->dir_output;
837 $object_type =
'ficheinter';
838 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
840 case 'FICHINTER_CLOSE':
841 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
842 $dir_output =
$conf->ficheinter->dir_output;
843 $object_type =
'ficheinter';
844 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
846 case 'ORDER_SUPPLIER_VALIDATE':
847 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
849 $object_type =
'order_supplier';
850 $labeltouse = isset(
$conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ?
$conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
851 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
852 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs));
853 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
855 case 'ORDER_SUPPLIER_CANCEL':
856 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
858 $object_type =
'order_supplier';
859 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
860 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($outputlangs));
861 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
863 case 'ORDER_SUPPLIER_APPROVE':
864 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
866 $object_type =
'order_supplier';
867 $labeltouse = isset(
$conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ?
$conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
868 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
869 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs));
870 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
872 case 'ORDER_SUPPLIER_SUBMIT':
873 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
875 $object_type =
'order_supplier';
876 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
877 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs));
878 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
880 case 'ORDER_SUPPLIER_REFUSE':
881 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
883 $object_type =
'order_supplier';
884 $labeltouse = isset(
$conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ?
$conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
885 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
886 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs));
887 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
889 case 'SHIPPING_MODIFY':
890 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
891 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
893 $object_type =
'shipping';
894 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionModified", $link, $context_info);
896 case 'SHIPPING_VALIDATE':
897 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
899 $object_type =
'shipping';
900 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
902 case 'EXPENSE_REPORT_VALIDATE':
903 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
904 $dir_output =
$conf->expensereport->dir_output;
905 $object_type =
'expensereport';
906 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
908 case 'EXPENSE_REPORT_APPROVE':
909 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
910 $dir_output =
$conf->expensereport->dir_output;
911 $object_type =
'expensereport';
912 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
914 case 'HOLIDAY_VALIDATE':
915 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
916 $dir_output =
$conf->holiday->dir_output;
917 $object_type =
'holiday';
918 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
920 case 'HOLIDAY_APPROVE':
921 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
922 $dir_output =
$conf->holiday->dir_output;
923 $object_type =
'holiday';
924 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
926 case 'ACTION_CREATE':
927 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
928 $dir_output =
$conf->agenda->dir_output;
929 $object_type =
'action';
930 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
932 case 'CONTRACT_MODIFY':
933 $link =
'<a href="'.$urlwithroot.
'/contrat/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
934 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
935 $dir_output =
$conf->contract->multidir_output;
936 $object_type =
'contract';
937 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextContractModified", $link, $context_info);
940 $object_type =
$object->element;
942 $template = $notifcode.
'_TEMPLATE';
943 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
947 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
948 $formmail =
new FormMail($this->db);
949 $arraydefaultmessage =
null;
951 $template = $notifcode.
'_TEMPLATE';
953 if (!empty($labeltouse)) {
954 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
956 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
957 if (method_exists(
$object,
'fetch_thirdparty') && empty(
$object->thirdparty)) {
963 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
964 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
966 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
967 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
973 $pdf_path = $dir_output.
"/".$ref.
".pdf";
974 if (!
dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
978 $filepdf = $pdf_path;
979 $filename_list[] = $filepdf;
980 $mimetype_list[] = mime_content_type($filepdf);
981 $mimefilename_list[] = $ref.
".pdf";
984 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
987 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
989 if ($user->fk_user > 0) {
990 $supervisoruser =
new User($this->db);
991 $supervisoruser->fetch($user->fk_user);
992 if ($supervisoruser->email) {
993 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
996 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
997 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
998 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
999 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1000 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1003 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'outputlangs' => $outputlangs,
'labeltouse' => $labeltouse);
1004 if (!isset($action)) {
1008 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1009 if (empty($reshook)) {
1010 if (!empty($hookmanager->resArray[
'files'])) {
1011 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1012 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1013 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1015 if (!empty($hookmanager->resArray[
'subject'])) {
1016 $subject .= $hookmanager->resArray[
'subject'];
1018 if (!empty($hookmanager->resArray[
'message'])) {
1019 $message .= $hookmanager->resArray[
'message'];
1042 if ($mailfile->sendfile()) {
1043 if ($obj->type_target ==
'touserid') {
1044 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, 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 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
1048 $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).
"')";
1050 if (!$this->db->query($sql)) {
1055 $this->errors[] = $mailfile->error;
1058 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
1063 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty(
$object->socid) ?
'' :
$object->socid));
1067 $this->errors[] = $this->db->lasterror();
1068 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
1075 foreach (
$conf->global as $key => $val) {
1077 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
1083 $threshold = (float) $reg[1];
1084 if (!empty(
$object->total_ht) &&
$object->total_ht <= $threshold) {
1085 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".
$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
1089 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
1090 if ($notifcodedefid <= 0) {
1099 $appli = $mysoc->name;
1101 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
1103 switch ($notifcode) {
1104 case 'BILL_VALIDATE':
1105 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1107 $object_type =
'facture';
1108 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
1111 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1113 $object_type =
'facture';
1114 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
1116 case 'ORDER_VALIDATE':
1117 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1119 $object_type =
'order';
1120 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
1123 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1125 $object_type =
'order';
1126 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
1128 case 'PROPAL_VALIDATE':
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(
"EMailTextProposalValidated", $link);
1134 case 'PROPAL_CLOSE_SIGNED':
1135 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1137 $object_type =
'propal';
1138 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
1140 case 'FICHINTER_ADD_CONTACT':
1141 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1142 $dir_output =
$conf->ficheinter->dir_output;
1143 $object_type =
'ficheinter';
1144 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
1146 case 'FICHINTER_VALIDATE':
1147 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1148 $dir_output =
$conf->facture->dir_output;
1149 $object_type =
'ficheinter';
1150 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
1152 case 'FICHINTER_MODIFY':
1153 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1154 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1155 $dir_output =
$conf->ficheinter->dir_output;
1156 $object_type =
'ficheinter';
1157 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
1159 case 'FICHINTER_CLOSE':
1160 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1161 $dir_output =
$conf->facture->dir_output;
1162 $object_type =
'ficheinter';
1163 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
1165 case 'ORDER_SUPPLIER_CANCEL':
1166 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1168 $object_type =
'order_supplier';
1169 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1170 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs));
1171 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1173 case 'ORDER_SUPPLIER_VALIDATE':
1174 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1176 $object_type =
'order_supplier';
1177 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1178 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
1179 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1181 case 'ORDER_SUPPLIER_APPROVE':
1182 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1184 $object_type =
'order_supplier';
1185 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1186 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
1187 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1189 case 'ORDER_SUPPLIER_SUBMIT':
1190 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1192 $object_type =
'order_supplier';
1193 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1194 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
1195 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1197 case 'ORDER_SUPPLIER_REFUSE':
1198 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1200 $object_type =
'order_supplier';
1201 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1202 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
1203 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1205 case 'SHIPPING_MODIFY':
1206 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1207 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1209 $object_type =
'order_supplier';
1210 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionModified", $link, $context_info);
1212 case 'SHIPPING_VALIDATE':
1213 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1215 $object_type =
'order_supplier';
1216 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
1218 case 'EXPENSE_REPORT_VALIDATE':
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(
"EMailTextExpenseReportValidated", $link);
1224 case 'EXPENSE_REPORT_APPROVE':
1225 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1226 $dir_output =
$conf->expensereport->dir_output;
1227 $object_type =
'expensereport';
1228 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
1230 case 'HOLIDAY_VALIDATE':
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(
"EMailTextHolidayValidated", $link);
1236 case 'HOLIDAY_APPROVE':
1237 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1238 $dir_output =
$conf->holiday->dir_output;
1239 $object_type =
'holiday';
1240 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
1242 case 'ACTION_CREATE':
1243 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1244 $dir_output =
$conf->agenda->dir_output;
1245 $object_type =
'action';
1246 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
1248 case 'CONTRACT_MODIFY':
1249 $link =
'<a href="'.$urlwithroot.
'/contrat/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1250 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1251 $dir_output =
$conf->contract->multidir_output;
1252 $object_type =
'contrat';
1253 $mesg = $langs->transnoentitiesnoconv(
"EMailTextContractModified", $link, $context_info);
1256 $object_type =
$object->element;
1258 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
1262 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
1267 $filepdf = $pdf_path;
1268 $filename_list[] = $pdf_path;
1269 $mimetype_list[] = mime_content_type($filepdf);
1270 $mimefilename_list[] = $ref.
".pdf";
1274 $outputlangs = $langs;
1279 $emailTemplate =
null;
1280 if (!empty($mailTemplateLabel)) {
1281 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1282 $formmail =
new FormMail($this->db);
1283 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $mailTemplateLabel);
1285 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
1286 if (property_exists(
$object,
'thirdparty')) {
1291 if (
$object->thirdparty instanceof
Societe &&
$object->thirdparty->default_lang &&
$object->thirdparty->default_lang != $langs->defaultlang) {
1293 $outputlangs->setDefaultLang(
$object->thirdparty->default_lang);
1294 $outputlangs->loadLangs(array(
'main',
'other'));
1300 $subject =
make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs);
1301 $message =
make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs);
1304 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
1308 $message = nl2br($message);
1312 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
1314 if ($user->fk_user > 0) {
1315 $supervisoruser =
new User($this->db);
1316 $supervisoruser->fetch($user->fk_user);
1317 if ($supervisoruser->email) {
1318 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1321 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1322 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1323 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1324 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1325 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1329 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'subject' => &$subject,
'message' => &$message);
1330 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1331 if (empty($reshook)) {
1332 if (!empty($hookmanager->resArray[
'files'])) {
1333 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1334 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1335 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1337 if (!empty($hookmanager->resArray[
'subject'])) {
1338 $subject .= $hookmanager->resArray[
'subject'];
1340 if (!empty($hookmanager->resArray[
'message'])) {
1341 $message .= $hookmanager->resArray[
'message'];
1363 if ($mailfile->sendfile()) {
1364 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1365 $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).
"')";
1366 if (!$this->db->query($sql)) {
1371 $this->errors[] = $mailfile->error;