609 public function send($notifcode,
$object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
611 global $user, $conf, $langs, $mysoc;
613 global $dolibarr_main_url_root;
617 if (!is_object($hookmanager)) {
618 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
621 $hookmanager->initHooks(array(
'notification'));
623 $parameters = array(
'notifcode' => $notifcode);
624 $reshook = $hookmanager->executeHooks(
'notifsupported', $parameters,
$object, $action);
625 if (empty($reshook)) {
626 if (!empty($hookmanager->resArray[
'arrayofnotifsupported'])) {
627 Notify::$arrayofnotifsupported = array_merge(Notify::$arrayofnotifsupported, $hookmanager->resArray[
'arrayofnotifsupported']);
632 if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
636 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
638 dol_syslog(get_class($this).
"::send notifcode=".$notifcode.
", object id=".
$object->id);
640 $langs->load(
"other");
643 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
644 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
648 $application =
'Dolibarr';
665 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
666 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
667 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
668 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
669 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
670 $sql .=
" ".$this->db->prefix().
"societe as s";
671 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
672 $sql .=
" AND n.fk_soc = s.rowid";
673 $sql .=
" AND c.statut = 1";
674 if (is_numeric($notifcode)) {
675 $sql .=
" AND n.fk_action = ".((int) $notifcode);
677 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
679 $sql .=
" AND s.rowid = ".((int)
$object->socid);
685 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as 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().
"user as c,";
688 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
689 $sql .=
" ".$this->db->prefix().
"notify_def as n";
690 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
691 $sql .=
" AND c.statut = 1";
692 if (is_numeric($notifcode)) {
693 $sql .=
" AND n.fk_action = ".((int) $notifcode);
695 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
703 $result = $this->db->query($sql);
705 $num = $this->db->num_rows($result);
707 if (is_object(
$object->project) ||
$object->fetch_project() > 0) {
708 $projtitle =
'('.$object->project->title.
')';
713 while ($i < $num && !$error) {
714 $obj = $this->db->fetch_object($result);
717 $notifcodedefid = $obj->adid;
719 if ($obj->type_target ==
'tocontactid') {
720 $trackid =
'ctc'.$obj->cid;
722 if ($obj->type_target ==
'touserid') {
723 $trackid =
'use'.$obj->cid;
728 $outputlangs = $langs;
729 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
731 $outputlangs->setDefaultLang($obj->default_lang);
732 $outputlangs->loadLangs(array(
"main",
"other"));
735 $appli = $mysoc->name;
737 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
739 switch ($notifcode) {
741 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
742 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
743 $object_type =
'facture';
744 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceCanceled", $link);
746 case 'BILL_VALIDATE':
747 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
748 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
749 $object_type =
'facture';
750 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
753 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
754 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
755 $object_type =
'facture';
756 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
759 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
760 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
761 $object_type =
'order';
762 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderCanceled", $link);
764 case 'ORDER_VALIDATE':
765 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
766 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
767 $object_type =
'order';
768 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
771 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
772 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
773 $object_type =
'order';
775 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
777 case 'PROPAL_VALIDATE':
778 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
780 $object_type =
'propal';
781 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
783 case 'PROPAL_CLOSE_REFUSED':
784 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
786 $object_type =
'propal';
788 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
789 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
790 $mesg .=
' - From online page';
793 case 'PROPAL_CLOSE_SIGNED':
794 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
796 $object_type =
'propal';
797 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
798 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
799 $mesg .=
' - From online page';
802 case 'FICHINTER_ADD_CONTACT':
803 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
804 $dir_output = $conf->ficheinter->dir_output;
805 $object_type =
'ficheinter';
806 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
808 case 'FICHINTER_VALIDATE':
809 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
810 $dir_output = $conf->ficheinter->dir_output;
811 $object_type =
'ficheinter';
812 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
814 case 'FICHINTER_CLOSE':
815 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
816 $dir_output = $conf->ficheinter->dir_output;
817 $object_type =
'ficheinter';
818 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
820 case 'ORDER_SUPPLIER_VALIDATE':
821 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
822 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
823 $object_type =
'order_supplier';
824 $labeltouse = isset($conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
825 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
826 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs));
827 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
829 case 'ORDER_SUPPLIER_CANCEL':
830 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
831 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
832 $object_type =
'order_supplier';
833 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
834 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($outputlangs));
835 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
837 case 'ORDER_SUPPLIER_APPROVE':
838 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
839 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
840 $object_type =
'order_supplier';
841 $labeltouse = isset($conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
842 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
843 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs));
844 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
846 case 'ORDER_SUPPLIER_SUBMIT':
847 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
848 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
849 $object_type =
'order_supplier';
850 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
851 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs));
852 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
854 case 'ORDER_SUPPLIER_REFUSE':
855 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
856 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
857 $object_type =
'order_supplier';
858 $labeltouse = isset($conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
859 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
860 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs));
861 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
863 case 'SHIPPING_VALIDATE':
864 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
865 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
866 $object_type =
'shipping';
867 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
869 case 'EXPENSE_REPORT_VALIDATE':
870 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
871 $dir_output = $conf->expensereport->dir_output;
872 $object_type =
'expensereport';
873 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
875 case 'EXPENSE_REPORT_APPROVE':
876 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
877 $dir_output = $conf->expensereport->dir_output;
878 $object_type =
'expensereport';
879 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
881 case 'HOLIDAY_VALIDATE':
882 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
883 $dir_output = $conf->holiday->dir_output;
884 $object_type =
'holiday';
885 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
887 case 'HOLIDAY_APPROVE':
888 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
889 $dir_output = $conf->holiday->dir_output;
890 $object_type =
'holiday';
891 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
893 case 'ACTION_CREATE':
894 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
895 $dir_output = $conf->agenda->dir_output;
896 $object_type =
'action';
897 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
900 $object_type =
$object->element;
901 $dir_output = $conf->$object_type->multidir_output[
$object->entity ?
$object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1,
$object, $object_type);
902 $template = $notifcode.
'_TEMPLATE';
903 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
907 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
908 $formmail =
new FormMail($this->db);
909 $arraydefaultmessage =
null;
911 $template = $notifcode.
'_TEMPLATE';
913 if (!empty($labeltouse)) {
914 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
916 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
917 if (method_exists(
$object,
'fetch_thirdparty') && empty(
$object->thirdparty)) {
922 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
923 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
925 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
926 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
932 $pdf_path = $dir_output.
"/".$ref.
".pdf";
933 if (!
dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
937 $filepdf = $pdf_path;
938 $filename_list[] = $filepdf;
939 $mimetype_list[] = mime_content_type($filepdf);
940 $mimefilename_list[] = $ref.
".pdf";
943 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
946 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
948 if ($user->fk_user > 0) {
949 $supervisoruser =
new User($this->db);
950 $supervisoruser->fetch($user->fk_user);
951 if ($supervisoruser->email) {
952 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
955 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
956 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
957 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
958 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
959 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
962 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'outputlangs' => $outputlangs,
'labeltouse' => $labeltouse);
963 if (!isset($action)) {
967 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
968 if (empty($reshook)) {
969 if (!empty($hookmanager->resArray[
'files'])) {
970 $filename_list = $hookmanager->resArray[
'files'][
'file'];
971 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
972 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
974 if (!empty($hookmanager->resArray[
'subject'])) {
975 $subject .= $hookmanager->resArray[
'subject'];
977 if (!empty($hookmanager->resArray[
'message'])) {
978 $message .= $hookmanager->resArray[
'message'];
1001 if ($mailfile->sendfile()) {
1002 if ($obj->type_target ==
'touserid') {
1003 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
1004 $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).
"')";
1006 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
1007 $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).
"')";
1009 if (!$this->db->query($sql)) {
1014 $this->errors[] = $mailfile->error;
1017 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
1022 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty(
$object->socid) ?
'' :
$object->socid));
1026 $this->errors[] = $this->db->lasterror();
1027 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
1034 foreach ($conf->global as $key => $val) {
1036 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
1042 $threshold = (float) $reg[1];
1043 if (!empty(
$object->total_ht) &&
$object->total_ht <= $threshold) {
1044 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".
$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
1048 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
1049 if ($notifcodedefid <= 0) {
1058 $appli = $mysoc->name;
1060 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
1062 switch ($notifcode) {
1063 case 'BILL_VALIDATE':
1064 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1065 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1066 $object_type =
'facture';
1067 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
1070 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1071 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1072 $object_type =
'facture';
1073 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
1075 case 'ORDER_VALIDATE':
1076 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1077 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1078 $object_type =
'order';
1079 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
1082 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1083 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1084 $object_type =
'order';
1085 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
1087 case 'PROPAL_VALIDATE':
1088 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1090 $object_type =
'propal';
1091 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
1093 case 'PROPAL_CLOSE_SIGNED':
1094 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1096 $object_type =
'propal';
1097 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
1099 case 'FICHINTER_ADD_CONTACT':
1100 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1101 $dir_output = $conf->ficheinter->dir_output;
1102 $object_type =
'ficheinter';
1103 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
1105 case 'FICHINTER_VALIDATE':
1106 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1107 $dir_output = $conf->facture->dir_output;
1108 $object_type =
'ficheinter';
1109 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
1111 case 'FICHINTER_CLOSE':
1112 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1113 $dir_output = $conf->facture->dir_output;
1114 $object_type =
'ficheinter';
1115 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
1117 case 'ORDER_SUPPLIER_CANCEL':
1118 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1119 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1120 $object_type =
'order_supplier';
1121 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1122 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs));
1123 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1125 case 'ORDER_SUPPLIER_VALIDATE':
1126 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1127 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1128 $object_type =
'order_supplier';
1129 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1130 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
1131 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1133 case 'ORDER_SUPPLIER_APPROVE':
1134 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1135 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1136 $object_type =
'order_supplier';
1137 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1138 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
1139 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1141 case 'ORDER_SUPPLIER_SUBMIT':
1142 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1143 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1144 $object_type =
'order_supplier';
1145 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1146 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
1147 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1149 case 'ORDER_SUPPLIER_REFUSE':
1150 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1151 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1152 $object_type =
'order_supplier';
1153 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1154 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
1155 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1157 case 'SHIPPING_VALIDATE':
1158 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1159 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
1160 $object_type =
'order_supplier';
1161 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
1163 case 'EXPENSE_REPORT_VALIDATE':
1164 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1165 $dir_output = $conf->expensereport->dir_output;
1166 $object_type =
'expensereport';
1167 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
1169 case 'EXPENSE_REPORT_APPROVE':
1170 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1171 $dir_output = $conf->expensereport->dir_output;
1172 $object_type =
'expensereport';
1173 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
1175 case 'HOLIDAY_VALIDATE':
1176 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1177 $dir_output = $conf->holiday->dir_output;
1178 $object_type =
'holiday';
1179 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
1181 case 'HOLIDAY_APPROVE':
1182 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1183 $dir_output = $conf->holiday->dir_output;
1184 $object_type =
'holiday';
1185 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
1187 case 'ACTION_CREATE':
1188 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1189 $dir_output = $conf->agenda->dir_output;
1190 $object_type =
'action';
1191 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
1194 $object_type =
$object->element;
1195 $dir_output = $conf->$object_type->multidir_output[
$object->entity ?
$object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1,
$object, $object_type);
1196 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
1200 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
1205 $filepdf = $pdf_path;
1206 $filename_list[] = $pdf_path;
1207 $mimetype_list[] = mime_content_type($filepdf);
1208 $mimefilename_list[] = $ref.
".pdf";
1212 $outputlangs = $langs;
1217 $emailTemplate =
null;
1218 if (!empty($mailTemplateLabel)) {
1219 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1220 $formmail =
new FormMail($this->db);
1221 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $mailTemplateLabel);
1223 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
1224 if (property_exists(
$object,
'thirdparty')) {
1229 if (
$object->thirdparty instanceof
Societe &&
$object->thirdparty->default_lang &&
$object->thirdparty->default_lang != $langs->defaultlang) {
1230 $outputlangs =
new Translate(
'', $conf);
1231 $outputlangs->setDefaultLang(
$object->thirdparty->default_lang);
1232 $outputlangs->loadLangs(array(
'main',
'other'));
1237 $subject =
make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs);
1238 $message =
make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs);
1241 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
1245 $message = nl2br($message);
1249 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
1251 if ($user->fk_user > 0) {
1252 $supervisoruser =
new User($this->db);
1253 $supervisoruser->fetch($user->fk_user);
1254 if ($supervisoruser->email) {
1255 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1258 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1259 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1260 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1261 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1262 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1266 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'subject' => &$subject,
'message' => &$message);
1267 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1268 if (empty($reshook)) {
1269 if (!empty($hookmanager->resArray[
'files'])) {
1270 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1271 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1272 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1274 if (!empty($hookmanager->resArray[
'subject'])) {
1275 $subject .= $hookmanager->resArray[
'subject'];
1277 if (!empty($hookmanager->resArray[
'message'])) {
1278 $message .= $hookmanager->resArray[
'message'];
1300 if ($mailfile->sendfile()) {
1301 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1302 $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).
"')";
1303 if (!$this->db->query($sql)) {
1308 $this->errors[] = $mailfile->error;