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)
17 * @author Roberto Berto <roberto@berto.net>
18 * @credits Monte Ohrt <monte AT ohrt DOT com>
22 * @uses smarty_make_timestamp()
24 function smarty_function_html_select_time($params, &$smarty)
26 require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
27 require_once $smarty->_get_plugin_filepath('function','html_options');
31 $display_hours = true;
32 $display_minutes = true;
33 $display_seconds = true;
34 $display_meridian = true;
38 /* Should the select boxes be part of an array when returned from PHP?
39 e.g. setting it to "birthday", would create "birthday[Hour]",
40 "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".
41 Can be combined with prefix. */
47 $meridian_extra = null;
49 foreach ($params as $_key=>$_value) {
58 case 'meridian_extra':
59 $
$_key = (string)$_value;
63 case 'display_minutes':
64 case 'display_seconds':
65 case 'display_meridian':
67 $
$_key = (bool)$_value;
70 case 'minute_interval':
71 case 'second_interval':
72 $
$_key = (int)$_value;
76 $smarty->trigger_error("[html_select_time] unknown parameter $_key", E_USER_WARNING
);
80 $time = smarty_make_timestamp($time);
85 $hours = $use_24_hours ?
range(0, 23) : range(1, 12);
86 $hour_fmt = $use_24_hours ?
'%H' : '%I';
87 for ($i = 0, $for_max = count($hours); $i < $for_max; $i++
)
88 $hours[$i] = sprintf('%02d', $hours[$i]);
89 $html_result .= '<select name=';
90 if (null !== $field_array) {
91 $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
93 $html_result .= '"' . $prefix . 'Hour"';
95 if (null !== $hour_extra){
96 $html_result .= ' ' . $hour_extra;
98 if (null !== $all_extra){
99 $html_result .= ' ' . $all_extra;
101 $html_result .= '>'."\n";
102 $html_result .= smarty_function_html_options(array('output' => $hours,
104 'selected' => strftime($hour_fmt, $time),
105 'print_result' => false),
107 $html_result .= "</select>\n";
110 if ($display_minutes) {
111 $all_minutes = range(0, 59);
112 for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+
= $minute_interval)
113 $minutes[] = sprintf('%02d', $all_minutes[$i]);
114 $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);
115 $html_result .= '<select name=';
116 if (null !== $field_array) {
117 $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
119 $html_result .= '"' . $prefix . 'Minute"';
121 if (null !== $minute_extra){
122 $html_result .= ' ' . $minute_extra;
124 if (null !== $all_extra){
125 $html_result .= ' ' . $all_extra;
127 $html_result .= '>'."\n";
129 $html_result .= smarty_function_html_options(array('output' => $minutes,
130 'values' => $minutes,
131 'selected' => $selected,
132 'print_result' => false),
134 $html_result .= "</select>\n";
137 if ($display_seconds) {
138 $all_seconds = range(0, 59);
139 for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+
= $second_interval)
140 $seconds[] = sprintf('%02d', $all_seconds[$i]);
141 $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);
142 $html_result .= '<select name=';
143 if (null !== $field_array) {
144 $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
146 $html_result .= '"' . $prefix . 'Second"';
149 if (null !== $second_extra){
150 $html_result .= ' ' . $second_extra;
152 if (null !== $all_extra){
153 $html_result .= ' ' . $all_extra;
155 $html_result .= '>'."\n";
157 $html_result .= smarty_function_html_options(array('output' => $seconds,
158 'values' => $seconds,
159 'selected' => $selected,
160 'print_result' => false),
162 $html_result .= "</select>\n";
165 if ($display_meridian && !$use_24_hours) {
166 $html_result .= '<select name=';
167 if (null !== $field_array) {
168 $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
170 $html_result .= '"' . $prefix . 'Meridian"';
173 if (null !== $meridian_extra){
174 $html_result .= ' ' . $meridian_extra;
176 if (null !== $all_extra){
177 $html_result .= ' ' . $all_extra;
179 $html_result .= '>'."\n";
181 $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'),
182 'values' => array('am', 'pm'),
183 'selected' => strtolower(strftime('%p', $time)),
184 'print_result' => false),
186 $html_result .= "</select>\n";
192 /* vim: set expandtab: */
This page took 1.726441 seconds and 4 git commands to generate.