473 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
476 global
$conf, $langs, $user, $hookmanager, $form;
478 if (!is_object($form)) {
479 $form =
new Form($this->db);
483 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
484 $formfile =
new FormFile($this->db);
486 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formai.class.php';
487 $formai =
new FormAI($this->db);
490 $langs->loadLangs(array(
'other',
'mails',
'members'));
493 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
498 $hookmanager->initHooks(array(
'formmail'));
501 'addfileaction' => $addfileaction,
502 'removefileaction' => $removefileaction,
503 'trackid' => $this->trackid
505 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
507 if (!empty($reshook)) {
508 return $hookmanager->resPrint;
512 $disablebademails = 1;
515 $outputlangs = $langs;
517 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
518 $newlang = $this->param[
'langsmodels'];
520 if (!empty($newlang)) {
522 $outputlangs->setDefaultLang($newlang);
523 $outputlangs->load(
'other');
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') {
594 setEventMessages($this->error, $this->errors,
'errors');
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.
'>';
785 dol_print_error($this->db);
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 $parameters = array();
829 $reshook = $hookmanager->executeHooks(
'printEmailRecipients', $parameters, $this);
831 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
833 $out .= $hookmanager->resPrint;
834 if (empty($reshook)) {
836 if (!empty($this->withto) || is_array($this->withto)) {
841 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
843 $out .= $langs->trans(
"MailToUsers");
847 $tmparray = $this->withtouser;
848 foreach ($tmparray as $key => $val) {
851 $withtoselected =
GETPOST(
"receiveruser",
'array');
852 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
853 $withtoselected = array_keys($tmparray);
855 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
856 $out .=
"</td></tr>\n";
860 if (!empty($this->withoptiononeemailperrecipient)) {
861 if (abs($this->withoptiononeemailperrecipient) == 1) {
862 $out .=
'<tr><td class="minwidth200">';
863 $out .= $langs->trans(
"GroupEmails");
865 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
866 $out .=
'<label for="oneemailperrecipient">';
867 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
873 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
874 if (!empty($this->withto) && !is_array($this->withto)) {
875 $out .=
' <span class="opacitymedium">'.$langs->trans(
"or").
'</span> <input type="email" name="emailto" value="">';
878 $out .=
'</td></tr>';
880 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
885 if (!empty($this->withtocc) || is_array($this->withtocc)) {
890 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
892 $out .= $langs->trans(
"MailToCCUsers");
896 $tmparray = $this->withtoccuser;
897 foreach ($tmparray as $key => $val) {
900 $withtoselected =
GETPOST(
"receiverccuser",
'array');
901 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
902 $withtoselected = array_keys($tmparray);
904 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
905 $out .=
"</td></tr>\n";
909 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
915 if (!empty($this->withreplyto)) {
916 if ($this->withreplytoreadonly) {
917 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
918 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
919 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
920 $out .=
"</td></tr>\n";
925 if (!empty($this->witherrorsto)) {
930 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
935 if (!empty($this->withtopic)) {
936 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
940 if (!empty($this->withfile)) {
942 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
946 if ($this->withmaindocfile) {
949 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
950 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
952 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
956 if (!empty($this->withmaindocfile)) {
957 if ($this->withmaindocfile == 1) {
958 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
959 } elseif ($this->withmaindocfile == -1) {
960 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
963 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
965 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
969 if (is_numeric($this->withfile)) {
971 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
972 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
973 $out .=
'jQuery(document).ready(function () {';
974 $out .=
' jQuery(".removedfile").click(function() {';
975 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
978 $out .=
'</script>'.
"\n";
979 if (count($listofpaths)) {
980 foreach ($listofpaths as $key => $val) {
981 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
983 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] :
$conf->entity);
985 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
988 $formfile_params = array();
989 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
991 $out .=
'<div id="attachfile_'.$key.
'">';
993 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
995 $out .=
' '.$formfile->showPreview(array(
'fullname' => $val,
'name' => basename($val)), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
997 if (!$this->withfilereadonly) {
998 $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.
'" />';
1001 $out .=
'<br></div>';
1006 if ($this->withfile == 2) {
1008 $maxmin = $maxfilesizearray[
'maxmin'];
1010 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1014 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
1016 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1019 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1022 $out .= $this->withfile;
1025 $out .=
"</td></tr>\n";
1029 if (!empty($this->withbody)) {
1030 $defaultmessage =
GETPOST(
'message',
'restricthtml');
1031 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
1032 if ($arraydefaultmessage && $arraydefaultmessage->content) {
1033 $defaultmessage = (string) $arraydefaultmessage->content;
1034 } elseif (!is_numeric($this->withbody)) {
1035 $defaultmessage = $this->withbody;
1042 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1043 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1045 if (empty($this->substit[
'__REF__'])) {
1048 $langs->loadLangs(array(
'paypal',
'other'));
1049 $typeforonlinepayment =
'free';
1050 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1051 $typeforonlinepayment =
'order';
1053 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1054 $typeforonlinepayment =
'invoice';
1056 if ($this->param[
"models"] ==
'member') {
1057 $typeforonlinepayment =
'member';
1059 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1063 if (count($validpaymentmethod) > 0 && $paymenturl) {
1064 $langs->load(
'other');
1065 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
1066 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
1067 } elseif (count($validpaymentmethod) > 0) {
1068 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
1069 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
1071 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1072 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1075 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1079 $defaultlines = $arraydefaultmessage->content_lines;
1080 if (isset($defaultlines)) {
1081 foreach ($this->substit_lines as $lineid => $substit_line) {
1085 $this->substit[
'__LINES__'] = $lines;
1087 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1090 $atleastonecomponentishtml = 0;
1091 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1092 $atleastonecomponentishtml++;
1094 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1095 $atleastonecomponentishtml++;
1097 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1098 $atleastonecomponentishtml++;
1100 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1101 $atleastonecomponentishtml++;
1104 $atleastonecomponentishtml++;
1106 if ($atleastonecomponentishtml) {
1108 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1110 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1111 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1114 $this->substit[
'__LINES__'] =
dol_nl2br($this->substit[
'__LINES__']);
1116 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1117 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1120 $defaultmessage =
dol_nl2br($defaultmessage);
1125 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1132 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1133 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1136 $out .=
'<!-- Message line from get_form -->';
1138 $out .=
'<td class="tdtop">';
1139 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1141 $out .=
'<td class="tdtop">';
1144 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1145 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1146 $showlinktoai = ($formmail->withaiprompt &&
isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1147 $showlinktoailabel = $langs->trans(
"AIEnhancements");
1148 $formatforouput =
'';
1149 $htmlname =
'message';
1151 $formai->substit = $this->substit;
1152 $formai->substit_lines = $this->substit_lines;
1156 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1162 $out .=
'<td colspan="2">';
1163 if ($this->withbodyreadonly) {
1164 $out .= nl2br($defaultmessage);
1165 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1167 if (!isset($this->ckeditortoolbar)) {
1168 $this->ckeditortoolbar =
'dolibarr_mailings';
1172 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1173 if ($this->withfckeditor == -1) {
1175 $this->withfckeditor = 1;
1177 $this->withfckeditor = 0;
1184 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true, $uselocalbrowser, $this->withfckeditor, 8,
'95%');
1185 $out .= $doleditor->Create(1);
1187 $out .=
"</td></tr>\n";
1190 $out .=
'</table>'.
"\n";
1192 if ($this->withform == 1 || $this->withform == -1) {
1193 $out .=
'<div class="center">';
1194 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1196 if ($this->withfile == 2 &&
$conf->use_javascript_ajax) {
1197 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1200 if ($this->withcancel) {
1201 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1203 $out .= '</div>'."\n
";
1206 if ($this->withform == 1) {
1207 $out .= '</form>'."\n
";
1210 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1211 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1212 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1213 $out .= 'jQuery(document).ready(function () {';
1214 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1215 var code = e.keyCode || e.which;
1217 console.log("Enter was intercepted and blocked
");
1223 $out .= '</script>';
1226 $out .= "<!-- End form mail -->\n
";
2039 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
2043 if ($id == -2 && empty($label)) {
2044 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
2047 if ($type_template === 'societe') {
2048 $type_template = 'thirdparty';
2049 } elseif ($type_template === 'action') { // Object type used by notifications for an event of the agenda
2050 $type_template = 'actioncomm';
2052 $ret = new CEmailTemplate($dbs);
2054 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
2055 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
2056 $tmparray = explode('_', $languagetosearch);
2057 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
2058 if ($languagetosearchmain == $languagetosearch) {
2059 $languagetosearchmain = '';
2062 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
2063 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
2064 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'".$dbs->escape($type_template)."_send' OR type_template =
'all')
";
2065 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
2066 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
2068 $sql .= " AND
active =
".((int) $active);
2070 if ($defaultfortype >= 0) {
2071 $sql .= " AND defaultfortype =
".((int) $defaultfortype);
2074 $sql .= " AND label =
'".$dbs->escape($label)."'";
2076 if (!($id > 0) && $languagetosearch) {
2077 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
2080 $sql .= " AND rowid =
".(int) $id;
2085 $sql .= " AND entity IN(
".getEntity('c_email_templates', 1).")
";
2086 if ($languagetosearch) {
2087 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
2089 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
2091 //$sql .= $dbs->plimit(1);
2094 $resql = $dbs->query($sql);
2096 dol_print_error($dbs);
2102 $obj = $dbs->fetch_object($resql);
2105 // If template is for a module, check module is enabled; if not, take next template
2107 $tempmodulekey = $obj->module;
2108 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
2113 // If a record was found
2114 $ret->id = (int) $obj->rowid;
2115 $ret->module = (string) $obj->module;
2116 $ret->label = (string) $obj->label;
2117 $ret->lang = $obj->lang;
2118 $ret->topic = $obj->topic;
2119 $ret->content = (string) $obj->content;
2120 $ret->content_lines = (string) $obj->content_lines;
2121 $ret->joinfiles = $obj->joinfiles;
2122 $ret->email_from = (string) $obj->email_from;
2123 $ret->email_tocc = (string) $obj->email_tocc;
2124 $ret->email_tobcc = (string) $obj->email_tobcc;
2128 // If no record found
2130 // Not found with the provided label
2133 // If there is no template at all
2134 $defaultmessage = '';
2136 if ($type_template == 'body') {
2137 // Special case to use this->withbody as content
2138 $defaultmessage = (string) $this->withbody;
2139 } elseif ($type_template == 'facture_send' || $type_template == 'facture' || $type_template == 'facture_relance') {
2140 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendInvoice
");
2141 } elseif ($type_template == 'propal_send' || $type_template == 'propal') {
2142 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendProposal
");
2143 } elseif ($type_template == 'supplier_proposal_send' || $type_template == 'supplier_proposal') {
2144 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendSupplierProposal
");
2145 } elseif ($type_template == 'order_send' || $type_template == 'order') {
2146 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendOrder
");
2147 } elseif ($type_template == 'order_supplier_send' || $type_template == 'order_supplier') {
2148 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendSupplierOrder
");
2149 } elseif ($type_template == 'invoice_supplier_send' || $type_template == 'invoice_supplier') {
2150 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendSupplierInvoice
");
2151 } elseif ($type_template == 'shipping_send' || $type_template == 'shipping') {
2152 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendShipping
");
2153 } elseif ($type_template == 'reception_send' || $type_template == 'reception') {
2154 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendReception
");
2155 } elseif ($type_template == 'fichinter_send' || $type_template == 'fichinter') {
2156 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendFichInter
");
2157 } elseif ($type_template == 'actioncomm_send' || $type_template == 'actioncomm') {
2158 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentSendActionComm
");
2159 } elseif (!empty($type_template)) {
2160 $defaultmessage = $outputlangs->transnoentitiesnoconv("PredefinedMailContentGeneric
");
2163 $ret->label = 'default';
2164 $ret->lang = $outputlangs->defaultlang;
2166 $ret->joinfiles = 1;
2167 $ret->content = $defaultmessage;
2168 $ret->content_lines = '';
2359 public function setSubstitFromObject($object, $outputlangs)
2361 global $extrafields;
2363 $parameters = array();
2364 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
2365 complete_substitutions_array($tmparray, $outputlangs, $object, $parameters);
2367 $this->substit = $tmparray;
2369 if (is_object($outputlangs) && !empty($outputlangs->defaultlang)) {
2370 $targetLang = trim((string) $outputlangs->defaultlang);
2373 // Fill substit_lines with each object lines content
2374 if (is_array($object->lines)) {
2375 foreach ($object->lines as $line) {
2376 $substit_line = array(
2377 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
2378 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
2379 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
2380 '__LABEL__' => isset($line->label) ? $line->label : '',
2381 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
2382 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
2383 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
2384 '__QUANTITY__' => $line->qty,
2385 '__SUBPRICE__' => price($line->subprice),
2386 '__AMOUNT__' => price($line->total_ttc),
2387 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
2390 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2391 if (!empty($line->fk_product)) {
2392 if (!is_object($extrafields)) {
2393 $extrafields = new ExtraFields($this->db);
2395 $product = new Product($this->db);
2396 $product->fetch($line->fk_product, '', '', '1');
2397 $product->fetch_optionals();
2399 if (getDolGlobalInt('MAIN_MULTILANGS') && $targetLang !== '' && !empty($product->multilangs) && is_array($product->multilangs)) {
2400 $translated = self::getBestProductTranslation($product->multilangs, $targetLang);
2401 $translatedLabel = trim((string) (isset($translated['label']) ? $translated['label'] : ''));
2402 $translatedDescription = trim((string) (isset($translated['description']) ? $translated['description'] : ''));
2404 $currentLabelNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_LABEL__']);
2405 $currentProductDescriptionNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_DESCRIPTION__']);
2406 $currentLineDescriptionNorm = self::normalizeTextForComparison($substit_line['__DESCRIPTION__']);
2407 $productLabelNorm = self::normalizeTextForComparison($product->label);
2408 $productDescriptionNorm = self::normalizeTextForComparison($product->description);
2410 if ($translatedLabel !== '' && ($currentLabelNorm === '' || $currentLabelNorm === $productLabelNorm)) {
2411 $substit_line['__PRODUCT_LABEL__'] = $translatedLabel;
2413 if ($translatedDescription !== '' && ($currentProductDescriptionNorm === '' || $currentProductDescriptionNorm === $productDescriptionNorm)) {
2414 $substit_line['__PRODUCT_DESCRIPTION__'] = $translatedDescription;
2416 if ($translatedDescription !== '' && ($currentLineDescriptionNorm === '' || $currentLineDescriptionNorm === $productDescriptionNorm || $currentLineDescriptionNorm === $currentProductDescriptionNorm)) {
2417 $substit_line['__DESCRIPTION__'] = $translatedDescription;
2421 $extrafields->fetch_name_optionals_label($product->table_element, true);
2423 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2424 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2425 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2430 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2442 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2446 $tmparray = array();
2447 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2448 $parameters = array('mode' => $mode);
2449 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email template creation, this may be null because it is related to all type of objects
2450 complete_substitutions_array($tmparray, $langs, null, $parameters);
2452 if ($mode == 'formemailwithlines') {
2453 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2455 if ($mode == 'formemailforlines') {
2456 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2460 if ($mode == 'emailing') {
2461 $parameters = array('mode' => $mode);
2462 $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
2463 complete_substitutions_array($tmparray, $langs, null, $parameters);
2465 // For mass emailing, we have different keys specific to the data into tagerts list
2466 $tmparray['__ID__'] = 'IdRecord';
2467 $tmparray['__EMAIL__'] = 'EMailRecipient';
2468 $tmparray['__LASTNAME__'] = 'Lastname';
2469 $tmparray['__FIRSTNAME__'] = 'Firstname';
2470 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2471 $tmparray['__OTHER1__'] = 'Other1';
2472 $tmparray['__OTHER2__'] = 'Other2';
2473 $tmparray['__OTHER3__'] = 'Other3';
2474 $tmparray['__OTHER4__'] = 'Other4';
2475 $tmparray['__OTHER5__'] = 'Other5';
2477 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode'; // If source is a thirdparty
2479 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2480 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2481 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2483 $onlinepaymentenabled = 0;
2484 if (isModEnabled('paypal')) {
2485 $onlinepaymentenabled++;
2487 if (isModEnabled('stripe')) {
2488 $onlinepaymentenabled++;
2490 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2491 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2492 if (isModEnabled('member')) {
2493 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2495 if (isModEnabled('don')) {
2496 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2498 if (isModEnabled('invoice')) {
2499 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2501 if (isModEnabled('order')) {
2502 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2504 if (isModEnabled('contract')) {
2505 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2508 //Online payment link
2509 if (isModEnabled('member')) {
2510 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2512 if (isModEnabled('don')) {
2513 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2515 if (isModEnabled('invoice')) {
2516 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2518 if (isModEnabled('order')) {
2519 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2521 if (isModEnabled('contract')) {
2522 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2525 /* No need to show into tooltip help, option is not enabled
2526 $vars['__SECUREKEYPAYMENT__']='';
2527 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2528 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2529 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2530 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2533 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2534 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2538 foreach ($tmparray as $key => $val) {
2540 $tmparray[$key] = $key;