365 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
368 global $conf, $langs, $user, $hookmanager, $form;
371 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
372 $formfile =
new FormFile($this->db);
374 if (!is_object($form)) {
375 $form =
new Form($this->db);
379 $langs->loadLangs(array(
'other',
'mails',
'members'));
382 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
387 $hookmanager->initHooks(array(
'formmail'));
390 'addfileaction' => $addfileaction,
391 'removefileaction'=> $removefileaction,
392 'trackid'=> $this->trackid
394 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
396 if (!empty($reshook)) {
397 return $hookmanager->resPrint;
401 $disablebademails = 1;
404 $outputlangs = $langs;
406 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
407 $newlang = $this->param[
'langsmodels'];
409 if (!empty($newlang)) {
411 $outputlangs->setDefaultLang($newlang);
412 $outputlangs->load(
'other');
416 $arraydefaultmessage = -1;
417 if ($this->param[
'models'] !=
'none') {
419 if (array_key_exists(
'models_id', $this->param)) {
420 $model_id = $this->param[
"models_id"];
423 $arraydefaultmessage = $this->
getEMailTemplate($this->db, $this->param[
"models"], $user, $outputlangs, $model_id, 1,
'', ($model_id > 0 ? -1 : 1));
427 $listofpaths = array();
428 $listofnames = array();
429 $listofmimes = array();
430 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
432 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
433 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
434 foreach ($this->param[
'fileinit'] as $file) {
442 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
443 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
445 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
446 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
448 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
449 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
453 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
454 if ($this->withform == 1) {
455 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
457 $out .=
'<a id="formmail" name="formmail"></a>';
458 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
459 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
460 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
461 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
463 if (!empty($this->withfrom)) {
464 if (!empty($this->withfromreadonly)) {
465 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
466 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
469 foreach ($this->param as $key => $value) {
470 if (is_array($value)) {
471 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
473 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
477 $modelmail_array = array();
478 if ($this->param[
'models'] !=
'none') {
484 foreach ($this->lines_model as $line) {
486 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
487 $labeltouse = $langs->trans($reg[1]);
489 $labeltouse = $line->label;
495 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
497 if ($line->private) {
498 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
504 if (count($modelmail_array) > 0) {
505 $model_mail_selected_id = GETPOSTISSET(
'modelmailselected') ?
GETPOST(
'modelmailselected',
'int') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
508 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
510 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
512 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
514 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
518 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
521 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
522 'propal_send',
'order_send',
'facture_send',
523 'shipping_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
524 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'all'
527 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
528 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
529 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
531 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
534 $out .=
'<input type="submit" class="button" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
538 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
542 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
545 $helpforsubstitution =
'';
546 if (is_array($this->substit) && count($this->substit)) {
547 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br><br><span class="small">'.
"\n";
549 foreach ($this->substit as $key => $val) {
551 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
556 if (is_array($this->substit) && count($this->substit)) {
557 $helpforsubstitution .=
'</span>';
560 if (!empty($this->withsubstit)) {
561 $out .=
'<tr><td colspan="2" class="right">';
562 if (is_numeric($this->withsubstit)) {
563 $out .= $form->textwithpicto($langs->trans(
"EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
565 $out .= $form->textwithpicto($langs->trans(
'AvailableVariables'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
567 $out .=
"</td></tr>\n";
571 if (!empty($this->withfrom)) {
572 if (!empty($this->withfromreadonly)) {
573 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
576 if (!($this->fromtype ===
'user' && $this->fromid > 0)
577 && !($this->fromtype ===
'company')
578 && !($this->fromtype ===
'robot')
579 && !preg_match(
'/user_aliases/', $this->fromtype)
580 && !preg_match(
'/global_aliases/', $this->fromtype)
581 && !preg_match(
'/senderprofile/', $this->fromtype)
584 $out .= $this->fromname;
585 if ($this->frommail) {
586 $out .=
' <'.$this->frommail.
'>';
588 if ($this->fromtype) {
589 $langs->load(
'errors');
590 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
597 if (empty($user->email)) {
598 $langs->load(
'errors');
599 $s = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
601 $s = $user->getFullName($langs).
' <'.$user->email.
'>';
603 $liste[
'user'] = array(
'label' => $s,
'data-html' => $s);
606 if (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL)) {
607 $s = (empty($conf->global->MAIN_INFO_SOCIETE_NOM)?$conf->global->MAIN_INFO_SOCIETE_EMAIL:$conf->global->MAIN_INFO_SOCIETE_NOM).
' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.
'>';
608 $liste[
'company'] = array(
'label' => $s,
'data-html' => $s);
612 $listaliases = array(
613 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
618 if (!empty($this->fromalsorobot)) {
620 $s = $conf->global->MAIN_MAIL_EMAIL_FROM;
621 if ($this->frommail) {
622 $s .=
' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.
'>';
624 array(
'label' => $s,
'data-html' => $s);
629 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
630 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
")";
631 $sql .=
" ORDER BY position";
632 $resql = $this->db->query($sql);
634 $num = $this->db->num_rows($resql);
637 $obj = $this->db->fetch_object($resql);
639 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
647 foreach ($listaliases as $typealias => $listalias) {
649 $listaliasarray = explode(
',', $listalias);
650 foreach ($listaliasarray as $listaliasval) {
652 $listaliasval = trim($listaliasval);
654 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
655 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
656 if (!preg_match(
'/</', $listaliasval)) {
657 $listaliasval =
'<'.$listaliasval.
'>';
659 $liste[$typealias.
'_'.$posalias] = array(
'label' => $listaliasval,
'data-html' => $listaliasval);
666 $out .=
' '.$form->selectarray(
'fromtype', $liste, $this->fromtype, 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 0,
'', $disablebademails);
669 $out .=
"</td></tr>\n";
671 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
672 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
673 $out .=
' ';
674 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
675 $out .=
"</td></tr>\n";
680 if (!empty($this->withto) || is_array($this->withto)) {
685 if (!empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
687 $out .= $langs->trans(
"MailToUsers");
691 $tmparray = $this->withtouser;
692 foreach ($tmparray as $key => $val) {
695 $withtoselected =
GETPOST(
"receiveruser",
'array');
696 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
697 $withtoselected = array_keys($tmparray);
699 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
700 $out .=
"</td></tr>\n";
704 if (!empty($this->withoptiononeemailperrecipient)) {
705 if (abs($this->withoptiononeemailperrecipient) == 1) {
706 $out .=
'<tr><td class="minwidth200">';
707 $out .= $langs->trans(
"GroupEmails");
709 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
710 $out .=
'<label for="oneemailperrecipient">';
711 $out .= $form->textwithpicto($langs->trans(
"OneEmailPerRecipient"), $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail"), 1,
'help');
717 if (
getDolGlobalString(
'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
718 if (!empty($this->withto) && !is_array($this->withto)) {
719 $out .=
' '.$langs->trans(
"or").
' <input type="email" name="emailto" value="">';
722 $out .=
'</td></tr>';
724 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
729 if (!empty($this->withtocc) || is_array($this->withtocc)) {
734 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
736 $out .= $langs->trans(
"MailToCCUsers");
740 $tmparray = $this->withtoccuser;
741 foreach ($tmparray as $key => $val) {
744 $withtoselected =
GETPOST(
"receiverccuser",
'array');
745 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
746 $withtoselected = array_keys($tmparray);
748 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
749 $out .=
"</td></tr>\n";
753 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
758 if (!empty($this->withreplyto)) {
759 if ($this->withreplytoreadonly) {
760 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
761 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
762 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
763 $out .=
"</td></tr>\n";
768 if (!empty($this->witherrorsto)) {
773 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
774 $out .= $this->getHtmlForDeliveryReceipt();
778 if (!empty($this->withtopic)) {
779 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
783 if (!empty($this->withfile)) {
785 $out .=
'<td>'.$langs->trans(
"MailFile").
'</td>';
789 if ($this->withmaindocfile) {
791 if (GETPOSTISSET(
'sendmail')) {
792 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
793 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
795 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
799 if (!empty($this->withmaindocfile)) {
800 if ($this->withmaindocfile == 1) {
801 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
802 } elseif ($this->withmaindocfile == -1) {
803 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
805 if (!empty($conf->global->MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND)) {
806 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
808 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
812 if (is_numeric($this->withfile)) {
814 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
815 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
816 $out .=
'jQuery(document).ready(function () {';
817 $out .=
' jQuery(".removedfile").click(function() {';
818 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
821 $out .=
'</script>'.
"\n";
822 if (count($listofpaths)) {
823 foreach ($listofpaths as $key => $val) {
824 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
826 if ($conf->entity > 1) {
827 $relativepathtofile = str_replace(
'/'.$conf->entity.
'/',
'/', $relativepathtofile);
830 $formfile_params = array();
831 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
833 $out .=
'<div id="attachfile_'.$key.
'">';
835 $out .=
img_mime($listofnames[$key]).
' '.$listofnames[$key];
837 $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]);
838 if (!$this->withfilereadonly) {
839 $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.
'" />';
842 $out .=
'<br></div>';
844 } elseif (empty($this->withmaindocfile)) {
847 if ($this->withfile == 2) {
849 $maxmin = $maxfilesizearray[
'maxmin'];
851 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
854 if (empty($conf->global->FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE)) {
855 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
857 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
860 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
863 $out .= $this->withfile;
866 $out .=
"</td></tr>\n";
870 if (!empty($this->withbody)) {
871 $defaultmessage =
GETPOST(
'message',
'restricthtml');
872 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
873 if ($arraydefaultmessage && $arraydefaultmessage->content) {
874 $defaultmessage = $arraydefaultmessage->content;
875 } elseif (!is_numeric($this->withbody)) {
876 $defaultmessage = $this->withbody;
883 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
884 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
885 if (empty($this->substit[
'__REF__'])) {
888 $langs->loadLangs(array(
'paypal',
'other'));
889 $typeforonlinepayment =
'free';
890 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
891 $typeforonlinepayment =
'order';
893 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
894 $typeforonlinepayment =
'invoice';
896 if ($this->param[
"models"] ==
'member') {
897 $typeforonlinepayment =
'member';
899 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
903 if (count($validpaymentmethod) > 0 && $paymenturl) {
904 $langs->load(
'other');
905 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
906 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
907 } elseif (count($validpaymentmethod) > 0) {
908 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'__ONLINE_PAYMENT_TEXT_AND_URL__';
909 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'__ONLINE_PAYMENT_URL__';
911 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
912 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
915 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
919 $defaultlines = $arraydefaultmessage->content_lines;
920 if (isset($defaultlines)) {
921 foreach ($this->substit_lines as $substit_line) {
925 $this->substit[
'__LINES__'] = $lines;
927 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
930 $atleastonecomponentishtml = 0;
931 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
932 $atleastonecomponentishtml++;
934 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
935 $atleastonecomponentishtml++;
937 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
938 $atleastonecomponentishtml++;
940 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
941 $atleastonecomponentishtml++;
944 $atleastonecomponentishtml++;
946 if ($atleastonecomponentishtml) {
948 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
950 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
951 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
953 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
954 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
957 $defaultmessage =
dol_nl2br($defaultmessage);
961 if (GETPOSTISSET(
"message") && !
GETPOST(
'modelselected')) {
962 $defaultmessage =
GETPOST(
"message",
"restricthtml");
966 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
967 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
971 $out .=
'<td colspan="2">';
972 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
977 $out .=
'<td colspan="2">';
978 if ($this->withbodyreadonly) {
979 $out .= nl2br($defaultmessage);
980 $out .=
'<input type="hidden" id="message" name="message" value="'.$defaultmessage.
'" />';
982 if (!isset($this->ckeditortoolbar)) {
983 $this->ckeditortoolbar =
'dolibarr_mailings';
987 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
988 if ($this->withfckeditor == -1) {
989 if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
990 $this->withfckeditor = 1;
992 $this->withfckeditor = 0;
996 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
997 $out .= $doleditor->Create(1);
999 $out .=
"</td></tr>\n";
1002 $out .=
'</table>'.
"\n";
1004 if ($this->withform == 1 || $this->withform == -1) {
1005 $out .=
'<div class="center">';
1006 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1008 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1009 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1012 if ($this->withcancel) {
1013 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1015 $out .= '</div>'."\n
";
1018 if ($this->withform == 1) {
1019 $out .= '</form>'."\n
";
1022 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1023 if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) {
1024 $out .= '<script nonce="'.getNonce().'" type="text/javascript
">';
1025 $out .= 'jQuery(document).ready(function () {';
1026 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1027 var code = e.keyCode || e.which;
1029 console.log("Enter was intercepted and blocked
");
1035 $out .= '</script>';
1038 $out .= "<!-- End form mail -->\n
";
1550 public function setSubstitFromObject($object, $outputlangs)
1552 global $conf, $user, $extrafields;
1554 $parameters = array();
1555 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1556 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1558 $this->substit = $tmparray;
1560 // Fill substit_lines with each object lines content
1561 if (is_array($object->lines)) {
1562 foreach ($object->lines as $line) {
1563 $substit_line = array(
1564 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1565 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1566 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1567 '__LABEL__' => isset($line->label) ? $line->label : '',
1568 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1569 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1570 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1571 '__QUANTITY__' => $line->qty,
1572 '__SUBPRICE__' => price($line->subprice),
1573 '__AMOUNT__' => price($line->total_ttc),
1574 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1577 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1578 if (!empty($line->fk_product)) {
1579 if (!is_object($extrafields)) {
1580 $extrafields = new ExtraFields($this->db);
1582 $product = new Product($this->db);
1583 $product->fetch($line->fk_product, '', '', 1);
1584 $product->fetch_optionals();
1586 $extrafields->fetch_name_optionals_label($product->table_element, true);
1588 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1589 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1590 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1594 $this->substit_lines[] = $substit_line;
1607 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1609 global $conf, $langs;
1611 $tmparray = array();
1612 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1613 $parameters = array('mode'=>$mode);
1614 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1615 complete_substitutions_array($tmparray, $langs, null, $parameters);
1617 if ($mode == 'formwithlines') {
1618 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1620 if ($mode == 'formforlines') {
1621 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1625 if ($mode == 'emailing') {
1626 $parameters = array('mode'=>$mode);
1627 $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
1628 complete_substitutions_array($tmparray, $langs, null, $parameters);
1630 // For mass emailing, we have different keys specific to the data into tagerts list
1631 $tmparray['__ID__'] = 'IdRecord';
1632 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1633 $tmparray['__EMAIL__'] = 'EMailRecipient';
1634 $tmparray['__LASTNAME__'] = 'Lastname';
1635 $tmparray['__FIRSTNAME__'] = 'Firstname';
1636 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1637 $tmparray['__OTHER1__'] = 'Other1';
1638 $tmparray['__OTHER2__'] = 'Other2';
1639 $tmparray['__OTHER3__'] = 'Other3';
1640 $tmparray['__OTHER4__'] = 'Other4';
1641 $tmparray['__OTHER5__'] = 'Other5';
1642 //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
1644 $onlinepaymentenabled = 0;
1645 if (isModEnabled('paypal')) {
1646 $onlinepaymentenabled++;
1648 if (isModEnabled('paybox')) {
1649 $onlinepaymentenabled++;
1651 if (isModEnabled('stripe')) {
1652 $onlinepaymentenabled++;
1654 if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
1655 $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN;
1656 if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
1657 if (isModEnabled('adherent')) {
1658 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1660 if (isModEnabled('don')) {
1661 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1663 if (isModEnabled('facture')) {
1664 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1666 if (isModEnabled('commande')) {
1667 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1669 if (isModEnabled('contrat')) {
1670 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1673 //Online payment link
1674 if (isModEnabled('adherent')) {
1675 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1677 if (isModEnabled('don')) {
1678 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1680 if (isModEnabled('facture')) {
1681 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1683 if (isModEnabled('commande')) {
1684 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1686 if (isModEnabled('contrat')) {
1687 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1691 /* No need to show into tooltip help, option is not enabled
1692 $vars['__SECUREKEYPAYMENT__']='';
1693 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1694 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1695 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1696 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1699 if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
1700 $substitutionarray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1704 foreach ($tmparray as $key => $val) {
1706 $tmparray[$key] = $key;