PEEL Shopping
Open source ecommerce : PEEL Shopping
function.html_options.php
Go to the documentation of this file.
1 <?php
36 function smarty_function_html_options($params, $template)
37 {
38  require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
39 
40  $name = null;
41  $values = null;
42  $options = null;
43  $selected = null;
44  $output = null;
45  $id = null;
46  $class = null;
47 
48  $extra = '';
49 
50  foreach ($params as $_key => $_val) {
51  switch ($_key) {
52  case 'name':
53  case 'class':
54  case 'id':
55  $$_key = (string) $_val;
56  break;
57 
58  case 'options':
59  $options = (array) $_val;
60  break;
61 
62  case 'values':
63  case 'output':
64  $$_key = array_values((array) $_val);
65  break;
66 
67  case 'selected':
68  if (is_array($_val)) {
69  $selected = array();
70  foreach ($_val as $_sel) {
71  if (is_object($_sel)) {
72  if (method_exists($_sel, "__toString")) {
73  $_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
74  } else {
75  trigger_error("html_options: selected attribute contains an object of class '". get_class($_sel) ."' without __toString() method", E_USER_NOTICE);
76  continue;
77  }
78  } else {
79  $_sel = smarty_function_escape_special_chars((string) $_sel);
80  }
81  $selected[$_sel] = true;
82  }
83  } elseif (is_object($_val)) {
84  if (method_exists($_val, "__toString")) {
85  $selected = smarty_function_escape_special_chars((string) $_val->__toString());
86  } else {
87  trigger_error("html_options: selected attribute is an object of class '". get_class($_val) ."' without __toString() method", E_USER_NOTICE);
88  }
89  } else {
90  $selected = smarty_function_escape_special_chars((string) $_val);
91  }
92  break;
93 
94  case 'strict': break;
95 
96  case 'disabled':
97  case 'readonly':
98  if (!empty($params['strict'])) {
99  if (!is_scalar($_val)) {
100  trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE);
101  }
102 
103  if ($_val === true || $_val === $_key) {
104  $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
105  }
106 
107  break;
108  }
109  // omit break; to fall through!
110 
111  default:
112  if (!is_array($_val)) {
113  $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
114  } else {
115  trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
116  }
117  break;
118  }
119  }
120 
121  if (!isset($options) && !isset($values)) {
122  /* raise error here? */
123  return '';
124  }
125 
126  $_html_result = '';
127  $_idx = 0;
128 
129  if (isset($options)) {
130  foreach ($options as $_key => $_val) {
131  $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
132  }
133  } else {
134  foreach ($values as $_i => $_key) {
135  $_val = isset($output[$_i]) ? $output[$_i] : '';
136  $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
137  }
138  }
139 
140  if (!empty($name)) {
141  $_html_class = !empty($class) ? ' class="'.$class.'"' : '';
142  $_html_id = !empty($id) ? ' id="'.$id.'"' : '';
143  $_html_result = '<select class="form-control" name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";
144  }
145 
146  return $_html_result;
147 }
148 
149 function smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, &$idx)
150 {
151  if (!is_array($value)) {
152  $_key = smarty_function_escape_special_chars($key);
153  $_html_result = '<option value="' . $_key . '"';
154  if (is_array($selected)) {
155  if (isset($selected[$_key])) {
156  $_html_result .= ' selected="selected"';
157  }
158  } elseif ($_key === $selected) {
159  $_html_result .= ' selected="selected"';
160  }
161  $_html_class = !empty($class) ? ' class="'.$class.' option"' : '';
162  $_html_id = !empty($id) ? ' id="'.$id.'-'.$idx.'"' : '';
163  if (is_object($value)) {
164  if (method_exists($value, "__toString")) {
165  $value = smarty_function_escape_special_chars((string) $value->__toString());
166  } else {
167  trigger_error("html_options: value is an object of class '". get_class($value) ."' without __toString() method", E_USER_NOTICE);
168  return '';
169  }
170  } else {
171  $value = smarty_function_escape_special_chars((string) $value);
172  }
173  $_html_result .= $_html_class . $_html_id . '>' . $value . '</option>' . "\n";
174  $idx++;
175  } else {
176  $_idx = 0;
177  $_html_result = smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id.'-'.$idx) : null, $class, $_idx);
178  $idx++;
179  }
180  return $_html_result;
181 }
182 
183 function smarty_function_html_options_optgroup($key, $values, $selected, $id, $class, &$idx)
184 {
185  $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";
186  foreach ($values as $key => $value) {
187  $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, $idx);
188  }
189  $optgroup_html .= "</optgroup>\n";
190  return $optgroup_html;
191 }
192 
193 ?>
if($rub=fetch_assoc($rub_query)) if(check_if_module_active('url_rewriting')) $class
Definition: index.php:68
smarty_function_html_options_optgroup($key, $values, $selected, $id, $class, &$idx)
smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, &$idx)
smarty_function_html_options($params, $template)
Smarty {html_options} 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
$id
Definition: articles.php:22

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.