1 |
cvsjoko |
1.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 .= "<option value=\"$key\""; |
25 |
|
|
if (in_array($key, $selected)) |
26 |
|
|
$html_result .= " selected=\"selected\""; |
27 |
|
|
$html_result .= ">$value</option>\n"; |
28 |
|
|
} |
29 |
|
|
} else { |
30 |
|
|
settype($output, 'array'); |
31 |
|
|
settype($values, 'array'); |
32 |
|
|
for ($i = 0, $for_max = count($output); $i < $for_max; $i++) { |
33 |
|
|
/* By default, check value against $selected */ |
34 |
|
|
$sel_check = $values[$i]; |
35 |
|
|
$html_result .= "<option"; |
36 |
|
|
if ($i < count($values)) |
37 |
|
|
$html_result .= " value=\"".$values[$i]."\""; |
38 |
|
|
else |
39 |
|
|
$sel_check = $output[$i]; /* if more outputs than values, then |
40 |
|
|
check output against $selected */ |
41 |
|
|
if (in_array($sel_check, $selected)) |
42 |
|
|
$html_result .= " selected=\"selected\""; |
43 |
|
|
$html_result .= ">".$output[$i]."</option>\n"; |
44 |
|
|
} |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
if ($print_result) |
48 |
|
|
print $html_result; |
49 |
|
|
else |
50 |
|
|
return $html_result; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
/* vim: set expandtab: */ |
54 |
|
|
|
55 |
|
|
?> |