610 public function send($notifcode,
$object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
612 global $user, $conf, $langs, $mysoc;
614 global $dolibarr_main_url_root;
618 if (!is_object($hookmanager)) {
619 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
622 $hookmanager->initHooks(array(
'notification'));
624 $parameters = array(
'notifcode' => $notifcode);
625 $reshook = $hookmanager->executeHooks(
'notifsupported', $parameters,
$object, $action);
626 if (empty($reshook)) {
627 if (!empty($hookmanager->resArray[
'arrayofnotifsupported'])) {
628 Notify::$arrayofnotifsupported = array_merge(Notify::$arrayofnotifsupported, $hookmanager->resArray[
'arrayofnotifsupported']);
633 if (!in_array($notifcode, Notify::$arrayofnotifsupported)) {
637 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
639 dol_syslog(get_class($this).
"::send notifcode=".$notifcode.
", object id=".
$object->id);
641 $langs->load(
"other");
644 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
645 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
649 $application =
'Dolibarr';
666 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
667 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
668 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
669 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
670 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
671 $sql .=
" ".$this->db->prefix().
"societe as s";
672 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
673 $sql .=
" AND n.fk_soc = s.rowid";
674 $sql .=
" AND c.statut = 1";
675 if (is_numeric($notifcode)) {
676 $sql .=
" AND n.fk_action = ".((int) $notifcode);
678 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
680 $sql .=
" AND s.rowid = ".((int)
$object->socid);
686 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
687 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
688 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
689 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
690 $sql .=
" ".$this->db->prefix().
"notify_def as n";
691 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
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).
"'";
704 $result = $this->db->query($sql);
706 $num = $this->db->num_rows($result);
708 if (is_object(
$object->project) ||
$object->fetch_project() > 0) {
709 $projtitle =
'('.$object->project->title.
')';
714 while ($i < $num && !$error) {
715 $obj = $this->db->fetch_object($result);
718 $notifcodedefid = $obj->adid;
720 if ($obj->type_target ==
'tocontactid') {
721 $trackid =
'ctc'.$obj->cid;
723 if ($obj->type_target ==
'touserid') {
724 $trackid =
'use'.$obj->cid;
729 $outputlangs = $langs;
730 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
732 $outputlangs->setDefaultLang($obj->default_lang);
733 $outputlangs->loadLangs(array(
"main",
"other"));
736 $appli = $mysoc->name;
738 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
740 switch ($notifcode) {
742 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
743 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
744 $object_type =
'facture';
745 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceCanceled", $link);
747 case 'BILL_VALIDATE':
748 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
749 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
750 $object_type =
'facture';
751 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
754 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
755 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
756 $object_type =
'facture';
757 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
760 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
761 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
762 $object_type =
'order';
763 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderCanceled", $link);
765 case 'ORDER_VALIDATE':
766 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
767 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
768 $object_type =
'order';
769 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
772 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
773 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
774 $object_type =
'order';
776 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
778 case 'PROPAL_VALIDATE':
779 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
781 $object_type =
'propal';
782 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
784 case 'PROPAL_CLOSE_REFUSED':
785 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
787 $object_type =
'propal';
789 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
790 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
791 $mesg .=
' - From online page';
794 case 'PROPAL_CLOSE_SIGNED':
795 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
797 $object_type =
'propal';
798 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
799 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
800 $mesg .=
' - From online page';
803 case 'FICHINTER_ADD_CONTACT':
804 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
805 $dir_output = $conf->ficheinter->dir_output;
806 $object_type =
'ficheinter';
807 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
809 case 'FICHINTER_VALIDATE':
810 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
811 $dir_output = $conf->ficheinter->dir_output;
812 $object_type =
'ficheinter';
813 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
815 case 'FICHINTER_MODIFY':
816 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
817 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
818 $dir_output = $conf->ficheinter->dir_output;
819 $object_type =
'ficheinter';
820 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
822 case 'FICHINTER_CLOSE':
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(
"EMailTextInterventionClosed", $link);
828 case 'ORDER_SUPPLIER_VALIDATE':
829 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
830 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
831 $object_type =
'order_supplier';
832 $labeltouse = isset($conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
833 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
834 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs));
835 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
837 case 'ORDER_SUPPLIER_CANCEL':
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 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
842 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($outputlangs));
843 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
845 case 'ORDER_SUPPLIER_APPROVE':
846 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
847 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
848 $object_type =
'order_supplier';
849 $labeltouse = isset($conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
850 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
851 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs));
852 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
854 case 'ORDER_SUPPLIER_SUBMIT':
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 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
859 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs));
860 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
862 case 'ORDER_SUPPLIER_REFUSE':
863 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
864 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
865 $object_type =
'order_supplier';
866 $labeltouse = isset($conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
867 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
868 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs));
869 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
871 case 'SHIPPING_VALIDATE':
872 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
873 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
874 $object_type =
'shipping';
875 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
877 case 'EXPENSE_REPORT_VALIDATE':
878 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
879 $dir_output = $conf->expensereport->dir_output;
880 $object_type =
'expensereport';
881 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
883 case 'EXPENSE_REPORT_APPROVE':
884 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
885 $dir_output = $conf->expensereport->dir_output;
886 $object_type =
'expensereport';
887 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
889 case 'HOLIDAY_VALIDATE':
890 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
891 $dir_output = $conf->holiday->dir_output;
892 $object_type =
'holiday';
893 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
895 case 'HOLIDAY_APPROVE':
896 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
897 $dir_output = $conf->holiday->dir_output;
898 $object_type =
'holiday';
899 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
901 case 'ACTION_CREATE':
902 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
903 $dir_output = $conf->agenda->dir_output;
904 $object_type =
'action';
905 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
908 $object_type =
$object->element;
909 $dir_output = $conf->$object_type->multidir_output[
$object->entity ?
$object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1,
$object, $object_type);
910 $template = $notifcode.
'_TEMPLATE';
911 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
915 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
916 $formmail =
new FormMail($this->db);
917 $arraydefaultmessage =
null;
919 $template = $notifcode.
'_TEMPLATE';
921 if (!empty($labeltouse)) {
922 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
924 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
927 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
928 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
930 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
931 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
937 $pdf_path = $dir_output.
"/".$ref.
".pdf";
938 if (!
dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
942 $filepdf = $pdf_path;
943 $filename_list[] = $filepdf;
944 $mimetype_list[] = mime_content_type($filepdf);
945 $mimefilename_list[] = $ref.
".pdf";
948 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
951 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
953 if ($user->fk_user > 0) {
954 $supervisoruser =
new User($this->db);
955 $supervisoruser->fetch($user->fk_user);
956 if ($supervisoruser->email) {
957 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
960 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
961 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
962 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
963 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
964 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
967 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'outputlangs' => $outputlangs,
'labeltouse' => $labeltouse);
968 if (!isset($action)) {
972 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
973 if (empty($reshook)) {
974 if (!empty($hookmanager->resArray[
'files'])) {
975 $filename_list = $hookmanager->resArray[
'files'][
'file'];
976 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
977 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
979 if (!empty($hookmanager->resArray[
'subject'])) {
980 $subject .= $hookmanager->resArray[
'subject'];
982 if (!empty($hookmanager->resArray[
'message'])) {
983 $message .= $hookmanager->resArray[
'message'];
1006 if ($mailfile->sendfile()) {
1007 if ($obj->type_target ==
'touserid') {
1008 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
1009 $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).
"')";
1011 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
1012 $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).
"')";
1014 if (!$this->db->query($sql)) {
1019 $this->errors[] = $mailfile->error;
1022 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
1027 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty(
$object->socid) ?
'' :
$object->socid));
1031 $this->errors[] = $this->db->lasterror();
1032 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
1039 foreach ($conf->global as $key => $val) {
1041 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
1047 $threshold = (float) $reg[1];
1048 if (!empty(
$object->total_ht) &&
$object->total_ht <= $threshold) {
1049 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".
$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
1053 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
1054 if ($notifcodedefid <= 0) {
1063 $appli = $mysoc->name;
1065 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
1067 switch ($notifcode) {
1068 case 'BILL_VALIDATE':
1069 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1070 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1071 $object_type =
'facture';
1072 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
1075 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1076 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1077 $object_type =
'facture';
1078 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
1080 case 'ORDER_VALIDATE':
1081 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1082 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1083 $object_type =
'order';
1084 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
1087 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1088 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1089 $object_type =
'order';
1090 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
1092 case 'PROPAL_VALIDATE':
1093 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1095 $object_type =
'propal';
1096 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
1098 case 'PROPAL_CLOSE_SIGNED':
1099 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1101 $object_type =
'propal';
1102 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
1104 case 'FICHINTER_ADD_CONTACT':
1105 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1106 $dir_output = $conf->ficheinter->dir_output;
1107 $object_type =
'ficheinter';
1108 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
1110 case 'FICHINTER_VALIDATE':
1111 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1112 $dir_output = $conf->facture->dir_output;
1113 $object_type =
'ficheinter';
1114 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
1116 case 'FICHINTER_MODIFY':
1117 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1118 $context_info = array_key_exists(
'signature',
$object->context) ?
$object->getLibSignedStatus() :
'';
1119 $dir_output = $conf->ficheinter->dir_output;
1120 $object_type =
'ficheinter';
1121 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionModified", $link, $context_info);
1123 case 'FICHINTER_CLOSE':
1124 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1125 $dir_output = $conf->facture->dir_output;
1126 $object_type =
'ficheinter';
1127 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
1129 case 'ORDER_SUPPLIER_CANCEL':
1130 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1131 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1132 $object_type =
'order_supplier';
1133 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1134 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs));
1135 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1137 case 'ORDER_SUPPLIER_VALIDATE':
1138 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1139 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1140 $object_type =
'order_supplier';
1141 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1142 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
1143 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1145 case 'ORDER_SUPPLIER_APPROVE':
1146 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1147 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1148 $object_type =
'order_supplier';
1149 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1150 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
1151 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1153 case 'ORDER_SUPPLIER_SUBMIT':
1154 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1155 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1156 $object_type =
'order_supplier';
1157 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1158 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
1159 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1161 case 'ORDER_SUPPLIER_REFUSE':
1162 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1163 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1164 $object_type =
'order_supplier';
1165 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1166 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
1167 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1169 case 'SHIPPING_VALIDATE':
1170 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1171 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
1172 $object_type =
'order_supplier';
1173 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
1175 case 'EXPENSE_REPORT_VALIDATE':
1176 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1177 $dir_output = $conf->expensereport->dir_output;
1178 $object_type =
'expensereport';
1179 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
1181 case 'EXPENSE_REPORT_APPROVE':
1182 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1183 $dir_output = $conf->expensereport->dir_output;
1184 $object_type =
'expensereport';
1185 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
1187 case 'HOLIDAY_VALIDATE':
1188 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1189 $dir_output = $conf->holiday->dir_output;
1190 $object_type =
'holiday';
1191 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
1193 case 'HOLIDAY_APPROVE':
1194 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1195 $dir_output = $conf->holiday->dir_output;
1196 $object_type =
'holiday';
1197 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
1199 case 'ACTION_CREATE':
1200 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1201 $dir_output = $conf->agenda->dir_output;
1202 $object_type =
'action';
1203 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
1206 $object_type =
$object->element;
1207 $dir_output = $conf->$object_type->multidir_output[
$object->entity ?
$object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1,
$object, $object_type);
1208 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
1212 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
1217 $filepdf = $pdf_path;
1218 $filename_list[] = $pdf_path;
1219 $mimetype_list[] = mime_content_type($filepdf);
1220 $mimefilename_list[] = $ref.
".pdf";
1224 $outputlangs = $langs;
1229 $emailTemplate =
null;
1230 if (!empty($mailTemplateLabel)) {
1231 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1232 $formmail =
new FormMail($this->db);
1233 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $mailTemplateLabel);
1235 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
1236 if (property_exists(
$object,
'thirdparty') &&
$object->thirdparty instanceof
Societe &&
$object->thirdparty->default_lang &&
$object->thirdparty->default_lang != $langs->defaultlang) {
1237 $outputlangs =
new Translate(
'', $conf);
1238 $outputlangs->setDefaultLang(
$object->thirdparty->default_lang);
1239 $outputlangs->loadLangs(array(
'main',
'other'));
1243 $subject =
make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs);
1244 $message =
make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs);
1247 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
1251 $message = nl2br($message);
1255 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
1257 if ($user->fk_user > 0) {
1258 $supervisoruser =
new User($this->db);
1259 $supervisoruser->fetch($user->fk_user);
1260 if ($supervisoruser->email) {
1261 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1264 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1265 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1266 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1267 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1268 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1272 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'subject' => &$subject,
'message' => &$message);
1273 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1274 if (empty($reshook)) {
1275 if (!empty($hookmanager->resArray[
'files'])) {
1276 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1277 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1278 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1280 if (!empty($hookmanager->resArray[
'subject'])) {
1281 $subject .= $hookmanager->resArray[
'subject'];
1283 if (!empty($hookmanager->resArray[
'message'])) {
1284 $message .= $hookmanager->resArray[
'message'];
1306 if ($mailfile->sendfile()) {
1307 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1308 $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).
"')";
1309 if (!$this->db->query($sql)) {
1314 $this->errors[] = $mailfile->error;