1 |
<?php |
2 |
|
3 |
/* |
4 |
* Smarty plugin |
5 |
* ------------------------------------------------------------- |
6 |
* Type: function |
7 |
* Name: html_options |
8 |
* Purpose: Prints the list of <option> tags generated from |
9 |
* the passed parameters |
10 |
* ------------------------------------------------------------- |
11 |
*/ |
12 |
function smarty_function_html_options($params, &$smarty) |
13 |
{ |
14 |
$print_result = true; |
15 |
|
16 |
extract($params); |
17 |
|
18 |
$html_result = ''; |
19 |
|
20 |
settype($selected, 'array'); |
21 |
if (isset($options)) { |
22 |
settype($options, 'array'); |
23 |
foreach ($options as $key => $value) { |
24 |
$html_result .= smarty_function_html_options_optoutput($key, $value, $selected); |
25 |
} |
26 |
} else { |
27 |
settype($output, 'array'); |
28 |
settype($values, 'array'); |
29 |
for ($i = 0, $for_max = count($output); $i < $for_max; $i++) { |
30 |
if ($i < count($values)) { |
31 |
$html_result .= smarty_function_html_options_optoutput($values[$i], $output[$i], $selected); |
32 |
} else { |
33 |
$html_result .= smarty_function_html_options_optoutput($output[$i], $output[$i], $selected); |
34 |
} |
35 |
} |
36 |
} |
37 |
|
38 |
if ($print_result) |
39 |
print $html_result; |
40 |
else |
41 |
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: */ |
66 |
|
67 |
?> |