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