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;
905 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
906 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
907 if (empty($this->substit[
'__REF__'])) {
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__']);
925 if (count($validpaymentmethod) > 0 && $paymenturl) {
926 $langs->load(
'other');
927 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
928 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
929 } elseif (count($validpaymentmethod) > 0) {
930 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
931 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
933 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
934 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
937 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
941 $defaultlines = $arraydefaultmessage->content_lines;
942 if (isset($defaultlines)) {
943 foreach ($this->substit_lines as $substit_line) {
947 $this->substit[
'__LINES__'] = $lines;
949 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
952 $atleastonecomponentishtml = 0;
953 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
954 $atleastonecomponentishtml++;
956 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
957 $atleastonecomponentishtml++;
959 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
960 $atleastonecomponentishtml++;
962 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
963 $atleastonecomponentishtml++;
966 $atleastonecomponentishtml++;
968 if ($atleastonecomponentishtml) {
970 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
972 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
973 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
975 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
976 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
979 $defaultmessage =
dol_nl2br($defaultmessage);
983 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
984 $defaultmessage =
GETPOST(
"message",
"restricthtml");
988 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
989 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
993 $out .=
'<td colspan="2">';
994 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
999 $out .=
'<td colspan="2">';
1000 if ($this->withbodyreadonly) {
1001 $out .= nl2br($defaultmessage);
1002 $out .=
'<input type="hidden" id="message" name="message" value="'.$defaultmessage.
'" />';
1004 if (!isset($this->ckeditortoolbar)) {
1005 $this->ckeditortoolbar =
'dolibarr_mailings';
1009 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1010 if ($this->withfckeditor == -1) {
1012 $this->withfckeditor = 1;
1014 $this->withfckeditor = 0;
1018 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1019 $out .= $doleditor->Create(1);
1021 $out .=
"</td></tr>\n";
1024 $out .=
'</table>'.
"\n";
1026 if ($this->withform == 1 || $this->withform == -1) {
1027 $out .=
'<div class="center">';
1028 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1030 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1031 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1034 if ($this->withcancel) {
1035 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1037 $out .= '</div>'."\n
";
1040 if ($this->withform == 1) {
1041 $out .= '</form>'."\n
";
1044 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1045 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1046 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1047 $out .= 'jQuery(document).ready(function () {';
1048 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1049 var code = e.keyCode || e.which;
1051 console.log("Enter was intercepted and blocked
");
1057 $out .= '</script>';
1060 $out .= "<!-- End form mail -->\n
";
1629 public function setSubstitFromObject($object, $outputlangs)
1631 global $conf, $user, $extrafields;
1633 $parameters = array();
1634 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1635 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1637 $this->substit = $tmparray;
1639 // Fill substit_lines with each object lines content
1640 if (is_array($object->lines)) {
1641 foreach ($object->lines as $line) {
1642 $substit_line = array(
1643 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1644 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1645 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1646 '__LABEL__' => isset($line->label) ? $line->label : '',
1647 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1648 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1649 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1650 '__QUANTITY__' => $line->qty,
1651 '__SUBPRICE__' => price($line->subprice),
1652 '__AMOUNT__' => price($line->total_ttc),
1653 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1656 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1657 if (!empty($line->fk_product)) {
1658 if (!is_object($extrafields)) {
1659 $extrafields = new ExtraFields($this->db);
1661 $product = new Product($this->db);
1662 $product->fetch($line->fk_product, '', '', 1);
1663 $product->fetch_optionals();
1665 $extrafields->fetch_name_optionals_label($product->table_element, true);
1667 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1668 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1669 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1673 $this->substit_lines[] = $substit_line;
1686 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1688 global $conf, $langs;
1690 $tmparray = array();
1691 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1692 $parameters = array('mode'=>$mode);
1693 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1694 complete_substitutions_array($tmparray, $langs, null, $parameters);
1696 if ($mode == 'formwithlines') {
1697 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1699 if ($mode == 'formforlines') {
1700 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1704 if ($mode == 'emailing') {
1705 $parameters = array('mode'=>$mode);
1706 $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
1707 complete_substitutions_array($tmparray, $langs, null, $parameters);
1709 // For mass emailing, we have different keys specific to the data into tagerts list
1710 $tmparray['__ID__'] = 'IdRecord';
1711 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1712 $tmparray['__EMAIL__'] = 'EMailRecipient';
1713 $tmparray['__LASTNAME__'] = 'Lastname';
1714 $tmparray['__FIRSTNAME__'] = 'Firstname';
1715 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1716 $tmparray['__OTHER1__'] = 'Other1';
1717 $tmparray['__OTHER2__'] = 'Other2';
1718 $tmparray['__OTHER3__'] = 'Other3';
1719 $tmparray['__OTHER4__'] = 'Other4';
1720 $tmparray['__OTHER5__'] = 'Other5';
1721 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
1722 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
1723 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
1725 $onlinepaymentenabled = 0;
1726 if (isModEnabled('paypal')) {
1727 $onlinepaymentenabled++;
1729 if (isModEnabled('paybox')) {
1730 $onlinepaymentenabled++;
1732 if (isModEnabled('stripe')) {
1733 $onlinepaymentenabled++;
1735 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
1736 $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN;
1737 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
1738 if (isModEnabled('adherent')) {
1739 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1741 if (isModEnabled('don')) {
1742 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1744 if (isModEnabled('facture')) {
1745 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1747 if (isModEnabled('commande')) {
1748 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1750 if (isModEnabled('contrat')) {
1751 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1754 //Online payment link
1755 if (isModEnabled('adherent')) {
1756 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1758 if (isModEnabled('don')) {
1759 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1761 if (isModEnabled('facture')) {
1762 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1764 if (isModEnabled('commande')) {
1765 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1767 if (isModEnabled('contrat')) {
1768 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1772 /* No need to show into tooltip help, option is not enabled
1773 $vars['__SECUREKEYPAYMENT__']='';
1774 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1775 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1776 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1777 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1780 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
1781 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1785 foreach ($tmparray as $key => $val) {
1787 $tmparray[$key] = $key;