470 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
473 global
$conf, $langs, $user, $hookmanager, $form;
475 if (!is_object($form)) {
476 $form =
new Form($this->db);
480 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
481 $formfile =
new FormFile($this->db);
483 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formai.class.php';
484 $formai =
new FormAI($this->db);
487 $langs->loadLangs(array(
'other',
'mails',
'members'));
490 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
495 $hookmanager->initHooks(array(
'formmail'));
498 'addfileaction' => $addfileaction,
499 'removefileaction' => $removefileaction,
500 'trackid' => $this->trackid
502 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
504 if (!empty($reshook)) {
505 return $hookmanager->resPrint;
509 $disablebademails = 1;
512 $outputlangs = $langs;
514 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
515 $newlang = $this->param[
'langsmodels'];
517 if (!empty($newlang)) {
519 $outputlangs->setDefaultLang($newlang);
520 $outputlangs->load(
'other');
524 $arraydefaultmessage = -1;
525 if ($this->param[
'models'] !=
'none') {
527 if (array_key_exists(
'models_id', $this->param)) {
528 $model_id = $this->param[
"models_id"];
531 $arraydefaultmessage = $this->
getEMailTemplate($this->db, $this->param[
"models"], $user, $outputlangs, $model_id, 1,
'', ($model_id > 0 ? -1 : 1));
535 $listofpaths = array();
536 $listofnames = array();
537 $listofmimes = array();
538 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
540 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
541 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
542 foreach ($this->param[
'fileinit'] as $path) {
550 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
551 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
553 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
554 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
556 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
557 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
561 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
562 if ($this->withform == 1) {
563 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
565 $out .=
'<a id="formmail" name="formmail"></a>';
566 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
567 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
568 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
569 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
571 if (!empty($this->withfrom)) {
572 if (!empty($this->withfromreadonly)) {
573 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
574 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
577 foreach ($this->param as $key => $value) {
578 if (is_array($value)) {
579 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
581 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
585 $modelmail_array = array();
586 if ($this->param[
'models'] !=
'none') {
592 foreach ($this->lines_model as $line) {
594 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
595 $labeltouse = $langs->trans($reg[1]);
597 $labeltouse = $line->label;
603 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
605 if ($line->private) {
606 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
612 if (count($modelmail_array) > 0) {
613 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOSTINT(
'modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
616 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
618 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans(
'SelectMailModel'), 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
620 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
624 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
627 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
628 'propal_send',
'order_send',
'facture_send',
629 'shipping_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
630 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'product_send',
'all'
633 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
634 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
635 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
637 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
640 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
644 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
648 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
651 $helpforsubstitution =
'';
652 if (is_array($this->substit) && count($this->substit)) {
653 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
655 foreach ($this->substit as $key => $val) {
657 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
662 if (is_array($this->substit) && count($this->substit)) {
663 $helpforsubstitution .=
'</span>';
678 if (!empty($this->withfrom)) {
679 if (!empty($this->withfromreadonly)) {
680 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
683 if (!($this->fromtype ===
'user' && $this->fromid > 0)
684 && !($this->fromtype ===
'company')
685 && !($this->fromtype ===
'robot')
686 && !preg_match(
'/user_aliases/', $this->fromtype)
687 && !preg_match(
'/global_aliases/', $this->fromtype)
688 && !preg_match(
'/senderprofile/', $this->fromtype)
691 $out .= $this->fromname;
692 if ($this->frommail) {
693 $out .=
' <'.$this->frommail.
'>';
695 if ($this->fromtype) {
696 $langs->load(
'errors');
697 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
704 if (empty($user->email)) {
705 $langs->load(
'errors');
706 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
708 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
710 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
715 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
719 $listaliases = array(
720 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
724 if (!empty($arraydefaultmessage->email_from)) {
725 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
726 $liste[
'from_template_'.$arraydefaultmessage->id] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
730 if (!empty($this->fromalsorobot)) {
733 if ($this->frommail) {
736 $liste[
'main_from'] = array(
'label' => $s,
'data-html' => $s);
741 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
742 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
") AND entity IN (".
getEntity(
'c_email_senderprofile').
")";
743 $sql .=
" ORDER BY position";
744 $resql = $this->db->query($sql);
746 $num = $this->db->num_rows($resql);
749 $obj = $this->db->fetch_object($resql);
751 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
759 foreach ($listaliases as $typealias => $listalias) {
761 $listaliasarray = explode(
',', $listalias);
762 foreach ($listaliasarray as $listaliasval) {
764 $listaliasval = trim($listaliasval);
766 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
767 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
768 if (!preg_match(
'/</', $listaliasval)) {
769 $listaliasval =
'<'.$listaliasval.
'>';
771 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
779 foreach ($liste as $key => $val) {
780 if (!empty($liste[$key][
'data-html'])) {
781 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
782 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
785 $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);
788 $out .=
"</td></tr>\n";
790 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
791 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
792 $out .=
' ';
793 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
794 $out .=
"</td></tr>\n";
799 if (!empty($this->withto) || is_array($this->withto)) {
804 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
806 $out .= $langs->trans(
"MailToUsers");
810 $tmparray = $this->withtouser;
811 foreach ($tmparray as $key => $val) {
814 $withtoselected =
GETPOST(
"receiveruser",
'array');
815 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
816 $withtoselected = array_keys($tmparray);
818 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
819 $out .=
"</td></tr>\n";
823 if (!empty($this->withoptiononeemailperrecipient)) {
824 if (abs($this->withoptiononeemailperrecipient) == 1) {
825 $out .=
'<tr><td class="minwidth200">';
826 $out .= $langs->trans(
"GroupEmails");
828 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
829 $out .=
'<label for="oneemailperrecipient">';
830 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
836 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
837 if (!empty($this->withto) && !is_array($this->withto)) {
838 $out .=
' '.$langs->trans(
"or").
' <input type="email" name="emailto" value="">';
841 $out .=
'</td></tr>';
843 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
848 if (!empty($this->withtocc) || is_array($this->withtocc)) {
853 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
855 $out .= $langs->trans(
"MailToCCUsers");
859 $tmparray = $this->withtoccuser;
860 foreach ($tmparray as $key => $val) {
863 $withtoselected =
GETPOST(
"receiverccuser",
'array');
864 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
865 $withtoselected = array_keys($tmparray);
867 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
868 $out .=
"</td></tr>\n";
872 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
877 if (!empty($this->withreplyto)) {
878 if ($this->withreplytoreadonly) {
879 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
880 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
881 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
882 $out .=
"</td></tr>\n";
887 if (!empty($this->witherrorsto)) {
892 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
897 if (!empty($this->withtopic)) {
898 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
902 if (!empty($this->withfile)) {
904 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
908 if ($this->withmaindocfile) {
910 if (GETPOSTISSET(
'sendmail')) {
911 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
912 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
914 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
918 if (!empty($this->withmaindocfile)) {
919 if ($this->withmaindocfile == 1) {
920 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
921 } elseif ($this->withmaindocfile == -1) {
922 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
925 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
927 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
931 if (is_numeric($this->withfile)) {
933 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
934 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
935 $out .=
'jQuery(document).ready(function () {';
936 $out .=
' jQuery(".removedfile").click(function() {';
937 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
940 $out .=
'</script>'.
"\n";
941 if (count($listofpaths)) {
942 foreach ($listofpaths as $key => $val) {
943 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
945 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] :
$conf->entity);
947 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
950 $formfile_params = array();
951 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
953 $out .=
'<div id="attachfile_'.$key.
'">';
955 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
957 $out .=
' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
959 if (!$this->withfilereadonly) {
960 $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.
'" />';
963 $out .=
'<br></div>';
968 if ($this->withfile == 2) {
970 $maxmin = $maxfilesizearray[
'maxmin'];
972 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
976 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
978 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
981 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
984 $out .= $this->withfile;
987 $out .=
"</td></tr>\n";
991 if (!empty($this->withbody)) {
992 $defaultmessage =
GETPOST(
'message',
'restricthtml');
993 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
994 if ($arraydefaultmessage && $arraydefaultmessage->content) {
995 $defaultmessage = (string) $arraydefaultmessage->content;
996 } elseif (!is_numeric($this->withbody)) {
997 $defaultmessage = $this->withbody;
1004 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1005 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1007 if (empty($this->substit[
'__REF__'])) {
1010 $langs->loadLangs(array(
'paypal',
'other'));
1011 $typeforonlinepayment =
'free';
1012 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1013 $typeforonlinepayment =
'order';
1015 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1016 $typeforonlinepayment =
'invoice';
1018 if ($this->param[
"models"] ==
'member') {
1019 $typeforonlinepayment =
'member';
1021 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1025 if (count($validpaymentmethod) > 0 && $paymenturl) {
1026 $langs->load(
'other');
1027 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
1028 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
1029 } elseif (count($validpaymentmethod) > 0) {
1030 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
1031 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
1033 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1034 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1037 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1041 $defaultlines = $arraydefaultmessage->content_lines;
1042 if (isset($defaultlines)) {
1043 foreach ($this->substit_lines as $lineid => $substit_line) {
1047 $this->substit[
'__LINES__'] = $lines;
1049 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1052 $atleastonecomponentishtml = 0;
1053 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1054 $atleastonecomponentishtml++;
1056 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1057 $atleastonecomponentishtml++;
1059 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1060 $atleastonecomponentishtml++;
1062 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1063 $atleastonecomponentishtml++;
1066 $atleastonecomponentishtml++;
1068 if ($atleastonecomponentishtml) {
1070 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1072 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1073 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1076 $this->substit[
'__LINES__'] =
dol_nl2br($this->substit[
'__LINES__']);
1078 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1079 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1082 $defaultmessage =
dol_nl2br($defaultmessage);
1086 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
1087 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1091 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1092 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1096 $out .=
'<td class="tdtop">';
1097 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1099 $out .=
'<td class="tdtop">';
1102 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1103 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1104 $showlinktoai = ($formmail->withaiprompt && isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1105 $showlinktoailabel = $langs->trans(
"AIEnhancements");
1106 $formatforouput =
'';
1107 $htmlname =
'message';
1109 $formai->substit = $this->substit;
1110 $formai->substit_lines = $this->substit_lines;
1114 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1120 $out .=
'<td colspan="2">';
1121 if ($this->withbodyreadonly) {
1122 $out .= nl2br($defaultmessage);
1123 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1125 if (!isset($this->ckeditortoolbar)) {
1126 $this->ckeditortoolbar =
'dolibarr_mailings';
1130 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1131 if ($this->withfckeditor == -1) {
1133 $this->withfckeditor = 1;
1135 $this->withfckeditor = 0;
1139 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1140 $out .= $doleditor->Create(1);
1142 $out .=
"</td></tr>\n";
1145 $out .=
'</table>'.
"\n";
1147 if ($this->withform == 1 || $this->withform == -1) {
1148 $out .=
'<div class="center">';
1149 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1151 if ($this->withfile == 2 &&
$conf->use_javascript_ajax) {
1152 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1155 if ($this->withcancel) {
1156 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1158 $out .= '</div>'."\n
";
1161 if ($this->withform == 1) {
1162 $out .= '</form>'."\n
";
1165 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1166 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1167 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1168 $out .= 'jQuery(document).ready(function () {';
1169 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1170 var code = e.keyCode || e.which;
1172 console.log("Enter was intercepted and blocked
");
1178 $out .= '</script>';
1181 $out .= "<!-- End form mail -->\n
";
1950 public function setSubstitFromObject($object, $outputlangs)
1952 global $extrafields;
1954 $parameters = array();
1955 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1956 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1958 $this->substit = $tmparray;
1960 // Fill substit_lines with each object lines content
1961 if (is_array($object->lines)) {
1962 foreach ($object->lines as $line) {
1963 $substit_line = array(
1964 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1965 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1966 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1967 '__LABEL__' => isset($line->label) ? $line->label : '',
1968 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1969 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
1970 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
1971 '__QUANTITY__' => $line->qty,
1972 '__SUBPRICE__' => price($line->subprice),
1973 '__AMOUNT__' => price($line->total_ttc),
1974 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1977 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1978 if (!empty($line->fk_product)) {
1979 if (!is_object($extrafields)) {
1980 $extrafields = new ExtraFields($this->db);
1982 $product = new Product($this->db);
1983 $product->fetch($line->fk_product, '', '', '1');
1984 $product->fetch_optionals();
1986 $extrafields->fetch_name_optionals_label($product->table_element, true);
1988 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1989 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1990 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1995 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2008 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2012 $tmparray = array();
2013 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2014 $parameters = array('mode' => $mode);
2015 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
2016 complete_substitutions_array($tmparray, $langs, null, $parameters);
2018 if ($mode == 'formwithlines') {
2019 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2021 if ($mode == 'formforlines') {
2022 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2026 if ($mode == 'emailing') {
2027 $parameters = array('mode' => $mode);
2028 $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
2029 complete_substitutions_array($tmparray, $langs, null, $parameters);
2031 // For mass emailing, we have different keys specific to the data into tagerts list
2032 $tmparray['__ID__'] = 'IdRecord';
2033 $tmparray['__EMAIL__'] = 'EMailRecipient';
2034 $tmparray['__LASTNAME__'] = 'Lastname';
2035 $tmparray['__FIRSTNAME__'] = 'Firstname';
2036 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2037 $tmparray['__OTHER1__'] = 'Other1';
2038 $tmparray['__OTHER2__'] = 'Other2';
2039 $tmparray['__OTHER3__'] = 'Other3';
2040 $tmparray['__OTHER4__'] = 'Other4';
2041 $tmparray['__OTHER5__'] = 'Other5';
2043 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode'; // If source is a thirdparty
2045 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2046 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2047 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2049 $onlinepaymentenabled = 0;
2050 if (isModEnabled('paypal')) {
2051 $onlinepaymentenabled++;
2053 if (isModEnabled('paybox')) {
2054 $onlinepaymentenabled++;
2056 if (isModEnabled('stripe')) {
2057 $onlinepaymentenabled++;
2059 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2060 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2061 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
2062 if (isModEnabled('member')) {
2063 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2065 if (isModEnabled('don')) {
2066 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2068 if (isModEnabled('invoice')) {
2069 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2071 if (isModEnabled('order')) {
2072 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2074 if (isModEnabled('contract')) {
2075 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2078 //Online payment link
2079 if (isModEnabled('member')) {
2080 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2082 if (isModEnabled('don')) {
2083 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2085 if (isModEnabled('invoice')) {
2086 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2088 if (isModEnabled('order')) {
2089 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2091 if (isModEnabled('contract')) {
2092 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2096 /* No need to show into tooltip help, option is not enabled
2097 $vars['__SECUREKEYPAYMENT__']='';
2098 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2099 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2100 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2101 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2104 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2105 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2109 foreach ($tmparray as $key => $val) {
2111 $tmparray[$key] = $key;