374 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
377 global $conf, $langs, $user, $hookmanager, $form;
380 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
381 $formfile =
new FormFile($this->db);
383 if (!is_object($form)) {
384 $form =
new Form($this->db);
388 $langs->loadLangs(array(
'other',
'mails',
'members'));
391 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
396 $hookmanager->initHooks(array(
'formmail'));
399 'addfileaction' => $addfileaction,
400 'removefileaction'=> $removefileaction,
401 'trackid'=> $this->trackid
403 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
405 if (!empty($reshook)) {
406 return $hookmanager->resPrint;
410 $disablebademails = 1;
413 $outputlangs = $langs;
415 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
416 $newlang = $this->param[
'langsmodels'];
418 if (!empty($newlang)) {
420 $outputlangs->setDefaultLang($newlang);
421 $outputlangs->load(
'other');
425 $arraydefaultmessage = -1;
426 if ($this->param[
'models'] !=
'none') {
428 if (array_key_exists(
'models_id', $this->param)) {
429 $model_id = $this->param[
"models_id"];
432 $arraydefaultmessage = $this->
getEMailTemplate($this->db, $this->param[
"models"], $user, $outputlangs, $model_id, 1,
'', ($model_id > 0 ? -1 : 1));
436 $listofpaths = array();
437 $listofnames = array();
438 $listofmimes = array();
439 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
441 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
442 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
443 foreach ($this->param[
'fileinit'] as $path) {
451 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
452 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
454 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
455 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
457 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
458 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
462 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
463 if ($this->withform == 1) {
464 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
466 $out .=
'<a id="formmail" name="formmail"></a>';
467 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
468 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
469 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
470 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
472 if (!empty($this->withfrom)) {
473 if (!empty($this->withfromreadonly)) {
474 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
475 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
478 foreach ($this->param as $key => $value) {
479 if (is_array($value)) {
480 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
482 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
486 $modelmail_array = array();
487 if ($this->param[
'models'] !=
'none') {
493 foreach ($this->lines_model as $line) {
495 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
496 $labeltouse = $langs->trans($reg[1]);
498 $labeltouse = $line->label;
504 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
506 if ($line->private) {
507 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
513 if (count($modelmail_array) > 0) {
514 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOST(
'modelmailselected',
'int') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
517 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
519 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
521 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
523 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
527 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
530 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
531 'propal_send',
'order_send',
'facture_send',
532 'shipping_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
533 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'all'
536 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
537 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
538 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
540 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
543 $out .=
'<input type="submit" class="button" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
547 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
551 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
554 $helpforsubstitution =
'';
555 if (is_array($this->substit) && count($this->substit)) {
556 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
558 foreach ($this->substit as $key => $val) {
560 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
565 if (is_array($this->substit) && count($this->substit)) {
566 $helpforsubstitution .=
'</span>';
569 if (!empty($this->withsubstit)) {
570 $out .=
'<tr><td colspan="2" class="right">';
571 if (is_numeric($this->withsubstit)) {
572 $out .= $form->textwithpicto($langs->trans(
"EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
574 $out .= $form->textwithpicto($langs->trans(
'AvailableVariables'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
576 $out .=
"</td></tr>\n";
580 if (!empty($this->withfrom)) {
581 if (!empty($this->withfromreadonly)) {
582 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
585 if (!($this->fromtype ===
'user' && $this->fromid > 0)
586 && !($this->fromtype ===
'company')
587 && !($this->fromtype ===
'robot')
588 && !preg_match(
'/user_aliases/', $this->fromtype)
589 && !preg_match(
'/global_aliases/', $this->fromtype)
590 && !preg_match(
'/senderprofile/', $this->fromtype)
593 $out .= $this->fromname;
594 if ($this->frommail) {
595 $out .=
' <'.$this->frommail.
'>';
597 if ($this->fromtype) {
598 $langs->load(
'errors');
599 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
606 if (empty($user->email)) {
607 $langs->load(
'errors');
608 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
610 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
612 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
616 $s = (!
getDolGlobalString(
'MAIN_INFO_SOCIETE_NOM') ? $conf->global->MAIN_INFO_SOCIETE_EMAIL : $conf->global->MAIN_INFO_SOCIETE_NOM).
' <' .
getDolGlobalString(
'MAIN_INFO_SOCIETE_MAIL').
'>';
617 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
621 $listaliases = array(
622 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
626 if (!empty($arraydefaultmessage->email_from)) {
627 $templatemailfrom =
' <'.$arraydefaultmessage->email_from.
'>';
628 $liste[
'from_template_'.GETPOST(
'modelmailselected')] = array(
'label' => $templatemailfrom,
'data-html' => $templatemailfrom);
632 if (!empty($this->fromalsorobot)) {
634 $s = $conf->global->MAIN_MAIL_EMAIL_FROM;
635 if ($this->frommail) {
638 array(
'label' => $s,
'data-html' => $s);
643 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
644 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
")";
645 $sql .=
" ORDER BY position";
646 $resql = $this->db->query($sql);
648 $num = $this->db->num_rows($resql);
651 $obj = $this->db->fetch_object($resql);
653 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
661 foreach ($listaliases as $typealias => $listalias) {
663 $listaliasarray = explode(
',', $listalias);
664 foreach ($listaliasarray as $listaliasval) {
666 $listaliasval = trim($listaliasval);
668 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
669 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
670 if (!preg_match(
'/</', $listaliasval)) {
671 $listaliasval =
'<'.$listaliasval.
'>';
673 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
681 foreach ($liste as $key => $val) {
682 if (!empty($liste[$key][
'data-html'])) {
683 $liste[$key][
'data-html'] = str_replace(array(
'<',
'<',
'>',
'>'), array(
'__LTCHAR__',
'__LTCHAR__',
'__GTCHAR__',
'__GTCHAR__'), $liste[$key][
'data-html']);
684 $liste[$key][
'data-html'] = str_replace(array(
'__LTCHAR__',
'__GTCHAR__'), array(
'<span class="opacitymedium">(',
')</span>'), $liste[$key][
'data-html']);
687 $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);
690 $out .=
"</td></tr>\n";
692 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
693 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
694 $out .=
' ';
695 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
696 $out .=
"</td></tr>\n";
701 if (!empty($this->withto) || is_array($this->withto)) {
706 if (!empty($this->withtouser) && is_array($this->withtouser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
708 $out .= $langs->trans(
"MailToUsers");
712 $tmparray = $this->withtouser;
713 foreach ($tmparray as $key => $val) {
716 $withtoselected =
GETPOST(
"receiveruser",
'array');
717 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
718 $withtoselected = array_keys($tmparray);
720 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
721 $out .=
"</td></tr>\n";
725 if (!empty($this->withoptiononeemailperrecipient)) {
726 if (abs($this->withoptiononeemailperrecipient) == 1) {
727 $out .=
'<tr><td class="minwidth200">';
728 $out .= $langs->trans(
"GroupEmails");
730 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
731 $out .=
'<label for="oneemailperrecipient">';
732 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
738 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
739 if (!empty($this->withto) && !is_array($this->withto)) {
740 $out .=
' '.$langs->trans(
"or").
' <input type="email" name="emailto" value="">';
743 $out .=
'</td></tr>';
745 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
750 if (!empty($this->withtocc) || is_array($this->withtocc)) {
755 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) &&
getDolGlobalString(
'MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
757 $out .= $langs->trans(
"MailToCCUsers");
761 $tmparray = $this->withtoccuser;
762 foreach ($tmparray as $key => $val) {
765 $withtoselected =
GETPOST(
"receiverccuser",
'array');
766 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
767 $withtoselected = array_keys($tmparray);
769 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
770 $out .=
"</td></tr>\n";
774 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
779 if (!empty($this->withreplyto)) {
780 if ($this->withreplytoreadonly) {
781 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
782 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
783 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
784 $out .=
"</td></tr>\n";
789 if (!empty($this->witherrorsto)) {
794 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
795 $out .= $this->getHtmlForDeliveryReceipt();
799 if (!empty($this->withtopic)) {
800 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
804 if (!empty($this->withfile)) {
806 $out .=
'<td>'.$langs->trans(
"MailFile").
'</td>';
810 if ($this->withmaindocfile) {
812 if (GETPOSTISSET(
'sendmail')) {
813 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
814 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
816 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
820 if (!empty($this->withmaindocfile)) {
821 if ($this->withmaindocfile == 1) {
822 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
823 } elseif ($this->withmaindocfile == -1) {
824 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
827 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
829 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
833 if (is_numeric($this->withfile)) {
835 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
836 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
837 $out .=
'jQuery(document).ready(function () {';
838 $out .=
' jQuery(".removedfile").click(function() {';
839 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
842 $out .=
'</script>'.
"\n";
843 if (count($listofpaths)) {
844 foreach ($listofpaths as $key => $val) {
845 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
847 $entity = (isset($this->param[
'object_entity']) ? $this->param[
'object_entity'] : $conf->entity);
849 $relativepathtofile = str_replace(
'/'.$entity.
'/',
'/', $relativepathtofile);
852 $formfile_params = array();
853 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
855 $out .=
'<div id="attachfile_'.$key.
'">';
857 $out .=
img_mime($listofnames[$key]).
' '.$listofnames[$key];
859 $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ?
'' :
'entity='.((int) $entity)));
860 if (!$this->withfilereadonly) {
861 $out .=
' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.
'/theme/'.$conf->theme.
'/img/delete.png" value="'.($key + 1).
'" class="removedfile" id="removedfile_'.$key.
'" name="removedfile_'.$key.
'" />';
864 $out .=
'<br></div>';
866 } elseif (empty($this->withmaindocfile)) {
869 if ($this->withfile == 2) {
871 $maxmin = $maxfilesizearray[
'maxmin'];
873 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
877 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
879 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
882 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
885 $out .= $this->withfile;
888 $out .=
"</td></tr>\n";
892 if (!empty($this->withbody)) {
893 $defaultmessage =
GETPOST(
'message',
'restricthtml');
894 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
895 if ($arraydefaultmessage && $arraydefaultmessage->content) {
896 $defaultmessage = $arraydefaultmessage->content;
897 } elseif (!is_numeric($this->withbody)) {
898 $defaultmessage = $this->withbody;
904 $validpaymentmethod = array();
905 if (empty($this->substit[
'__REF__'])) {
909 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
910 $langs->loadLangs(array(
'paypal',
'other'));
911 $typeforonlinepayment =
'free';
912 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
913 $typeforonlinepayment =
'order';
915 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
916 $typeforonlinepayment =
'invoice';
918 if ($this->param[
"models"] ==
'member') {
919 $typeforonlinepayment =
'member';
921 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
924 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
927 if (count($validpaymentmethod) > 0 && $paymenturl) {
928 $langs->load(
'other');
929 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
930 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
932 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
933 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
936 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
940 $defaultlines = $arraydefaultmessage->content_lines;
941 if (isset($defaultlines)) {
942 foreach ($this->substit_lines as $substit_line) {
946 $this->substit[
'__LINES__'] = $lines;
948 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
951 $atleastonecomponentishtml = 0;
952 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
953 $atleastonecomponentishtml++;
955 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
956 $atleastonecomponentishtml++;
958 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
959 $atleastonecomponentishtml++;
961 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
962 $atleastonecomponentishtml++;
965 $atleastonecomponentishtml++;
967 if ($atleastonecomponentishtml) {
969 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
971 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
972 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
974 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
975 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
978 $defaultmessage =
dol_nl2br($defaultmessage);
982 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
983 $defaultmessage =
GETPOST(
"message",
"restricthtml");
987 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
988 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
992 $out .=
'<td colspan="2">';
993 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
998 $out .=
'<td colspan="2">';
999 if ($this->withbodyreadonly) {
1000 $out .= nl2br($defaultmessage);
1001 $out .=
'<input type="hidden" id="message" name="message" value="'.$defaultmessage.
'" />';
1003 if (!isset($this->ckeditortoolbar)) {
1004 $this->ckeditortoolbar =
'dolibarr_mailings';
1008 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1009 if ($this->withfckeditor == -1) {
1011 $this->withfckeditor = 1;
1013 $this->withfckeditor = 0;
1017 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1018 $out .= $doleditor->Create(1);
1020 $out .=
"</td></tr>\n";
1023 $out .=
'</table>'.
"\n";
1025 if ($this->withform == 1 || $this->withform == -1) {
1026 $out .=
'<div class="center">';
1027 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1029 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1030 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1033 if ($this->withcancel) {
1034 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1036 $out .= '</div>'."\n
";
1039 if ($this->withform == 1) {
1040 $out .= '</form>'."\n
";
1043 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1044 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1045 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1046 $out .= 'jQuery(document).ready(function () {';
1047 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1048 var code = e.keyCode || e.which;
1050 console.log("Enter was intercepted and blocked
");
1056 $out .= '</script>';
1059 $out .= "<!-- End form mail -->\n
";
1628 public function setSubstitFromObject($object, $outputlangs)
1630 global $conf, $user, $extrafields;
1632 $parameters = array();
1633 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1634 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1636 $this->substit = $tmparray;
1638 // Fill substit_lines with each object lines content
1639 if (is_array($object->lines)) {
1640 foreach ($object->lines as $line) {
1641 $substit_line = array(
1642 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1643 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1644 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1645 '__LABEL__' => isset($line->label) ? $line->label : '',
1646 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1647 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1648 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1649 '__QUANTITY__' => $line->qty,
1650 '__SUBPRICE__' => price($line->subprice),
1651 '__AMOUNT__' => price($line->total_ttc),
1652 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1655 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1656 if (!empty($line->fk_product)) {
1657 if (!is_object($extrafields)) {
1658 $extrafields = new ExtraFields($this->db);
1660 $product = new Product($this->db);
1661 $product->fetch($line->fk_product, '', '', 1);
1662 $product->fetch_optionals();
1664 $extrafields->fetch_name_optionals_label($product->table_element, true);
1666 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1667 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1668 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1672 $this->substit_lines[] = $substit_line;
1685 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1687 global $conf, $langs;
1689 $tmparray = array();
1690 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1691 $parameters = array('mode'=>$mode);
1692 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1693 complete_substitutions_array($tmparray, $langs, null, $parameters);
1695 if ($mode == 'formwithlines') {
1696 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1698 if ($mode == 'formforlines') {
1699 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1703 if ($mode == 'emailing') {
1704 $parameters = array('mode'=>$mode);
1705 $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
1706 complete_substitutions_array($tmparray, $langs, null, $parameters);
1708 // For mass emailing, we have different keys specific to the data into tagerts list
1709 $tmparray['__ID__'] = 'IdRecord';
1710 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1711 $tmparray['__EMAIL__'] = 'EMailRecipient';
1712 $tmparray['__LASTNAME__'] = 'Lastname';
1713 $tmparray['__FIRSTNAME__'] = 'Firstname';
1714 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1715 $tmparray['__OTHER1__'] = 'Other1';
1716 $tmparray['__OTHER2__'] = 'Other2';
1717 $tmparray['__OTHER3__'] = 'Other3';
1718 $tmparray['__OTHER4__'] = 'Other4';
1719 $tmparray['__OTHER5__'] = 'Other5';
1720 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
1721 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
1722 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
1724 $onlinepaymentenabled = 0;
1725 if (isModEnabled('paypal')) {
1726 $onlinepaymentenabled++;
1728 if (isModEnabled('paybox')) {
1729 $onlinepaymentenabled++;
1731 if (isModEnabled('stripe')) {
1732 $onlinepaymentenabled++;
1734 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
1735 $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN;
1736 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
1737 if (isModEnabled('adherent')) {
1738 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1740 if (isModEnabled('don')) {
1741 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1743 if (isModEnabled('facture')) {
1744 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1746 if (isModEnabled('commande')) {
1747 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1749 if (isModEnabled('contrat')) {
1750 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1753 //Online payment link
1754 if (isModEnabled('adherent')) {
1755 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1757 if (isModEnabled('don')) {
1758 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1760 if (isModEnabled('facture')) {
1761 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1763 if (isModEnabled('commande')) {
1764 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1766 if (isModEnabled('contrat')) {
1767 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1771 /* No need to show into tooltip help, option is not enabled
1772 $vars['__SECUREKEYPAYMENT__']='';
1773 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1774 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1775 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1776 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1779 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
1780 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1784 foreach ($tmparray as $key => $val) {
1786 $tmparray[$key] = $key;