+++ /dev/null
-<?php\r
-/**\r
- * Smarty plugin\r
- * @package Smarty\r
- * @subpackage plugins\r
- */\r
-\r
-\r
-/**\r
- * Smarty {html_options} function plugin\r
- *\r
- * Type: function<br>\r
- * Name: html_options<br>\r
- * Input:<br>\r
- * - name (optional) - string default "select"\r
- * - values (required if no options supplied) - array\r
- * - options (required if no values supplied) - associative array\r
- * - selected (optional) - string default not set\r
- * - output (required if not options supplied) - array\r
- * Purpose: Prints the list of <option> tags generated from\r
- * the passed parameters\r
- * @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image}\r
- * (Smarty online manual)\r
- * @param array\r
- * @param Smarty\r
- * @return string\r
- * @uses smarty_function_escape_special_chars()\r
- */\r
-function smarty_function_html_options($params, &$smarty)\r
-{\r
- require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');\r
- \r
- $name = null;\r
- $values = null;\r
- $options = null;\r
- $selected = array();\r
- $output = null;\r
-\r
- $extra = '';\r
- \r
- foreach($params as $_key => $_val) { \r
- switch($_key) {\r
- case 'name':\r
- $$_key = (string)$_val;\r
- break;\r
-\r
- case 'options':\r
- $$_key = (array)$_val;\r
- break;\r
-\r
- case 'selected':\r
- case 'values':\r
- case 'output':\r
- $$_key = array_values((array)$_val); \r
- break;\r
-\r
- default:\r
- if(!is_array($_val)) {\r
- $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';\r
- } else {\r
- $smarty->trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE);\r
- }\r
- break; \r
- }\r
- }\r
-\r
- if (!isset($options) && !isset($values))\r
- return ''; /* raise error here? */\r
-\r
- $_html_result = '';\r
-\r
- if (is_array($options)) {\r
-\r
- foreach ($options as $_key=>$_val)\r
- $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected); \r
- \r
- } else { \r
-\r
- foreach ((array)$values as $_i=>$_key) {\r
- $_val = isset($output[$_i]) ? $output[$_i] : '';\r
- $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected); \r
- }\r
-\r
- }\r
-\r
- if(!empty($name)) {\r
- $_html_result = '<select name="' . $name . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";\r
- }\r
-\r
- return $_html_result;\r
-\r
-}\r
-\r
-function smarty_function_html_options_optoutput($key, $value, $selected) {\r
- if(!is_array($value)) {\r
- $_html_result = '<option label="' . smarty_function_escape_special_chars($value) . '" value="' . \r
- smarty_function_escape_special_chars($key) . '"';\r
- if (in_array($key, $selected))\r
- $_html_result .= ' selected="selected"';\r
- $_html_result .= '>' . smarty_function_escape_special_chars($value) . '</option>' . "\n";\r
- } else {\r
- $_html_result = smarty_function_html_options_optgroup($key, $value, $selected);\r
- }\r
- return $_html_result; \r
-}\r
-\r
-function smarty_function_html_options_optgroup($key, $values, $selected) {\r
- $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";\r
- foreach ($values as $key => $value) {\r
- $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected);\r
- }\r
- $optgroup_html .= "</optgroup>\n";\r
- return $optgroup_html;\r
-}\r
-\r
-/* vim: set expandtab: */\r
-\r
-?>\r