470 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
473 global
$conf, $langs, $user, $hookmanager, $form;
476 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
477 $formfile =
new FormFile($this->db);
479 if (!is_object($form)) {
480 $form =
new Form($this->db);
484 $langs->loadLangs(array(
'other',
'mails',
'members'));
487 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
492 $hookmanager->initHooks(array(
'formmail'));
495 'addfileaction' => $addfileaction,
496 'removefileaction' => $removefileaction,
497 'trackid' => $this->trackid
499 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
501 if (!empty($reshook)) {
502 return $hookmanager->resPrint;
506 $disablebademails = 1;
509 $outputlangs = $langs;
511 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
512 $newlang = $this->param[
'langsmodels'];
514 if (!empty($newlang)) {
516 $outputlangs->setDefaultLang($newlang);
517 $outputlangs->load(
'other');
521 $arraydefaultmessage = -1;
522 if ($this->param[
'models'] !=
'none') {
524 if (array_key_exists(
'models_id', $this->param)) {
525 $model_id = $this->param[
"models_id"];
528 $arraydefaultmessage = $this->
getEMailTemplate($this->db, $this->param[
"models"], $user, $outputlangs, $model_id, 1,
'', ($model_id > 0 ? -1 : 1));
532 $listofpaths = array();
533 $listofnames = array();
534 $listofmimes = array();
535 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
537 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
538 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
539 foreach ($this->param[
'fileinit'] as $path) {
547 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
548 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
550 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
551 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
553 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
554 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
558 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
559 if ($this->withform == 1) {
560 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
562 $out .=
'<a id="formmail" name="formmail"></a>';
563 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
564 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
565 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
566 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
568 if (!empty($this->withfrom)) {
569 if (!empty($this->withfromreadonly)) {
570 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
571 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
574 foreach ($this->param as $key => $value) {
575 if (is_array($value)) {
576 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
578 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
582 $modelmail_array = array();
583 if ($this->param[
'models'] !=
'none') {
589 foreach ($this->lines_model as $line) {
591 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
592 $labeltouse = $langs->trans($reg[1]);
594 $labeltouse = $line->label;
600 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
602 if ($line->private) {
603 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
609 if (count($modelmail_array) > 0) {
610 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOSTINT(
'modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
613 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
615 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans(
'SelectMailModel'), 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
617 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
621 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
624 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
625 'propal_send',
'order_send',
'facture_send',
626 'shipping_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
627 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'all'
630 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
631 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
632 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
634 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
637 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
641 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
645 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
648 $helpforsubstitution =
'';
649 if (is_array($this->substit) && count($this->substit)) {
650 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
652 foreach ($this->substit as $key => $val) {
654 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
659 if (is_array($this->substit) && count($this->substit)) {
660 $helpforsubstitution .=
'</span>';
675 if (!empty($this->withfrom)) {
676 if (!empty($this->withfromreadonly)) {
677 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
680 if (!($this->fromtype ===
'user' && $this->fromid > 0)
681 && !($this->fromtype ===
'company')
682 && !($this->fromtype ===
'robot')
683 && !preg_match(
'/user_aliases/', $this->fromtype)
684 && !preg_match(
'/global_aliases/', $this->fromtype)
685 && !preg_match(
'/senderprofile/', $this->fromtype)
688 $out .= $this->fromname;
689 if ($this->frommail) {
690 $out .=
' <'.$this->frommail.
'>';
692 if ($this->fromtype) {
693 $langs->load(
'errors');
694 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
701 if (empty($user->email)) {
702 $langs->load(
'errors');
703 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
705 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
707 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
712 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
716 $listaliases = array(
717 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
721 if (!empty($arraydefaultmessage->email_from)) {
722 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
723 $liste[
'from_template_'.GETPOST(
'modelmailselected')] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
727 if (!empty($this->fromalsorobot)) {
730 if ($this->frommail) {
733 $liste[
'main_from'] = array(
'label' => $s,
'data-html' => $s);
738 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
739 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
")";
740 $sql .=
" ORDER BY position";
741 $resql = $this->db->query($sql);
743 $num = $this->db->num_rows($resql);
746 $obj = $this->db->fetch_object($resql);
748 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
756 foreach ($listaliases as $typealias => $listalias) {
758 $listaliasarray = explode(
',', $listalias);
759 foreach ($listaliasarray as $listaliasval) {
761 $listaliasval = trim($listaliasval);
763 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
764 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
765 if (!preg_match(
'/</', $listaliasval)) {
766 $listaliasval =
'<'.$listaliasval.
'>';
768 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
776 foreach ($liste as $key => $val) {
777 if (!empty($liste[$key][
'data-html'])) {
778 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
779 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
782 $out .=
' '.$form->selectarray(
'fromtype', $liste, empty($arraydefaultmessage->email_from) ? $this->fromtype :
'from_template_'.GETPOST(
'modelmailselected'), 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 1,
'', $disablebademails);
785 $out .=
"</td></tr>\n";
787 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
788 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
789 $out .=
' ';
790 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
791 $out .=
"</td></tr>\n";
796 if (!empty($this->withto) || is_array($this->withto)) {
801 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
803 $out .= $langs->trans(
"MailToUsers");
807 $tmparray = $this->withtouser;
808 foreach ($tmparray as $key => $val) {
811 $withtoselected =
GETPOST(
"receiveruser",
'array');
812 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
813 $withtoselected = array_keys($tmparray);
815 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
816 $out .=
"</td></tr>\n";
820 if (!empty($this->withoptiononeemailperrecipient)) {
821 if (abs($this->withoptiononeemailperrecipient) == 1) {
822 $out .=
'<tr><td class="minwidth200">';
823 $out .= $langs->trans(
"GroupEmails");
825 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
826 $out .=
'<label for="oneemailperrecipient">';
827 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
833 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
834 if (!empty($this->withto) && !is_array($this->withto)) {
835 $out .=
' '.$langs->trans(
"or").
' <input type="email" name="emailto" value="">';
838 $out .=
'</td></tr>';
840 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
845 if (!empty($this->withtocc) || is_array($this->withtocc)) {
850 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
852 $out .= $langs->trans(
"MailToCCUsers");
856 $tmparray = $this->withtoccuser;
857 foreach ($tmparray as $key => $val) {
860 $withtoselected =
GETPOST(
"receiverccuser",
'array');
861 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
862 $withtoselected = array_keys($tmparray);
864 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
865 $out .=
"</td></tr>\n";
869 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
874 if (!empty($this->withreplyto)) {
875 if ($this->withreplytoreadonly) {
876 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
877 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
878 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
879 $out .=
"</td></tr>\n";
884 if (!empty($this->witherrorsto)) {
889 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
894 if (!empty($this->withtopic)) {
895 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
899 if (!empty($this->withfile)) {
901 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
905 if ($this->withmaindocfile) {
907 if (GETPOSTISSET(
'sendmail')) {
908 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
909 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
911 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
915 if (!empty($this->withmaindocfile)) {
916 if ($this->withmaindocfile == 1) {
917 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
918 } elseif ($this->withmaindocfile == -1) {
919 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
922 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
924 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
928 if (is_numeric($this->withfile)) {
930 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
931 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
932 $out .=
'jQuery(document).ready(function () {';
933 $out .=
' jQuery(".removedfile").click(function() {';
934 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
937 $out .=
'</script>'.
"\n";
938 if (count($listofpaths)) {
939 foreach ($listofpaths as $key => $val) {
940 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
942 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] :
$conf->entity);
944 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
947 $formfile_params = array();
948 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
950 $out .=
'<div id="attachfile_'.$key.
'">';
952 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
954 $out .=
' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
956 if (!$this->withfilereadonly) {
957 $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.
'" />';
960 $out .=
'<br></div>';
965 if ($this->withfile == 2) {
967 $maxmin = $maxfilesizearray[
'maxmin'];
969 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
973 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
975 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
978 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
981 $out .= $this->withfile;
984 $out .=
"</td></tr>\n";
988 if (!empty($this->withbody)) {
989 $defaultmessage =
GETPOST(
'message',
'restricthtml');
990 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
991 if ($arraydefaultmessage && $arraydefaultmessage->content) {
992 $defaultmessage = $arraydefaultmessage->content;
993 } elseif (!is_numeric($this->withbody)) {
994 $defaultmessage = $this->withbody;
1001 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1002 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1004 if (empty($this->substit[
'__REF__'])) {
1007 $langs->loadLangs(array(
'paypal',
'other'));
1008 $typeforonlinepayment =
'free';
1009 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1010 $typeforonlinepayment =
'order';
1012 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1013 $typeforonlinepayment =
'invoice';
1015 if ($this->param[
"models"] ==
'member') {
1016 $typeforonlinepayment =
'member';
1018 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1022 if (count($validpaymentmethod) > 0 && $paymenturl) {
1023 $langs->load(
'other');
1024 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
1025 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
1026 } elseif (count($validpaymentmethod) > 0) {
1027 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
1028 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
1030 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1031 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1034 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1038 $defaultlines = $arraydefaultmessage->content_lines;
1039 if (isset($defaultlines)) {
1040 foreach ($this->substit_lines as $lineid => $substit_line) {
1044 $this->substit[
'__LINES__'] = $lines;
1046 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1049 $atleastonecomponentishtml = 0;
1050 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1051 $atleastonecomponentishtml++;
1053 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1054 $atleastonecomponentishtml++;
1056 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1057 $atleastonecomponentishtml++;
1059 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1060 $atleastonecomponentishtml++;
1063 $atleastonecomponentishtml++;
1065 if ($atleastonecomponentishtml) {
1067 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1069 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1070 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1072 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1073 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1076 $defaultmessage =
dol_nl2br($defaultmessage);
1080 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
1081 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1085 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1086 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1090 $out .=
'<td class="tdtop">';
1091 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1093 $out .=
'<td class="tdtop">';
1096 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1097 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1098 $showlinktoai = ($formmail->withaiprompt && isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1099 $showlinktoailabel = $langs->trans(
"FillMessageWithAIContent");
1100 $formatforouput =
'';
1101 $htmlname =
'message';
1104 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1110 $out .=
'<td colspan="2">';
1111 if ($this->withbodyreadonly) {
1112 $out .= nl2br($defaultmessage);
1113 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1115 if (!isset($this->ckeditortoolbar)) {
1116 $this->ckeditortoolbar =
'dolibarr_mailings';
1120 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1121 if ($this->withfckeditor == -1) {
1123 $this->withfckeditor = 1;
1125 $this->withfckeditor = 0;
1129 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1130 $out .= $doleditor->Create(1);
1132 $out .=
"</td></tr>\n";
1135 $out .=
'</table>'.
"\n";
1137 if ($this->withform == 1 || $this->withform == -1) {
1138 $out .=
'<div class="center">';
1139 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1141 if ($this->withfile == 2 &&
$conf->use_javascript_ajax) {
1142 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1145 if ($this->withcancel) {
1146 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1148 $out .= '</div>'."\n
";
1151 if ($this->withform == 1) {
1152 $out .= '</form>'."\n
";
1155 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1156 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1157 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1158 $out .= 'jQuery(document).ready(function () {';
1159 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1160 var code = e.keyCode || e.which;
1162 console.log("Enter was intercepted and blocked
");
1168 $out .= '</script>';
1171 $out .= "<!-- End form mail -->\n
";
1826 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1830 if ($id == -2 && empty($label)) {
1831 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1835 $ret = new ModelMail($dbs);
1837 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1838 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1839 $tmparray = explode('_', $languagetosearch);
1840 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1841 if ($languagetosearchmain == $languagetosearch) {
1842 $languagetosearchmain = '';
1845 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1846 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1847 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'all')
";
1848 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1849 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1851 $sql .= " AND active =
".((int) $active);
1853 if ($defaultfortype >= 0) {
1854 $sql .= " AND defaultfortype =
".((int) $defaultfortype);
1857 $sql .= " AND label =
'".$dbs->escape($label)."'";
1859 if (!($id > 0) && $languagetosearch) {
1860 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1863 $sql .= " AND rowid =
".(int) $id;
1868 $sql .= " AND entity IN(
".getEntity('c_email_templates', 1).")
";
1869 if ($languagetosearch) {
1870 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1872 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1874 //$sql .= $dbs->plimit(1);
1877 $resql = $dbs->query($sql);
1879 dol_print_error($dbs);
1885 $obj = $dbs->fetch_object($resql);
1888 // If template is for a module, check module is enabled; if not, take next template
1890 $tempmodulekey = $obj->module;
1891 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1896 // If a record was found
1897 $ret->id = $obj->rowid;
1898 $ret->module = $obj->module;
1899 $ret->label = $obj->label;
1900 $ret->lang = $obj->lang;
1901 $ret->topic = $obj->topic;
1902 $ret->content = $obj->content;
1903 $ret->content_lines = $obj->content_lines;
1904 $ret->joinfiles = $obj->joinfiles;
1905 $ret->email_from = $obj->email_from;
1909 // If no record found
1911 // Not found with the provided label
1914 // If there is no template at all
1915 $defaultmessage = '';
1917 if ($type_template == 'body') {
1918 // Special case to use this->withbody as content
1919 $defaultmessage = $this->withbody;
1920 } elseif ($type_template == 'facture_send') {
1921 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1922 } elseif ($type_template == 'facture_relance') {
1923 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder
");
1924 } elseif ($type_template == 'propal_send') {
1925 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1926 } elseif ($type_template == 'supplier_proposal_send') {
1927 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1928 } elseif ($type_template == 'order_send') {
1929 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1930 } elseif ($type_template == 'order_supplier_send') {
1931 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1932 } elseif ($type_template == 'invoice_supplier_send') {
1933 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1934 } elseif ($type_template == 'shipping_send') {
1935 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1936 } elseif ($type_template == 'fichinter_send') {
1937 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1938 } elseif ($type_template == 'actioncomm_send') {
1939 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1940 } elseif (!empty($type_template)) {
1941 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1944 $ret->label = 'default';
1945 $ret->lang = $outputlangs->defaultlang;
1947 $ret->joinfiles = 1;
1948 $ret->content = $defaultmessage;
1949 $ret->content_lines = '';
2064 public function setSubstitFromObject($object, $outputlangs)
2066 global $extrafields;
2068 $parameters = array();
2069 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
2070 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
2072 $this->substit = $tmparray;
2074 // Fill substit_lines with each object lines content
2075 if (is_array($object->lines)) {
2076 foreach ($object->lines as $line) {
2077 $substit_line = array(
2078 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
2079 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
2080 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
2081 '__LABEL__' => isset($line->label) ? $line->label : '',
2082 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
2083 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
2084 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
2085 '__QUANTITY__' => $line->qty,
2086 '__SUBPRICE__' => price($line->subprice),
2087 '__AMOUNT__' => price($line->total_ttc),
2088 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
2091 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2092 if (!empty($line->fk_product)) {
2093 if (!is_object($extrafields)) {
2094 $extrafields = new ExtraFields($this->db);
2096 $product = new Product($this->db);
2097 $product->fetch($line->fk_product, '', '', 1);
2098 $product->fetch_optionals();
2100 $extrafields->fetch_name_optionals_label($product->table_element, true);
2102 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2103 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2104 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2109 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2122 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2126 $tmparray = array();
2127 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2128 $parameters = array('mode' => $mode);
2129 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
2130 complete_substitutions_array($tmparray, $langs, null, $parameters);
2132 if ($mode == 'formwithlines') {
2133 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2135 if ($mode == 'formforlines') {
2136 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2140 if ($mode == 'emailing') {
2141 $parameters = array('mode' => $mode);
2142 $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
2143 complete_substitutions_array($tmparray, $langs, null, $parameters);
2145 // For mass emailing, we have different keys specific to the data into tagerts list
2146 $tmparray['__ID__'] = 'IdRecord';
2147 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
2148 $tmparray['__EMAIL__'] = 'EMailRecipient';
2149 $tmparray['__LASTNAME__'] = 'Lastname';
2150 $tmparray['__FIRSTNAME__'] = 'Firstname';
2151 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2152 $tmparray['__OTHER1__'] = 'Other1';
2153 $tmparray['__OTHER2__'] = 'Other2';
2154 $tmparray['__OTHER3__'] = 'Other3';
2155 $tmparray['__OTHER4__'] = 'Other4';
2156 $tmparray['__OTHER5__'] = 'Other5';
2157 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2158 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2159 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2161 $onlinepaymentenabled = 0;
2162 if (isModEnabled('paypal')) {
2163 $onlinepaymentenabled++;
2165 if (isModEnabled('paybox')) {
2166 $onlinepaymentenabled++;
2168 if (isModEnabled('stripe')) {
2169 $onlinepaymentenabled++;
2171 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2172 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2173 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
2174 if (isModEnabled('member')) {
2175 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2177 if (isModEnabled('don')) {
2178 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2180 if (isModEnabled('invoice')) {
2181 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2183 if (isModEnabled('order')) {
2184 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2186 if (isModEnabled('contract')) {
2187 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2190 //Online payment link
2191 if (isModEnabled('member')) {
2192 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2194 if (isModEnabled('don')) {
2195 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2197 if (isModEnabled('invoice')) {
2198 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2200 if (isModEnabled('order')) {
2201 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2203 if (isModEnabled('contract')) {
2204 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2208 /* No need to show into tooltip help, option is not enabled
2209 $vars['__SECUREKEYPAYMENT__']='';
2210 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2211 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2212 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2213 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2216 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2217 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2221 foreach ($tmparray as $key => $val) {
2223 $tmparray[$key] = $key;