00001 <?php 00030 function smarty_function_html_options($params, &$smarty) 00031 { 00032 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); 00033 00034 $name = null; 00035 $values = null; 00036 $options = null; 00037 $selected = array(); 00038 $output = null; 00039 00040 $extra = ''; 00041 00042 foreach($params as $_key => $_val) { 00043 switch($_key) { 00044 case 'name': 00045 $$_key = (string)$_val; 00046 break; 00047 00048 case 'options': 00049 $$_key = (array)$_val; 00050 break; 00051 00052 case 'values': 00053 case 'output': 00054 $$_key = array_values((array)$_val); 00055 break; 00056 00057 case 'selected': 00058 $$_key = array_map('strval', array_values((array)$_val)); 00059 break; 00060 00061 default: 00062 if(!is_array($_val)) { 00063 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; 00064 } else { 00065 $smarty->trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 00066 } 00067 break; 00068 } 00069 } 00070 00071 if (!isset($options) && !isset($values)) 00072 return ''; /* raise error here? */ 00073 00074 $_html_result = ''; 00075 00076 if (isset($options)) { 00077 00078 foreach ($options as $_key=>$_val) 00079 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected); 00080 00081 } else { 00082 00083 foreach ($values as $_i=>$_key) { 00084 $_val = isset($output[$_i]) ? $output[$_i] : ''; 00085 $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected); 00086 } 00087 00088 } 00089 00090 if(!empty($name)) { 00091 $_html_result = '<select name="' . $name . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n"; 00092 } 00093 00094 return $_html_result; 00095 00096 } 00097 00098 function smarty_function_html_options_optoutput($key, $value, $selected) { 00099 if(!is_array($value)) { 00100 $_html_result = '<option label="' . smarty_function_escape_special_chars($value) . '" value="' . 00101 smarty_function_escape_special_chars($key) . '"'; 00102 if (in_array((string)$key, $selected)) 00103 $_html_result .= ' selected="selected"'; 00104 $_html_result .= '>' . smarty_function_escape_special_chars($value) . '</option>' . "\n"; 00105 } else { 00106 $_html_result = smarty_function_html_options_optgroup($key, $value, $selected); 00107 } 00108 return $_html_result; 00109 } 00110 00111 function smarty_function_html_options_optgroup($key, $values, $selected) { 00112 $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n"; 00113 foreach ($values as $key => $value) { 00114 $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected); 00115 } 00116 $optgroup_html .= "</optgroup>\n"; 00117 return $optgroup_html; 00118 } 00119 00120 /* vim: set expandtab: */ 00121 00122 ?>
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
