This commit is contained in:
Frédéric FRANCE 2021-01-04 23:41:20 +01:00 committed by GitHub
parent 07a3367f52
commit c468db5a7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -116,7 +116,12 @@ class FormMail extends Form
*/
public $withto; // Show recipient emails
public $withtofree; // Show free text for recipient emails
/**
* @var int|string 0 = Do not Show free text for recipient emails
* 1 = Show free text for recipient emails
* or a free email
*/
public $withtofree;
public $withtocc;
public $withtoccc;
public $withtopic;
@ -354,14 +359,15 @@ class FormMail extends Form
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$formfile = new Formfile($this->db);
if (!is_object($form)) $form = new Form($this->db);
if (!is_object($form)) {
$form = new Form($this->db);
}
// Load translation files required by the page
$langs->loadLangs(array('other', 'mails'));
// Clear temp files. Must be done at beginning, before call of triggers
if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1'))
{
if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) {
$this->clear_attached_files();
}
@ -375,8 +381,7 @@ class FormMail extends Form
);
$reshook = $hookmanager->executeHooks('getFormMail', $parameters, $this);
if (!empty($reshook))
{
if (!empty($reshook)) {
return $hookmanager->resPrint;
} else {
$out = '';
@ -387,8 +392,7 @@ class FormMail extends Form
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $this->param['langsmodels'];
if (!empty($newlang))
{
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('other');
@ -396,11 +400,9 @@ class FormMail extends Form
// Get message template for $this->param["models"] into c_email_templates
$arraydefaultmessage = -1;
if ($this->param['models'] != 'none')
{
if ($this->param['models'] != 'none') {
$model_id = 0;
if (array_key_exists('models_id', $this->param))
{
if (array_key_exists('models_id', $this->param)) {
$model_id = $this->param["models_id"];
}
@ -413,25 +415,27 @@ class FormMail extends Form
$listofmimes = array();
$keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1'))
{
if (!empty($arraydefaultmessage->joinfiles) && is_array($this->param['fileinit']))
{
foreach ($this->param['fileinit'] as $file)
{
if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) {
if (!empty($arraydefaultmessage->joinfiles) && is_array($this->param['fileinit'])) {
foreach ($this->param['fileinit'] as $file) {
$this->add_attached_files($file, basename($file), dol_mimetype($file));
}
}
}
if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
$listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
}
if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
$listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
}
if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
$listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
}
$out .= "\n".'<!-- Begin form mail type='.$this->param["models"].' --><div id="mailformdiv"></div>'."\n";
if ($this->withform == 1)
{
if ($this->withform == 1) {
$out .= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param["returnurl"].'#formmail">'."\n";
$out .= '<a id="formmail" name="formmail"></a>';
@ -439,16 +443,13 @@ class FormMail extends Form
$out .= '<input type="hidden" name="token" value="'.newToken().'" />';
$out .= '<input type="hidden" name="trackid" value="'.$this->trackid.'" />';
}
if (!empty($this->withfrom))
{
if (!empty($this->withfromreadonly))
{
if (!empty($this->withfrom)) {
if (!empty($this->withfromreadonly)) {
$out .= '<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.'" />';
$out .= '<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.'" />';
}
}
foreach ($this->param as $key=>$value)
{
foreach ($this->param as $key=>$value) {
if (is_array($value)) {
$out .= "<!-- param key=".$key." is array, we do not output input filed for it -->\n";
} else {
@ -457,17 +458,14 @@ class FormMail extends Form
}
$modelmail_array = array();
if ($this->param['models'] != 'none')
{
if ($this->param['models'] != 'none') {
$result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
if ($result < 0)
{
if ($result < 0) {
setEventMessages($this->error, $this->errors, 'errors');
}
$langs->trans("members");
foreach ($this->lines_model as $line)
{
foreach ($this->lines_model as $line) {
$reg = array();
if (preg_match('/\((.*)\)/', $line->label, $reg)) {
$labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__
@ -483,8 +481,7 @@ class FormMail extends Form
}
// Zone to select email template
if (count($modelmail_array) > 0)
{
if (count($modelmail_array) > 0) {
// If list of template is filled
$out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
$out .= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> ';
@ -498,8 +495,7 @@ class FormMail extends Form
'propal_send', 'order_send', 'facture_send',
'shipping_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send',
'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'all'
)))
{
))) {
// If list of template is empty
$out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
$out .= $langs->trans('SelectMailModel').': <select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans("NoTemplateDefined").'</option></select>'; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy.
@ -518,12 +514,10 @@ class FormMail extends Form
// Substitution array/string
$helpforsubstitution = '';
if (is_array($this->substit) && count($this->substit)) $helpforsubstitution .= $langs->trans('AvailableVariables').' :<br>'."\n";
foreach ($this->substit as $key => $val)
{
foreach ($this->substit as $key => $val) {
$helpforsubstitution .= $key.' -> '.$langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))).'<br>';
}
if (!empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this.
{
if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this.
$out .= '<tr><td colspan="2" class="right">';
//$out.='<div class="floatright">';
if (is_numeric($this->withsubstit)) $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage
@ -538,10 +532,8 @@ class FormMail extends Form
var_dump($this->fromname);*/
// From
if (!empty($this->withfrom))
{
if (!empty($this->withfromreadonly))
{
if (!empty($this->withfrom)) {
if (!empty($this->withfromreadonly)) {
$out .= '<tr><td class="fieldrequired minwidth200">'.$langs->trans("MailFrom").'</td><td>';
// $this->fromtype is the default value to use to select sender
@ -551,16 +543,13 @@ class FormMail extends Form
&& !preg_match('/user_aliases/', $this->fromtype)
&& !preg_match('/global_aliases/', $this->fromtype)
&& !preg_match('/senderprofile/', $this->fromtype)
)
{
) {
// Use this->fromname and this->frommail or error if not defined
$out .= $this->fromname;
if ($this->frommail)
{
if ($this->frommail) {
$out .= ' &lt;'.$this->frommail.'&gt;';
} else {
if ($this->fromtype)
{
if ($this->fromtype) {
$langs->load('errors');
$out .= '<span class="warning"> &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt; </span>';
}
@ -569,8 +558,7 @@ class FormMail extends Form
$liste = array();
// Add user email
if (empty($user->email))
{
if (empty($user->email)) {
$langs->load('errors');
$liste['user'] = $user->getFullName($langs).' &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt;';
} else {
@ -584,13 +572,10 @@ class FormMail extends Form
$listaliases = array('user_aliases'=>$user->email_aliases, 'global_aliases'=>$conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
// Also add robot email
if (!empty($this->fromalsorobot))
{
if (!empty($conf->global->MAIN_MAIL_EMAIL_FROM) && $conf->global->MAIN_MAIL_EMAIL_FROM != $conf->global->MAIN_INFO_SOCIETE_MAIL)
{
if (!empty($this->fromalsorobot)) {
if (!empty($conf->global->MAIN_MAIL_EMAIL_FROM) && $conf->global->MAIN_MAIL_EMAIL_FROM != $conf->global->MAIN_INFO_SOCIETE_MAIL) {
$liste['robot'] = $conf->global->MAIN_MAIL_EMAIL_FROM;
if ($this->frommail)
{
if ($this->frommail) {
$liste['robot'] .= ' &lt;'.$conf->global->MAIN_MAIL_EMAIL_FROM.'&gt;';
}
}
@ -601,31 +586,27 @@ class FormMail extends Form
$sql .= ' WHERE active = 1 AND (private = 0 OR private = '.$user->id.')';
$sql .= ' ORDER BY position';
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
if ($obj)
{
if ($obj) {
$listaliases['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
}
$i++;
}
} else dol_print_error($this->db);
} else {
dol_print_error($this->db);
}
foreach ($listaliases as $typealias => $listalias)
{
foreach ($listaliases as $typealias => $listalias) {
$posalias = 0;
$listaliasarray = explode(',', $listalias);
foreach ($listaliasarray as $listaliasval)
{
foreach ($listaliasarray as $listaliasval) {
$posalias++;
$listaliasval = trim($listaliasval);
if ($listaliasval)
{
if ($listaliasval) {
$listaliasval = preg_replace('/</', '&lt;', $listaliasval);
$listaliasval = preg_replace('/>/', '&gt;', $listaliasval);
if (!preg_match('/&lt;/', $listaliasval)) $listaliasval = '&lt;'.$listaliasval.'&gt;';
@ -637,8 +618,7 @@ class FormMail extends Form
// Set the default "From"
$defaultfrom = '';
$reshook = $hookmanager->executeHooks('getDefaultFromEmail', $parameters, $this);
if (empty($reshook))
{
if (empty($reshook)) {
$defaultfrom = $this->fromtype;
}
if (!empty($hookmanager->resArray['defaultfrom'])) $defaultfrom = $hookmanager->resArray['defaultfrom'];
@ -665,19 +645,15 @@ class FormMail extends Form
if ($this->withtofree) $out .= $form->textwithpicto($langs->trans("MailTo"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
else $out .= $langs->trans("MailTo");
$out .= '</td><td>';
if ($this->withtoreadonly)
{
if (!empty($this->toname) && !empty($this->tomail))
{
if ($this->withtoreadonly) {
if (!empty($this->toname) && !empty($this->tomail)) {
$out .= '<input type="hidden" id="toname" name="toname" value="'.$this->toname.'" />';
$out .= '<input type="hidden" id="tomail" name="tomail" value="'.$this->tomail.'" />';
if ($this->totype == 'thirdparty')
{
if ($this->totype == 'thirdparty') {
$soc = new Societe($this->db);
$soc->fetch($this->toid);
$out .= $soc->getNomUrl(1);
} elseif ($this->totype == 'contact')
{
} elseif ($this->totype == 'contact') {
$contact = new Contact($this->db);
$contact->fetch($this->toid);
$out .= $contact->getNomUrl(1);
@ -685,8 +661,7 @@ class FormMail extends Form
$out .= $this->toname;
}
$out .= ' &lt;'.$this->tomail.'&gt;';
if ($this->withtofree)
{
if ($this->withtofree) {
$out .= '<br>'.$langs->trans("and").' <input class="minwidth200" id="sendto" name="sendto" value="'.(!is_array($this->withto) && !is_numeric($this->withto) ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "").'" />';
}
} else {
@ -695,25 +670,21 @@ class FormMail extends Form
}
} else {
// The free input of email
if (!empty($this->withtofree))
{
if (!empty($this->withtofree)) {
$out .= '<input class="minwidth200" id="sendto" name="sendto" value="'.(($this->withtofree && !is_numeric($this->withtofree)) ? $this->withtofree : (!is_array($this->withto) && !is_numeric($this->withto) ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "")).'" />';
}
// The select combo
if (!empty($this->withto) && is_array($this->withto))
{
if (!empty($this->withto) && is_array($this->withto)) {
if (!empty($this->withtofree)) $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray = $this->withto;
foreach ($tmparray as $key => $val)
{
foreach ($tmparray as $key => $val) {
$tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
}
$withtoselected = GETPOST("receiver", 'array'); // Array of selected value
if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend')
{
if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
$withtoselected = array_keys($tmparray);
}
$out .= $form->multiselectarray("receiver", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
@ -723,21 +694,18 @@ class FormMail extends Form
}
// To User
if (!empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT))
{
if (!empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
$out .= '<tr><td>';
$out .= $langs->trans("MailToUsers");
$out .= '</td><td>';
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray = $this->withtouser;
foreach ($tmparray as $key => $val)
{
foreach ($tmparray as $key => $val) {
$tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
}
$withtoselected = GETPOST("receiveruser", 'array'); // Array of selected value
if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend')
{
if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
$withtoselected = array_keys($tmparray);
}
$out .= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
@ -745,8 +713,7 @@ class FormMail extends Form
}
// With option one email per recipient
if (!empty($this->withoptiononeemailperrecipient))
{
if (!empty($this->withoptiononeemailperrecipient)) {
$out .= '<tr><td class="minwidth200">';
$out .= $langs->trans("GroupEmails");
$out .= '</td><td>';
@ -760,23 +727,19 @@ class FormMail extends Form
}
// CC
if (!empty($this->withtocc) || is_array($this->withtocc))
{
if (!empty($this->withtocc) || is_array($this->withtocc)) {
$out .= '<tr><td>';
$out .= $form->textwithpicto($langs->trans("MailCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
$out .= '</td><td>';
if ($this->withtoccreadonly)
{
if ($this->withtoccreadonly) {
$out .= (!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : "";
} else {
$out .= '<input class="minwidth200" id="sendtocc" name="sendtocc" value="'.(GETPOST("sendtocc", "alpha") ? GETPOST("sendtocc", "alpha") : ((!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : '')).'" />';
if (!empty($this->withtocc) && is_array($this->withtocc))
{
if (!empty($this->withtocc) && is_array($this->withtocc)) {
$out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray = $this->withtocc;
foreach ($tmparray as $key => $val)
{
foreach ($tmparray as $key => $val) {
$tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
}
$withtoccselected = GETPOST("receivercc", 'array'); // Array of selected value
@ -787,21 +750,18 @@ class FormMail extends Form
}
// To User cc
if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT))
{
if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
$out .= '<tr><td>';
$out .= $langs->trans("MailToCCUsers");
$out .= '</td><td>';
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray = $this->withtoccuser;
foreach ($tmparray as $key => $val)
{
foreach ($tmparray as $key => $val) {
$tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
}
$withtoselected = GETPOST("receiverccuser", 'array'); // Array of selected value
if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend')
{
if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
$withtoselected = array_keys($tmparray);
}
$out .= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
@ -814,10 +774,8 @@ class FormMail extends Form
}
// Replyto
if (!empty($this->withreplyto))
{
if ($this->withreplytoreadonly)
{
if (!empty($this->withreplyto)) {
if ($this->withreplytoreadonly) {
$out .= '<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.'" />';
$out .= '<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.'" />';
$out .= "<tr><td>".$langs->trans("MailReply")."</td><td>".$this->replytoname.($this->replytomail ? (" &lt;".$this->replytomail."&gt;") : "");
@ -841,41 +799,32 @@ class FormMail extends Form
}
// Attached files
if (!empty($this->withfile))
{
if (!empty($this->withfile)) {
$out .= '<tr>';
$out .= '<td>'.$langs->trans("MailFile").'</td>';
$out .= '<td>';
if ($this->withmaindocfile) // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked)
{
if (GETPOSTISSET('sendmail'))
{
if ($this->withmaindocfile) { // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked)
if (GETPOSTISSET('sendmail')) {
$this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1);
}
// If a template was selected, we use setup of template to define if join file checkbox is selected or not.
elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
{
} elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
// If a template was selected, we use setup of template to define if join file checkbox is selected or not.
$this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
}
}
if (!empty($this->withmaindocfile))
{
if ($this->withmaindocfile == 1)
{
if (!empty($this->withmaindocfile)) {
if ($this->withmaindocfile == 1) {
$out .= '<input type="checkbox" name="addmaindocfile" value="1" />';
}
if ($this->withmaindocfile == -1)
{
if ($this->withmaindocfile == -1) {
$out .= '<input type="checkbox" name="addmaindocfile" value="1" checked="checked" />';
}
$out .= ' '.$langs->trans("JoinMainDoc").'.<br>';
}
if (is_numeric($this->withfile))
{
if (is_numeric($this->withfile)) {
// TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript
$out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
$out .= '<script type="text/javascript" language="javascript">';
@ -885,28 +834,23 @@ class FormMail extends Form
$out .= ' });';
$out .= '})';
$out .= '</script>'."\n";
if (count($listofpaths))
{
foreach ($listofpaths as $key => $val)
{
if (count($listofpaths)) {
foreach ($listofpaths as $key => $val) {
$out .= '<div id="attachfile_'.$key.'">';
// Preview of attachment
preg_match('#^(/)(\w+)(/)(.+)$#', substr($val, (strlen(DOL_DATA_ROOT) - strlen($val))), $formfile_params);
$out .= img_mime($listofnames[$key]).' '.$listofnames[$key];
$out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]);
if (!$this->withfilereadonly)
{
if (!$this->withfilereadonly) {
$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.'" />';
//$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>';
}
$out .= '<br></div>';
}
} elseif (empty($this->withmaindocfile)) // Do not show message if we asked to show the checkbox
{
} elseif (empty($this->withmaindocfile)) { // Do not show message if we asked to show the checkbox
$out .= $langs->trans("NoAttachedFiles").'<br>';
}
if ($this->withfile == 2) // Can add other files
{
if ($this->withfile == 2) { // Can add other files
if (!empty($conf->global->FROM_MAIL_USE_INPUT_FILE_MULTIPLE)) $out .= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans("Upload").'" multiple />';
else $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
$out .= ' ';
@ -920,11 +864,9 @@ class FormMail extends Form
}
// Message
if (!empty($this->withbody))
{
if (!empty($this->withbody)) {
$defaultmessage = GETPOST('message', 'restricthtml');
if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1')
{
if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
if ($arraydefaultmessage && $arraydefaultmessage->content) {
$defaultmessage = $arraydefaultmessage->content;
} elseif (!is_numeric($this->withbody)) {
@ -934,25 +876,29 @@ class FormMail extends Form
// Complete substitution array with the url to make online payment
$paymenturl = ''; $validpaymentmethod = array();
if (empty($this->substit['__REF__']))
{
if (empty($this->substit['__REF__'])) {
$paymenturl = '';
} else {
// Set the online payment url link into __ONLINE_PAYMENT_URL__ key
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
$langs->loadLangs(array('paypal', 'other'));
$typeforonlinepayment = 'free';
if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') $typeforonlinepayment = 'order'; // TODO use detection on something else than template
if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') $typeforonlinepayment = 'invoice'; // TODO use detection on something else than template
if ($this->param["models"] == 'member') $typeforonlinepayment = 'member'; // TODO use detection on something else than template
if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') {
$typeforonlinepayment = 'order'; // TODO use detection on something else than template
}
if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') {
$typeforonlinepayment = 'invoice'; // TODO use detection on something else than template
}
if ($this->param["models"] == 'member') {
$typeforonlinepayment = 'member'; // TODO use detection on something else than template
}
$url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']);
$paymenturl = $url;
$validpaymentmethod = getValidOnlinePaymentMethods('');
}
if (count($validpaymentmethod) > 0 && $paymenturl)
{
if (count($validpaymentmethod) > 0 && $paymenturl) {
$langs->load('other');
$this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl));
$this->substit['__ONLINE_PAYMENT_URL__'] = $paymenturl;
@ -966,10 +912,8 @@ class FormMail extends Form
// Add lines substitution key from each line
$lines = '';
$defaultlines = $arraydefaultmessage->content_lines;
if (isset($defaultlines))
{
foreach ($this->substit_lines as $substit_line)
{
if (isset($defaultlines)) {
foreach ($this->substit_lines as $substit_line) {
$lines .= make_substitutions($defaultlines, $substit_line)."\n";
}
}
@ -1003,8 +947,9 @@ class FormMail extends Form
}
}
if (GETPOSTISSET("message") && !$_POST['modelselected']) $defaultmessage = $_POST["message"];
else {
if (GETPOSTISSET("message") && !$_POST['modelselected']) {
$defaultmessage = $_POST["message"];
} else {
$defaultmessage = make_substitutions($defaultmessage, $this->substit);
// Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
$defaultmessage = preg_replace("/^(<br>)+/", "", $defaultmessage);
@ -1016,17 +961,17 @@ class FormMail extends Form
$out .= $form->textwithpicto($langs->trans('MailText'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody');
$out .= '</td>';
$out .= '<td>';
if ($this->withbodyreadonly)
{
if ($this->withbodyreadonly) {
$out .= nl2br($defaultmessage);
$out .= '<input type="hidden" id="message" name="message" value="'.$defaultmessage.'" />';
} else {
if (!isset($this->ckeditortoolbar)) $this->ckeditortoolbar = 'dolibarr_notes';
if (!isset($this->ckeditortoolbar)) {
$this->ckeditortoolbar = 'dolibarr_notes';
}
// Editor wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
if ($this->withfckeditor == -1)
{
if ($this->withfckeditor == -1) {
if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $this->withfckeditor = 1;
else $this->withfckeditor = 0;
}
@ -1039,29 +984,27 @@ class FormMail extends Form
$out .= '</table>'."\n";
if ($this->withform == 1 || $this->withform == -1)
{
if ($this->withform == 1 || $this->withform == -1) {
$out .= '<br><div class="center">';
$out .= '<input class="button" type="submit" id="sendmail" name="sendmail" value="'.$langs->trans("SendMail").'"';
// Add a javascript test to avoid to forget to submit file before sending email
if ($this->withfile == 2 && $conf->use_javascript_ajax)
{
if ($this->withfile == 2 && $conf->use_javascript_ajax) {
$out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"';
}
$out .= ' />';
if ($this->withcancel)
{
if ($this->withcancel) {
$out .= ' &nbsp; &nbsp; ';
$out .= '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'" />';
}
$out .= '</div>'."\n";
}
if ($this->withform == 1) $out .= '</form>'."\n";
if ($this->withform == 1) {
$out .= '</form>'."\n";
}
// Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY))
{
if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) {
$out .= '<script type="text/javascript" language="javascript">';
$out .= 'jQuery(document).ready(function () {';
$out .= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */