PEEL Shopping
Open source ecommerce : PEEL Shopping
function.html_checkboxes.php
Go to the documentation of this file.
1 <?php
45 function smarty_function_html_checkboxes($params, $template)
46 {
47  require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
48 
49  $name = 'checkbox';
50  $values = null;
51  $options = null;
52  $selected = array();
53  $separator = '';
54  $escape = true;
55  $labels = true;
56  $label_ids = false;
57  $output = null;
58 
59  $extra = '';
60 
61  foreach($params as $_key => $_val) {
62  switch($_key) {
63  case 'name':
64  case 'separator':
65  $$_key = (string) $_val;
66  break;
67 
68  case 'escape':
69  case 'labels':
70  case 'label_ids':
71  $$_key = (bool) $_val;
72  break;
73 
74  case 'options':
75  $$_key = (array) $_val;
76  break;
77 
78  case 'values':
79  case 'output':
80  $$_key = array_values((array) $_val);
81  break;
82 
83  case 'checked':
84  case 'selected':
85  if (is_array($_val)) {
86  $selected = array();
87  foreach ($_val as $_sel) {
88  if (is_object($_sel)) {
89  if (method_exists($_sel, "__toString")) {
90  $_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
91  } else {
92  trigger_error("html_checkboxes: selected attribute contains an object of class '". get_class($_sel) ."' without __toString() method", E_USER_NOTICE);
93  continue;
94  }
95  } else {
96  $_sel = smarty_function_escape_special_chars((string) $_sel);
97  }
98  $selected[$_sel] = true;
99  }
100  } elseif (is_object($_val)) {
101  if (method_exists($_val, "__toString")) {
102  $selected = smarty_function_escape_special_chars((string) $_val->__toString());
103  } else {
104  trigger_error("html_checkboxes: selected attribute is an object of class '". get_class($_val) ."' without __toString() method", E_USER_NOTICE);
105  }
106  } else {
107  $selected = smarty_function_escape_special_chars((string) $_val);
108  }
109  break;
110 
111  case 'checkboxes':
112  trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING);
113  $options = (array) $_val;
114  break;
115 
116  case 'assign':
117  break;
118 
119  case 'strict': break;
120 
121  case 'disabled':
122  case 'readonly':
123  if (!empty($params['strict'])) {
124  if (!is_scalar($_val)) {
125  trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE);
126  }
127 
128  if ($_val === true || $_val === $_key) {
129  $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
130  }
131 
132  break;
133  }
134  // omit break; to fall through!
135 
136  default:
137  if(!is_array($_val)) {
138  $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
139  } else {
140  trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
141  }
142  break;
143  }
144  }
145 
146  if (!isset($options) && !isset($values))
147  return ''; /* raise error here? */
148 
149  $_html_result = array();
150 
151  if (isset($options)) {
152  foreach ($options as $_key=>$_val) {
153  $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
154  }
155  } else {
156  foreach ($values as $_i=>$_key) {
157  $_val = isset($output[$_i]) ? $output[$_i] : '';
158  $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
159  }
160  }
161 
162  if(!empty($params['assign'])) {
163  $template->assign($params['assign'], $_html_result);
164  } else {
165  return implode("\n", $_html_result);
166  }
167 
168 }
169 
170 function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape=true) {
171  $_output = '';
172 
173  if (is_object($value)) {
174  if (method_exists($value, "__toString")) {
175  $value = (string) $value->__toString();
176  } else {
177  trigger_error("html_options: value is an object of class '". get_class($value) ."' without __toString() method", E_USER_NOTICE);
178  return '';
179  }
180  } else {
181  $value = (string) $value;
182  }
183 
184  if (is_object($output)) {
185  if (method_exists($output, "__toString")) {
186  $output = (string) $output->__toString();
187  } else {
188  trigger_error("html_options: output is an object of class '". get_class($output) ."' without __toString() method", E_USER_NOTICE);
189  return '';
190  }
191  } else {
192  $output = (string) $output;
193  }
194 
195  if ($labels) {
196  if ($label_ids) {
197  $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $name . '_' . $value));
198  $_output .= '<label for="' . $_id . '">';
199  } else {
200  $_output .= '<label class="label_checkbox">';
201  }
202  }
203 
204  $name = smarty_function_escape_special_chars($name);
205  $value = smarty_function_escape_special_chars($value);
206  if ($escape) {
207  $output = smarty_function_escape_special_chars($output);
208  }
209 
210  $_output .= '<input type="checkbox" name="' . $name . '[]" value="' . $value . '"';
211 
212  if ($labels && $label_ids) {
213  $_output .= ' id="' . $_id . '"';
214  }
215 
216  if (is_array($selected)) {
217  if (isset($selected[$value])) {
218  $_output .= ' checked="checked"';
219  }
220  } elseif ($value === $selected) {
221  $_output .= ' checked="checked"';
222  }
223 
224  $_output .= $extra . ' /> ' . $output;
225  if ($labels) {
226  $_output .= '</label>';
227  }
228 
229  $_output .= $separator;
230  return $_output;
231 }
232 
233 ?>
static $_UTF8_MODIFIER
Flag denoting if PCRE should run in UTF-8 mode.
smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape=true)
smarty_function_html_checkboxes($params, $template)
Smarty {html_checkboxes} function plugin.
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:16 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.