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="trackid" value="'.$this->trackid.
'" />';
570 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
572 if (!empty($this->withfrom)) {
573 if (!empty($this->withfromreadonly)) {
574 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
575 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
578 foreach ($this->param as $key => $value) {
579 if (is_array($value)) {
580 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
582 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
586 $modelmail_array = array();
587 if ($this->param[
'models'] !=
'none') {
593 foreach ($this->lines_model as $line) {
595 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
596 $labeltouse = $langs->trans($reg[1]);
598 $labeltouse = $line->label;
604 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
606 if ($line->private) {
607 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
613 if (count($modelmail_array) > 0) {
614 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOSTINT(
'modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
617 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
619 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans(
'SelectMailModel'), 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
621 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
625 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
628 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
629 'propal_send',
'order_send',
'facture_send',
630 'shipping_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
631 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'product_send',
'all'
634 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
635 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
636 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
638 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
641 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
645 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
649 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
652 $helpforsubstitution =
'';
653 if (is_array($this->substit) && count($this->substit)) {
654 $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__'))) {
663 if (is_array($this->substit) && count($this->substit)) {
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)
690 && !preg_match(
'/from_template_(\d+)/', $this->fromtype)
693 $out .= $this->fromname;
694 if ($this->frommail) {
695 $out .=
' <'.$this->frommail.
'>';
697 if ($this->fromtype) {
698 $langs->load(
'errors');
699 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
706 if (empty($user->email)) {
707 $langs->load(
'errors');
708 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
710 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
712 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
717 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
721 $listaliases = array(
722 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
726 if (!empty($arraydefaultmessage->email_from)) {
727 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
728 $liste[
'from_template_'.$arraydefaultmessage->id] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
732 if (!empty($this->fromalsorobot)) {
735 if ($this->frommail) {
738 $liste[
'main_from'] = array(
'label' => $s,
'data-html' => $s);
743 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
744 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
") AND entity IN (".
getEntity(
'c_email_senderprofile').
")";
745 $sql .=
" ORDER BY position";
746 $resql = $this->db->query($sql);
748 $num = $this->db->num_rows($resql);
751 $obj = $this->db->fetch_object($resql);
753 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
761 foreach ($listaliases as $typealias => $listalias) {
763 $listaliasarray = explode(
',', $listalias);
764 foreach ($listaliasarray as $listaliasval) {
766 $listaliasval = trim($listaliasval);
768 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
769 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
770 if (!preg_match(
'/</', $listaliasval)) {
771 $listaliasval =
'<'.$listaliasval.
'>';
773 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
781 foreach ($liste as $key => $val) {
782 if (!empty($liste[$key][
'data-html'])) {
783 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
784 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
787 $out .=
' '.$form->selectarray(
'fromtype', $liste, empty($arraydefaultmessage->email_from) ? $this->fromtype :
'from_template_'.$arraydefaultmessage->id, 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 1,
'', $disablebademails);
790 $out .=
"</td></tr>\n";
792 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
793 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
794 $out .=
' ';
795 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
796 $out .=
"</td></tr>\n";
801 if (!empty($this->withto) || is_array($this->withto)) {
806 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
808 $out .= $langs->trans(
"MailToUsers");
812 $tmparray = $this->withtouser;
813 foreach ($tmparray as $key => $val) {
816 $withtoselected =
GETPOST(
"receiveruser",
'array');
817 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
818 $withtoselected = array_keys($tmparray);
820 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
821 $out .=
"</td></tr>\n";
825 if (!empty($this->withoptiononeemailperrecipient)) {
826 if (abs($this->withoptiononeemailperrecipient) == 1) {
827 $out .=
'<tr><td class="minwidth200">';
828 $out .= $langs->trans(
"GroupEmails");
830 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
831 $out .=
'<label for="oneemailperrecipient">';
832 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
838 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
839 if (!empty($this->withto) && !is_array($this->withto)) {
840 $out .=
' '.$langs->trans(
"or").
' <input type="email" name="emailto" value="">';
843 $out .=
'</td></tr>';
845 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
850 if (!empty($this->withtocc) || is_array($this->withtocc)) {
855 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
857 $out .= $langs->trans(
"MailToCCUsers");
861 $tmparray = $this->withtoccuser;
862 foreach ($tmparray as $key => $val) {
865 $withtoselected =
GETPOST(
"receiverccuser",
'array');
866 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
867 $withtoselected = array_keys($tmparray);
869 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
870 $out .=
"</td></tr>\n";
874 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
879 if (!empty($this->withreplyto)) {
880 if ($this->withreplytoreadonly) {
881 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
882 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
883 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
884 $out .=
"</td></tr>\n";
889 if (!empty($this->witherrorsto)) {
894 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
899 if (!empty($this->withtopic)) {
900 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
904 if (!empty($this->withfile)) {
906 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
910 if ($this->withmaindocfile) {
912 if (GETPOSTISSET(
'sendmail')) {
913 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
914 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
916 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
920 if (!empty($this->withmaindocfile)) {
921 if ($this->withmaindocfile == 1) {
922 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
923 } elseif ($this->withmaindocfile == -1) {
924 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
927 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
929 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
933 if (is_numeric($this->withfile)) {
935 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
936 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
937 $out .=
'jQuery(document).ready(function () {';
938 $out .=
' jQuery(".removedfile").click(function() {';
939 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
942 $out .=
'</script>'.
"\n";
943 if (count($listofpaths)) {
944 foreach ($listofpaths as $key => $val) {
945 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
947 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] :
$conf->entity);
949 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
952 $formfile_params = array();
953 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
955 $out .=
'<div id="attachfile_'.$key.
'">';
957 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
959 $out .=
' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
961 if (!$this->withfilereadonly) {
962 $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.
'" />';
965 $out .=
'<br></div>';
970 if ($this->withfile == 2) {
972 $maxmin = $maxfilesizearray[
'maxmin'];
974 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
978 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
980 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
983 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
986 $out .= $this->withfile;
989 $out .=
"</td></tr>\n";
993 if (!empty($this->withbody)) {
994 $defaultmessage =
GETPOST(
'message',
'restricthtml');
995 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
996 if ($arraydefaultmessage && $arraydefaultmessage->content) {
997 $defaultmessage = (string) $arraydefaultmessage->content;
998 } elseif (!is_numeric($this->withbody)) {
999 $defaultmessage = $this->withbody;
1006 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1007 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1009 if (empty($this->substit[
'__REF__'])) {
1012 $langs->loadLangs(array(
'paypal',
'other'));
1013 $typeforonlinepayment =
'free';
1014 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1015 $typeforonlinepayment =
'order';
1017 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1018 $typeforonlinepayment =
'invoice';
1020 if ($this->param[
"models"] ==
'member') {
1021 $typeforonlinepayment =
'member';
1023 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1027 if (count($validpaymentmethod) > 0 && $paymenturl) {
1028 $langs->load(
'other');
1029 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
1030 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
1031 } elseif (count($validpaymentmethod) > 0) {
1032 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
1033 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
1035 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1036 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1039 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1043 $defaultlines = $arraydefaultmessage->content_lines;
1044 if (isset($defaultlines)) {
1045 foreach ($this->substit_lines as $lineid => $substit_line) {
1049 $this->substit[
'__LINES__'] = $lines;
1051 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1054 $atleastonecomponentishtml = 0;
1055 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1056 $atleastonecomponentishtml++;
1058 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1059 $atleastonecomponentishtml++;
1061 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1062 $atleastonecomponentishtml++;
1064 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1065 $atleastonecomponentishtml++;
1068 $atleastonecomponentishtml++;
1070 if ($atleastonecomponentishtml) {
1072 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1074 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1075 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1078 $this->substit[
'__LINES__'] =
dol_nl2br($this->substit[
'__LINES__']);
1080 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1081 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1084 $defaultmessage =
dol_nl2br($defaultmessage);
1088 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
1089 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1096 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1097 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1101 $out .=
'<td class="tdtop">';
1102 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1104 $out .=
'<td class="tdtop">';
1107 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1108 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1109 $showlinktoai = ($formmail->withaiprompt && isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1110 $showlinktoailabel = $langs->trans(
"AIEnhancements");
1111 $formatforouput =
'';
1112 $htmlname =
'message';
1114 $formai->substit = $this->substit;
1115 $formai->substit_lines = $this->substit_lines;
1119 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1125 $out .=
'<td colspan="2">';
1126 if ($this->withbodyreadonly) {
1127 $out .= nl2br($defaultmessage);
1128 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1130 if (!isset($this->ckeditortoolbar)) {
1131 $this->ckeditortoolbar =
'dolibarr_mailings';
1135 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1136 if ($this->withfckeditor == -1) {
1138 $this->withfckeditor = 1;
1140 $this->withfckeditor = 0;
1144 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1145 $out .= $doleditor->Create(1);
1147 $out .=
"</td></tr>\n";
1150 $out .=
'</table>'.
"\n";
1152 if ($this->withform == 1 || $this->withform == -1) {
1153 $out .=
'<div class="center">';
1154 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1156 if ($this->withfile == 2 &&
$conf->use_javascript_ajax) {
1157 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1160 if ($this->withcancel) {
1161 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1163 $out .= '</div>'."\n
";
1166 if ($this->withform == 1) {
1167 $out .= '</form>'."\n
";
1170 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1171 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1172 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1173 $out .= 'jQuery(document).ready(function () {';
1174 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1175 var code = e.keyCode || e.which;
1177 console.log("Enter was intercepted and blocked
");
1183 $out .= '</script>';
1186 $out .= "<!-- End form mail -->\n
";
1965 public function setSubstitFromObject($object, $outputlangs)
1967 global $extrafields;
1969 $parameters = array();
1970 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1971 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1973 $this->substit = $tmparray;
1975 // Fill substit_lines with each object lines content
1976 if (is_array($object->lines)) {
1977 foreach ($object->lines as $line) {
1978 $substit_line = array(
1979 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1980 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1981 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1982 '__LABEL__' => isset($line->label) ? $line->label : '',
1983 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1984 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
1985 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
1986 '__QUANTITY__' => $line->qty,
1987 '__SUBPRICE__' => price($line->subprice),
1988 '__AMOUNT__' => price($line->total_ttc),
1989 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1992 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1993 if (!empty($line->fk_product)) {
1994 if (!is_object($extrafields)) {
1995 $extrafields = new ExtraFields($this->db);
1997 $product = new Product($this->db);
1998 $product->fetch($line->fk_product, '', '', '1');
1999 $product->fetch_optionals();
2001 $extrafields->fetch_name_optionals_label($product->table_element, true);
2003 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2004 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2005 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2010 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2023 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2027 $tmparray = array();
2028 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2029 $parameters = array('mode' => $mode);
2030 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
2031 complete_substitutions_array($tmparray, $langs, null, $parameters);
2033 if ($mode == 'formwithlines') {
2034 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2036 if ($mode == 'formforlines') {
2037 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2041 if ($mode == 'emailing') {
2042 $parameters = array('mode' => $mode);
2043 $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
2044 complete_substitutions_array($tmparray, $langs, null, $parameters);
2046 // For mass emailing, we have different keys specific to the data into tagerts list
2047 $tmparray['__ID__'] = 'IdRecord';
2048 $tmparray['__EMAIL__'] = 'EMailRecipient';
2049 $tmparray['__LASTNAME__'] = 'Lastname';
2050 $tmparray['__FIRSTNAME__'] = 'Firstname';
2051 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2052 $tmparray['__OTHER1__'] = 'Other1';
2053 $tmparray['__OTHER2__'] = 'Other2';
2054 $tmparray['__OTHER3__'] = 'Other3';
2055 $tmparray['__OTHER4__'] = 'Other4';
2056 $tmparray['__OTHER5__'] = 'Other5';
2058 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode'; // If source is a thirdparty
2060 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2061 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2062 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2064 $onlinepaymentenabled = 0;
2065 if (isModEnabled('paypal')) {
2066 $onlinepaymentenabled++;
2068 if (isModEnabled('paybox')) {
2069 $onlinepaymentenabled++;
2071 if (isModEnabled('stripe')) {
2072 $onlinepaymentenabled++;
2074 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2075 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2076 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
2077 if (isModEnabled('member')) {
2078 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2080 if (isModEnabled('don')) {
2081 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2083 if (isModEnabled('invoice')) {
2084 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2086 if (isModEnabled('order')) {
2087 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2089 if (isModEnabled('contract')) {
2090 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2093 //Online payment link
2094 if (isModEnabled('member')) {
2095 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2097 if (isModEnabled('don')) {
2098 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2100 if (isModEnabled('invoice')) {
2101 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2103 if (isModEnabled('order')) {
2104 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2106 if (isModEnabled('contract')) {
2107 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2111 /* No need to show into tooltip help, option is not enabled
2112 $vars['__SECUREKEYPAYMENT__']='';
2113 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2114 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2115 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2116 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2119 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2120 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2124 foreach ($tmparray as $key => $val) {
2126 $tmparray[$key] = $key;