00001 <?php 00041 function smarty_function_html_checkboxes($params, &$smarty) 00042 { 00043 require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); 00044 00045 $name = 'checkbox'; 00046 $values = null; 00047 $options = null; 00048 $selected = null; 00049 $separator = ''; 00050 $labels = true; 00051 $output = null; 00052 00053 $extra = ''; 00054 00055 foreach($params as $_key => $_val) { 00056 switch($_key) { 00057 case 'name': 00058 case 'separator': 00059 $$_key = $_val; 00060 break; 00061 00062 case 'labels': 00063 $$_key = (bool)$_val; 00064 break; 00065 00066 case 'options': 00067 $$_key = (array)$_val; 00068 break; 00069 00070 case 'values': 00071 case 'output': 00072 $$_key = array_values((array)$_val); 00073 break; 00074 00075 case 'checked': 00076 case 'selected': 00077 $selected = array_map('strval', array_values((array)$_val)); 00078 break; 00079 00080 case 'checkboxes': 00081 $smarty->trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); 00082 $options = (array)$_val; 00083 break; 00084 00085 case 'assign': 00086 break; 00087 00088 default: 00089 if(!is_array($_val)) { 00090 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; 00091 } else { 00092 $smarty->trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 00093 } 00094 break; 00095 } 00096 } 00097 00098 if (!isset($options) && !isset($values)) 00099 return ''; /* raise error here? */ 00100 00101 settype($selected, 'array'); 00102 $_html_result = array(); 00103 00104 if (isset($options)) { 00105 00106 foreach ($options as $_key=>$_val) 00107 $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); 00108 00109 00110 } else { 00111 foreach ($values as $_i=>$_key) { 00112 $_val = isset($output[$_i]) ? $output[$_i] : ''; 00113 $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); 00114 } 00115 00116 } 00117 00118 if(!empty($params['assign'])) { 00119 $smarty->assign($params['assign'], $_html_result); 00120 } else { 00121 return implode("\n",$_html_result); 00122 } 00123 00124 } 00125 00126 function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels) { 00127 $_output = ''; 00128 if ($labels) $_output .= '<label>'; 00129 $_output .= '<input type="checkbox" name="' 00130 . smarty_function_escape_special_chars($name) . '[]" value="' 00131 . smarty_function_escape_special_chars($value) . '"'; 00132 00133 if (in_array((string)$value, $selected)) { 00134 $_output .= ' checked="checked"'; 00135 } 00136 $_output .= $extra . ' />' . $output; 00137 if ($labels) $_output .= '</label>'; 00138 $_output .= $separator; 00139 00140 return $_output; 00141 } 00142 00143 ?>
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
