diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index c9e57eeaa4d90e19c98a8083f3f2e15f0ab301ab..8abe3f271f7509c0c24f6b9933188a6d78d4c740 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -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=' '; } + //var_dump($selectOptionValue); $out.=$selectOptionValue; $out.="</option>\n"; } diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 6d88e73577037db3f90d60a883aac8a9cbe70490..013b34699d7480f69a56f21fffc1d886e9469941 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -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) .' <'.$user->email.'>'; + if (empty($user->email)) + { + $langs->load('errors'); + $liste['user'] = $user->getFullName($langs) . ' <'.$langs->trans('ErrorNoMailDefinedForThisUser').'>'; + } + else + { + $liste['user'] = $user->getFullName($langs) .' <'.$user->email.'>'; + } $liste['company'] = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; // 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";