2002-01-31 20:49:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Smarty plugin
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
* Type: function
|
|
|
|
* Name: html_options
|
|
|
|
* Purpose: Prints the list of <option> tags generated from
|
|
|
|
* the passed parameters
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
function smarty_function_html_options($params, &$smarty)
|
|
|
|
{
|
|
|
|
$print_result = true;
|
|
|
|
|
|
|
|
extract($params);
|
|
|
|
|
|
|
|
$html_result = '';
|
|
|
|
|
|
|
|
settype($selected, 'array');
|
|
|
|
if (isset($options)) {
|
|
|
|
settype($options, 'array');
|
|
|
|
foreach ($options as $key => $value) {
|
2002-11-01 15:18:27 +00:00
|
|
|
$html_result .= smarty_function_html_options_optoutput($key, $value, $selected);
|
2002-01-31 20:49:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
settype($output, 'array');
|
|
|
|
settype($values, 'array');
|
2002-06-03 16:05:33 +00:00
|
|
|
for ($i = 0, $for_max = count($output); $i < $for_max; $i++) {
|
2002-11-01 15:18:27 +00:00
|
|
|
if ($i < count($values)) {
|
|
|
|
$html_result .= smarty_function_html_options_optoutput($values[$i], $output[$i], $selected);
|
|
|
|
} else {
|
|
|
|
$html_result .= smarty_function_html_options_optoutput($output[$i], $output[$i], $selected);
|
|
|
|
}
|
2002-01-31 20:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($print_result)
|
|
|
|
print $html_result;
|
|
|
|
else
|
|
|
|
return $html_result;
|
|
|
|
}
|
|
|
|
|
2002-11-01 15:18:27 +00:00
|
|
|
function smarty_function_html_options_optoutput($key, $value, $selected) {
|
|
|
|
if(!is_array($value)) {
|
2002-12-10 14:52:07 +00:00
|
|
|
$html_result = "<option label=\"$value\" value=\"$key\"";
|
2002-11-01 15:18:27 +00:00
|
|
|
if (in_array($key, $selected))
|
|
|
|
$html_result .= " selected=\"selected\"";
|
|
|
|
$html_result .= ">$value</option>\n";
|
|
|
|
} else {
|
|
|
|
$html_result = smarty_function_html_options_optgroup($key, $value, $selected);
|
|
|
|
}
|
|
|
|
return $html_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function smarty_function_html_options_optgroup($key, $values, $selected) {
|
2002-12-10 14:52:07 +00:00
|
|
|
$optgroup_html = "<optgroup label=\"$value\">\n";
|
2002-11-01 15:18:27 +00:00
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
$optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected);
|
|
|
|
}
|
|
|
|
$optgroup_html .= "</optgroup>\n";
|
|
|
|
return $optgroup_html;
|
|
|
|
}
|
|
|
|
|
2002-01-31 20:49:40 +00:00
|
|
|
/* vim: set expandtab: */
|
|
|
|
|
|
|
|
?>
|