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);
711 $s = (!
getDolGlobalString(
'MAIN_INFO_SOCIETE_NOM') ? $conf->global->MAIN_INFO_SOCIETE_EMAIL : $conf->global->MAIN_INFO_SOCIETE_NOM).
' <' .
getDolGlobalString(
'MAIN_INFO_SOCIETE_MAIL').
'>';
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;
999 $validpaymentmethod = array();
1000 if (empty($this->substit[
'__REF__'])) {
1004 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1005 $langs->loadLangs(array(
'paypal',
'other'));
1006 $typeforonlinepayment =
'free';
1007 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1008 $typeforonlinepayment =
'order';
1010 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1011 $typeforonlinepayment =
'invoice';
1013 if ($this->param[
"models"] ==
'member') {
1014 $typeforonlinepayment =
'member';
1016 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1019 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
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;
1027 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1028 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1031 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1035 $defaultlines = $arraydefaultmessage->content_lines;
1036 if (isset($defaultlines)) {
1037 foreach ($this->substit_lines as $lineid => $substit_line) {
1041 $this->substit[
'__LINES__'] = $lines;
1043 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1046 $atleastonecomponentishtml = 0;
1047 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1048 $atleastonecomponentishtml++;
1050 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1051 $atleastonecomponentishtml++;
1053 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1054 $atleastonecomponentishtml++;
1056 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1057 $atleastonecomponentishtml++;
1060 $atleastonecomponentishtml++;
1062 if ($atleastonecomponentishtml) {
1064 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1066 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1067 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1069 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1070 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1073 $defaultmessage =
dol_nl2br($defaultmessage);
1077 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
1078 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1082 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1083 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1087 $out .=
'<td class="tdtop">';
1088 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1090 $out .=
'<td class="tdtop">';
1093 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1094 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1095 $showlinktoai = ($formmail->withaiprompt && isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1096 $showlinktoailabel = $langs->trans(
"FillMessageWithAIContent");
1097 $formatforouput =
'';
1098 $htmlname =
'message';
1101 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1107 $out .=
'<td colspan="2">';
1108 if ($this->withbodyreadonly) {
1109 $out .= nl2br($defaultmessage);
1110 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1112 if (!isset($this->ckeditortoolbar)) {
1113 $this->ckeditortoolbar =
'dolibarr_mailings';
1117 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1118 if ($this->withfckeditor == -1) {
1120 $this->withfckeditor = 1;
1122 $this->withfckeditor = 0;
1126 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1127 $out .= $doleditor->Create(1);
1129 $out .=
"</td></tr>\n";
1132 $out .=
'</table>'.
"\n";
1134 if ($this->withform == 1 || $this->withform == -1) {
1135 $out .=
'<div class="center">';
1136 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1138 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1139 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1142 if ($this->withcancel) {
1143 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1145 $out .= '</div>'."\n
";
1148 if ($this->withform == 1) {
1149 $out .= '</form>'."\n
";
1152 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1153 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1154 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1155 $out .= 'jQuery(document).ready(function () {';
1156 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1157 var code = e.keyCode || e.which;
1159 console.log("Enter was intercepted and blocked
");
1165 $out .= '</script>';
1168 $out .= "<!-- End form mail -->\n
";
1823 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1827 if ($id == -2 && empty($label)) {
1828 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1832 $ret = new ModelMail($dbs);
1834 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1835 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1836 $tmparray = explode('_', $languagetosearch);
1837 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1838 if ($languagetosearchmain == $languagetosearch) {
1839 $languagetosearchmain = '';
1842 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1843 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1844 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'all')
";
1845 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1846 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1848 $sql .= " AND active =
".((int) $active);
1850 if ($defaultfortype >= 0) {
1851 $sql .= " AND defaultfortype =
".((int) $defaultfortype);
1854 $sql .= " AND label =
'".$dbs->escape($label)."'";
1856 if (!($id > 0) && $languagetosearch) {
1857 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1860 $sql .= " AND rowid =
".(int) $id;
1865 $sql .= " AND entity IN(
".getEntity('c_email_templates', 1).")
";
1866 if ($languagetosearch) {
1867 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1869 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1871 //$sql .= $dbs->plimit(1);
1874 $resql = $dbs->query($sql);
1876 dol_print_error($dbs);
1882 $obj = $dbs->fetch_object($resql);
1885 // If template is for a module, check module is enabled; if not, take next template
1887 $tempmodulekey = $obj->module;
1888 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1893 // If a record was found
1894 $ret->id = $obj->rowid;
1895 $ret->module = $obj->module;
1896 $ret->label = $obj->label;
1897 $ret->lang = $obj->lang;
1898 $ret->topic = $obj->topic;
1899 $ret->content = $obj->content;
1900 $ret->content_lines = $obj->content_lines;
1901 $ret->joinfiles = $obj->joinfiles;
1902 $ret->email_from = $obj->email_from;
1906 // If no record found
1908 // Not found with the provided label
1911 // If there is no template at all
1912 $defaultmessage = '';
1914 if ($type_template == 'body') {
1915 // Special case to use this->withbody as content
1916 $defaultmessage = $this->withbody;
1917 } elseif ($type_template == 'facture_send') {
1918 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1919 } elseif ($type_template == 'facture_relance') {
1920 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder
");
1921 } elseif ($type_template == 'propal_send') {
1922 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1923 } elseif ($type_template == 'supplier_proposal_send') {
1924 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1925 } elseif ($type_template == 'order_send') {
1926 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1927 } elseif ($type_template == 'order_supplier_send') {
1928 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1929 } elseif ($type_template == 'invoice_supplier_send') {
1930 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1931 } elseif ($type_template == 'shipping_send') {
1932 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1933 } elseif ($type_template == 'fichinter_send') {
1934 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1935 } elseif ($type_template == 'actioncomm_send') {
1936 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1937 } elseif (!empty($type_template)) {
1938 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1941 $ret->label = 'default';
1942 $ret->lang = $outputlangs->defaultlang;
1944 $ret->joinfiles = 1;
1945 $ret->content = $defaultmessage;
1946 $ret->content_lines = '';
2061 public function setSubstitFromObject($object, $outputlangs)
2063 global $extrafields;
2065 $parameters = array();
2066 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
2067 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
2069 $this->substit = $tmparray;
2071 // Fill substit_lines with each object lines content
2072 if (is_array($object->lines)) {
2073 foreach ($object->lines as $line) {
2074 $substit_line = array(
2075 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
2076 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
2077 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
2078 '__LABEL__' => isset($line->label) ? $line->label : '',
2079 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
2080 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
2081 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
2082 '__QUANTITY__' => $line->qty,
2083 '__SUBPRICE__' => price($line->subprice),
2084 '__AMOUNT__' => price($line->total_ttc),
2085 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
2088 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2089 if (!empty($line->fk_product)) {
2090 if (!is_object($extrafields)) {
2091 $extrafields = new ExtraFields($this->db);
2093 $product = new Product($this->db);
2094 $product->fetch($line->fk_product, '', '', 1);
2095 $product->fetch_optionals();
2097 $extrafields->fetch_name_optionals_label($product->table_element, true);
2099 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2100 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2101 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2106 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2119 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2123 $tmparray = array();
2124 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2125 $parameters = array('mode' => $mode);
2126 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
2127 complete_substitutions_array($tmparray, $langs, null, $parameters);
2129 if ($mode == 'formwithlines') {
2130 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2132 if ($mode == 'formforlines') {
2133 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2137 if ($mode == 'emailing') {
2138 $parameters = array('mode' => $mode);
2139 $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
2140 complete_substitutions_array($tmparray, $langs, null, $parameters);
2142 // For mass emailing, we have different keys specific to the data into tagerts list
2143 $tmparray['__ID__'] = 'IdRecord';
2144 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
2145 $tmparray['__EMAIL__'] = 'EMailRecipient';
2146 $tmparray['__LASTNAME__'] = 'Lastname';
2147 $tmparray['__FIRSTNAME__'] = 'Firstname';
2148 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2149 $tmparray['__OTHER1__'] = 'Other1';
2150 $tmparray['__OTHER2__'] = 'Other2';
2151 $tmparray['__OTHER3__'] = 'Other3';
2152 $tmparray['__OTHER4__'] = 'Other4';
2153 $tmparray['__OTHER5__'] = 'Other5';
2154 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2155 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2156 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2158 $onlinepaymentenabled = 0;
2159 if (isModEnabled('paypal')) {
2160 $onlinepaymentenabled++;
2162 if (isModEnabled('paybox')) {
2163 $onlinepaymentenabled++;
2165 if (isModEnabled('stripe')) {
2166 $onlinepaymentenabled++;
2168 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2169 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2170 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
2171 if (isModEnabled('member')) {
2172 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2174 if (isModEnabled('don')) {
2175 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2177 if (isModEnabled('invoice')) {
2178 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2180 if (isModEnabled('order')) {
2181 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2183 if (isModEnabled('contract')) {
2184 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2187 //Online payment link
2188 if (isModEnabled('member')) {
2189 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2191 if (isModEnabled('don')) {
2192 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2194 if (isModEnabled('invoice')) {
2195 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2197 if (isModEnabled('order')) {
2198 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2200 if (isModEnabled('contract')) {
2201 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2205 /* No need to show into tooltip help, option is not enabled
2206 $vars['__SECUREKEYPAYMENT__']='';
2207 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2208 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2209 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2210 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2213 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2214 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2218 foreach ($tmparray as $key => $val) {
2220 $tmparray[$key] = $key;