Fix regression losing warning on not defined emails

This commit is contained in:
Laurent Destailleur 2016-12-19 18:11:53 +01:00
parent 8fb9a55d8a
commit be19a999f5
2 changed files with 36 additions and 10 deletions

View File

@ -4857,12 +4857,13 @@ class Form
* @param int $disabled Html select box is disabled
* @param string $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' or 'POS' = Do not sort, we keep original order
* @param string $morecss Add more class to css styles
* @param int $addjscombo Add js combo
* @param int $addjscombo Add js combo
* @param string $moreparamonempty Add more param on the empty option line. Not used if show_empty not set.
* @return string HTML select string.
* @param int $disablebademail Check if an email is found into value and if not disable and colorize entry.
* @return string HTML select string.
* @see multiselectarray
*/
static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0, $moreparamonempty='')
static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0, $moreparamonempty='',$disablebademail=0)
{
global $conf, $langs;
@ -4907,7 +4908,10 @@ class Form
// Translate
if ($translate)
{
foreach($array as $key => $value) $array[$key]=$langs->trans($value);
foreach($array as $key => $value)
{
$array[$key]=$langs->trans($value);
}
}
// Sort
@ -4916,8 +4920,19 @@ class Form
foreach($array as $key => $value)
{
$disabled=''; $style='';
if (! empty($disablebademail))
{
if (! preg_match('/<.+@.+>/', $value))
{
//$value=preg_replace('/'.preg_quote($a,'/').'/', $b, $value);
$disabled=' disabled';
$style=' class="warning"';
}
}
$out.='<option value="'.$key.'"';
if ($id != '' && $id == $key) $out.=' selected'; // To preselect a value
$out.=$style.$disabled;
if ($id != '' && $id == $key && ! $disabled) $out.=' selected'; // To preselect a value
$out.='>';
if ($key_in_label)
@ -4929,6 +4944,7 @@ class Form
$selectOptionValue = dol_escape_htmltag($maxlen?dol_trunc($value,$maxlen):$value);
if ($value == '' || $value == '-') $selectOptionValue='&nbsp;';
}
//var_dump($selectOptionValue);
$out.=$selectOptionValue;
$out.="</option>\n";
}

View File

@ -264,6 +264,8 @@ class FormMail extends Form
{
$out='';
$disablebademails=1;
// Define list of attached files
$listofpaths=array();
$listofnames=array();
@ -392,7 +394,15 @@ class FormMail extends Form
}
} else {
$liste = array();
$liste['user'] = $user->getFullName($langs) .' &lt;'.$user->email.'&gt;';
if (empty($user->email))
{
$langs->load('errors');
$liste['user'] = $user->getFullName($langs) . ' &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt;';
}
else
{
$liste['user'] = $user->getFullName($langs) .' &lt;'.$user->email.'&gt;';
}
$liste['company'] = $conf->global->MAIN_INFO_SOCIETE_NOM .' &lt;'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'&gt;';
// Add also email aliases if there is one
$listaliases=array('user_aliases'=>$user->email_aliases, 'global_aliases'=>$conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
@ -413,7 +423,7 @@ class FormMail extends Form
}
}
}
$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0);
$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails);
}
$out.= "</td></tr>\n";
@ -510,7 +520,7 @@ class FormMail extends Form
if (! empty($this->withto) && is_array($this->withto))
{
if (! empty($this->withtofree)) $out.= " ".$langs->trans("or")." ";
$out.= $form->selectarray("receiver", $this->withto, GETPOST("receiver"), 1);
$out.= $form->selectarray("receiver", $this->withto, GETPOST("receiver"), 1, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails);
}
if (isset($this->withtosocid) && $this->withtosocid > 0) // deprecated. TODO Remove this. Instead, fill withto with array before calling method.
{
@ -522,7 +532,7 @@ class FormMail extends Form
$liste[$key]=$value;
}
if ($this->withtofree) $out.= " ".$langs->trans("or")." ";
$out.= $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
$out.= $form->selectarray("receiver", $liste, GETPOST("receiver"), 1, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails);
}
}
$out.= "</td></tr>\n";
@ -544,7 +554,7 @@ class FormMail extends Form
if (! empty($this->withtocc) && is_array($this->withtocc))
{
$out.= " ".$langs->trans("or")." ";
$out.= $form->selectarray("receivercc", $this->withtocc, GETPOST("receivercc"), 1);
$out.= $form->selectarray("receivercc", $this->withtocc, GETPOST("receivercc"), 1, 0, 0, '', 0, 0, 0, '', '', 0, '', $disablebademails);
}
}
$out.= "</td></tr>\n";