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();
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;
606 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
608 if ($line->private) {
609 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
615 if (count($modelmail_array) > 0) {
616 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOSTINT(
'modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
619 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
621 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans(
'SelectMailModel'), 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
623 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
627 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
630 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
631 'propal_send',
'order_send',
'facture_send',
632 'shipping_send',
'reception_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
633 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'product_send',
'all'
636 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
637 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
638 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
640 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
643 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
647 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
651 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
654 $helpforsubstitution =
'';
655 if (is_array($this->substit) && count($this->substit)) {
656 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
657 foreach ($this->substit as $key => $val) {
659 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
662 if (is_array($val)) $val = implode(
', ', $val);
665 $helpforsubstitution .=
'</span>';
680 if (!empty($this->withfrom)) {
681 if (!empty($this->withfromreadonly)) {
682 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
685 if (!($this->fromtype ===
'user' && $this->fromid > 0)
686 && !($this->fromtype ===
'company')
687 && !($this->fromtype ===
'robot')
688 && !preg_match(
'/user_aliases/', $this->fromtype)
689 && !preg_match(
'/global_aliases/', $this->fromtype)
690 && !preg_match(
'/senderprofile/', $this->fromtype)
691 && !preg_match(
'/from_template_(\d+)/', $this->fromtype)
694 $out .= $this->fromname;
695 if ($this->frommail) {
696 $out .=
' <'.$this->frommail.
'>';
698 if ($this->fromtype) {
699 $langs->load(
'errors');
700 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
707 if (empty($user->email)) {
708 $langs->load(
'errors');
709 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
711 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
713 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
718 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
722 $listaliases = array(
723 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
727 if (!empty($arraydefaultmessage->email_from) && !empty($arraydefaultmessage->id)) {
728 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
729 $liste[
'from_template_'.((int) $arraydefaultmessage->id)] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
733 if (!empty($this->fromalsorobot)) {
736 if ($this->frommail) {
739 $liste[
'main_from'] = array(
'label' => $s,
'data-html' => $s);
744 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
745 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
") AND entity IN (".
getEntity(
'c_email_senderprofile').
")";
746 $sql .=
" ORDER BY position";
747 $resql = $this->db->query($sql);
749 $num = $this->db->num_rows($resql);
752 $obj = $this->db->fetch_object($resql);
754 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
762 foreach ($listaliases as $typealias => $listalias) {
764 $listaliasarray = explode(
',', $listalias);
765 foreach ($listaliasarray as $listaliasval) {
767 $listaliasval = trim($listaliasval);
769 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
770 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
771 if (!preg_match(
'/</', $listaliasval)) {
772 $listaliasval =
'<'.$listaliasval.
'>';
774 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
782 foreach ($liste as $key => $val) {
783 if (!empty($liste[$key][
'data-html'])) {
784 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
785 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
788 $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);
791 $out .=
"</td></tr>\n";
793 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
794 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
795 $out .=
' ';
796 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
797 $out .=
"</td></tr>\n";
802 if (!empty($this->withto) || is_array($this->withto)) {
807 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
809 $out .= $langs->trans(
"MailToUsers");
813 $tmparray = $this->withtouser;
814 foreach ($tmparray as $key => $val) {
817 $withtoselected =
GETPOST(
"receiveruser",
'array');
818 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
819 $withtoselected = array_keys($tmparray);
821 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
822 $out .=
"</td></tr>\n";
826 if (!empty($this->withoptiononeemailperrecipient)) {
827 if (abs($this->withoptiononeemailperrecipient) == 1) {
828 $out .=
'<tr><td class="minwidth200">';
829 $out .= $langs->trans(
"GroupEmails");
831 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
832 $out .=
'<label for="oneemailperrecipient">';
833 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
839 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
840 if (!empty($this->withto) && !is_array($this->withto)) {
841 $out .=
' <span class="opacitymedium">'.$langs->trans(
"or").
'</span> <input type="email" name="emailto" value="">';
844 $out .=
'</td></tr>';
846 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
851 if (!empty($this->withtocc) || is_array($this->withtocc)) {
856 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
858 $out .= $langs->trans(
"MailToCCUsers");
862 $tmparray = $this->withtoccuser;
863 foreach ($tmparray as $key => $val) {
866 $withtoselected =
GETPOST(
"receiverccuser",
'array');
867 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
868 $withtoselected = array_keys($tmparray);
870 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, 0, 0,
'inline-block minwidth500', 0,
"");
871 $out .=
"</td></tr>\n";
875 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
880 if (!empty($this->withreplyto)) {
881 if ($this->withreplytoreadonly) {
882 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
883 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
884 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
885 $out .=
"</td></tr>\n";
890 if (!empty($this->witherrorsto)) {
895 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
900 if (!empty($this->withtopic)) {
901 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
905 if (!empty($this->withfile)) {
907 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
911 if ($this->withmaindocfile) {
913 if (GETPOSTISSET(
'sendmail')) {
914 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
915 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
917 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
921 if (!empty($this->withmaindocfile)) {
922 if ($this->withmaindocfile == 1) {
923 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
924 } elseif ($this->withmaindocfile == -1) {
925 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
928 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
930 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
934 if (is_numeric($this->withfile)) {
936 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
937 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
938 $out .=
'jQuery(document).ready(function () {';
939 $out .=
' jQuery(".removedfile").click(function() {';
940 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
943 $out .=
'</script>'.
"\n";
944 if (count($listofpaths)) {
945 foreach ($listofpaths as $key => $val) {
946 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
948 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] : $conf->entity);
950 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
953 $formfile_params = array();
954 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
956 $out .=
'<div id="attachfile_'.$key.
'">';
958 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
960 $out .=
' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
962 if (!$this->withfilereadonly) {
963 $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.
'" />';
966 $out .=
'<br></div>';
971 if ($this->withfile == 2) {
973 $maxmin = $maxfilesizearray[
'maxmin'];
975 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
979 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
981 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
984 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
987 $out .= $this->withfile;
990 $out .=
"</td></tr>\n";
994 if (!empty($this->withbody)) {
995 $defaultmessage =
GETPOST(
'message',
'restricthtml');
996 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
997 if ($arraydefaultmessage && $arraydefaultmessage->content) {
998 $defaultmessage = (string) $arraydefaultmessage->content;
999 } elseif (!is_numeric($this->withbody)) {
1000 $defaultmessage = $this->withbody;
1007 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1008 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1010 if (empty($this->substit[
'__REF__'])) {
1013 $langs->loadLangs(array(
'paypal',
'other'));
1014 $typeforonlinepayment =
'free';
1015 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
1016 $typeforonlinepayment =
'order';
1018 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
1019 $typeforonlinepayment =
'invoice';
1021 if ($this->param[
"models"] ==
'member') {
1022 $typeforonlinepayment =
'member';
1024 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
1028 if (count($validpaymentmethod) > 0 && $paymenturl) {
1029 $langs->load(
'other');
1030 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
1031 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
1032 } elseif (count($validpaymentmethod) > 0) {
1033 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
1034 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
1036 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
1037 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
1040 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
1044 $defaultlines = $arraydefaultmessage->content_lines;
1045 if (isset($defaultlines)) {
1046 foreach ($this->substit_lines as $lineid => $substit_line) {
1050 $this->substit[
'__LINES__'] = $lines;
1052 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
1055 $atleastonecomponentishtml = 0;
1056 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
1057 $atleastonecomponentishtml++;
1059 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1060 $atleastonecomponentishtml++;
1062 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1063 $atleastonecomponentishtml++;
1065 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1066 $atleastonecomponentishtml++;
1069 $atleastonecomponentishtml++;
1071 if ($atleastonecomponentishtml) {
1073 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
1075 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
1076 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
1079 $this->substit[
'__LINES__'] =
dol_nl2br($this->substit[
'__LINES__']);
1081 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1082 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
1085 $defaultmessage =
dol_nl2br($defaultmessage);
1089 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
1090 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1097 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1098 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1102 $out .=
'<td class="tdtop">';
1103 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1105 $out .=
'<td class="tdtop">';
1108 $showlinktolayout = ($formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout :
'';
1109 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1110 $showlinktoai = ($formmail->withaiprompt &&
isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1111 $showlinktoailabel = $langs->trans(
"AIEnhancements");
1112 $formatforouput =
'';
1113 $htmlname =
'message';
1115 $formai->substit = $this->substit;
1116 $formai->substit_lines = $this->substit_lines;
1120 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1126 $out .=
'<td colspan="2">';
1127 if ($this->withbodyreadonly) {
1128 $out .= nl2br($defaultmessage);
1129 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1131 if (!isset($this->ckeditortoolbar)) {
1132 $this->ckeditortoolbar =
'dolibarr_mailings';
1136 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1137 if ($this->withfckeditor == -1) {
1139 $this->withfckeditor = 1;
1141 $this->withfckeditor = 0;
1145 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1146 $out .= $doleditor->Create(1);
1148 $out .=
"</td></tr>\n";
1151 $out .=
'</table>'.
"\n";
1153 if ($this->withform == 1 || $this->withform == -1) {
1154 $out .=
'<div class="center">';
1155 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1157 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1158 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1161 if ($this->withcancel) {
1162 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1164 $out .= '</div>'."\n
";
1167 if ($this->withform == 1) {
1168 $out .= '</form>'."\n
";
1171 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1172 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1173 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1174 $out .= 'jQuery(document).ready(function () {';
1175 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1176 var code = e.keyCode || e.which;
1178 console.log("Enter was intercepted and blocked
");
1184 $out .= '</script>';
1187 $out .= "<!-- End form mail -->\n
";
1760 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1764 if ($id == -2 && empty($label)) {
1765 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1768 if ($type_template === 'societe') {
1769 $type_template = 'thirdparty';
1771 $ret = new CEmailTemplate($dbs);
1773 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1774 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1775 $tmparray = explode('_', $languagetosearch);
1776 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1777 if ($languagetosearchmain == $languagetosearch) {
1778 $languagetosearchmain = '';
1781 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1782 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1783 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'".$dbs->escape($type_template)."_send' OR type_template =
'all')
";
1784 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1785 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1787 $sql .= " AND
active =
".((int) $active);
1789 if ($defaultfortype >= 0) {
1790 $sql .= " AND defaultfortype =
".((int) $defaultfortype);
1793 $sql .= " AND label =
'".$dbs->escape($label)."'";
1795 if (!($id > 0) && $languagetosearch) {
1796 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1799 $sql .= " AND rowid =
".(int) $id;
1804 $sql .= " AND entity IN(
".getEntity('c_email_templates', 1).")
";
1805 if ($languagetosearch) {
1806 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1808 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1810 //$sql .= $dbs->plimit(1);
1813 $resql = $dbs->query($sql);
1815 dol_print_error($dbs);
1821 $obj = $dbs->fetch_object($resql);
1824 // If template is for a module, check module is enabled; if not, take next template
1826 $tempmodulekey = $obj->module;
1827 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1832 // If a record was found
1833 $ret->id = (int) $obj->rowid;
1834 $ret->module = (string) $obj->module;
1835 $ret->label = (string) $obj->label;
1836 $ret->lang = $obj->lang;
1837 $ret->topic = $obj->topic;
1838 $ret->content = (string) $obj->content;
1839 $ret->content_lines = (string) $obj->content_lines;
1840 $ret->joinfiles = $obj->joinfiles;
1841 $ret->email_from = (string) $obj->email_from;
1845 // If no record found
1847 // Not found with the provided label
1850 // If there is no template at all
1851 $defaultmessage = '';
1853 if ($type_template == 'body') {
1854 // Special case to use this->withbody as content
1855 $defaultmessage = (string) $this->withbody;
1856 } elseif ($type_template == 'facture_send' || $type_template == 'facture' || $type_template == 'facture_relance') {
1857 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1858 } elseif ($type_template == 'propal_send' || $type_template == 'propal') {
1859 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1860 } elseif ($type_template == 'supplier_proposal_send' || $type_template == 'supplier_proposal') {
1861 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1862 } elseif ($type_template == 'order_send' || $type_template == 'order') {
1863 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1864 } elseif ($type_template == 'order_supplier_send' || $type_template == 'order_supplier') {
1865 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1866 } elseif ($type_template == 'invoice_supplier_send' || $type_template == 'invoice_supplier') {
1867 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1868 } elseif ($type_template == 'shipping_send' || $type_template == 'shipping') {
1869 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1870 } elseif ($type_template == 'reception_send' || $type_template == 'reception') {
1871 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendReception
");
1872 } elseif ($type_template == 'fichinter_send' || $type_template == 'fichinter') {
1873 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1874 } elseif ($type_template == 'actioncomm_send' || $type_template == 'actioncomm') {
1875 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1876 } elseif (!empty($type_template)) {
1877 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1880 $ret->label = 'default';
1881 $ret->lang = $outputlangs->defaultlang;
1883 $ret->joinfiles = 1;
1884 $ret->content = $defaultmessage;
1885 $ret->content_lines = '';
2000 public function setSubstitFromObject($object, $outputlangs)
2002 global $extrafields;
2004 $parameters = array();
2005 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
2006 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
2008 $this->substit = $tmparray;
2010 // Fill substit_lines with each object lines content
2011 if (is_array($object->lines)) {
2012 foreach ($object->lines as $line) {
2013 $substit_line = array(
2014 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
2015 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
2016 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
2017 '__LABEL__' => isset($line->label) ? $line->label : '',
2018 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
2019 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
2020 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
2021 '__QUANTITY__' => $line->qty,
2022 '__SUBPRICE__' => price($line->subprice),
2023 '__AMOUNT__' => price($line->total_ttc),
2024 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
2027 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2028 if (!empty($line->fk_product)) {
2029 if (!is_object($extrafields)) {
2030 $extrafields = new ExtraFields($this->db);
2032 $product = new Product($this->db);
2033 $product->fetch($line->fk_product, '', '', '1');
2034 $product->fetch_optionals();
2036 $extrafields->fetch_name_optionals_label($product->table_element, true);
2038 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2039 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2040 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2045 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2058 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2062 $tmparray = array();
2063 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2064 $parameters = array('mode' => $mode);
2065 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
2066 complete_substitutions_array($tmparray, $langs, null, $parameters);
2068 if ($mode == 'formwithlines') {
2069 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2071 if ($mode == 'formforlines') {
2072 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2076 if ($mode == 'emailing') {
2077 $parameters = array('mode' => $mode);
2078 $tmparray = getCommonSubstitutionArray($langs, 2, array('object', 'objectamount'), $object); // Note: On email templated edition, this is null because it is related to all type of objects
2079 complete_substitutions_array($tmparray, $langs, null, $parameters);
2081 // For mass emailing, we have different keys specific to the data into tagerts list
2082 $tmparray['__ID__'] = 'IdRecord';
2083 $tmparray['__EMAIL__'] = 'EMailRecipient';
2084 $tmparray['__LASTNAME__'] = 'Lastname';
2085 $tmparray['__FIRSTNAME__'] = 'Firstname';
2086 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2087 $tmparray['__OTHER1__'] = 'Other1';
2088 $tmparray['__OTHER2__'] = 'Other2';
2089 $tmparray['__OTHER3__'] = 'Other3';
2090 $tmparray['__OTHER4__'] = 'Other4';
2091 $tmparray['__OTHER5__'] = 'Other5';
2093 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode'; // If source is a thirdparty
2095 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2096 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2097 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2099 $onlinepaymentenabled = 0;
2100 if (isModEnabled('paypal')) {
2101 $onlinepaymentenabled++;
2103 if (isModEnabled('paybox')) {
2104 $onlinepaymentenabled++;
2106 if (isModEnabled('stripe')) {
2107 $onlinepaymentenabled++;
2109 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2110 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2111 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
2112 if (isModEnabled('member')) {
2113 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2115 if (isModEnabled('don')) {
2116 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2118 if (isModEnabled('invoice')) {
2119 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2121 if (isModEnabled('order')) {
2122 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2124 if (isModEnabled('contract')) {
2125 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2128 //Online payment link
2129 if (isModEnabled('member')) {
2130 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2132 if (isModEnabled('don')) {
2133 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2135 if (isModEnabled('invoice')) {
2136 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2138 if (isModEnabled('order')) {
2139 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2141 if (isModEnabled('contract')) {
2142 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2146 /* No need to show into tooltip help, option is not enabled
2147 $vars['__SECUREKEYPAYMENT__']='';
2148 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2149 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2150 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2151 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2154 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2155 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2159 foreach ($tmparray as $key => $val) {
2161 $tmparray[$key] = $key;