471 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
474 global
$conf, $langs, $user, $hookmanager, $form;
476 if (!is_object($form)) {
477 $form =
new Form($this->db);
481 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
482 $formfile =
new FormFile($this->db);
484 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formai.class.php';
485 $formai =
new FormAI($this->db);
488 $langs->loadLangs(array(
'other',
'mails',
'members'));
491 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
496 $hookmanager->initHooks(array(
'formmail'));
499 'addfileaction' => $addfileaction,
500 'removefileaction' => $removefileaction,
501 'trackid' => $this->trackid
503 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
505 if (!empty($reshook)) {
506 return $hookmanager->resPrint;
510 $disablebademails = 1;
513 $outputlangs = $langs;
515 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
516 $newlang = $this->param[
'langsmodels'];
518 if (!empty($newlang)) {
520 $outputlangs->setDefaultLang($newlang);
521 $outputlangs->load(
'other');
525 $arraydefaultmessage = -1;
526 if ($this->param[
'models'] !=
'none') {
528 if (array_key_exists(
'models_id', $this->param)) {
529 $model_id = $this->param[
"models_id"];
532 $arraydefaultmessage = $this->
getEMailTemplate($this->db, $this->param[
"models"], $user, $outputlangs, $model_id, 1,
'', ($model_id > 0 ? -1 : 1));
536 $listofpaths = array();
537 $listofnames = array();
538 $listofmimes = array();
539 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
541 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
542 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
543 foreach ($this->param[
'fileinit'] as $path) {
551 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
552 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
554 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
555 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
557 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
558 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
562 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
563 if ($this->withform == 1) {
564 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
566 $out .=
'<a id="formmail" name="formmail"></a>';
567 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
568 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
569 $out .=
'<input type="hidden" name="page_y" value="" />';
570 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
571 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
573 if (!empty($this->withfrom)) {
574 if (!empty($this->withfromreadonly)) {
575 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
576 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
579 foreach ($this->param as $key => $value) {
580 if (is_array($value)) {
581 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
583 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
587 $modelmail_array = array();
589 if ($this->param[
'models'] !=
'none') {
595 foreach ($this->lines_model as $line) {
597 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
598 $labeltouse = $langs->trans($reg[1]);
600 $labeltouse = $line->label;
603 if ($break != $line->lang) {
606 $shtml =
'----- '.$langs->trans(
"Language_".$line->lang).
' -----';
607 $modelmail_array[
'separator_'.$line->lang] = array(
'label' => $s,
'data-html' => $shtml,
'disabled' =>
'disabled');
616 if ($line->private) {
617 $shtml .=
' - <span class="opacitymedium small">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
620 $modelmail_array[$line->id] = array(
'label' => $s,
'data-html' => $shtml);
625 if (count($modelmail_array) > 0) {
626 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOSTINT(
'modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
629 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
631 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans(
'SelectMailModel'), 0, 0,
'', 0, 0, 0,
'',
'minwidth150', 1,
'', 0, 1);
633 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
642 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
644 $currentlang = (is_object($outputlangs) ? $outputlangs->defaultlang : $langs->defaultlang);
646 $out .= $formadmin->select_language($currentlang,
'lang_id', 0, array(), 1, 0, 0,
'maxwidth150');
650 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
653 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
654 'propal_send',
'order_send',
'facture_send',
655 'shipping_send',
'reception_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
656 'invoice_supplier_send',
'supplier_payment_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'product_send',
'all'
659 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
660 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
661 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
663 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
666 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
670 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
674 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
677 $helpforsubstitution =
'';
678 if (is_array($this->substit) && count($this->substit)) {
679 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
680 foreach ($this->substit as $key => $val) {
682 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
685 if (is_array($val)) {
686 $val = implode(
', ', $val);
690 $helpforsubstitution .=
'</span>';
705 if (!empty($this->withfrom)) {
706 if (!empty($this->withfromreadonly)) {
707 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
710 if (!($this->fromtype ===
'user' && $this->fromid > 0)
711 && !($this->fromtype ===
'company')
712 && !($this->fromtype ===
'robot')
713 && !preg_match(
'/user_aliases/', $this->fromtype)
714 && !preg_match(
'/global_aliases/', $this->fromtype)
715 && !preg_match(
'/senderprofile/', $this->fromtype)
718 $out .= $this->fromname;
719 if ($this->frommail) {
720 $out .=
' <'.$this->frommail.
'>';
722 if ($this->fromtype) {
723 $langs->load(
'errors');
724 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
731 if (empty($user->email)) {
732 $langs->load(
'errors');
733 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
735 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
737 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
742 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
746 $listaliases = array(
750 if (!empty($arraydefaultmessage->email_from) && !empty($arraydefaultmessage->id)) {
751 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
752 $liste[
'from_template_'.((int) $arraydefaultmessage->id)] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
756 if (!empty($this->fromalsorobot)) {
759 if ($this->frommail) {
762 $liste[
'main_from'] = array(
'label' => $s,
'data-html' => $s);
767 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
768 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
") AND entity IN (".
getEntity(
'c_email_senderprofile').
")";
769 $sql .=
" ORDER BY position";
770 $resql = $this->db->query($sql);
772 $num = $this->db->num_rows($resql);
775 $obj = $this->db->fetch_object($resql);
777 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
785 foreach ($listaliases as $typealias => $listalias) {
787 $listaliasarray = explode(
',', $listalias);
788 foreach ($listaliasarray as $listaliasval) {
790 $listaliasval = trim($listaliasval);
792 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
793 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
794 if (!preg_match(
'/</', $listaliasval)) {
795 $listaliasval =
'<'.$listaliasval.
'>';
797 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
805 foreach ($liste as $key => $val) {
806 if (!empty($liste[$key][
'data-html'])) {
807 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
808 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
811 $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);
814 $out .=
"</td></tr>\n";
816 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
817 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
818 $out .=
' ';
819 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
820 $out .=
"</td></tr>\n";
825 if (!empty($this->withto) || is_array($this->withto)) {
830 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
832 $out .= $langs->trans(
"MailToUsers");
836 $tmparray = $this->withtouser;
837 foreach ($tmparray as $key => $val) {
840 $withtoselected =
GETPOST(
"receiveruser",
'array');
841 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
842 $withtoselected = array_keys($tmparray);
844 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
845 $out .=
"</td></tr>\n";
849 if (!empty($this->withoptiononeemailperrecipient)) {
850 if (abs($this->withoptiononeemailperrecipient) == 1) {
851 $out .=
'<tr><td class="minwidth200">';
852 $out .= $langs->trans(
"GroupEmails");
854 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
855 $out .=
'<label for="oneemailperrecipient">';
856 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
862 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
863 if (!empty($this->withto) && !is_array($this->withto)) {
864 $out .=
' <span class="opacitymedium">'.$langs->trans(
"or").
'</span> <input type="email" name="emailto" value="">';
867 $out .=
'</td></tr>';
869 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
874 if (!empty($this->withtocc) || is_array($this->withtocc)) {
879 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
881 $out .= $langs->trans(
"MailToCCUsers");
885 $tmparray = $this->withtoccuser;
886 foreach ($tmparray as $key => $val) {
889 $withtoselected =
GETPOST(
"receiverccuser",
'array');
890 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
891 $withtoselected = array_keys($tmparray);
893 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
894 $out .=
"</td></tr>\n";
898 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
903 if (!empty($this->withreplyto)) {
904 if ($this->withreplytoreadonly) {
905 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
906 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
907 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
908 $out .=
"</td></tr>\n";
913 if (!empty($this->witherrorsto)) {
918 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
923 if (!empty($this->withtopic)) {
924 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
928 if (!empty($this->withfile)) {
930 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
934 if ($this->withmaindocfile) {
936 if (GETPOSTISSET(
'sendmail')) {
937 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
938 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
940 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
944 if (!empty($this->withmaindocfile)) {
945 if ($this->withmaindocfile == 1) {
946 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
947 } elseif ($this->withmaindocfile == -1) {
948 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
951 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
953 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
957 if (is_numeric($this->withfile)) {
959 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
960 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
961 $out .=
'jQuery(document).ready(function () {';
962 $out .=
' jQuery(".removedfile").click(function() {';
963 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
966 $out .=
'</script>'.
"\n";
967 if (count($listofpaths)) {
968 foreach ($listofpaths as $key => $val) {
969 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
971 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] :
$conf->entity);
973 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
976 $formfile_params = array();
977 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
979 $out .=
'<div id="attachfile_'.$key.
'">';
981 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
983 $out .=
' '.$formfile->showPreview(array(
'fullname' => $val,
'name' => basename($val)), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
985 if (!$this->withfilereadonly) {
986 $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.
'" />';
989 $out .=
'<br></div>';
994 if ($this->withfile == 2) {
996 $maxmin = $maxfilesizearray[
'maxmin'];
998 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1002 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
1004 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1007 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1010 $out .= $this->withfile;
1013 $out .=
"</td></tr>\n";
1017 if (!empty($this->withbody)) {
1018 $defaultmessage =
GETPOST(
'message',
'restricthtml');
1019 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
1020 if ($arraydefaultmessage && $arraydefaultmessage->content) {
1021 $defaultmessage = (
string) $arraydefaultmessage->content;
1022 } elseif (!is_numeric($this->withbody)) {
1023 $defaultmessage = $this->withbody;
1030 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1031 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1033 if (empty($this->substit[
'__REF__'])) {
1036 $langs->loadLangs(array(
'paypal',
'other'));
1037 $typeforonlinepayment =
'free';
1038 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1039 $typeforonlinepayment =
'order';
1041 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1042 $typeforonlinepayment =
'invoice';
1044 if ($this->param[
"models"] ==
'member') {
1045 $typeforonlinepayment =
'member';
1047 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1051 if (count($validpaymentmethod) > 0 && $paymenturl) {
1052 $langs->load(
'other');
1053 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
1054 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
1055 } elseif (count($validpaymentmethod) > 0) {
1056 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
1057 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
1059 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1060 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1063 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1067 $defaultlines = $arraydefaultmessage->content_lines;
1068 if (isset($defaultlines)) {
1069 foreach ($this->substit_lines as $lineid => $substit_line) {
1073 $this->substit[
'__LINES__'] = $lines;
1075 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1078 $atleastonecomponentishtml = 0;
1079 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1080 $atleastonecomponentishtml++;
1082 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1083 $atleastonecomponentishtml++;
1085 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1086 $atleastonecomponentishtml++;
1088 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1089 $atleastonecomponentishtml++;
1092 $atleastonecomponentishtml++;
1094 if ($atleastonecomponentishtml) {
1096 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1098 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1099 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1102 $this->substit[
'__LINES__'] =
dol_nl2br($this->substit[
'__LINES__']);
1104 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1105 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1108 $defaultmessage =
dol_nl2br($defaultmessage);
1112 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
1113 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1120 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1121 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1124 $out .=
'<!-- Message line from get_form -->';
1126 $out .=
'<td class="tdtop">';
1127 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1129 $out .=
'<td class="tdtop">';
1132 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1133 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1134 $showlinktoai = ($formmail->withaiprompt &&
isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1135 $showlinktoailabel = $langs->trans(
"AIEnhancements");
1136 $formatforouput =
'';
1137 $htmlname =
'message';
1139 $formai->substit = $this->substit;
1140 $formai->substit_lines = $this->substit_lines;
1144 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1150 $out .=
'<td colspan="2">';
1151 if ($this->withbodyreadonly) {
1152 $out .= nl2br($defaultmessage);
1153 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1155 if (!isset($this->ckeditortoolbar)) {
1156 $this->ckeditortoolbar =
'dolibarr_mailings';
1160 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1161 if ($this->withfckeditor == -1) {
1163 $this->withfckeditor = 1;
1165 $this->withfckeditor = 0;
1172 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true, $uselocalbrowser, $this->withfckeditor, 8,
'95%');
1173 $out .= $doleditor->Create(1);
1175 $out .=
"</td></tr>\n";
1178 $out .=
'</table>'.
"\n";
1180 if ($this->withform == 1 || $this->withform == -1) {
1181 $out .=
'<div class="center">';
1182 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1184 if ($this->withfile == 2 &&
$conf->use_javascript_ajax) {
1185 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1188 if ($this->withcancel) {
1189 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1191 $out .= '</div>'."\n
";
1194 if ($this->withform == 1) {
1195 $out .= '</form>'."\n
";
1198 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1199 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1200 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1201 $out .= 'jQuery(document).ready(function () {';
1202 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1203 var code = e.keyCode || e.which;
1205 console.log("Enter was intercepted and blocked
");
1211 $out .= '</script>';
1214 $out .= "<!-- End form mail -->\n
";
1790 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1794 if ($id == -2 && empty($label)) {
1795 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1798 if ($type_template === 'societe') {
1799 $type_template = 'thirdparty';
1801 $ret = new CEmailTemplate($dbs);
1803 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1804 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1805 $tmparray = explode('_', $languagetosearch);
1806 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1807 if ($languagetosearchmain == $languagetosearch) {
1808 $languagetosearchmain = '';
1811 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1812 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1813 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'".$dbs->escape($type_template)."_send' OR type_template =
'all')
";
1814 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1815 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1817 $sql .= " AND
active =
".((int) $active);
1819 if ($defaultfortype >= 0) {
1820 $sql .= " AND defaultfortype =
".((int) $defaultfortype);
1823 $sql .= " AND label =
'".$dbs->escape($label)."'";
1825 if (!($id > 0) && $languagetosearch) {
1826 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1829 $sql .= " AND rowid =
".(int) $id;
1834 $sql .= " AND entity IN(
".getEntity('c_email_templates', 1).")
";
1835 if ($languagetosearch) {
1836 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1838 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1840 //$sql .= $dbs->plimit(1);
1843 $resql = $dbs->query($sql);
1845 dol_print_error($dbs);
1851 $obj = $dbs->fetch_object($resql);
1854 // If template is for a module, check module is enabled; if not, take next template
1856 $tempmodulekey = $obj->module;
1857 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1862 // If a record was found
1863 $ret->id = (int) $obj->rowid;
1864 $ret->module = (string) $obj->module;
1865 $ret->label = (string) $obj->label;
1866 $ret->lang = $obj->lang;
1867 $ret->topic = $obj->topic;
1868 $ret->content = (string) $obj->content;
1869 $ret->content_lines = (string) $obj->content_lines;
1870 $ret->joinfiles = $obj->joinfiles;
1871 $ret->email_from = (string) $obj->email_from;
1872 $ret->email_tocc = (string) $obj->email_tocc;
1873 $ret->email_tobcc = (string) $obj->email_tobcc;
1877 // If no record found
1879 // Not found with the provided label
1882 // If there is no template at all
1883 $defaultmessage = '';
1885 if ($type_template == 'body') {
1886 // Special case to use this->withbody as content
1887 $defaultmessage = (string) $this->withbody;
1888 } elseif ($type_template == 'facture_send' || $type_template == 'facture' || $type_template == 'facture_relance') {
1889 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1890 } elseif ($type_template == 'propal_send' || $type_template == 'propal') {
1891 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1892 } elseif ($type_template == 'supplier_proposal_send' || $type_template == 'supplier_proposal') {
1893 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1894 } elseif ($type_template == 'order_send' || $type_template == 'order') {
1895 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1896 } elseif ($type_template == 'order_supplier_send' || $type_template == 'order_supplier') {
1897 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1898 } elseif ($type_template == 'invoice_supplier_send' || $type_template == 'invoice_supplier') {
1899 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1900 } elseif ($type_template == 'shipping_send' || $type_template == 'shipping') {
1901 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1902 } elseif ($type_template == 'reception_send' || $type_template == 'reception') {
1903 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendReception
");
1904 } elseif ($type_template == 'fichinter_send' || $type_template == 'fichinter') {
1905 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1906 } elseif ($type_template == 'actioncomm_send' || $type_template == 'actioncomm') {
1907 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1908 } elseif (!empty($type_template)) {
1909 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1912 $ret->label = 'default';
1913 $ret->lang = $outputlangs->defaultlang;
1915 $ret->joinfiles = 1;
1916 $ret->content = $defaultmessage;
1917 $ret->content_lines = '';
2108 public function setSubstitFromObject($object, $outputlangs)
2110 global $extrafields;
2112 $parameters = array();
2113 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
2114 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
2116 $this->substit = $tmparray;
2118 if (is_object($outputlangs) && !empty($outputlangs->defaultlang)) {
2119 $targetLang = trim((string) $outputlangs->defaultlang);
2122 // Fill substit_lines with each object lines content
2123 if (is_array($object->lines)) {
2124 foreach ($object->lines as $line) {
2125 $substit_line = array(
2126 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
2127 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
2128 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
2129 '__LABEL__' => isset($line->label) ? $line->label : '',
2130 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
2131 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
2132 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
2133 '__QUANTITY__' => $line->qty,
2134 '__SUBPRICE__' => price($line->subprice),
2135 '__AMOUNT__' => price($line->total_ttc),
2136 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
2139 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2140 if (!empty($line->fk_product)) {
2141 if (!is_object($extrafields)) {
2142 $extrafields = new ExtraFields($this->db);
2144 $product = new Product($this->db);
2145 $product->fetch($line->fk_product, '', '', '1');
2146 $product->fetch_optionals();
2148 if (getDolGlobalInt('MAIN_MULTILANGS') && $targetLang !== '' && !empty($product->multilangs) && is_array($product->multilangs)) {
2149 $translated = self::getBestProductTranslation($product->multilangs, $targetLang);
2150 $translatedLabel = trim((string) (isset($translated['label']) ? $translated['label'] : ''));
2151 $translatedDescription = trim((string) (isset($translated['description']) ? $translated['description'] : ''));
2153 $currentLabelNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_LABEL__']);
2154 $currentProductDescriptionNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_DESCRIPTION__']);
2155 $currentLineDescriptionNorm = self::normalizeTextForComparison($substit_line['__DESCRIPTION__']);
2156 $productLabelNorm = self::normalizeTextForComparison($product->label);
2157 $productDescriptionNorm = self::normalizeTextForComparison($product->description);
2159 if ($translatedLabel !== '' && ($currentLabelNorm === '' || $currentLabelNorm === $productLabelNorm)) {
2160 $substit_line['__PRODUCT_LABEL__'] = $translatedLabel;
2162 if ($translatedDescription !== '' && ($currentProductDescriptionNorm === '' || $currentProductDescriptionNorm === $productDescriptionNorm)) {
2163 $substit_line['__PRODUCT_DESCRIPTION__'] = $translatedDescription;
2165 if ($translatedDescription !== '' && ($currentLineDescriptionNorm === '' || $currentLineDescriptionNorm === $productDescriptionNorm || $currentLineDescriptionNorm === $currentProductDescriptionNorm)) {
2166 $substit_line['__DESCRIPTION__'] = $translatedDescription;
2170 $extrafields->fetch_name_optionals_label($product->table_element, true);
2172 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2173 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2174 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2179 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2191 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2195 $tmparray = array();
2196 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2197 $parameters = array('mode' => $mode);
2198 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email template creation, this may be null because it is related to all type of objects
2199 complete_substitutions_array($tmparray, $langs, null, $parameters);
2201 if ($mode == 'formwithlines') {
2202 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2204 if ($mode == 'formforlines') {
2205 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2209 if ($mode == 'emailing') {
2210 $parameters = array('mode' => $mode);
2211 $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
2212 complete_substitutions_array($tmparray, $langs, null, $parameters);
2214 // For mass emailing, we have different keys specific to the data into tagerts list
2215 $tmparray['__ID__'] = 'IdRecord';
2216 $tmparray['__EMAIL__'] = 'EMailRecipient';
2217 $tmparray['__LASTNAME__'] = 'Lastname';
2218 $tmparray['__FIRSTNAME__'] = 'Firstname';
2219 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2220 $tmparray['__OTHER1__'] = 'Other1';
2221 $tmparray['__OTHER2__'] = 'Other2';
2222 $tmparray['__OTHER3__'] = 'Other3';
2223 $tmparray['__OTHER4__'] = 'Other4';
2224 $tmparray['__OTHER5__'] = 'Other5';
2226 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode'; // If source is a thirdparty
2228 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2229 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2230 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2232 $onlinepaymentenabled = 0;
2233 if (isModEnabled('paypal')) {
2234 $onlinepaymentenabled++;
2236 if (isModEnabled('stripe')) {
2237 $onlinepaymentenabled++;
2239 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2240 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2241 if (isModEnabled('member')) {
2242 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2244 if (isModEnabled('don')) {
2245 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2247 if (isModEnabled('invoice')) {
2248 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2250 if (isModEnabled('order')) {
2251 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2253 if (isModEnabled('contract')) {
2254 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2257 //Online payment link
2258 if (isModEnabled('member')) {
2259 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2261 if (isModEnabled('don')) {
2262 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2264 if (isModEnabled('invoice')) {
2265 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2267 if (isModEnabled('order')) {
2268 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2270 if (isModEnabled('contract')) {
2271 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2274 /* No need to show into tooltip help, option is not enabled
2275 $vars['__SECUREKEYPAYMENT__']='';
2276 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2277 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2278 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2279 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2282 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2283 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2287 foreach ($tmparray as $key => $val) {
2289 $tmparray[$key] = $key;