21 |
if (isset($options)) { |
if (isset($options)) { |
22 |
settype($options, 'array'); |
settype($options, 'array'); |
23 |
foreach ($options as $key => $value) { |
foreach ($options as $key => $value) { |
24 |
$html_result .= "<option value=\"$key\""; |
$html_result .= smarty_function_html_options_optoutput($key, $value, $selected); |
|
if (in_array($key, $selected)) |
|
|
$html_result .= " selected=\"selected\""; |
|
|
$html_result .= ">$value</option>\n"; |
|
25 |
} |
} |
26 |
} else { |
} else { |
27 |
settype($output, 'array'); |
settype($output, 'array'); |
28 |
settype($values, 'array'); |
settype($values, 'array'); |
29 |
for ($i = 0, $for_max = count($output); $i < $for_max; $i++) { |
for ($i = 0, $for_max = count($output); $i < $for_max; $i++) { |
30 |
/* By default, check value against $selected */ |
if ($i < count($values)) { |
31 |
$sel_check = $values[$i]; |
$html_result .= smarty_function_html_options_optoutput($values[$i], $output[$i], $selected); |
32 |
$html_result .= "<option"; |
} else { |
33 |
if ($i < count($values)) |
$html_result .= smarty_function_html_options_optoutput($output[$i], $output[$i], $selected); |
34 |
$html_result .= " value=\"".$values[$i]."\""; |
} |
|
else |
|
|
$sel_check = $output[$i]; /* if more outputs than values, then |
|
|
check output against $selected */ |
|
|
if (in_array($sel_check, $selected)) |
|
|
$html_result .= " selected=\"selected\""; |
|
|
$html_result .= ">".$output[$i]."</option>\n"; |
|
35 |
} |
} |
36 |
} |
} |
37 |
|
|
41 |
return $html_result; |
return $html_result; |
42 |
} |
} |
43 |
|
|
44 |
|
function smarty_function_html_options_optoutput($key, $value, $selected) { |
45 |
|
if(!is_array($value)) { |
46 |
|
$html_result = "<option label=\"$key\" value=\"$key\""; |
47 |
|
if (in_array($key, $selected)) |
48 |
|
$html_result .= " selected=\"selected\""; |
49 |
|
$html_result .= ">$value</option>\n"; |
50 |
|
} else { |
51 |
|
$html_result = smarty_function_html_options_optgroup($key, $value, $selected); |
52 |
|
} |
53 |
|
return $html_result; |
54 |
|
} |
55 |
|
|
56 |
|
function smarty_function_html_options_optgroup($key, $values, $selected) { |
57 |
|
$optgroup_html = "<optgroup label=\"$key\">\n"; |
58 |
|
foreach ($values as $key => $value) { |
59 |
|
$optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected); |
60 |
|
} |
61 |
|
$optgroup_html .= "</optgroup>\n"; |
62 |
|
return $optgroup_html; |
63 |
|
} |
64 |
|
|
65 |
/* vim: set expandtab: */ |
/* vim: set expandtab: */ |
66 |
|
|
67 |
?> |
?> |