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;
47 foreach ($params as $_key=>$_value) {
56 case 'meridian_extra':
57 $
$_key = (string)$_value;
61 case 'display_minutes':
62 case 'display_seconds':
63 case 'display_meridian':
65 $
$_key = (bool)$_value;
68 case 'minute_interval':
69 case 'second_interval':
70 $
$_key = (int)$_value;
74 $smarty->trigger_error("[html_select_time] unknown parameter $_key", E_USER_WARNING
);
78 $time = smarty_make_timestamp($time);
83 $hours = $use_24_hours ?
range(0, 23) : range(1, 12);
84 $hour_fmt = $use_24_hours ?
'%H' : '%I';
85 for ($i = 0, $for_max = count($hours); $i < $for_max; $i++
)
86 $hours[$i] = sprintf('%02d', $hours[$i]);
87 $html_result .= '<select name=';
88 if (null !== $field_array) {
89 $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
91 $html_result .= '"' . $prefix . 'Hour"';
93 if (null !== $hour_extra){
94 $html_result .= ' ' . $hour_extra;
96 if (null !== $all_extra){
97 $html_result .= ' ' . $all_extra;
99 $html_result .= '>'."\n";
100 $html_result .= smarty_function_html_options(array('output' => $hours,
102 'selected' => strftime($hour_fmt, $time),
103 'print_result' => false),
105 $html_result .= "</select>\n";
108 if ($display_minutes) {
109 $all_minutes = range(0, 59);
110 for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+
= $minute_interval)
111 $minutes[] = sprintf('%02d', $all_minutes[$i]);
112 $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);
113 $html_result .= '<select name=';
114 if (null !== $field_array) {
115 $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
117 $html_result .= '"' . $prefix . 'Minute"';
119 if (null !== $minute_extra){
120 $html_result .= ' ' . $minute_extra;
122 if (null !== $all_extra){
123 $html_result .= ' ' . $all_extra;
125 $html_result .= '>'."\n";
127 $html_result .= smarty_function_html_options(array('output' => $minutes,
128 'values' => $minutes,
129 'selected' => $selected,
130 'print_result' => false),
132 $html_result .= "</select>\n";
135 if ($display_seconds) {
136 $all_seconds = range(0, 59);
137 for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+
= $second_interval)
138 $seconds[] = sprintf('%02d', $all_seconds[$i]);
139 $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);
140 $html_result .= '<select name=';
141 if (null !== $field_array) {
142 $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
144 $html_result .= '"' . $prefix . 'Second"';
147 if (null !== $second_extra){
148 $html_result .= ' ' . $second_extra;
150 if (null !== $all_extra){
151 $html_result .= ' ' . $all_extra;
153 $html_result .= '>'."\n";
155 $html_result .= smarty_function_html_options(array('output' => $seconds,
156 'values' => $seconds,
157 'selected' => $selected,
158 'print_result' => false),
160 $html_result .= "</select>\n";
163 if ($display_meridian && !$use_24_hours) {
164 $html_result .= '<select name=';
165 if (null !== $field_array) {
166 $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
168 $html_result .= '"' . $prefix . 'Meridian"';
171 if (null !== $meridian_extra){
172 $html_result .= ' ' . $meridian_extra;
174 if (null !== $all_extra){
175 $html_result .= ' ' . $all_extra;
177 $html_result .= '>'."\n";
179 $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'),
180 'values' => array('am', 'pm'),
181 'selected' => strtolower(strftime('%p', $time)),
182 'print_result' => false),
184 $html_result .= "</select>\n";
190 /* vim: set expandtab: */