471 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
474 global $conf, $langs, $user, $hookmanager, $form;
476 if (!is_object($form)) {
477 $form =
new Form($this->db);
481 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
482 $formfile =
new FormFile($this->db);
484 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formai.class.php';
485 $formai =
new FormAI($this->db);
488 $langs->loadLangs(array(
'other',
'mails',
'members'));
491 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
496 $hookmanager->initHooks(array(
'formmail'));
499 'addfileaction' => $addfileaction,
500 'removefileaction' => $removefileaction,
501 'trackid' => $this->trackid
503 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
505 if (!empty($reshook)) {
506 return $hookmanager->resPrint;
510 $disablebademails = 1;
513 $outputlangs = $langs;
515 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
516 $newlang = $this->param[
'langsmodels'];
518 if (!empty($newlang)) {
520 $outputlangs->setDefaultLang($newlang);
521 $outputlangs->load(
'other');
525 $arraydefaultmessage = -1;
526 if ($this->param[
'models'] !=
'none') {
528 if (array_key_exists(
'models_id', $this->param)) {
529 $model_id = $this->param[
"models_id"];
532 $arraydefaultmessage = $this->
getEMailTemplate($this->db, $this->param[
"models"], $user, $outputlangs, $model_id, 1,
'', ($model_id > 0 ? -1 : 1));
536 $listofpaths = array();
537 $listofnames = array();
538 $listofmimes = array();
539 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
541 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
542 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
543 foreach ($this->param[
'fileinit'] as $path) {
551 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
552 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
554 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
555 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
557 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
558 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
562 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
563 if ($this->withform == 1) {
564 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
566 $out .=
'<a id="formmail" name="formmail"></a>';
567 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
568 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
569 $out .=
'<input type="hidden" name="page_y" value="" />';
570 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
571 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
573 if (!empty($this->withfrom)) {
574 if (!empty($this->withfromreadonly)) {
575 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
576 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
579 foreach ($this->param as $key => $value) {
580 if (is_array($value)) {
581 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
583 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
587 $modelmail_array = array();
588 if ($this->param[
'models'] !=
'none') {
594 foreach ($this->lines_model as $line) {
596 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
597 $labeltouse = $langs->trans($reg[1]);
599 $labeltouse = $line->label;
605 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
607 if ($line->private) {
608 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
614 if (count($modelmail_array) > 0) {
615 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOSTINT(
'modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
618 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
620 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans(
'SelectMailModel'), 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
622 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
626 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
629 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
630 'propal_send',
'order_send',
'facture_send',
631 'shipping_send',
'reception_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
632 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'product_send',
'all'
635 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
636 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
637 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
639 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
642 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
646 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
650 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
653 $helpforsubstitution =
'';
654 if (is_array($this->substit) && count($this->substit)) {
655 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
656 foreach ($this->substit as $key => $val) {
658 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
661 if (is_array($val)) $val = implode(
', ', $val);
664 $helpforsubstitution .=
'</span>';
679 if (!empty($this->withfrom)) {
680 if (!empty($this->withfromreadonly)) {
681 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
684 if (!($this->fromtype ===
'user' && $this->fromid > 0)
685 && !($this->fromtype ===
'company')
686 && !($this->fromtype ===
'robot')
687 && !preg_match(
'/user_aliases/', $this->fromtype)
688 && !preg_match(
'/global_aliases/', $this->fromtype)
689 && !preg_match(
'/senderprofile/', $this->fromtype)
692 $out .= $this->fromname;
693 if ($this->frommail) {
694 $out .=
' <'.$this->frommail.
'>';
696 if ($this->fromtype) {
697 $langs->load(
'errors');
698 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
705 if (empty($user->email)) {
706 $langs->load(
'errors');
707 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
709 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
711 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
716 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
720 $listaliases = array(
721 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
725 if (!empty($arraydefaultmessage->email_from) && !empty($arraydefaultmessage->id)) {
726 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
727 $liste[
'from_template_'.((int) $arraydefaultmessage->id)] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
731 if (!empty($this->fromalsorobot)) {
734 if ($this->frommail) {
737 $liste[
'main_from'] = array(
'label' => $s,
'data-html' => $s);
742 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
743 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
") AND entity IN (".
getEntity(
'c_email_senderprofile').
")";
744 $sql .=
" ORDER BY position";
745 $resql = $this->db->query($sql);
747 $num = $this->db->num_rows($resql);
750 $obj = $this->db->fetch_object($resql);
752 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
760 foreach ($listaliases as $typealias => $listalias) {
762 $listaliasarray = explode(
',', $listalias);
763 foreach ($listaliasarray as $listaliasval) {
765 $listaliasval = trim($listaliasval);
767 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
768 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
769 if (!preg_match(
'/</', $listaliasval)) {
770 $listaliasval =
'<'.$listaliasval.
'>';
772 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
780 foreach ($liste as $key => $val) {
781 if (!empty($liste[$key][
'data-html'])) {
782 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
783 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
786 $out .=
' '.$form->selectarray(
'fromtype', $liste, (empty($arraydefaultmessage->email_from) || empty($arraydefaultmessage->id)) ? $this->fromtype :
'from_template_'.((int) $arraydefaultmessage->id), 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 1,
'', $disablebademails);
789 $out .=
"</td></tr>\n";
791 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
792 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
793 $out .=
' ';
794 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
795 $out .=
"</td></tr>\n";
800 if (!empty($this->withto) || is_array($this->withto)) {
805 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
807 $out .= $langs->trans(
"MailToUsers");
811 $tmparray = $this->withtouser;
812 foreach ($tmparray as $key => $val) {
815 $withtoselected =
GETPOST(
"receiveruser",
'array');
816 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
817 $withtoselected = array_keys($tmparray);
819 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
820 $out .=
"</td></tr>\n";
824 if (!empty($this->withoptiononeemailperrecipient)) {
825 if (abs($this->withoptiononeemailperrecipient) == 1) {
826 $out .=
'<tr><td class="minwidth200">';
827 $out .= $langs->trans(
"GroupEmails");
829 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
830 $out .=
'<label for="oneemailperrecipient">';
831 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
837 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
838 if (!empty($this->withto) && !is_array($this->withto)) {
839 $out .=
' <span class="opacitymedium">'.$langs->trans(
"or").
'</span> <input type="email" name="emailto" value="">';
842 $out .=
'</td></tr>';
844 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
849 if (!empty($this->withtocc) || is_array($this->withtocc)) {
854 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
856 $out .= $langs->trans(
"MailToCCUsers");
860 $tmparray = $this->withtoccuser;
861 foreach ($tmparray as $key => $val) {
864 $withtoselected =
GETPOST(
"receiverccuser",
'array');
865 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
866 $withtoselected = array_keys($tmparray);
868 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
869 $out .=
"</td></tr>\n";
873 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
878 if (!empty($this->withreplyto)) {
879 if ($this->withreplytoreadonly) {
880 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
881 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
882 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
883 $out .=
"</td></tr>\n";
888 if (!empty($this->witherrorsto)) {
893 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
898 if (!empty($this->withtopic)) {
899 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
903 if (!empty($this->withfile)) {
905 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
909 if ($this->withmaindocfile) {
911 if (GETPOSTISSET(
'sendmail')) {
912 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
913 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
915 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
919 if (!empty($this->withmaindocfile)) {
920 if ($this->withmaindocfile == 1) {
921 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
922 } elseif ($this->withmaindocfile == -1) {
923 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
926 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
928 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
932 if (is_numeric($this->withfile)) {
934 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
935 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
936 $out .=
'jQuery(document).ready(function () {';
937 $out .=
' jQuery(".removedfile").click(function() {';
938 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
941 $out .=
'</script>'.
"\n";
942 if (count($listofpaths)) {
943 foreach ($listofpaths as $key => $val) {
944 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
946 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] : $conf->entity);
948 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
951 $formfile_params = array();
952 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
954 $out .=
'<div id="attachfile_'.$key.
'">';
956 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
958 $out .=
' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
960 if (!$this->withfilereadonly) {
961 $out .=
' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.
'/theme/'.$conf->theme.
'/img/delete.png" value="'.($key + 1).
'" class="removedfile input-nobottom" id="removedfile_'.$key.
'" name="removedfile_'.$key.
'" />';
964 $out .=
'<br></div>';
969 if ($this->withfile == 2) {
971 $maxmin = $maxfilesizearray[
'maxmin'];
973 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
977 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
979 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
982 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
985 $out .= $this->withfile;
988 $out .=
"</td></tr>\n";
992 if (!empty($this->withbody)) {
993 $defaultmessage =
GETPOST(
'message',
'restricthtml');
994 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
995 if ($arraydefaultmessage && $arraydefaultmessage->content) {
996 $defaultmessage = (string) $arraydefaultmessage->content;
997 } elseif (!is_numeric($this->withbody)) {
998 $defaultmessage = $this->withbody;
1005 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1006 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1008 if (empty($this->substit[
'__REF__'])) {
1011 $langs->loadLangs(array(
'paypal',
'other'));
1012 $typeforonlinepayment =
'free';
1013 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1014 $typeforonlinepayment =
'order';
1016 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1017 $typeforonlinepayment =
'invoice';
1019 if ($this->param[
"models"] ==
'member') {
1020 $typeforonlinepayment =
'member';
1022 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1026 if (count($validpaymentmethod) > 0 && $paymenturl) {
1027 $langs->load(
'other');
1028 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
1029 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
1030 } elseif (count($validpaymentmethod) > 0) {
1031 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
1032 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
1034 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1035 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1038 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1042 $defaultlines = $arraydefaultmessage->content_lines;
1043 if (isset($defaultlines)) {
1044 foreach ($this->substit_lines as $lineid => $substit_line) {
1048 $this->substit[
'__LINES__'] = $lines;
1050 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1053 $atleastonecomponentishtml = 0;
1054 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1055 $atleastonecomponentishtml++;
1057 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1058 $atleastonecomponentishtml++;
1060 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1061 $atleastonecomponentishtml++;
1063 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1064 $atleastonecomponentishtml++;
1067 $atleastonecomponentishtml++;
1069 if ($atleastonecomponentishtml) {
1071 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1073 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1074 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1077 $this->substit[
'__LINES__'] =
dol_nl2br($this->substit[
'__LINES__']);
1079 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1080 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1083 $defaultmessage =
dol_nl2br($defaultmessage);
1087 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
1088 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1095 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1096 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1100 $out .=
'<td class="tdtop">';
1101 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1103 $out .=
'<td class="tdtop">';
1106 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1107 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1108 $showlinktoai = ($formmail->withaiprompt &&
isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1109 $showlinktoailabel = $langs->trans(
"AIEnhancements");
1110 $formatforouput =
'';
1111 $htmlname =
'message';
1113 $formai->substit = $this->substit;
1114 $formai->substit_lines = $this->substit_lines;
1118 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1124 $out .=
'<td colspan="2">';
1125 if ($this->withbodyreadonly) {
1126 $out .= nl2br($defaultmessage);
1127 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1129 if (!isset($this->ckeditortoolbar)) {
1130 $this->ckeditortoolbar =
'dolibarr_mailings';
1134 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1135 if ($this->withfckeditor == -1) {
1137 $this->withfckeditor = 1;
1139 $this->withfckeditor = 0;
1143 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1144 $out .= $doleditor->Create(1);
1146 $out .=
"</td></tr>\n";
1149 $out .=
'</table>'.
"\n";
1151 if ($this->withform == 1 || $this->withform == -1) {
1152 $out .=
'<div class="center">';
1153 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1155 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1156 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1159 if ($this->withcancel) {
1160 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1162 $out .= '</div>'."\n
";
1165 if ($this->withform == 1) {
1166 $out .= '</form>'."\n
";
1169 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1170 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1171 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1172 $out .= 'jQuery(document).ready(function () {';
1173 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1174 var code = e.keyCode || e.which;
1176 console.log("Enter was intercepted and blocked
");
1182 $out .= '</script>';
1185 $out .= "<!-- End form mail -->\n
";
1758 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1762 if ($id == -2 && empty($label)) {
1763 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1766 if ($type_template === 'societe') {
1767 $type_template = 'thirdparty';
1769 $ret = new CEmailTemplate($dbs);
1771 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1772 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1773 $tmparray = explode('_', $languagetosearch);
1774 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1775 if ($languagetosearchmain == $languagetosearch) {
1776 $languagetosearchmain = '';
1779 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1780 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1781 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'".$dbs->escape($type_template)."_send' OR type_template =
'all')
";
1782 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1783 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1785 $sql .= " AND
active =
".((int) $active);
1787 if ($defaultfortype >= 0) {
1788 $sql .= " AND defaultfortype =
".((int) $defaultfortype);
1791 $sql .= " AND label =
'".$dbs->escape($label)."'";
1793 if (!($id > 0) && $languagetosearch) {
1794 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1797 $sql .= " AND rowid =
".(int) $id;
1802 $sql .= " AND entity IN(
".getEntity('c_email_templates', 1).")
";
1803 if ($languagetosearch) {
1804 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1806 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1808 //$sql .= $dbs->plimit(1);
1811 $resql = $dbs->query($sql);
1813 dol_print_error($dbs);
1819 $obj = $dbs->fetch_object($resql);
1822 // If template is for a module, check module is enabled; if not, take next template
1824 $tempmodulekey = $obj->module;
1825 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1830 // If a record was found
1831 $ret->id = (int) $obj->rowid;
1832 $ret->module = (string) $obj->module;
1833 $ret->label = (string) $obj->label;
1834 $ret->lang = $obj->lang;
1835 $ret->topic = $obj->topic;
1836 $ret->content = (string) $obj->content;
1837 $ret->content_lines = (string) $obj->content_lines;
1838 $ret->joinfiles = $obj->joinfiles;
1839 $ret->email_from = (string) $obj->email_from;
1843 // If no record found
1845 // Not found with the provided label
1848 // If there is no template at all
1849 $defaultmessage = '';
1851 if ($type_template == 'body') {
1852 // Special case to use this->withbody as content
1853 $defaultmessage = (string) $this->withbody;
1854 } elseif ($type_template == 'facture_send' || $type_template == 'facture' || $type_template == 'facture_relance') {
1855 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1856 } elseif ($type_template == 'propal_send' || $type_template == 'propal') {
1857 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1858 } elseif ($type_template == 'supplier_proposal_send' || $type_template == 'supplier_proposal') {
1859 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1860 } elseif ($type_template == 'order_send' || $type_template == 'order') {
1861 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1862 } elseif ($type_template == 'order_supplier_send' || $type_template == 'order_supplier') {
1863 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1864 } elseif ($type_template == 'invoice_supplier_send' || $type_template == 'invoice_supplier') {
1865 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1866 } elseif ($type_template == 'shipping_send' || $type_template == 'shipping') {
1867 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1868 } elseif ($type_template == 'reception_send' || $type_template == 'reception') {
1869 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendReception
");
1870 } elseif ($type_template == 'fichinter_send' || $type_template == 'fichinter') {
1871 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1872 } elseif ($type_template == 'actioncomm_send' || $type_template == 'actioncomm') {
1873 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1874 } elseif (!empty($type_template)) {
1875 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1878 $ret->label = 'default';
1879 $ret->lang = $outputlangs->defaultlang;
1881 $ret->joinfiles = 1;
1882 $ret->content = $defaultmessage;
1883 $ret->content_lines = '';
1998 public function setSubstitFromObject($object, $outputlangs)
2000 global $extrafields;
2002 $parameters = array();
2003 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
2004 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
2006 $this->substit = $tmparray;
2008 // Fill substit_lines with each object lines content
2009 if (is_array($object->lines)) {
2010 foreach ($object->lines as $line) {
2011 $substit_line = array(
2012 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
2013 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
2014 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
2015 '__LABEL__' => isset($line->label) ? $line->label : '',
2016 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
2017 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
2018 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
2019 '__QUANTITY__' => $line->qty,
2020 '__SUBPRICE__' => price($line->subprice),
2021 '__AMOUNT__' => price($line->total_ttc),
2022 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
2025 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2026 if (!empty($line->fk_product)) {
2027 if (!is_object($extrafields)) {
2028 $extrafields = new ExtraFields($this->db);
2030 $product = new Product($this->db);
2031 $product->fetch($line->fk_product, '', '', '1');
2032 $product->fetch_optionals();
2034 $extrafields->fetch_name_optionals_label($product->table_element, true);
2036 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2037 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2038 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2043 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2056 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2060 $tmparray = array();
2061 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2062 $parameters = array('mode' => $mode);
2063 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
2064 complete_substitutions_array($tmparray, $langs, null, $parameters);
2066 if ($mode == 'formwithlines') {
2067 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2069 if ($mode == 'formforlines') {
2070 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2074 if ($mode == 'emailing') {
2075 $parameters = array('mode' => $mode);
2076 $tmparray = getCommonSubstitutionArray($langs, 2, array('object', 'objectamount'), $object); // Note: On email templated edition, this is null because it is related to all type of objects
2077 complete_substitutions_array($tmparray, $langs, null, $parameters);
2079 // For mass emailing, we have different keys specific to the data into tagerts list
2080 $tmparray['__ID__'] = 'IdRecord';
2081 $tmparray['__EMAIL__'] = 'EMailRecipient';
2082 $tmparray['__LASTNAME__'] = 'Lastname';
2083 $tmparray['__FIRSTNAME__'] = 'Firstname';
2084 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2085 $tmparray['__OTHER1__'] = 'Other1';
2086 $tmparray['__OTHER2__'] = 'Other2';
2087 $tmparray['__OTHER3__'] = 'Other3';
2088 $tmparray['__OTHER4__'] = 'Other4';
2089 $tmparray['__OTHER5__'] = 'Other5';
2091 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode'; // If source is a thirdparty
2093 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2094 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2095 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2097 $onlinepaymentenabled = 0;
2098 if (isModEnabled('paypal')) {
2099 $onlinepaymentenabled++;
2101 if (isModEnabled('paybox')) {
2102 $onlinepaymentenabled++;
2104 if (isModEnabled('stripe')) {
2105 $onlinepaymentenabled++;
2107 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2108 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2109 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
2110 if (isModEnabled('member')) {
2111 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2113 if (isModEnabled('don')) {
2114 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2116 if (isModEnabled('invoice')) {
2117 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2119 if (isModEnabled('order')) {
2120 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2122 if (isModEnabled('contract')) {
2123 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2126 //Online payment link
2127 if (isModEnabled('member')) {
2128 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2130 if (isModEnabled('don')) {
2131 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2133 if (isModEnabled('invoice')) {
2134 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2136 if (isModEnabled('order')) {
2137 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2139 if (isModEnabled('contract')) {
2140 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2144 /* No need to show into tooltip help, option is not enabled
2145 $vars['__SECUREKEYPAYMENT__']='';
2146 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2147 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2148 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2149 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2152 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2153 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2157 foreach ($tmparray as $key => $val) {
2159 $tmparray[$key] = $key;