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);
522 $outputlangs->load(
'other');
526 $arraydefaultmessage = -1;
527 if ($this->param[
'models'] !=
'none') {
529 if (array_key_exists(
'models_id', $this->param)) {
530 $model_id = $this->param[
"models_id"];
533 $arraydefaultmessage = $this->
getEMailTemplate($this->db, $this->param[
"models"], $user, $outputlangs, $model_id, 1,
'', ($model_id > 0 ? -1 : 1));
537 $listofpaths = array();
538 $listofnames = array();
539 $listofmimes = array();
540 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
542 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
543 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
544 foreach ($this->param[
'fileinit'] as $path) {
552 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
553 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
555 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
556 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
558 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
559 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
563 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
564 if ($this->withform == 1) {
565 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
567 $out .=
'<a id="formmail" name="formmail"></a>';
568 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
569 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
570 $out .=
'<input type="hidden" name="page_y" value="" />';
571 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
572 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
574 if (!empty($this->withfrom)) {
575 if (!empty($this->withfromreadonly)) {
576 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
577 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
580 foreach ($this->param as $key => $value) {
581 if (is_array($value)) {
582 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
584 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
588 $modelmail_array = array();
590 if ($this->param[
'models'] !=
'none') {
596 foreach ($this->lines_model as $line) {
598 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
599 $labeltouse = $langs->trans($reg[1]);
601 $labeltouse = $line->label;
604 if ($break != $line->lang) {
607 $shtml =
'----- '.$langs->trans(
"Language_".$line->lang).
' -----';
608 $modelmail_array[
'separator_'.$line->lang] = array(
'label' => $s,
'data-html' => $shtml,
'disabled' =>
'disabled');
617 if ($line->private) {
618 $shtml .=
' - <span class="opacitymedium small">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
621 $modelmail_array[$line->id] = array(
'label' => $s,
'data-html' => $shtml);
626 if (count($modelmail_array) > 0) {
627 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOSTINT(
'modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
630 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
632 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans(
'SelectMailModel'), 0, 0,
'', 0, 0, 0,
'',
'minwidth150', 1,
'', 0, 1);
634 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
643 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
645 $currentlang = (is_object($outputlangs) ? $outputlangs->defaultlang : $langs->defaultlang);
647 $out .= $formadmin->select_language($currentlang,
'lang_id', 0, array(), 1, 0, 0,
'maxwidth150');
651 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
654 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
655 'propal_send',
'order_send',
'facture_send',
656 'shipping_send',
'reception_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
657 'invoice_supplier_send',
'supplier_payment_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'product_send',
'all'
660 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
661 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
662 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
664 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
667 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
671 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
675 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
678 $helpforsubstitution =
'';
679 if (is_array($this->substit) && count($this->substit)) {
680 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
681 foreach ($this->substit as $key => $val) {
683 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
686 if (is_array($val)) {
687 $val = implode(
', ', $val);
691 $helpforsubstitution .=
'</span>';
706 if (!empty($this->withfrom)) {
707 if (!empty($this->withfromreadonly)) {
708 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
711 if (!($this->fromtype ===
'user' && $this->fromid > 0)
712 && !($this->fromtype ===
'company')
713 && !($this->fromtype ===
'robot')
714 && !preg_match(
'/user_aliases/', $this->fromtype)
715 && !preg_match(
'/global_aliases/', $this->fromtype)
716 && !preg_match(
'/senderprofile/', $this->fromtype)
719 $out .= $this->fromname;
720 if ($this->frommail) {
721 $out .=
' <'.$this->frommail.
'>';
723 if ($this->fromtype) {
724 $langs->load(
'errors');
725 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
732 if (empty($user->email)) {
733 $langs->load(
'errors');
734 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
736 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
738 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
743 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
747 $listaliases = array(
751 if (!empty($arraydefaultmessage->email_from) && !empty($arraydefaultmessage->id)) {
752 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
753 $liste[
'from_template_'.((int) $arraydefaultmessage->id)] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
757 if (!empty($this->fromalsorobot)) {
760 if ($this->frommail) {
763 $liste[
'main_from'] = array(
'label' => $s,
'data-html' => $s);
768 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
769 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
") AND entity IN (".
getEntity(
'c_email_senderprofile').
")";
770 $sql .=
" ORDER BY position";
771 $resql = $this->db->query($sql);
773 $num = $this->db->num_rows($resql);
776 $obj = $this->db->fetch_object($resql);
778 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
786 foreach ($listaliases as $typealias => $listalias) {
788 $listaliasarray = explode(
',', $listalias);
789 foreach ($listaliasarray as $listaliasval) {
791 $listaliasval = trim($listaliasval);
793 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
794 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
795 if (!preg_match(
'/</', $listaliasval)) {
796 $listaliasval =
'<'.$listaliasval.
'>';
798 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
806 foreach ($liste as $key => $val) {
807 if (!empty($liste[$key][
'data-html'])) {
808 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
809 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
812 $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);
815 $out .=
"</td></tr>\n";
817 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
818 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
819 $out .=
' ';
820 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
821 $out .=
"</td></tr>\n";
826 $parameters = array();
827 $reshook = $hookmanager->executeHooks(
'printEmailRecipients', $parameters, $this);
831 $out .= $hookmanager->resPrint;
832 if (empty($reshook)) {
834 if (!empty($this->withto) || is_array($this->withto)) {
839 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
841 $out .= $langs->trans(
"MailToUsers");
845 $tmparray = $this->withtouser;
846 foreach ($tmparray as $key => $val) {
849 $withtoselected =
GETPOST(
"receiveruser",
'array');
850 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
851 $withtoselected = array_keys($tmparray);
853 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
854 $out .=
"</td></tr>\n";
858 if (!empty($this->withoptiononeemailperrecipient)) {
859 if (abs($this->withoptiononeemailperrecipient) == 1) {
860 $out .=
'<tr><td class="minwidth200">';
861 $out .= $langs->trans(
"GroupEmails");
863 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
864 $out .=
'<label for="oneemailperrecipient">';
865 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
871 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
872 if (!empty($this->withto) && !is_array($this->withto)) {
873 $out .=
' <span class="opacitymedium">'.$langs->trans(
"or").
'</span> <input type="email" name="emailto" value="">';
876 $out .=
'</td></tr>';
878 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
883 if (!empty($this->withtocc) || is_array($this->withtocc)) {
888 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
890 $out .= $langs->trans(
"MailToCCUsers");
894 $tmparray = $this->withtoccuser;
895 foreach ($tmparray as $key => $val) {
898 $withtoselected =
GETPOST(
"receiverccuser",
'array');
899 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
900 $withtoselected = array_keys($tmparray);
902 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
903 $out .=
"</td></tr>\n";
907 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
913 if (!empty($this->withreplyto)) {
914 if ($this->withreplytoreadonly) {
915 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
916 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
917 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
918 $out .=
"</td></tr>\n";
923 if (!empty($this->witherrorsto)) {
928 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
933 if (!empty($this->withtopic)) {
934 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
938 if (!empty($this->withfile)) {
940 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
944 if ($this->withmaindocfile) {
946 if (GETPOSTISSET(
'sendmail')) {
947 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
948 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
950 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
954 if (!empty($this->withmaindocfile)) {
955 if ($this->withmaindocfile == 1) {
956 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
957 } elseif ($this->withmaindocfile == -1) {
958 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
961 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
963 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
967 if (is_numeric($this->withfile)) {
969 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
970 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
971 $out .=
'jQuery(document).ready(function () {';
972 $out .=
' jQuery(".removedfile").click(function() {';
973 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
976 $out .=
'</script>'.
"\n";
977 if (count($listofpaths)) {
978 foreach ($listofpaths as $key => $val) {
979 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
981 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] :
$conf->entity);
983 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
986 $formfile_params = array();
987 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
989 $out .=
'<div id="attachfile_'.$key.
'">';
991 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
993 $out .=
' '.$formfile->showPreview(array(
'fullname' => $val,
'name' => basename($val)), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
995 if (!$this->withfilereadonly) {
996 $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.
'" />';
999 $out .=
'<br></div>';
1004 if ($this->withfile == 2) {
1006 $maxmin = $maxfilesizearray[
'maxmin'];
1008 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1012 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
1014 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
1017 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
1020 $out .= $this->withfile;
1023 $out .=
"</td></tr>\n";
1027 if (!empty($this->withbody)) {
1028 $defaultmessage =
GETPOST(
'message',
'restricthtml');
1029 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
1030 if ($arraydefaultmessage && $arraydefaultmessage->content) {
1031 $defaultmessage = (
string) $arraydefaultmessage->content;
1032 } elseif (!is_numeric($this->withbody)) {
1033 $defaultmessage = $this->withbody;
1040 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1041 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1043 if (empty($this->substit[
'__REF__'])) {
1046 $langs->loadLangs(array(
'paypal',
'other'));
1047 $typeforonlinepayment =
'free';
1048 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1049 $typeforonlinepayment =
'order';
1051 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1052 $typeforonlinepayment =
'invoice';
1054 if ($this->param[
"models"] ==
'member') {
1055 $typeforonlinepayment =
'member';
1057 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1061 if (count($validpaymentmethod) > 0 && $paymenturl) {
1062 $langs->load(
'other');
1063 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
1064 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
1065 } elseif (count($validpaymentmethod) > 0) {
1066 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
1067 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
1069 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1070 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1073 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1077 $defaultlines = $arraydefaultmessage->content_lines;
1078 if (isset($defaultlines)) {
1079 foreach ($this->substit_lines as $lineid => $substit_line) {
1083 $this->substit[
'__LINES__'] = $lines;
1085 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1088 $atleastonecomponentishtml = 0;
1089 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1090 $atleastonecomponentishtml++;
1092 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1093 $atleastonecomponentishtml++;
1095 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1096 $atleastonecomponentishtml++;
1098 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1099 $atleastonecomponentishtml++;
1102 $atleastonecomponentishtml++;
1104 if ($atleastonecomponentishtml) {
1106 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1108 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1109 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1112 $this->substit[
'__LINES__'] =
dol_nl2br($this->substit[
'__LINES__']);
1114 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1115 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1118 $defaultmessage =
dol_nl2br($defaultmessage);
1122 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
1123 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1130 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1131 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1134 $out .=
'<!-- Message line from get_form -->';
1136 $out .=
'<td class="tdtop">';
1137 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1139 $out .=
'<td class="tdtop">';
1142 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1143 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1144 $showlinktoai = ($formmail->withaiprompt &&
isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1145 $showlinktoailabel = $langs->trans(
"AIEnhancements");
1146 $formatforouput =
'';
1147 $htmlname =
'message';
1149 $formai->substit = $this->substit;
1150 $formai->substit_lines = $this->substit_lines;
1154 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1160 $out .=
'<td colspan="2">';
1161 if ($this->withbodyreadonly) {
1162 $out .= nl2br($defaultmessage);
1163 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1165 if (!isset($this->ckeditortoolbar)) {
1166 $this->ckeditortoolbar =
'dolibarr_mailings';
1170 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1171 if ($this->withfckeditor == -1) {
1173 $this->withfckeditor = 1;
1175 $this->withfckeditor = 0;
1182 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true, $uselocalbrowser, $this->withfckeditor, 8,
'95%');
1183 $out .= $doleditor->Create(1);
1185 $out .=
"</td></tr>\n";
1188 $out .=
'</table>'.
"\n";
1190 if ($this->withform == 1 || $this->withform == -1) {
1191 $out .=
'<div class="center">';
1192 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1194 if ($this->withfile == 2 &&
$conf->use_javascript_ajax) {
1195 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1198 if ($this->withcancel) {
1199 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1201 $out .= '</div>'."\n
";
1204 if ($this->withform == 1) {
1205 $out .= '</form>'."\n
";
1208 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1209 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1210 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1211 $out .= 'jQuery(document).ready(function () {';
1212 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1213 var code = e.keyCode || e.which;
1215 console.log("Enter was intercepted and blocked
");
1221 $out .= '</script>';
1224 $out .= "<!-- End form mail -->\n
";
1800 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1804 if ($id == -2 && empty($label)) {
1805 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1808 if ($type_template === 'societe') {
1809 $type_template = 'thirdparty';
1811 $ret = new CEmailTemplate($dbs);
1813 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1814 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1815 $tmparray = explode('_', $languagetosearch);
1816 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1817 if ($languagetosearchmain == $languagetosearch) {
1818 $languagetosearchmain = '';
1821 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1822 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1823 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'".$dbs->escape($type_template)."_send' OR type_template =
'all')
";
1824 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1825 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1827 $sql .= " AND
active =
".((int) $active);
1829 if ($defaultfortype >= 0) {
1830 $sql .= " AND defaultfortype =
".((int) $defaultfortype);
1833 $sql .= " AND label =
'".$dbs->escape($label)."'";
1835 if (!($id > 0) && $languagetosearch) {
1836 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1839 $sql .= " AND rowid =
".(int) $id;
1844 $sql .= " AND entity IN(
".getEntity('c_email_templates', 1).")
";
1845 if ($languagetosearch) {
1846 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1848 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1850 //$sql .= $dbs->plimit(1);
1853 $resql = $dbs->query($sql);
1855 dol_print_error($dbs);
1861 $obj = $dbs->fetch_object($resql);
1864 // If template is for a module, check module is enabled; if not, take next template
1866 $tempmodulekey = $obj->module;
1867 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1872 // If a record was found
1873 $ret->id = (int) $obj->rowid;
1874 $ret->module = (string) $obj->module;
1875 $ret->label = (string) $obj->label;
1876 $ret->lang = $obj->lang;
1877 $ret->topic = $obj->topic;
1878 $ret->content = (string) $obj->content;
1879 $ret->content_lines = (string) $obj->content_lines;
1880 $ret->joinfiles = $obj->joinfiles;
1881 $ret->email_from = (string) $obj->email_from;
1882 $ret->email_tocc = (string) $obj->email_tocc;
1883 $ret->email_tobcc = (string) $obj->email_tobcc;
1887 // If no record found
1889 // Not found with the provided label
1892 // If there is no template at all
1893 $defaultmessage = '';
1895 if ($type_template == 'body') {
1896 // Special case to use this->withbody as content
1897 $defaultmessage = (string) $this->withbody;
1898 } elseif ($type_template == 'facture_send' || $type_template == 'facture' || $type_template == 'facture_relance') {
1899 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1900 } elseif ($type_template == 'propal_send' || $type_template == 'propal') {
1901 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1902 } elseif ($type_template == 'supplier_proposal_send' || $type_template == 'supplier_proposal') {
1903 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1904 } elseif ($type_template == 'order_send' || $type_template == 'order') {
1905 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1906 } elseif ($type_template == 'order_supplier_send' || $type_template == 'order_supplier') {
1907 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1908 } elseif ($type_template == 'invoice_supplier_send' || $type_template == 'invoice_supplier') {
1909 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1910 } elseif ($type_template == 'shipping_send' || $type_template == 'shipping') {
1911 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1912 } elseif ($type_template == 'reception_send' || $type_template == 'reception') {
1913 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendReception
");
1914 } elseif ($type_template == 'fichinter_send' || $type_template == 'fichinter') {
1915 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1916 } elseif ($type_template == 'actioncomm_send' || $type_template == 'actioncomm') {
1917 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1918 } elseif (!empty($type_template)) {
1919 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1922 $ret->label = 'default';
1923 $ret->lang = $outputlangs->defaultlang;
1925 $ret->joinfiles = 1;
1926 $ret->content = $defaultmessage;
1927 $ret->content_lines = '';
2118 public function setSubstitFromObject($object, $outputlangs)
2120 global $extrafields;
2122 $parameters = array();
2123 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
2124 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
2126 $this->substit = $tmparray;
2128 if (is_object($outputlangs) && !empty($outputlangs->defaultlang)) {
2129 $targetLang = trim((string) $outputlangs->defaultlang);
2132 // Fill substit_lines with each object lines content
2133 if (is_array($object->lines)) {
2134 foreach ($object->lines as $line) {
2135 $substit_line = array(
2136 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
2137 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
2138 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
2139 '__LABEL__' => isset($line->label) ? $line->label : '',
2140 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
2141 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
2142 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
2143 '__QUANTITY__' => $line->qty,
2144 '__SUBPRICE__' => price($line->subprice),
2145 '__AMOUNT__' => price($line->total_ttc),
2146 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
2149 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2150 if (!empty($line->fk_product)) {
2151 if (!is_object($extrafields)) {
2152 $extrafields = new ExtraFields($this->db);
2154 $product = new Product($this->db);
2155 $product->fetch($line->fk_product, '', '', '1');
2156 $product->fetch_optionals();
2158 if (getDolGlobalInt('MAIN_MULTILANGS') && $targetLang !== '' && !empty($product->multilangs) && is_array($product->multilangs)) {
2159 $translated = self::getBestProductTranslation($product->multilangs, $targetLang);
2160 $translatedLabel = trim((string) (isset($translated['label']) ? $translated['label'] : ''));
2161 $translatedDescription = trim((string) (isset($translated['description']) ? $translated['description'] : ''));
2163 $currentLabelNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_LABEL__']);
2164 $currentProductDescriptionNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_DESCRIPTION__']);
2165 $currentLineDescriptionNorm = self::normalizeTextForComparison($substit_line['__DESCRIPTION__']);
2166 $productLabelNorm = self::normalizeTextForComparison($product->label);
2167 $productDescriptionNorm = self::normalizeTextForComparison($product->description);
2169 if ($translatedLabel !== '' && ($currentLabelNorm === '' || $currentLabelNorm === $productLabelNorm)) {
2170 $substit_line['__PRODUCT_LABEL__'] = $translatedLabel;
2172 if ($translatedDescription !== '' && ($currentProductDescriptionNorm === '' || $currentProductDescriptionNorm === $productDescriptionNorm)) {
2173 $substit_line['__PRODUCT_DESCRIPTION__'] = $translatedDescription;
2175 if ($translatedDescription !== '' && ($currentLineDescriptionNorm === '' || $currentLineDescriptionNorm === $productDescriptionNorm || $currentLineDescriptionNorm === $currentProductDescriptionNorm)) {
2176 $substit_line['__DESCRIPTION__'] = $translatedDescription;
2180 $extrafields->fetch_name_optionals_label($product->table_element, true);
2182 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2183 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2184 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2189 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2201 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2205 $tmparray = array();
2206 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2207 $parameters = array('mode' => $mode);
2208 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email template creation, this may be null because it is related to all type of objects
2209 complete_substitutions_array($tmparray, $langs, null, $parameters);
2211 if ($mode == 'formwithlines') {
2212 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2214 if ($mode == 'formforlines') {
2215 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2219 if ($mode == 'emailing') {
2220 $parameters = array('mode' => $mode);
2221 $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
2222 complete_substitutions_array($tmparray, $langs, null, $parameters);
2224 // For mass emailing, we have different keys specific to the data into tagerts list
2225 $tmparray['__ID__'] = 'IdRecord';
2226 $tmparray['__EMAIL__'] = 'EMailRecipient';
2227 $tmparray['__LASTNAME__'] = 'Lastname';
2228 $tmparray['__FIRSTNAME__'] = 'Firstname';
2229 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2230 $tmparray['__OTHER1__'] = 'Other1';
2231 $tmparray['__OTHER2__'] = 'Other2';
2232 $tmparray['__OTHER3__'] = 'Other3';
2233 $tmparray['__OTHER4__'] = 'Other4';
2234 $tmparray['__OTHER5__'] = 'Other5';
2236 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode'; // If source is a thirdparty
2238 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2239 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2240 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2242 $onlinepaymentenabled = 0;
2243 if (isModEnabled('paypal')) {
2244 $onlinepaymentenabled++;
2246 if (isModEnabled('stripe')) {
2247 $onlinepaymentenabled++;
2249 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2250 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2251 if (isModEnabled('member')) {
2252 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2254 if (isModEnabled('don')) {
2255 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2257 if (isModEnabled('invoice')) {
2258 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2260 if (isModEnabled('order')) {
2261 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2263 if (isModEnabled('contract')) {
2264 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2267 //Online payment link
2268 if (isModEnabled('member')) {
2269 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2271 if (isModEnabled('don')) {
2272 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2274 if (isModEnabled('invoice')) {
2275 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2277 if (isModEnabled('order')) {
2278 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2280 if (isModEnabled('contract')) {
2281 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2284 /* No need to show into tooltip help, option is not enabled
2285 $vars['__SECUREKEYPAYMENT__']='';
2286 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2287 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2288 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2289 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2292 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2293 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2297 foreach ($tmparray as $key => $val) {
2299 $tmparray[$key] = $key;