10 * Smarty {html_select_time} function plugin
13 * Name: html_select_time<br>
14 * Purpose: Prints the dropdowns for time selection
15 * @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time}
16 * (Smarty online manual)
20 * @uses smarty_make_timestamp()
22 function smarty_function_html_select_time($params, &$smarty)
24 require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
25 require_once $smarty->_get_plugin_filepath('function','html_options');
29 $display_hours = true;
30 $display_minutes = true;
31 $display_seconds = true;
32 $display_meridian = true;
36 /* Should the select boxes be part of an array when returned from PHP?
37 e.g. setting it to "birthday", would create "birthday[Hour]",
38 "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".
39 Can be combined with prefix. */
45 $meridian_extra = null;
49 $time = smarty_make_timestamp($time);
54 $hours = $use_24_hours ?
range(0, 23) : range(1, 12);
55 $hour_fmt = $use_24_hours ?
'%H' : '%I';
56 for ($i = 0, $for_max = count($hours); $i < $for_max; $i++
)
57 $hours[$i] = sprintf('%02d', $hours[$i]);
58 $html_result .= '<select name=';
59 if (null !== $field_array) {
60 $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
62 $html_result .= '"' . $prefix . 'Hour"';
64 if (null !== $hour_extra){
65 $html_result .= ' ' . $hour_extra;
67 if (null !== $all_extra){
68 $html_result .= ' ' . $all_extra;
70 $html_result .= '>'."\n";
71 $html_result .= smarty_function_html_options(array('output' => $hours,
73 'selected' => strftime($hour_fmt, $time),
74 'print_result' => false),
76 $html_result .= "</select>\n";
79 if ($display_minutes) {
80 $all_minutes = range(0, 59);
81 for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+
= $minute_interval)
82 $minutes[] = sprintf('%02d', $all_minutes[$i]);
83 $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);
84 $html_result .= '<select name=';
85 if (null !== $field_array) {
86 $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
88 $html_result .= '"' . $prefix . 'Minute"';
90 if (null !== $minute_extra){
91 $html_result .= ' ' . $minute_extra;
93 if (null !== $all_extra){
94 $html_result .= ' ' . $all_extra;
96 $html_result .= '>'."\n";
98 $html_result .= smarty_function_html_options(array('output' => $minutes,
100 'selected' => $selected,
101 'print_result' => false),
103 $html_result .= "</select>\n";
106 if ($display_seconds) {
107 $all_seconds = range(0, 59);
108 for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+
= $second_interval)
109 $seconds[] = sprintf('%02d', $all_seconds[$i]);
110 $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);
111 $html_result .= '<select name=';
112 if (null !== $field_array) {
113 $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
115 $html_result .= '"' . $prefix . 'Second"';
118 if (null !== $second_extra){
119 $html_result .= ' ' . $second_extra;
121 if (null !== $all_extra){
122 $html_result .= ' ' . $all_extra;
124 $html_result .= '>'."\n";
126 $html_result .= smarty_function_html_options(array('output' => $seconds,
127 'values' => $seconds,
128 'selected' => $selected,
129 'print_result' => false),
131 $html_result .= "</select>\n";
134 if ($display_meridian && !$use_24_hours) {
135 $html_result .= '<select name=';
136 if (null !== $field_array) {
137 $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
139 $html_result .= '"' . $prefix . 'Meridian"';
142 if (null !== $meridian_extra){
143 $html_result .= ' ' . $meridian_extra;
145 if (null !== $all_extra){
146 $html_result .= ' ' . $all_extra;
148 $html_result .= '>'."\n";
150 $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'),
151 'values' => array('am', 'pm'),
152 'selected' => strtolower(strftime('%p', $time)),
153 'print_result' => false),
155 $html_result .= "</select>\n";
161 /* vim: set expandtab: */
This page took 0.537603 seconds and 4 git commands to generate.