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';
668 $sql .=
"SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
669 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
670 $sql .=
" FROM ".$this->db->prefix().
"socpeople as c,";
671 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
672 $sql .=
" ".$this->db->prefix().
"notify_def as n,";
673 $sql .=
" ".$this->db->prefix().
"societe as s";
674 $sql .=
" WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
675 $sql .=
" AND n.fk_soc = s.rowid";
676 $sql .=
" AND c.statut = 1";
677 if (is_numeric($notifcode)) {
678 $sql .=
" AND n.fk_action = ".((int) $notifcode);
680 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
682 $sql .=
" AND s.rowid = ".((int)
$object->socid);
688 $sql .=
"SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,";
689 $sql .=
" a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type";
690 $sql .=
" FROM ".$this->db->prefix().
"user as c,";
691 $sql .=
" ".$this->db->prefix().
"c_action_trigger as a,";
692 $sql .=
" ".$this->db->prefix().
"notify_def as n";
693 $sql .=
" WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
694 $sql .=
" AND c.statut = 1";
695 if (is_numeric($notifcode)) {
696 $sql .=
" AND n.fk_action = ".((int) $notifcode);
698 $sql .=
" AND a.code = '".$this->db->escape($notifcode).
"'";
706 $result = $this->db->query($sql);
708 $num = $this->db->num_rows($result);
710 if (is_object(
$object->project) ||
$object->fetch_project() > 0) {
711 $projtitle =
'('.$object->project->title.
')';
716 while ($i < $num && !$error) {
717 $obj = $this->db->fetch_object($result);
720 $notifcodedefid = $obj->adid;
722 if ($obj->type_target ==
'tocontactid') {
723 $trackid =
'ctc'.$obj->cid;
725 if ($obj->type_target ==
'touserid') {
726 $trackid =
'use'.$obj->cid;
731 $outputlangs = $langs;
732 if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
734 $outputlangs->setDefaultLang($obj->default_lang);
735 $outputlangs->loadLangs(array(
"main",
"other"));
738 $appli = $mysoc->name;
740 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
742 switch ($notifcode) {
744 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
745 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
746 $object_type =
'facture';
747 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceCanceled", $link);
749 case 'BILL_VALIDATE':
750 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
751 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
752 $object_type =
'facture';
753 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
756 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
757 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
758 $object_type =
'facture';
759 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
762 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
763 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
764 $object_type =
'order';
765 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderCanceled", $link);
767 case 'ORDER_VALIDATE':
768 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
769 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
770 $object_type =
'order';
771 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
774 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
775 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
776 $object_type =
'order';
778 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
780 case 'PROPAL_VALIDATE':
781 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
783 $object_type =
'propal';
784 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
786 case 'PROPAL_CLOSE_REFUSED':
787 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
789 $object_type =
'propal';
791 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextProposalClosedRefused", $link);
792 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
793 $mesg .=
' - From online page';
796 case 'PROPAL_CLOSE_SIGNED':
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(
"EMailTextProposalClosedSigned", $link);
801 if (!empty(
$object->context[
'closedfromonlinesignature'])) {
802 $mesg .=
' - From online page';
805 case 'FICHINTER_ADD_CONTACT':
806 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
807 $dir_output = $conf->ficheinter->dir_output;
808 $object_type =
'ficheinter';
809 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
811 case 'FICHINTER_VALIDATE':
812 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
813 $dir_output = $conf->ficheinter->dir_output;
814 $object_type =
'ficheinter';
815 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
817 case 'FICHINTER_CLOSE':
818 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
819 $dir_output = $conf->ficheinter->dir_output;
820 $object_type =
'ficheinter';
821 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
823 case 'ORDER_SUPPLIER_VALIDATE':
824 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
825 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
826 $object_type =
'order_supplier';
827 $labeltouse = isset($conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE :
'';
828 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
829 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs));
830 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
832 case 'ORDER_SUPPLIER_CANCEL':
833 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
834 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
835 $object_type =
'order_supplier';
836 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
837 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($outputlangs));
838 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
840 case 'ORDER_SUPPLIER_APPROVE':
841 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
842 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
843 $object_type =
'order_supplier';
844 $labeltouse = isset($conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE :
'';
845 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
846 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs));
847 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
849 case 'ORDER_SUPPLIER_SUBMIT':
850 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
851 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
852 $object_type =
'order_supplier';
853 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
854 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs));
855 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
857 case 'ORDER_SUPPLIER_REFUSE':
858 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
859 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
860 $object_type =
'order_supplier';
861 $labeltouse = isset($conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE :
'';
862 $mesg = $outputlangs->transnoentitiesnoconv(
"Hello").
",\n\n";
863 $mesg .= $outputlangs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs));
864 $mesg .=
"\n\n".$outputlangs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
866 case 'SHIPPING_VALIDATE':
867 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
868 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
869 $object_type =
'shipping';
870 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
872 case 'EXPENSE_REPORT_VALIDATE':
873 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
874 $dir_output = $conf->expensereport->dir_output;
875 $object_type =
'expensereport';
876 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
878 case 'EXPENSE_REPORT_APPROVE':
879 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
880 $dir_output = $conf->expensereport->dir_output;
881 $object_type =
'expensereport';
882 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
884 case 'HOLIDAY_VALIDATE':
885 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
886 $dir_output = $conf->holiday->dir_output;
887 $object_type =
'holiday';
888 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
890 case 'HOLIDAY_APPROVE':
891 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
892 $dir_output = $conf->holiday->dir_output;
893 $object_type =
'holiday';
894 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
896 case 'ACTION_CREATE':
897 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
898 $dir_output = $conf->agenda->dir_output;
899 $object_type =
'action';
900 $mesg = $outputlangs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
903 $object_type =
$object->element;
904 $dir_output = $conf->$object_type->multidir_output[
$object->entity ?
$object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1,
$object, $object_type);
905 $template = $notifcode.
'_TEMPLATE';
906 $mesg = $outputlangs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref.
' '.$dir_output;
910 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
911 $formmail =
new FormMail($this->db);
912 $arraydefaultmessage =
null;
914 $template = $notifcode.
'_TEMPLATE';
916 if (!empty($labeltouse)) {
917 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $labeltouse);
919 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
920 if (method_exists(
$object,
'fetch_thirdparty') && empty(
$object->thirdparty)) {
925 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
926 $message =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
928 $message = $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification", $application, $mysoc->name).
"\n";
929 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
935 $pdf_path = $dir_output.
"/".$ref.
".pdf";
936 if (!
dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
940 $filepdf = $pdf_path;
941 $filename_list[] = $filepdf;
942 $mimetype_list[] = mime_content_type($filepdf);
943 $mimefilename_list[] = $ref.
".pdf";
946 $labeltouse = !empty($labeltouse) ? $labeltouse :
'';
949 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
951 if ($user->fk_user > 0) {
952 $supervisoruser =
new User($this->db);
953 $supervisoruser->fetch($user->fk_user);
954 if ($supervisoruser->email) {
955 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
958 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
959 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
960 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
961 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
962 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
965 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'outputlangs' => $outputlangs,
'labeltouse' => $labeltouse);
966 if (!isset($action)) {
970 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
971 if (empty($reshook)) {
972 if (!empty($hookmanager->resArray[
'files'])) {
973 $filename_list = $hookmanager->resArray[
'files'][
'file'];
974 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
975 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
977 if (!empty($hookmanager->resArray[
'subject'])) {
978 $subject .= $hookmanager->resArray[
'subject'];
980 if (!empty($hookmanager->resArray[
'message'])) {
981 $message .= $hookmanager->resArray[
'message'];
1004 if (! empty($mailfile->error) || ! empty($mailfile->errors)) {
1005 $this->error = $mailfile->error;
1006 $this->errors = $mailfile->errors;
1010 if ($mailfile->sendfile()) {
1011 if ($obj->type_target ==
'touserid') {
1012 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
1013 $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).
"')";
1015 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
1016 $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).
"')";
1018 if (!$this->db->query($sql)) {
1023 $this->errors[] = $mailfile->error;
1026 dol_syslog(
"No notification sent for ".$sendto.
" because email is empty");
1031 dol_syslog(
"No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".(empty(
$object->socid) ?
'' :
$object->socid));
1035 $this->errors[] = $this->db->lasterror();
1036 dol_syslog(
"Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR);
1043 foreach ($conf->global as $key => $val) {
1045 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.
'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
1051 $threshold = (float) $reg[1];
1052 if (!empty(
$object->total_ht) &&
$object->total_ht <= $threshold) {
1053 dol_syslog(
"A notification is requested for notifcode = ".$notifcode.
" but amount = ".
$object->total_ht.
" so lower than threshold = ".$threshold.
". We discard this notification");
1057 $notifcodedefid =
dol_getIdFromCode($this->db, $notifcode,
'c_action_trigger',
'code',
'rowid');
1058 if ($notifcodedefid <= 0) {
1067 $appli = $mysoc->name;
1069 $subject =
'['.$appli.
'] '.$langs->transnoentitiesnoconv(
"DolibarrNotification").($projtitle ?
' '.$projtitle :
'');
1071 switch ($notifcode) {
1072 case 'BILL_VALIDATE':
1073 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1074 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1075 $object_type =
'facture';
1076 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoiceValidated", $link);
1079 $link =
'<a href="'.$urlwithroot.
'/compta/facture/card.php?facid='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1080 $dir_output = $conf->facture->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'invoice');
1081 $object_type =
'facture';
1082 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInvoicePayed", $link);
1084 case 'ORDER_VALIDATE':
1085 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1086 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1087 $object_type =
'order';
1088 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderValidated", $link);
1091 $link =
'<a href="'.$urlwithroot.
'/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1092 $dir_output = $conf->commande->dir_output.
"/".
get_exdir(0, 0, 0, 1,
$object,
'commande');
1093 $object_type =
'order';
1094 $mesg = $langs->transnoentitiesnoconv(
"EMailTextOrderClose", $link);
1096 case 'PROPAL_VALIDATE':
1097 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1099 $object_type =
'propal';
1100 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalValidated", $link);
1102 case 'PROPAL_CLOSE_SIGNED':
1103 $link =
'<a href="'.$urlwithroot.
'/comm/propal/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1105 $object_type =
'propal';
1106 $mesg = $langs->transnoentitiesnoconv(
"EMailTextProposalClosedSigned", $link);
1108 case 'FICHINTER_ADD_CONTACT':
1109 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1110 $dir_output = $conf->ficheinter->dir_output;
1111 $object_type =
'ficheinter';
1112 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionAddedContact", $link);
1114 case 'FICHINTER_VALIDATE':
1115 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1116 $dir_output = $conf->facture->dir_output;
1117 $object_type =
'ficheinter';
1118 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionValidated", $link);
1120 case 'FICHINTER_CLOSE':
1121 $link =
'<a href="'.$urlwithroot.
'/fichinter/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1122 $dir_output = $conf->facture->dir_output;
1123 $object_type =
'ficheinter';
1124 $mesg = $langs->transnoentitiesnoconv(
"EMailTextInterventionClosed", $link);
1126 case 'ORDER_SUPPLIER_CANCEL':
1127 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1128 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1129 $object_type =
'order_supplier';
1130 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1131 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs));
1132 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1134 case 'ORDER_SUPPLIER_VALIDATE':
1135 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1136 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1137 $object_type =
'order_supplier';
1138 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1139 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs));
1140 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1142 case 'ORDER_SUPPLIER_APPROVE':
1143 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1144 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1145 $object_type =
'order_supplier';
1146 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1147 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs));
1148 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1150 case 'ORDER_SUPPLIER_SUBMIT':
1151 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1152 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1153 $object_type =
'order_supplier';
1154 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1155 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs));
1156 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1158 case 'ORDER_SUPPLIER_REFUSE':
1159 $link =
'<a href="'.$urlwithroot.
'/fourn/commande/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1160 $dir_output = $conf->fournisseur->commande->multidir_output[
$object->entity].
"/".
get_exdir(0, 0, 0, 1,
$object);
1161 $object_type =
'order_supplier';
1162 $mesg = $langs->transnoentitiesnoconv(
"Hello").
",\n\n";
1163 $mesg .= $langs->transnoentitiesnoconv(
"EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs));
1164 $mesg .=
"\n\n".$langs->transnoentitiesnoconv(
"Sincerely").
".\n\n";
1166 case 'SHIPPING_VALIDATE':
1167 $link =
'<a href="'.$urlwithroot.
'/expedition/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1168 $dir_output = $conf->expedition->dir_output.
"/sending/".
get_exdir(0, 0, 0, 1,
$object,
'shipment');
1169 $object_type =
'order_supplier';
1170 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpeditionValidated", $link);
1172 case 'EXPENSE_REPORT_VALIDATE':
1173 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1174 $dir_output = $conf->expensereport->dir_output;
1175 $object_type =
'expensereport';
1176 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportValidated", $link);
1178 case 'EXPENSE_REPORT_APPROVE':
1179 $link =
'<a href="'.$urlwithroot.
'/expensereport/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1180 $dir_output = $conf->expensereport->dir_output;
1181 $object_type =
'expensereport';
1182 $mesg = $langs->transnoentitiesnoconv(
"EMailTextExpenseReportApproved", $link);
1184 case 'HOLIDAY_VALIDATE':
1185 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1186 $dir_output = $conf->holiday->dir_output;
1187 $object_type =
'holiday';
1188 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayValidated", $link);
1190 case 'HOLIDAY_APPROVE':
1191 $link =
'<a href="'.$urlwithroot.
'/holiday/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1192 $dir_output = $conf->holiday->dir_output;
1193 $object_type =
'holiday';
1194 $mesg = $langs->transnoentitiesnoconv(
"EMailTextHolidayApproved", $link);
1196 case 'ACTION_CREATE':
1197 $link =
'<a href="'.$urlwithroot.
'/comm/action/card.php?id='.
$object->id.
'&entity='.
$object->entity.
'">'.$newref.
'</a>';
1198 $dir_output = $conf->agenda->dir_output;
1199 $object_type =
'action';
1200 $mesg = $langs->transnoentitiesnoconv(
"EMailTextActionAdded", $link);
1203 $object_type =
$object->element;
1204 $dir_output = $conf->$object_type->multidir_output[
$object->entity ?
$object->entity : $conf->entity].
"/".
get_exdir(0, 0, 0, 1,
$object, $object_type);
1205 $mesg = $langs->transnoentitiesnoconv(
'Notify_'.$notifcode).
' '.$newref;
1209 $pdf_path = $dir_output.
"/".$ref.
"/".$ref.
".pdf";
1214 $filepdf = $pdf_path;
1215 $filename_list[] = $pdf_path;
1216 $mimetype_list[] = mime_content_type($filepdf);
1217 $mimefilename_list[] = $ref.
".pdf";
1221 $outputlangs = $langs;
1226 $emailTemplate =
null;
1227 if (!empty($mailTemplateLabel)) {
1228 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1229 $formmail =
new FormMail($this->db);
1230 $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.
'_send', $user, $outputlangs, 0, 1, $mailTemplateLabel);
1232 if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) {
1233 if (property_exists(
$object,
'thirdparty')) {
1238 if (
$object->thirdparty instanceof
Societe &&
$object->thirdparty->default_lang &&
$object->thirdparty->default_lang != $langs->defaultlang) {
1239 $outputlangs =
new Translate(
'', $conf);
1240 $outputlangs->setDefaultLang(
$object->thirdparty->default_lang);
1241 $outputlangs->loadLangs(array(
'main',
'other'));
1247 $subject =
make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs);
1248 $message =
make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs);
1251 $message .= $outputlangs->transnoentities(
"YouReceiveMailBecauseOfNotification2", $application, $mysoc->name).
"\n";
1255 $message = nl2br($message);
1259 if (preg_match(
'/__SUPERVISOREMAIL__/', $sendto)) {
1261 if ($user->fk_user > 0) {
1262 $supervisoruser =
new User($this->db);
1263 $supervisoruser->fetch($user->fk_user);
1264 if ($supervisoruser->email) {
1265 $newval = trim(
dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).
' <'.$supervisoruser->email.
'>');
1268 dol_syslog(
"Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
1269 $sendto = preg_replace(
'/__SUPERVISOREMAIL__/', $newval, $sendto);
1270 $sendto = preg_replace(
'/,\s*,/',
',', $sendto);
1271 $sendto = preg_replace(
'/^[\s,]+/',
'', $sendto);
1272 $sendto = preg_replace(
'/[\s,]+$/',
'', $sendto);
1276 $parameters = array(
'notifcode' => $notifcode,
'sendto' => $sendto,
'from' => $from,
'file' => $filename_list,
'mimefile' => $mimetype_list,
'filename' => $mimefilename_list,
'subject' => &$subject,
'message' => &$message);
1277 $reshook = $hookmanager->executeHooks(
'formatNotificationMessage', $parameters,
$object, $action);
1278 if (empty($reshook)) {
1279 if (!empty($hookmanager->resArray[
'files'])) {
1280 $filename_list = $hookmanager->resArray[
'files'][
'file'];
1281 $mimetype_list = $hookmanager->resArray[
'files'][
'mimefile'];
1282 $mimefilename_list = $hookmanager->resArray[
'files'][
'filename'];
1284 if (!empty($hookmanager->resArray[
'subject'])) {
1285 $subject .= $hookmanager->resArray[
'subject'];
1287 if (!empty($hookmanager->resArray[
'message'])) {
1288 $message .= $hookmanager->resArray[
'message'];
1310 if (! empty($mailfile->error) || ! empty($mailfile->errors)) {
1311 $this->error = $mailfile->error;
1312 $this->errors = $mailfile->errors;
1316 if ($mailfile->sendfile()) {
1317 $sql =
"INSERT INTO ".$this->db->prefix().
"notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)";
1318 $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).
"')";
1319 if (!$this->db->query($sql)) {
1324 $this->errors[] = $mailfile->error;