6  * @subpackage PluginsFunction
 
  10  * Smarty {html_options} function plugin
 
  13  * Name:     html_options<br>
 
  14  * Purpose:  Prints the list of <option> tags generated from
 
  15  *            the passed parameters
 
  17  * @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image}
 
  18  *      (Smarty online manual)
 
  19  * @author Monte Ohrt <monte at ohrt dot com> 
 
  20  * @param array $params parameters
 
  22  *            - name       (optional) - string default "select"
 
  23  *            - values     (required if no options supplied) - array
 
  24  *            - options    (required if no values supplied) - associative array
 
  25  *            - selected   (optional) - string default not set
 
  26  *            - output     (required if not options supplied) - array
 
  27  * @param object $template template object
 
  29  * @uses smarty_function_escape_special_chars()
 
  31 function smarty_function_html_options($params, $template)
 
  33     require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
 
  46     foreach($params as $_key => $_val) {
 
  51                 $$_key = (string)$_val;
 
  55                 $$_key = (array)$_val;
 
  60                 $$_key = array_values((array)$_val);
 
  64                 $$_key = array_map('strval', array_values((array)$_val));
 
  68                 if (!is_array($_val)) {
 
  69                     $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
 
  71                     trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
 
  77     if (!isset($options) && !isset($values))
 
  79     /* raise error here? */
 
  84     if (isset($options)) {
 
  85         foreach ($options as $_key => $_val) {
 
  86           $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
 
  89         foreach ($values as $_i => $_key) {
 
  90             $_val = isset($output[$_i]) ? $output[$_i] : '';
 
  91             $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
 
  96         $_html_class = !empty($class) ? ' class="'.$class.'"' : '';
 
  97         $_html_id = !empty($id) ? ' id="'.$id.'"' : '';
 
  98         $_html_result = '<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";
 
 101     return $_html_result;
 
 104 function smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, &$idx)
 
 106     if (!is_array($value)) {
 
 107         $_html_result = '<option value="' .
 
 108         smarty_function_escape_special_chars($key) . '"';
 
 109         if (in_array((string)$key, $selected))
 
 110             $_html_result .= ' selected="selected"';
 
 111         $_html_class = !empty($class) ? ' class="'.$class.' option"' : '';
 
 112         $_html_id = !empty($id) ? ' id="'.$id.'-'.$idx.'"' : '';
 
 113         $_html_result .= $_html_class . $_html_id . '>' . smarty_function_escape_special_chars($value) . '</option>' . "\n";
 
 117         $_html_result = smarty_function_html_options_optgroup($key, $value, $selected, $id.'-'.$idx, $class, $_idx);
 
 120     return $_html_result;
 
 123 function smarty_function_html_options_optgroup($key, $values, $selected, $id, $class, &$idx)
 
 125     $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";
 
 126     foreach ($values as $key => $value) {
 
 127         $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, $idx);
 
 129     $optgroup_html .= "</optgroup>\n";
 
 130     return $optgroup_html;