472 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
475 global
$conf, $langs, $user, $hookmanager, $form;
477 if (!is_object($form)) {
478 $form =
new Form($this->db);
482 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
483 $formfile =
new FormFile($this->db);
485 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formai.class.php';
486 $formai =
new FormAI($this->db);
489 $langs->loadLangs(array(
'other',
'mails',
'members'));
492 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
497 $hookmanager->initHooks(array(
'formmail'));
500 'addfileaction' => $addfileaction,
501 'removefileaction' => $removefileaction,
502 'trackid' => $this->trackid
504 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
506 if (!empty($reshook)) {
507 return $hookmanager->resPrint;
511 $disablebademails = 1;
514 $outputlangs = $langs;
516 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
517 $newlang = $this->param[
'langsmodels'];
519 if (!empty($newlang)) {
521 $outputlangs->setDefaultLang($newlang);
523 $outputlangs->loadLangs(array(
'other',
'commercial',
'bills',
'orders',
'contracts',
'main',
'members',
'propal',
'products',
'supplier_proposal',
'interventions',
'receptions',
'sendings'));
527 $arraydefaultmessage = -1;
528 if ($this->param[
'models'] !=
'none') {
530 if (array_key_exists(
'models_id', $this->param)) {
531 $model_id = $this->param[
"models_id"];
534 $arraydefaultmessage = $this->
getEMailTemplate($this->db, $this->param[
"models"], $user, $outputlangs, $model_id, 1,
'', ($model_id > 0 ? -1 : 1));
538 $listofpaths = array();
539 $listofnames = array();
540 $listofmimes = array();
541 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
543 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
544 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
545 foreach ($this->param[
'fileinit'] as $path) {
553 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
554 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
556 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
557 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
559 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
560 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
564 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
565 if ($this->withform == 1) {
566 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
568 $out .=
'<a id="formmail" name="formmail"></a>';
569 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
570 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
571 $out .=
'<input type="hidden" name="page_y" value="" />';
572 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
573 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
575 if (!empty($this->withfrom)) {
576 if (!empty($this->withfromreadonly)) {
577 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
578 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
581 foreach ($this->param as $key => $value) {
582 if (is_array($value)) {
583 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
585 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
589 $modelmail_array = array();
591 if ($this->param[
'models'] !=
'none') {
597 foreach ($this->lines_model as $line) {
599 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
600 $labeltouse = $langs->trans($reg[1]);
602 $labeltouse = $line->label;
605 if ($break != $line->lang) {
608 $shtml =
'----- '.$langs->trans(
"Language_".$line->lang).
' -----';
609 $modelmail_array[
'separator_'.$line->lang] = array(
'label' => $s,
'data-html' => $shtml,
'disabled' =>
'disabled');
618 if ($line->private) {
619 $shtml .=
' - <span class="opacitymedium small">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
622 $modelmail_array[$line->id] = array(
'label' => $s,
'data-html' => $shtml);
627 if (count($modelmail_array) > 0) {
628 $model_mail_selected_id =
GETPOSTISSET(
'modelmailselected') ?
GETPOSTINT(
'modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
631 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
633 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans(
'SelectMailModel'), 0, 0,
'', 0, 0, 0,
'',
'minwidth150', 1,
'', 0, 1);
635 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
644 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
646 $currentlang = (is_object($outputlangs) ? $outputlangs->defaultlang : $langs->defaultlang);
648 $out .= $formadmin->select_language($currentlang,
'lang_id', 0, array(), 1, 0, 0,
'maxwidth150');
652 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
655 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
656 'propal_send',
'order_send',
'facture_send',
657 'shipping_send',
'reception_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
658 'invoice_supplier_send',
'supplier_payment_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'product_send',
'all'
661 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
662 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
663 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
665 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
668 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
672 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
676 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
679 $helpforsubstitution =
'';
680 if (is_array($this->substit) && count($this->substit)) {
681 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
682 foreach ($this->substit as $key => $val) {
684 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
687 if (is_array($val)) {
688 $val = implode(
', ', $val);
692 $helpforsubstitution .=
'</span>';
707 if (!empty($this->withfrom)) {
708 if (!empty($this->withfromreadonly)) {
709 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
712 if (!($this->fromtype ===
'user' && $this->fromid > 0)
713 && !($this->fromtype ===
'company')
714 && !($this->fromtype ===
'robot')
715 && !preg_match(
'/user_aliases/', $this->fromtype)
716 && !preg_match(
'/global_aliases/', $this->fromtype)
717 && !preg_match(
'/senderprofile/', $this->fromtype)
718 && !preg_match(
'/from_template_(\d+)/', $this->fromtype)
721 $out .= $this->fromname;
722 if ($this->frommail) {
723 $out .=
' <'.$this->frommail.
'>';
725 if ($this->fromtype) {
726 $langs->load(
'errors');
727 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
734 if (empty($user->email)) {
735 $langs->load(
'errors');
736 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
738 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
740 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
745 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
749 $listaliases = array(
753 if (!empty($arraydefaultmessage->email_from) && !empty($arraydefaultmessage->id)) {
754 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
755 $liste[
'from_template_'.((int) $arraydefaultmessage->id)] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
759 if (!empty($this->fromalsorobot)) {
762 if ($this->frommail) {
765 $liste[
'main_from'] = array(
'label' => $s,
'data-html' => $s);
770 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
771 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
") AND entity IN (".
getEntity(
'c_email_senderprofile').
")";
772 $sql .=
" ORDER BY position";
773 $resql = $this->db->query($sql);
775 $num = $this->db->num_rows($resql);
778 $obj = $this->db->fetch_object($resql);
780 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
788 foreach ($listaliases as $typealias => $listalias) {
790 $listaliasarray = explode(
',', $listalias);
791 foreach ($listaliasarray as $listaliasval) {
793 $listaliasval = trim($listaliasval);
795 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
796 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
797 if (!preg_match(
'/</', $listaliasval)) {
798 $listaliasval =
'<'.$listaliasval.
'>';
800 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
808 foreach ($liste as $key => $val) {
809 if (!empty($liste[$key][
'data-html'])) {
810 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
811 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
814 $out .=
' '.$form->selectarray(
'fromtype', $liste, (empty($arraydefaultmessage->email_from) || empty($arraydefaultmessage->id)) ? $this->fromtype :
'from_template_'.((int) $arraydefaultmessage->id), 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 1,
'', $disablebademails);
817 $out .=
"</td></tr>\n";
819 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
820 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
821 $out .=
' ';
822 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
823 $out .=
"</td></tr>\n";
828 if (!empty($this->withto) || is_array($this->withto)) {
833 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
835 $out .= $langs->trans(
"MailToUsers");
839 $tmparray = $this->withtouser;
840 foreach ($tmparray as $key => $val) {
843 $withtoselected =
GETPOST(
"receiveruser",
'array');
844 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
845 $withtoselected = array_keys($tmparray);
847 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
848 $out .=
"</td></tr>\n";
852 if (!empty($this->withoptiononeemailperrecipient)) {
853 if (abs($this->withoptiononeemailperrecipient) == 1) {
854 $out .=
'<tr><td class="minwidth200">';
855 $out .= $langs->trans(
"GroupEmails");
857 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
858 $out .=
'<label for="oneemailperrecipient">';
859 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
865 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
866 if (!empty($this->withto) && !is_array($this->withto)) {
867 $out .=
' <span class="opacitymedium">'.$langs->trans(
"or").
'</span> <input type="email" name="emailto" value="">';
870 $out .=
'</td></tr>';
872 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
877 if (!empty($this->withtocc) || is_array($this->withtocc)) {
882 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
884 $out .= $langs->trans(
"MailToCCUsers");
888 $tmparray = $this->withtoccuser;
889 foreach ($tmparray as $key => $val) {
892 $withtoselected =
GETPOST(
"receiverccuser",
'array');
893 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
894 $withtoselected = array_keys($tmparray);
896 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
897 $out .=
"</td></tr>\n";
901 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
906 if (!empty($this->withreplyto)) {
907 if ($this->withreplytoreadonly) {
908 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
909 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
910 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
911 $out .=
"</td></tr>\n";
916 if (!empty($this->witherrorsto)) {
921 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
926 if (!empty($this->withtopic)) {
927 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
931 if (!empty($this->withfile)) {
933 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
937 if ($this->withmaindocfile) {
940 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
941 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
943 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
947 if (!empty($this->withmaindocfile)) {
948 if ($this->withmaindocfile == 1) {
949 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
950 } elseif ($this->withmaindocfile == -1) {
951 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
954 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
956 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
960 if (is_numeric($this->withfile)) {
962 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
963 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
964 $out .=
'jQuery(document).ready(function () {';
965 $out .=
' jQuery(".removedfile").click(function() {';
966 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
969 $out .=
'</script>'.
"\n";
970 if (count($listofpaths)) {
971 foreach ($listofpaths as $key => $val) {
972 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
974 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] :
$conf->entity);
976 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
979 $formfile_params = array();
980 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
982 $out .=
'<div id="attachfile_'.$key.
'">';
984 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
986 $out .=
' '.$formfile->showPreview(array(
'fullname' => $val,
'name' => basename($val)), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
988 if (!$this->withfilereadonly) {
989 $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.
'" />';
992 $out .=
'<br></div>';
997 if ($this->withfile == 2) {
999 $maxmin = $maxfilesizearray[
'maxmin'];
1001 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1005 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
1007 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1010 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1013 $out .= $this->withfile;
1016 $out .=
"</td></tr>\n";
1020 if (!empty($this->withbody)) {
1021 $defaultmessage =
GETPOST(
'message',
'restricthtml');
1022 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
1023 if ($arraydefaultmessage && $arraydefaultmessage->content) {
1024 $defaultmessage = (
string) $arraydefaultmessage->content;
1025 } elseif (!is_numeric($this->withbody)) {
1026 $defaultmessage = $this->withbody;
1033 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1034 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1036 if (empty($this->substit[
'__REF__'])) {
1039 $langs->loadLangs(array(
'paypal',
'other'));
1040 $typeforonlinepayment =
'free';
1041 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1042 $typeforonlinepayment =
'order';
1044 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1045 $typeforonlinepayment =
'invoice';
1047 if ($this->param[
"models"] ==
'member') {
1048 $typeforonlinepayment =
'member';
1050 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1054 if (count($validpaymentmethod) > 0 && $paymenturl) {
1055 $langs->load(
'other');
1056 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
1057 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
1058 } elseif (count($validpaymentmethod) > 0) {
1059 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
1060 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
1062 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1063 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1066 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1070 $defaultlines = $arraydefaultmessage->content_lines;
1071 if (isset($defaultlines)) {
1072 foreach ($this->substit_lines as $lineid => $substit_line) {
1076 $this->substit[
'__LINES__'] = $lines;
1078 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1081 $atleastonecomponentishtml = 0;
1082 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1083 $atleastonecomponentishtml++;
1085 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1086 $atleastonecomponentishtml++;
1088 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1089 $atleastonecomponentishtml++;
1091 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1092 $atleastonecomponentishtml++;
1095 $atleastonecomponentishtml++;
1097 if ($atleastonecomponentishtml) {
1099 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1101 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1102 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1105 $this->substit[
'__LINES__'] =
dol_nl2br($this->substit[
'__LINES__']);
1107 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1108 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1111 $defaultmessage =
dol_nl2br($defaultmessage);
1116 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1123 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1124 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1127 $out .=
'<!-- Message line from get_form -->';
1129 $out .=
'<td class="tdtop">';
1130 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1132 $out .=
'<td class="tdtop">';
1135 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1136 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1137 $showlinktoai = ($formmail->withaiprompt &&
isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1138 $showlinktoailabel = $langs->trans(
"AIEnhancements");
1139 $formatforouput =
'';
1140 $htmlname =
'message';
1142 $formai->substit = $this->substit;
1143 $formai->substit_lines = $this->substit_lines;
1147 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1153 $out .=
'<td colspan="2">';
1154 if ($this->withbodyreadonly) {
1155 $out .= nl2br($defaultmessage);
1156 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1158 if (!isset($this->ckeditortoolbar)) {
1159 $this->ckeditortoolbar =
'dolibarr_mailings';
1163 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1164 if ($this->withfckeditor == -1) {
1166 $this->withfckeditor = 1;
1168 $this->withfckeditor = 0;
1175 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true, $uselocalbrowser, $this->withfckeditor, 8,
'95%');
1176 $out .= $doleditor->Create(1);
1178 $out .=
"</td></tr>\n";
1181 $out .=
'</table>'.
"\n";
1183 if ($this->withform == 1 || $this->withform == -1) {
1184 $out .=
'<div class="center">';
1185 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1187 if ($this->withfile == 2 &&
$conf->use_javascript_ajax) {
1188 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1191 if ($this->withcancel) {
1192 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1194 $out .= '</div>'."\n
";
1197 if ($this->withform == 1) {
1198 $out .= '</form>'."\n
";
1201 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1202 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1203 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1204 $out .= 'jQuery(document).ready(function () {';
1205 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1206 var code = e.keyCode || e.which;
1208 console.log("Enter was intercepted and blocked
");
1214 $out .= '</script>';
1217 $out .= "<!-- End form mail -->\n
";
1793 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1797 if ($id == -2 && empty($label)) {
1798 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1801 if ($type_template === 'societe') {
1802 $type_template = 'thirdparty';
1804 $ret = new CEmailTemplate($dbs);
1806 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1807 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1808 $tmparray = explode('_', $languagetosearch);
1809 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1810 if ($languagetosearchmain == $languagetosearch) {
1811 $languagetosearchmain = '';
1814 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1815 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1816 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'".$dbs->escape($type_template)."_send' OR type_template =
'all')
";
1817 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1818 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1820 $sql .= " AND
active =
".((int) $active);
1822 if ($defaultfortype >= 0) {
1823 $sql .= " AND defaultfortype =
".((int) $defaultfortype);
1826 $sql .= " AND label =
'".$dbs->escape($label)."'";
1828 if (!($id > 0) && $languagetosearch) {
1829 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1832 $sql .= " AND rowid =
".(int) $id;
1837 $sql .= " AND entity IN(
".getEntity('c_email_templates', 1).")
";
1838 if ($languagetosearch) {
1839 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1841 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1843 //$sql .= $dbs->plimit(1);
1846 $resql = $dbs->query($sql);
1848 dol_print_error($dbs);
1854 $obj = $dbs->fetch_object($resql);
1857 // If template is for a module, check module is enabled; if not, take next template
1859 $tempmodulekey = $obj->module;
1860 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1865 // If a record was found
1866 $ret->id = (int) $obj->rowid;
1867 $ret->module = (string) $obj->module;
1868 $ret->label = (string) $obj->label;
1869 $ret->lang = $obj->lang;
1870 $ret->topic = $obj->topic;
1871 $ret->content = (string) $obj->content;
1872 $ret->content_lines = (string) $obj->content_lines;
1873 $ret->joinfiles = $obj->joinfiles;
1874 $ret->email_from = (string) $obj->email_from;
1875 $ret->email_tocc = (string) $obj->email_tocc;
1876 $ret->email_tobcc = (string) $obj->email_tobcc;
1880 // If no record found
1882 // Not found with the provided label
1885 // If there is no template at all
1886 $defaultmessage = '';
1888 if ($type_template == 'body') {
1889 // Special case to use this->withbody as content
1890 $defaultmessage = (string) $this->withbody;
1891 } elseif ($type_template == 'facture_send' || $type_template == 'facture' || $type_template == 'facture_relance') {
1892 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendInvoice
");
1893 } elseif ($type_template == 'propal_send' || $type_template == 'propal') {
1894 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendProposal
");
1895 } elseif ($type_template == 'supplier_proposal_send' || $type_template == 'supplier_proposal') {
1896 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendSupplierProposal
");
1897 } elseif ($type_template == 'order_send' || $type_template == 'order') {
1898 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendOrder
");
1899 } elseif ($type_template == 'order_supplier_send' || $type_template == 'order_supplier') {
1900 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendSupplierOrder
");
1901 } elseif ($type_template == 'invoice_supplier_send' || $type_template == 'invoice_supplier') {
1902 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendSupplierInvoice
");
1903 } elseif ($type_template == 'shipping_send' || $type_template == 'shipping') {
1904 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendShipping
");
1905 } elseif ($type_template == 'reception_send' || $type_template == 'reception') {
1906 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendReception
");
1907 } elseif ($type_template == 'fichinter_send' || $type_template == 'fichinter') {
1908 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendFichInter
");
1909 } elseif ($type_template == 'actioncomm_send' || $type_template == 'actioncomm') {
1910 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendActionComm
");
1911 } elseif (!empty($type_template)) {
1912 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentGeneric
");
1915 $ret->label = 'default';
1916 $ret->lang = $outputlangs->defaultlang;
1918 $ret->joinfiles = 1;
1919 $ret->content = $defaultmessage;
1920 $ret->content_lines = '';
2111 public function setSubstitFromObject($object, $outputlangs)
2113 global $extrafields;
2115 $parameters = array();
2116 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
2117 complete_substitutions_array($tmparray, $outputlangs, $object, $parameters);
2119 $this->substit = $tmparray;
2121 if (is_object($outputlangs) && !empty($outputlangs->defaultlang)) {
2122 $targetLang = trim((string) $outputlangs->defaultlang);
2125 // Fill substit_lines with each object lines content
2126 if (is_array($object->lines)) {
2127 foreach ($object->lines as $line) {
2128 $substit_line = array(
2129 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
2130 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
2131 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
2132 '__LABEL__' => isset($line->label) ? $line->label : '',
2133 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
2134 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
2135 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
2136 '__QUANTITY__' => $line->qty,
2137 '__SUBPRICE__' => price($line->subprice),
2138 '__AMOUNT__' => price($line->total_ttc),
2139 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
2142 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2143 if (!empty($line->fk_product)) {
2144 if (!is_object($extrafields)) {
2145 $extrafields = new ExtraFields($this->db);
2147 $product = new Product($this->db);
2148 $product->fetch($line->fk_product, '', '', '1');
2149 $product->fetch_optionals();
2151 if (getDolGlobalInt('MAIN_MULTILANGS') && $targetLang !== '' && !empty($product->multilangs) && is_array($product->multilangs)) {
2152 $translated = self::getBestProductTranslation($product->multilangs, $targetLang);
2153 $translatedLabel = trim((string) (isset($translated['label']) ? $translated['label'] : ''));
2154 $translatedDescription = trim((string) (isset($translated['description']) ? $translated['description'] : ''));
2156 $currentLabelNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_LABEL__']);
2157 $currentProductDescriptionNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_DESCRIPTION__']);
2158 $currentLineDescriptionNorm = self::normalizeTextForComparison($substit_line['__DESCRIPTION__']);
2159 $productLabelNorm = self::normalizeTextForComparison($product->label);
2160 $productDescriptionNorm = self::normalizeTextForComparison($product->description);
2162 if ($translatedLabel !== '' && ($currentLabelNorm === '' || $currentLabelNorm === $productLabelNorm)) {
2163 $substit_line['__PRODUCT_LABEL__'] = $translatedLabel;
2165 if ($translatedDescription !== '' && ($currentProductDescriptionNorm === '' || $currentProductDescriptionNorm === $productDescriptionNorm)) {
2166 $substit_line['__PRODUCT_DESCRIPTION__'] = $translatedDescription;
2168 if ($translatedDescription !== '' && ($currentLineDescriptionNorm === '' || $currentLineDescriptionNorm === $productDescriptionNorm || $currentLineDescriptionNorm === $currentProductDescriptionNorm)) {
2169 $substit_line['__DESCRIPTION__'] = $translatedDescription;
2173 $extrafields->fetch_name_optionals_label($product->table_element, true);
2175 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2176 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2177 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2182 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2194 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2198 $tmparray = array();
2199 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2200 $parameters = array('mode' => $mode);
2201 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email template creation, this may be null because it is related to all type of objects
2202 complete_substitutions_array($tmparray, $langs, null, $parameters);
2204 if ($mode == 'formemailwithlines') {
2205 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2207 if ($mode == 'formemailforlines') {
2208 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2212 if ($mode == 'emailing') {
2213 $parameters = array('mode' => $mode);
2214 $tmparray = getCommonSubstitutionArray($langs, 2, array('object', 'objectamount'), $object); // Note: On email template creation, this may be null because it is related to all type of objects
2215 complete_substitutions_array($tmparray, $langs, null, $parameters);
2217 // For mass emailing, we have different keys specific to the data into tagerts list
2218 $tmparray['__ID__'] = 'IdRecord';
2219 $tmparray['__EMAIL__'] = 'EMailRecipient';
2220 $tmparray['__LASTNAME__'] = 'Lastname';
2221 $tmparray['__FIRSTNAME__'] = 'Firstname';
2222 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2223 $tmparray['__OTHER1__'] = 'Other1';
2224 $tmparray['__OTHER2__'] = 'Other2';
2225 $tmparray['__OTHER3__'] = 'Other3';
2226 $tmparray['__OTHER4__'] = 'Other4';
2227 $tmparray['__OTHER5__'] = 'Other5';
2229 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode'; // If source is a thirdparty
2231 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2232 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2233 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2235 $onlinepaymentenabled = 0;
2236 if (isModEnabled('paypal')) {
2237 $onlinepaymentenabled++;
2239 if (isModEnabled('stripe')) {
2240 $onlinepaymentenabled++;
2242 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2243 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2244 if (isModEnabled('member')) {
2245 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2247 if (isModEnabled('don')) {
2248 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2250 if (isModEnabled('invoice')) {
2251 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2253 if (isModEnabled('order')) {
2254 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2256 if (isModEnabled('contract')) {
2257 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2260 //Online payment link
2261 if (isModEnabled('member')) {
2262 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2264 if (isModEnabled('don')) {
2265 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2267 if (isModEnabled('invoice')) {
2268 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2270 if (isModEnabled('order')) {
2271 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2273 if (isModEnabled('contract')) {
2274 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2277 /* No need to show into tooltip help, option is not enabled
2278 $vars['__SECUREKEYPAYMENT__']='';
2279 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2280 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2281 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2282 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2285 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2286 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2290 foreach ($tmparray as $key => $val) {
2292 $tmparray[$key] = $key;