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) {
919 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
920 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
922 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
923 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
929 $pdf_path = $dir_output.
"/".$ref.
".pdf";
930 if (!
dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
934 $filepdf = $pdf_path;
935 $filename_list[] = $filepdf;
936 $mimetype_list[] = mime_content_type($filepdf);
937 $mimefilename_list[] = $ref.
".pdf";
940 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
943 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
945 if ($user->fk_user > 0) {
946 $supervisoruser =
new User($this->db);
947 $supervisoruser->fetch($user->fk_user);
948 if ($supervisoruser->email) {
949 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
952 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
953 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
954 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
955 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
956 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
959 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'outputlangs' => $outputlangs,
'labeltouse' => $labeltouse);
960 if (!isset($action)) {
964 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
965 if (empty($reshook)) {
966 if (!empty($hookmanager->resArray[
'files'])) {
967 $filename_list = $hookmanager->resArray[
'files'][
'file'];
968 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
969 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
971 if (!empty($hookmanager->resArray[
'subject'])) {
972 $subject .= $hookmanager->resArray[
'subject'];
974 if (!empty($hookmanager->resArray[
'message'])) {
975 $message .= $hookmanager->resArray[
'message'];
998 if ($mailfile->sendfile()) {
999 if ($obj->type_target ==
'touserid') {
1000 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
1001 $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).
"')";
1003 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, 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 if (!$this->db->query($sql)) {
1011 $this->errors[] = $mailfile->error;
1014 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
1019 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty(
$object->socid) ?
'' :
$object->socid));
1023 $this->errors[] = $this->db->lasterror();
1024 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
1031 foreach ($conf->global as $key => $val) {
1033 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
1039 $threshold = (float) $reg[1];
1040 if (!empty(
$object->total_ht) &&
$object->total_ht <= $threshold) {
1041 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".
$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
1045 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
1046 if ($notifcodedefid <= 0) {
1055 $appli = $mysoc->name;
1057 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
1059 switch ($notifcode) {
1060 case 'BILL_VALIDATE':
1061 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1062 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1063 $object_type =
'facture';
1064 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
1067 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1068 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1069 $object_type =
'facture';
1070 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
1072 case 'ORDER_VALIDATE':
1073 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1074 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1075 $object_type =
'order';
1076 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
1079 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1080 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1081 $object_type =
'order';
1082 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
1084 case 'PROPAL_VALIDATE':
1085 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1087 $object_type =
'propal';
1088 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
1090 case 'PROPAL_CLOSE_SIGNED':
1091 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1093 $object_type =
'propal';
1094 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
1096 case 'FICHINTER_ADD_CONTACT':
1097 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1098 $dir_output = $conf->ficheinter->dir_output;
1099 $object_type =
'ficheinter';
1100 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
1102 case 'FICHINTER_VALIDATE':
1103 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1104 $dir_output = $conf->facture->dir_output;
1105 $object_type =
'ficheinter';
1106 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
1108 case 'FICHINTER_CLOSE':
1109 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1110 $dir_output = $conf->facture->dir_output;
1111 $object_type =
'ficheinter';
1112 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
1114 case 'ORDER_SUPPLIER_CANCEL':
1115 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1116 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1117 $object_type =
'order_supplier';
1118 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1119 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs));
1120 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1122 case 'ORDER_SUPPLIER_VALIDATE':
1123 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1124 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1125 $object_type =
'order_supplier';
1126 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1127 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
1128 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1130 case 'ORDER_SUPPLIER_APPROVE':
1131 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1132 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1133 $object_type =
'order_supplier';
1134 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1135 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
1136 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1138 case 'ORDER_SUPPLIER_SUBMIT':
1139 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1140 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1141 $object_type =
'order_supplier';
1142 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1143 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
1144 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1146 case 'ORDER_SUPPLIER_REFUSE':
1147 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1148 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1149 $object_type =
'order_supplier';
1150 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1151 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
1152 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1154 case 'SHIPPING_VALIDATE':
1155 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1156 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
1157 $object_type =
'order_supplier';
1158 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
1160 case 'EXPENSE_REPORT_VALIDATE':
1161 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1162 $dir_output = $conf->expensereport->dir_output;
1163 $object_type =
'expensereport';
1164 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
1166 case 'EXPENSE_REPORT_APPROVE':
1167 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1168 $dir_output = $conf->expensereport->dir_output;
1169 $object_type =
'expensereport';
1170 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
1172 case 'HOLIDAY_VALIDATE':
1173 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1174 $dir_output = $conf->holiday->dir_output;
1175 $object_type =
'holiday';
1176 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
1178 case 'HOLIDAY_APPROVE':
1179 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1180 $dir_output = $conf->holiday->dir_output;
1181 $object_type =
'holiday';
1182 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
1184 case 'ACTION_CREATE':
1185 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1186 $dir_output = $conf->agenda->dir_output;
1187 $object_type =
'action';
1188 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
1191 $object_type =
$object->element;
1192 $dir_output = $conf->$object_type->multidir_output[
$object->entity ?
$object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1,
$object, $object_type);
1193 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
1197 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
1202 $filepdf = $pdf_path;
1203 $filename_list[] = $pdf_path;
1204 $mimetype_list[] = mime_content_type($filepdf);
1205 $mimefilename_list[] = $ref.
".pdf";
1209 $outputlangs = $langs;
1214 $emailTemplate =
null;
1215 if (!empty($mailTemplateLabel)) {
1216 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1217 $formmail =
new FormMail($this->db);
1218 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $mailTemplateLabel);
1220 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
1221 if (property_exists(
$object,
'thirdparty') &&
$object->thirdparty instanceof
Societe &&
$object->thirdparty->default_lang &&
$object->thirdparty->default_lang != $langs->defaultlang) {
1222 $outputlangs =
new Translate(
'', $conf);
1223 $outputlangs->setDefaultLang(
$object->thirdparty->default_lang);
1224 $outputlangs->loadLangs(array(
'main',
'other'));
1228 $subject =
make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs);
1229 $message =
make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs);
1232 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
1236 $message = nl2br($message);
1240 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
1242 if ($user->fk_user > 0) {
1243 $supervisoruser =
new User($this->db);
1244 $supervisoruser->fetch($user->fk_user);
1245 if ($supervisoruser->email) {
1246 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1249 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1250 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1251 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1252 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1253 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1257 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'subject' => &$subject,
'message' => &$message);
1258 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1259 if (empty($reshook)) {
1260 if (!empty($hookmanager->resArray[
'files'])) {
1261 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1262 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1263 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1265 if (!empty($hookmanager->resArray[
'subject'])) {
1266 $subject .= $hookmanager->resArray[
'subject'];
1268 if (!empty($hookmanager->resArray[
'message'])) {
1269 $message .= $hookmanager->resArray[
'message'];
1291 if ($mailfile->sendfile()) {
1292 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1293 $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).
"')";
1294 if (!$this->db->query($sql)) {
1299 $this->errors[] = $mailfile->error;