From 275b75be1aa83268bad0a5ecf7f4ffd0cbbce74f Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 5 Mar 2005 15:03:01 +0000 Subject: [PATCH] option to show selected items at the top of the multiselect-checkbox --- phpgwapi/inc/class.html.inc.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/phpgwapi/inc/class.html.inc.php b/phpgwapi/inc/class.html.inc.php index 3fe8db73ea..82f611500b 100644 --- a/phpgwapi/inc/class.html.inc.php +++ b/phpgwapi/inc/class.html.inc.php @@ -256,9 +256,10 @@ class html * @param boolean $no_lang NOT run the labels of the options through lang(), default false=use lang() * @param string $options additional options (e.g. 'width') * @param int $multiple number of lines for a multiselect, default 3 + * @param boolean $selected_first show the selected items before the not selected ones, default true * @return string to set for a template or to echo into html page */ - function checkbox_multiselect($name, $key, $arr=0,$no_lang=false,$options='',$multiple=3) + function checkbox_multiselect($name, $key, $arr=0,$no_lang=false,$options='',$multiple=3,$selected_first=true) { if (!is_array($arr)) { @@ -279,6 +280,23 @@ class html } $html = ''; $options_no_id = preg_replace('/id="[^"]+"/i','',$options); + + if ($selected_first) + { + $selected = $not_selected = array(); + foreach($arr as $val => $label) + { + if (in_array($val,$key)) + { + $selected[$val] = $label; + } + else + { + $not_selected[$val] = $label; + } + } + $arr = $selected + $not_selected; + } foreach($arr as $val => $label) { if ($label && !$no_lang) $label = lang($label); @@ -288,7 +306,7 @@ class html $html .= $this->label($this->checkbox($name,in_array($val,$key),$val,$options_no_id.' id="'.$base_name.'['.$val.']'.'" '). $this->htmlspecialchars($label),$base_name.'['.$val.']')."
\n"; } - $style = 'height: '.(1.7*$multiple).'em; width: '.(4+0.6*$max_len).'em; background-color: white; overflow: auto; border: lightgray 2px inset;'; + $style = 'height: '.(1.7*$multiple).'em; width: '.(4+0.65*$max_len).'em; background-color: white; overflow: auto; border: lightgray 2px inset;'; return $this->div($html,$options,'',$style); }