388 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
391 global $conf, $langs, $user, $hookmanager, $form;
394 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
395 $formfile =
new FormFile($this->db);
397 if (!is_object($form)) {
398 $form =
new Form($this->db);
402 $langs->loadLangs(array(
'other',
'mails',
'members'));
405 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
410 $hookmanager->initHooks(array(
'formmail'));
413 'addfileaction' => $addfileaction,
414 'removefileaction' => $removefileaction,
415 'trackid' => $this->trackid
417 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
419 if (!empty($reshook)) {
420 return $hookmanager->resPrint;
424 $disablebademails = 1;
427 $outputlangs = $langs;
429 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
430 $newlang = $this->param[
'langsmodels'];
432 if (!empty($newlang)) {
434 $outputlangs->setDefaultLang($newlang);
435 $outputlangs->load(
'other');
439 $arraydefaultmessage = -1;
440 if ($this->param[
'models'] !=
'none') {
442 if (array_key_exists(
'models_id', $this->param)) {
443 $model_id = $this->param[
"models_id"];
446 $arraydefaultmessage = $this->
getEMailTemplate($this->db, $this->param[
"models"], $user, $outputlangs, $model_id, 1,
'', ($model_id > 0 ? -1 : 1));
450 $listofpaths = array();
451 $listofnames = array();
452 $listofmimes = array();
453 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
455 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
456 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
457 foreach ($this->param[
'fileinit'] as $path) {
465 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
466 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
468 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
469 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
471 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
472 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
476 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
477 if ($this->withform == 1) {
478 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
480 $out .=
'<a id="formmail" name="formmail"></a>';
481 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
482 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
483 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
484 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
486 if (!empty($this->withfrom)) {
487 if (!empty($this->withfromreadonly)) {
488 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
489 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
492 foreach ($this->param as $key => $value) {
493 if (is_array($value)) {
494 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
496 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
500 $modelmail_array = array();
501 if ($this->param[
'models'] !=
'none') {
507 foreach ($this->lines_model as $line) {
509 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
510 $labeltouse = $langs->trans($reg[1]);
512 $labeltouse = $line->label;
518 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
520 if ($line->private) {
521 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
527 if (count($modelmail_array) > 0) {
528 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOSTINT(
'modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
531 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
533 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
535 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
537 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
541 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
544 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
545 'propal_send',
'order_send',
'facture_send',
546 'shipping_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
547 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'all'
550 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
551 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
552 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
554 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
557 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
561 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
565 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
568 $helpforsubstitution =
'';
569 if (is_array($this->substit) && count($this->substit)) {
570 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
572 foreach ($this->substit as $key => $val) {
574 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
579 if (is_array($this->substit) && count($this->substit)) {
580 $helpforsubstitution .=
'</span>';
595 if (!empty($this->withfrom)) {
596 if (!empty($this->withfromreadonly)) {
597 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
600 if (!($this->fromtype ===
'user' && $this->fromid > 0)
601 && !($this->fromtype ===
'company')
602 && !($this->fromtype ===
'robot')
603 && !preg_match(
'/user_aliases/', $this->fromtype)
604 && !preg_match(
'/global_aliases/', $this->fromtype)
605 && !preg_match(
'/senderprofile/', $this->fromtype)
608 $out .= $this->fromname;
609 if ($this->frommail) {
610 $out .=
' <'.$this->frommail.
'>';
612 if ($this->fromtype) {
613 $langs->load(
'errors');
614 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
621 if (empty($user->email)) {
622 $langs->load(
'errors');
623 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
625 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
627 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
631 $s = (!
getDolGlobalString(
'MAIN_INFO_SOCIETE_NOM') ? $conf->global->MAIN_INFO_SOCIETE_EMAIL : $conf->global->MAIN_INFO_SOCIETE_NOM).
' <' .
getDolGlobalString(
'MAIN_INFO_SOCIETE_MAIL').
'>';
632 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
636 $listaliases = array(
637 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
641 if (!empty($arraydefaultmessage->email_from)) {
642 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
643 $liste[
'from_template_'.GETPOST(
'modelmailselected')] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
647 if (!empty($this->fromalsorobot)) {
650 if ($this->frommail) {
653 $liste[
'main_from'] = array(
'label' => $s,
'data-html' => $s);
658 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
659 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
")";
660 $sql .=
" ORDER BY position";
661 $resql = $this->db->query($sql);
663 $num = $this->db->num_rows($resql);
666 $obj = $this->db->fetch_object($resql);
668 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
676 foreach ($listaliases as $typealias => $listalias) {
678 $listaliasarray = explode(
',', $listalias);
679 foreach ($listaliasarray as $listaliasval) {
681 $listaliasval = trim($listaliasval);
683 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
684 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
685 if (!preg_match(
'/</', $listaliasval)) {
686 $listaliasval =
'<'.$listaliasval.
'>';
688 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
696 foreach ($liste as $key => $val) {
697 if (!empty($liste[$key][
'data-html'])) {
698 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
699 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
702 $out .=
' '.$form->selectarray(
'fromtype', $liste, empty($arraydefaultmessage->email_from) ? $this->fromtype :
'from_template_'.GETPOST(
'modelmailselected'), 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 1,
'', $disablebademails);
705 $out .=
"</td></tr>\n";
707 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
708 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
709 $out .=
' ';
710 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
711 $out .=
"</td></tr>\n";
716 if (!empty($this->withto) || is_array($this->withto)) {
721 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
723 $out .= $langs->trans(
"MailToUsers");
727 $tmparray = $this->withtouser;
728 foreach ($tmparray as $key => $val) {
731 $withtoselected =
GETPOST(
"receiveruser",
'array');
732 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
733 $withtoselected = array_keys($tmparray);
735 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
736 $out .=
"</td></tr>\n";
740 if (!empty($this->withoptiononeemailperrecipient)) {
741 if (abs($this->withoptiononeemailperrecipient) == 1) {
742 $out .=
'<tr><td class="minwidth200">';
743 $out .= $langs->trans(
"GroupEmails");
745 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
746 $out .=
'<label for="oneemailperrecipient">';
747 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
753 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
754 if (!empty($this->withto) && !is_array($this->withto)) {
755 $out .=
' '.$langs->trans(
"or").
' <input type="email" name="emailto" value="">';
758 $out .=
'</td></tr>';
760 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
765 if (!empty($this->withtocc) || is_array($this->withtocc)) {
770 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
772 $out .= $langs->trans(
"MailToCCUsers");
776 $tmparray = $this->withtoccuser;
777 foreach ($tmparray as $key => $val) {
780 $withtoselected =
GETPOST(
"receiverccuser",
'array');
781 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
782 $withtoselected = array_keys($tmparray);
784 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
785 $out .=
"</td></tr>\n";
789 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
794 if (!empty($this->withreplyto)) {
795 if ($this->withreplytoreadonly) {
796 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
797 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
798 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
799 $out .=
"</td></tr>\n";
804 if (!empty($this->witherrorsto)) {
809 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
814 if (!empty($this->withtopic)) {
815 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
819 if (!empty($this->withfile)) {
821 $out .=
'<td class="tdtop">'.$langs->trans(
"MailFile").
'</td>';
825 if ($this->withmaindocfile) {
827 if (GETPOSTISSET(
'sendmail')) {
828 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
829 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
831 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
835 if (!empty($this->withmaindocfile)) {
836 if ($this->withmaindocfile == 1) {
837 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
838 } elseif ($this->withmaindocfile == -1) {
839 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
842 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
844 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
848 if (is_numeric($this->withfile)) {
850 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
851 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
852 $out .=
'jQuery(document).ready(function () {';
853 $out .=
' jQuery(".removedfile").click(function() {';
854 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
857 $out .=
'</script>'.
"\n";
858 if (count($listofpaths)) {
859 foreach ($listofpaths as $key => $val) {
860 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
862 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] : $conf->entity);
864 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
867 $formfile_params = array();
868 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
870 $out .=
'<div id="attachfile_'.$key.
'">';
872 $out .=
img_mime($listofnames[$key]).$listofnames[$key];
874 $out .=
' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
876 if (!$this->withfilereadonly) {
877 $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.
'" />';
880 $out .=
'<br></div>';
882 } elseif (empty($this->withmaindocfile)) {
885 if ($this->withfile == 2) {
887 $maxmin = $maxfilesizearray[
'maxmin'];
889 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
893 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
895 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
898 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
901 $out .= $this->withfile;
904 $out .=
"</td></tr>\n";
908 if (!empty($this->withbody)) {
909 $defaultmessage =
GETPOST(
'message',
'restricthtml');
910 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
911 if ($arraydefaultmessage && $arraydefaultmessage->content) {
912 $defaultmessage = $arraydefaultmessage->content;
913 } elseif (!is_numeric($this->withbody)) {
914 $defaultmessage = $this->withbody;
919 $validpaymentmethod = array();
920 if (empty($this->substit[
'__REF__'])) {
924 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
925 $langs->loadLangs(array(
'paypal',
'other'));
926 $typeforonlinepayment =
'free';
927 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
928 $typeforonlinepayment =
'order';
930 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
931 $typeforonlinepayment =
'invoice';
933 if ($this->param[
"models"] ==
'member') {
934 $typeforonlinepayment =
'member';
936 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
939 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
942 if (count($validpaymentmethod) > 0 && $paymenturl) {
943 $langs->load(
'other');
944 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
945 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
947 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
948 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
951 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
955 $defaultlines = $arraydefaultmessage->content_lines;
956 if (isset($defaultlines)) {
957 foreach ($this->substit_lines as $substit_line) {
961 $this->substit[
'__LINES__'] = $lines;
963 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
966 $atleastonecomponentishtml = 0;
967 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
968 $atleastonecomponentishtml++;
970 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
971 $atleastonecomponentishtml++;
973 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
974 $atleastonecomponentishtml++;
976 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
977 $atleastonecomponentishtml++;
980 $atleastonecomponentishtml++;
982 if ($atleastonecomponentishtml) {
984 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
986 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
987 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
989 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
990 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
993 $defaultmessage =
dol_nl2br($defaultmessage);
997 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
998 $defaultmessage =
GETPOST(
"message",
"restricthtml");
1002 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
1003 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
1007 $out .=
'<td class="tdtop">';
1008 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
1010 $out .=
'<td class="tdtop">';
1013 $showlinktolayout = $formmail->withlayout && $formmail->withfckeditor &&
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT');
1014 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1015 $showlinktoai = ($formmail->withaiprompt && isModEnabled(
'ai')) ?
'textgenerationemail' :
'';
1016 $showlinktoailabel = $langs->trans(
"FillMessageWithAIContent");
1017 $formatforouput =
'';
1018 $htmlname =
'message';
1021 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1027 $out .=
'<td colspan="2">';
1028 if ($this->withbodyreadonly) {
1029 $out .= nl2br($defaultmessage);
1030 $out .=
'<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.
'" />';
1032 if (!isset($this->ckeditortoolbar)) {
1033 $this->ckeditortoolbar =
'dolibarr_mailings';
1037 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1038 if ($this->withfckeditor == -1) {
1040 $this->withfckeditor = 1;
1042 $this->withfckeditor = 0;
1046 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1047 $out .= $doleditor->Create(1);
1049 $out .=
"</td></tr>\n";
1052 $out .=
'</table>'.
"\n";
1054 if ($this->withform == 1 || $this->withform == -1) {
1055 $out .=
'<div class="center">';
1056 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1058 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1059 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1062 if ($this->withcancel) {
1063 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1065 $out .= '</div>'."\n
";
1068 if ($this->withform == 1) {
1069 $out .= '</form>'."\n
";
1072 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1073 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1074 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1075 $out .= 'jQuery(document).ready(function () {';
1076 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1077 var code = e.keyCode || e.which;
1079 console.log("Enter was intercepted and blocked
");
1085 $out .= '</script>';
1088 $out .= "<!-- End form mail -->\n
";
1588 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1592 if ($id == -2 && empty($label)) {
1593 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1597 $ret = new ModelMail($dbs);
1599 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1600 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1601 $tmparray = explode('_', $languagetosearch);
1602 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1603 if ($languagetosearchmain == $languagetosearch) {
1604 $languagetosearchmain = '';
1607 $sql = "SELECT
rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1608 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1609 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'all')
";
1610 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1611 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1613 $sql .= " AND active =
".((int) $active);
1615 if ($defaultfortype >= 0) {
1616 $sql .= " AND defaultfortype =
".((int) $defaultfortype);
1619 $sql .= " AND label =
'".$dbs->escape($label)."'";
1621 if (!($id > 0) && $languagetosearch) {
1622 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1625 $sql .= " AND
rowid =
".(int) $id;
1630 $sql .= " AND entity IN(
".getEntity('c_email_templates', 1).")
";
1631 if ($languagetosearch) {
1632 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1634 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1636 //$sql .= $dbs->plimit(1);
1639 $resql = $dbs->query($sql);
1641 dol_print_error($dbs);
1647 $obj = $dbs->fetch_object($resql);
1650 // If template is for a module, check module is enabled; if not, take next template
1652 $tempmodulekey = $obj->module;
1653 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1658 // If a record was found
1659 $ret->id = $obj->rowid;
1660 $ret->module = $obj->module;
1661 $ret->label = $obj->label;
1662 $ret->lang = $obj->lang;
1663 $ret->topic = $obj->topic;
1664 $ret->content = $obj->content;
1665 $ret->content_lines = $obj->content_lines;
1666 $ret->joinfiles = $obj->joinfiles;
1667 $ret->email_from = $obj->email_from;
1671 // If no record found
1673 // Not found with the provided label
1676 // If there is no template at all
1677 $defaultmessage = '';
1679 if ($type_template == 'body') {
1680 // Special case to use this->withbody as content
1681 $defaultmessage = $this->withbody;
1682 } elseif ($type_template == 'facture_send') {
1683 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1684 } elseif ($type_template == 'facture_relance') {
1685 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder
");
1686 } elseif ($type_template == 'propal_send') {
1687 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1688 } elseif ($type_template == 'supplier_proposal_send') {
1689 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1690 } elseif ($type_template == 'order_send') {
1691 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1692 } elseif ($type_template == 'order_supplier_send') {
1693 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1694 } elseif ($type_template == 'invoice_supplier_send') {
1695 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1696 } elseif ($type_template == 'shipping_send') {
1697 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1698 } elseif ($type_template == 'fichinter_send') {
1699 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1700 } elseif ($type_template == 'actioncomm_send') {
1701 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1702 } elseif (!empty($type_template)) {
1703 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1706 $ret->label = 'default';
1707 $ret->lang = $outputlangs->defaultlang;
1709 $ret->joinfiles = 1;
1710 $ret->content = $defaultmessage;
1711 $ret->content_lines = '';
1826 public function setSubstitFromObject($object, $outputlangs)
1828 global $extrafields;
1830 $parameters = array();
1831 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1832 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1834 $this->substit = $tmparray;
1836 // Fill substit_lines with each object lines content
1837 if (is_array($object->lines)) {
1838 foreach ($object->lines as $line) {
1839 $substit_line = array(
1840 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1841 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1842 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1843 '__LABEL__' => isset($line->label) ? $line->label : '',
1844 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1845 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1846 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1847 '__QUANTITY__' => $line->qty,
1848 '__SUBPRICE__' => price($line->subprice),
1849 '__AMOUNT__' => price($line->total_ttc),
1850 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1853 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1854 if (!empty($line->fk_product)) {
1855 if (!is_object($extrafields)) {
1856 $extrafields = new ExtraFields($this->db);
1858 $product = new Product($this->db);
1859 $product->fetch($line->fk_product, '', '', 1);
1860 $product->fetch_optionals();
1862 $extrafields->fetch_name_optionals_label($product->table_element, true);
1864 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1865 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1866 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1870 $this->substit_lines[] = $substit_line;
1883 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1887 $tmparray = array();
1888 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1889 $parameters = array('mode' => $mode);
1890 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1891 complete_substitutions_array($tmparray, $langs, null, $parameters);
1893 if ($mode == 'formwithlines') {
1894 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1896 if ($mode == 'formforlines') {
1897 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1901 if ($mode == 'emailing') {
1902 $parameters = array('mode' => $mode);
1903 $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
1904 complete_substitutions_array($tmparray, $langs, null, $parameters);
1906 // For mass emailing, we have different keys specific to the data into tagerts list
1907 $tmparray['__ID__'] = 'IdRecord';
1908 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1909 $tmparray['__EMAIL__'] = 'EMailRecipient';
1910 $tmparray['__LASTNAME__'] = 'Lastname';
1911 $tmparray['__FIRSTNAME__'] = 'Firstname';
1912 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1913 $tmparray['__OTHER1__'] = 'Other1';
1914 $tmparray['__OTHER2__'] = 'Other2';
1915 $tmparray['__OTHER3__'] = 'Other3';
1916 $tmparray['__OTHER4__'] = 'Other4';
1917 $tmparray['__OTHER5__'] = 'Other5';
1918 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
1919 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
1920 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
1922 $onlinepaymentenabled = 0;
1923 if (isModEnabled('paypal')) {
1924 $onlinepaymentenabled++;
1926 if (isModEnabled('paybox')) {
1927 $onlinepaymentenabled++;
1929 if (isModEnabled('stripe')) {
1930 $onlinepaymentenabled++;
1932 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
1933 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
1934 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
1935 if (isModEnabled('member')) {
1936 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1938 if (isModEnabled('don')) {
1939 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1941 if (isModEnabled('invoice')) {
1942 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1944 if (isModEnabled('order')) {
1945 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1947 if (isModEnabled('contract')) {
1948 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1951 //Online payment link
1952 if (isModEnabled('member')) {
1953 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1955 if (isModEnabled('don')) {
1956 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1958 if (isModEnabled('invoice')) {
1959 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1961 if (isModEnabled('order')) {
1962 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1964 if (isModEnabled('contract')) {
1965 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1969 /* No need to show into tooltip help, option is not enabled
1970 $vars['__SECUREKEYPAYMENT__']='';
1971 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1972 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1973 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1974 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1977 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
1978 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1982 foreach ($tmparray as $key => $val) {
1984 $tmparray[$key] = $key;