PEEL Shopping
Open source ecommerce : PEEL Shopping
function.html_select_time.php
Go to the documentation of this file.
1 <?php
12 require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
16 require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
17 
34 function smarty_function_html_select_time($params, $template)
35 {
36  $prefix = "Time_";
37  $field_array = null;
38  $field_separator = "\n";
39  $option_separator = "\n";
40  $time = null;
41 
42  $display_hours = true;
43  $display_minutes = true;
44  $display_seconds = true;
45  $display_meridian = true;
46 
47  $hour_format = '%02d';
48  $hour_value_format = '%02d';
49  $minute_format = '%02d';
50  $minute_value_format = '%02d';
51  $second_format = '%02d';
52  $second_value_format = '%02d';
53 
54  $hour_size = null;
55  $minute_size = null;
56  $second_size = null;
57  $meridian_size = null;
58 
59  $all_empty = null;
60  $hour_empty = null;
61  $minute_empty = null;
62  $second_empty = null;
63  $meridian_empty = null;
64 
65  $all_id = null;
66  $hour_id = null;
67  $minute_id = null;
68  $second_id = null;
69  $meridian_id = null;
70 
71  $use_24_hours = true;
72  $minute_interval = 1;
73  $second_interval = 1;
74 
75  $extra_attrs = '';
76  $all_extra = null;
77  $hour_extra = null;
78  $minute_extra = null;
79  $second_extra = null;
80  $meridian_extra = null;
81 
82  foreach ($params as $_key => $_value) {
83  switch ($_key) {
84  case 'time':
85  if (!is_array($_value) && $_value !== null) {
86  $time = smarty_make_timestamp($_value);
87  }
88  break;
89 
90  case 'prefix':
91  case 'field_array':
92 
93  case 'field_separator':
94  case 'option_separator':
95 
96  case 'all_extra':
97  case 'hour_extra':
98  case 'minute_extra':
99  case 'second_extra':
100  case 'meridian_extra':
101 
102  case 'all_empty':
103  case 'hour_empty':
104  case 'minute_empty':
105  case 'second_empty':
106  case 'meridian_empty':
107 
108  case 'all_id':
109  case 'hour_id':
110  case 'minute_id':
111  case 'second_id':
112  case 'meridian_id':
113 
114  case 'hour_format':
115  case 'hour_value_format':
116  case 'minute_format':
117  case 'minute_value_format':
118  case 'second_format':
119  case 'second_value_format':
120  $$_key = (string)$_value;
121  break;
122 
123  case 'display_hours':
124  case 'display_minutes':
125  case 'display_seconds':
126  case 'display_meridian':
127  case 'use_24_hours':
128  $$_key = (bool)$_value;
129  break;
130 
131  case 'minute_interval':
132  case 'second_interval':
133 
134  case 'hour_size':
135  case 'minute_size':
136  case 'second_size':
137  case 'meridian_size':
138  $$_key = (int)$_value;
139  break;
140 
141  default:
142  if (!is_array($_value)) {
143  $extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"';
144  } else {
145  trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
146  }
147  break;
148  }
149  }
150 
151  if (isset($params['time']) && is_array($params['time'])) {
152  if (isset($params['time'][$prefix . 'Hour'])) {
153  // $_REQUEST[$field_array] given
154  foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) {
155  $_variableName = '_' . strtolower($_elementName);
156  $$_variableName = isset($params['time'][$prefix . $_elementName])
157  ? $params['time'][$prefix . $_elementName]
158  : date($_elementKey);
159  }
160  $_meridian = isset($params['time'][$prefix . 'Meridian'])
161  ? (' ' . $params['time'][$prefix . 'Meridian'])
162  : '';
163  $time = strtotime( $_hour . ':' . $_minute . ':' . $_second . $_meridian );
164  list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
165  } elseif (isset($params['time'][$field_array][$prefix . 'Hour'])) {
166  // $_REQUEST given
167  foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) {
168  $_variableName = '_' . strtolower($_elementName);
169  $$_variableName = isset($params['time'][$field_array][$prefix . $_elementName])
170  ? $params['time'][$field_array][$prefix . $_elementName]
171  : date($_elementKey);
172  }
173  $_meridian = isset($params['time'][$field_array][$prefix . 'Meridian'])
174  ? (' ' . $params['time'][$field_array][$prefix . 'Meridian'])
175  : '';
176  $time = strtotime( $_hour . ':' . $_minute . ':' . $_second . $_meridian );
177  list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
178  } else {
179  // no date found, use NOW
180  list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d'));
181  }
182  } elseif ($time === null) {
183  if (array_key_exists('time', $params)) {
184  $_hour = $_minute = $_second = $time = null;
185  } else {
186  list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s'));
187  }
188  } else {
189  list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
190  }
191 
192  // generate hour <select>
193  if ($display_hours) {
194  $_html_hours = '';
195  $_extra = '';
196  $_name = $field_array ? ($field_array . '[' . $prefix . 'Hour]') : ($prefix . 'Hour');
197  if ($all_extra) {
198  $_extra .= ' ' . $all_extra;
199  }
200  if ($hour_extra) {
201  $_extra .= ' ' . $hour_extra;
202  }
203 
204  $_html_hours = '<select name="' . $_name . '"';
205  if ($hour_id !== null || $all_id !== null) {
206  $_html_hours .= ' id="' . smarty_function_escape_special_chars(
207  $hour_id !== null ? ( $hour_id ? $hour_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name )
208  ) . '"';
209  }
210  if ($hour_size) {
211  $_html_hours .= ' size="' . $hour_size . '"';
212  }
213  $_html_hours .= $_extra . $extra_attrs . '>' . $option_separator;
214 
215  if (isset($hour_empty) || isset($all_empty)) {
216  $_html_hours .= '<option value="">' . ( isset($hour_empty) ? $hour_empty : $all_empty ) . '</option>' . $option_separator;
217  }
218 
219  $start = $use_24_hours ? 0 : 1;
220  $end = $use_24_hours ? 23 : 12;
221  for ($i=$start; $i <= $end; $i++) {
222  $_val = sprintf('%02d', $i);
223  $_text = $hour_format == '%02d' ? $_val : sprintf($hour_format, $i);
224  $_value = $hour_value_format == '%02d' ? $_val : sprintf($hour_value_format, $i);
225 
226  if (!$use_24_hours) {
227  $_hour12 = $_hour == 0
228  ? 12
229  : ($_hour <= 12 ? $_hour : $_hour -12);
230  }
231 
232  $selected = $_hour !== null ? ($use_24_hours ? $_hour == $_val : $_hour12 == $_val) : null;
233  $_html_hours .= '<option value="' . $_value . '"'
234  . ($selected ? ' selected="selected"' : '')
235  . '>' . $_text . '</option>' . $option_separator;
236  }
237 
238  $_html_hours .= '</select>';
239  }
240 
241  // generate minute <select>
242  if ($display_minutes) {
243  $_html_minutes = '';
244  $_extra = '';
245  $_name = $field_array ? ($field_array . '[' . $prefix . 'Minute]') : ($prefix . 'Minute');
246  if ($all_extra) {
247  $_extra .= ' ' . $all_extra;
248  }
249  if ($minute_extra) {
250  $_extra .= ' ' . $minute_extra;
251  }
252 
253  $_html_minutes = '<select name="' . $_name . '"';
254  if ($minute_id !== null || $all_id !== null) {
255  $_html_minutes .= ' id="' . smarty_function_escape_special_chars(
256  $minute_id !== null ? ( $minute_id ? $minute_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name )
257  ) . '"';
258  }
259  if ($minute_size) {
260  $_html_minutes .= ' size="' . $minute_size . '"';
261  }
262  $_html_minutes .= $_extra . $extra_attrs . '>' . $option_separator;
263 
264  if (isset($minute_empty) || isset($all_empty)) {
265  $_html_minutes .= '<option value="">' . ( isset($minute_empty) ? $minute_empty : $all_empty ) . '</option>' . $option_separator;
266  }
267 
268  $selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null;
269  for ($i=0; $i <= 59; $i += $minute_interval) {
270  $_val = sprintf('%02d', $i);
271  $_text = $minute_format == '%02d' ? $_val : sprintf($minute_format, $i);
272  $_value = $minute_value_format == '%02d' ? $_val : sprintf($minute_value_format, $i);
273  $_html_minutes .= '<option value="' . $_value . '"'
274  . ($selected === $i ? ' selected="selected"' : '')
275  . '>' . $_text . '</option>' . $option_separator;
276  }
277 
278  $_html_minutes .= '</select>';
279  }
280 
281  // generate second <select>
282  if ($display_seconds) {
283  $_html_seconds = '';
284  $_extra = '';
285  $_name = $field_array ? ($field_array . '[' . $prefix . 'Second]') : ($prefix . 'Second');
286  if ($all_extra) {
287  $_extra .= ' ' . $all_extra;
288  }
289  if ($second_extra) {
290  $_extra .= ' ' . $second_extra;
291  }
292 
293  $_html_seconds = '<select name="' . $_name . '"';
294  if ($second_id !== null || $all_id !== null) {
295  $_html_seconds .= ' id="' . smarty_function_escape_special_chars(
296  $second_id !== null ? ( $second_id ? $second_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name )
297  ) . '"';
298  }
299  if ($second_size) {
300  $_html_seconds .= ' size="' . $second_size . '"';
301  }
302  $_html_seconds .= $_extra . $extra_attrs . '>' . $option_separator;
303 
304  if (isset($second_empty) || isset($all_empty)) {
305  $_html_seconds .= '<option value="">' . ( isset($second_empty) ? $second_empty : $all_empty ) . '</option>' . $option_separator;
306  }
307 
308  $selected = $_second !== null ? ($_second - $_second % $second_interval) : null;
309  for ($i=0; $i <= 59; $i += $second_interval) {
310  $_val = sprintf('%02d', $i);
311  $_text = $second_format == '%02d' ? $_val : sprintf($second_format, $i);
312  $_value = $second_value_format == '%02d' ? $_val : sprintf($second_value_format, $i);
313  $_html_seconds .= '<option value="' . $_value . '"'
314  . ($selected === $i ? ' selected="selected"' : '')
315  . '>' . $_text . '</option>' . $option_separator;
316  }
317 
318  $_html_seconds .= '</select>';
319  }
320 
321  // generate meridian <select>
322  if ($display_meridian && !$use_24_hours) {
323  $_html_meridian = '';
324  $_extra = '';
325  $_name = $field_array ? ($field_array . '[' . $prefix . 'Meridian]') : ($prefix . 'Meridian');
326  if ($all_extra) {
327  $_extra .= ' ' . $all_extra;
328  }
329  if ($meridian_extra) {
330  $_extra .= ' ' . $meridian_extra;
331  }
332 
333  $_html_meridian = '<select name="' . $_name . '"';
334  if ($meridian_id !== null || $all_id !== null) {
335  $_html_meridian .= ' id="' . smarty_function_escape_special_chars(
336  $meridian_id !== null ? ( $meridian_id ? $meridian_id : $_name ) : ( $all_id ? ($all_id . $_name) : $_name )
337  ) . '"';
338  }
339  if ($meridian_size) {
340  $_html_meridian .= ' size="' . $meridian_size . '"';
341  }
342  $_html_meridian .= $_extra . $extra_attrs . '>' . $option_separator;
343 
344  if (isset($meridian_empty) || isset($all_empty)) {
345  $_html_meridian .= '<option value="">' . ( isset($meridian_empty) ? $meridian_empty : $all_empty ) . '</option>' . $option_separator;
346  }
347 
348  $_html_meridian .= '<option value="am"'. ($_hour < 12 ? ' selected="selected"' : '') .'>AM</option>' . $option_separator
349  . '<option value="pm"'. ($_hour < 12 ? '' : ' selected="selected"') .'>PM</option>' . $option_separator
350  . '</select>';
351  }
352 
353  $_html = '';
354  foreach (array('_html_hours', '_html_minutes', '_html_seconds', '_html_meridian') as $k) {
355  if (isset($$k)) {
356  if ($_html) {
357  $_html .= $field_separator;
358  }
359  $_html .= $$k;
360  }
361  }
362 
363  return $_html;
364 }
365 
366 ?>
$start
Definition: attributs.php:22
smarty_make_timestamp($string)
Function: smarty_make_timestamp Purpose: used by other smarty functions to make a timestamp from a s...
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
smarty_function_html_select_time($params, $template)

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.