1 |
cvsjoko |
1.1 |
<?php |
2 |
|
|
|
3 |
|
|
/* |
4 |
|
|
* Smarty plugin |
5 |
|
|
* ------------------------------------------------------------- |
6 |
|
|
* Type: function |
7 |
|
|
* Name: html_select_time |
8 |
|
|
* Purpose: Prints the dropdowns for time selection |
9 |
|
|
* ------------------------------------------------------------- |
10 |
|
|
*/ |
11 |
|
|
require_once $this->_get_plugin_filepath('shared','make_timestamp'); |
12 |
|
|
require_once $this->_get_plugin_filepath('function','html_options'); |
13 |
|
|
function smarty_function_html_select_time($params, &$smarty) |
14 |
|
|
{ |
15 |
|
|
/* Default values. */ |
16 |
|
|
$prefix = "Time_"; |
17 |
|
|
$time = time(); |
18 |
|
|
$display_hours = true; |
19 |
|
|
$display_minutes = true; |
20 |
|
|
$display_seconds = true; |
21 |
|
|
$display_meridian = true; |
22 |
|
|
$use_24_hours = true; |
23 |
|
|
$minute_interval = 1; |
24 |
|
|
$second_interval = 1; |
25 |
|
|
/* Should the select boxes be part of an array when returned from PHP? |
26 |
|
|
e.g. setting it to "birthday", would create "birthday[Hour]", |
27 |
|
|
"birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]". |
28 |
|
|
Can be combined with prefix. */ |
29 |
|
|
$field_array = null; |
30 |
|
|
$all_extra = null; |
31 |
|
|
$hour_extra = null; |
32 |
|
|
$minute_extra = null; |
33 |
|
|
$second_extra = null; |
34 |
|
|
$meridian_extra = null; |
35 |
|
|
|
36 |
|
|
extract($params); |
37 |
|
|
|
38 |
|
|
$time = smarty_make_timestamp($time); |
39 |
|
|
|
40 |
|
|
$html_result = ''; |
41 |
|
|
|
42 |
|
|
if ($display_hours) { |
43 |
|
|
$hours = $use_24_hours ? range(0, 23) : range(1, 12); |
44 |
|
|
$hour_fmt = $use_24_hours ? '%H' : '%I'; |
45 |
|
|
for ($i = 0, $for_max = count($hours); $i < $for_max; $i++) |
46 |
|
|
$hours[$i] = sprintf('%02d', $hours[$i]); |
47 |
|
|
$html_result .= '<select name='; |
48 |
|
|
if (null !== $field_array) { |
49 |
|
|
$html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"'; |
50 |
|
|
} else { |
51 |
|
|
$html_result .= '"' . $prefix . 'Hour"'; |
52 |
|
|
} |
53 |
|
|
if (null !== $hour_extra){ |
54 |
|
|
$html_result .= ' ' . $hour_extra; |
55 |
|
|
} |
56 |
|
|
if (null !== $all_extra){ |
57 |
|
|
$html_result .= ' ' . $all_extra; |
58 |
|
|
} |
59 |
|
|
$html_result .= '>'."\n"; |
60 |
|
|
$html_result .= smarty_function_html_options(array('output' => $hours, |
61 |
|
|
'values' => $hours, |
62 |
|
|
'selected' => strftime($hour_fmt, $time), |
63 |
|
|
'print_result' => false), |
64 |
|
|
$smarty); |
65 |
|
|
$html_result .= "</select>\n"; |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
if ($display_minutes) { |
69 |
|
|
$all_minutes = range(0, 59); |
70 |
|
|
for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+= $minute_interval) |
71 |
|
|
$minutes[] = sprintf('%02d', $all_minutes[$i]); |
72 |
|
|
$selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval); |
73 |
|
|
$html_result .= '<select name='; |
74 |
|
|
if (null !== $field_array) { |
75 |
|
|
$html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"'; |
76 |
|
|
} else { |
77 |
|
|
$html_result .= '"' . $prefix . 'Minute"'; |
78 |
|
|
} |
79 |
|
|
if (null !== $minute_extra){ |
80 |
|
|
$html_result .= ' ' . $minute_extra; |
81 |
|
|
} |
82 |
|
|
if (null !== $all_extra){ |
83 |
|
|
$html_result .= ' ' . $all_extra; |
84 |
|
|
} |
85 |
|
|
$html_result .= '>'."\n"; |
86 |
|
|
|
87 |
|
|
$html_result .= smarty_function_html_options(array('output' => $minutes, |
88 |
|
|
'values' => $minutes, |
89 |
|
|
'selected' => $selected, |
90 |
|
|
'print_result' => false), |
91 |
|
|
$smarty); |
92 |
|
|
$html_result .= "</select>\n"; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
if ($display_seconds) { |
96 |
|
|
$all_seconds = range(0, 59); |
97 |
|
|
for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+= $second_interval) |
98 |
|
|
$seconds[] = sprintf('%02d', $all_seconds[$i]); |
99 |
|
|
$selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval); |
100 |
|
|
$html_result .= '<select name='; |
101 |
|
|
if (null !== $field_array) { |
102 |
|
|
$html_result .= '"' . $field_array . '[' . $prefix . 'Second]"'; |
103 |
|
|
} else { |
104 |
|
|
$html_result .= '"' . $prefix . 'Second"'; |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
if (null !== $second_extra){ |
108 |
|
|
$html_result .= ' ' . $second_extra; |
109 |
|
|
} |
110 |
|
|
if (null !== $all_extra){ |
111 |
|
|
$html_result .= ' ' . $all_extra; |
112 |
|
|
} |
113 |
|
|
$html_result .= '>'."\n"; |
114 |
|
|
|
115 |
|
|
$html_result .= smarty_function_html_options(array('output' => $seconds, |
116 |
|
|
'values' => $seconds, |
117 |
|
|
'selected' => $selected, |
118 |
|
|
'print_result' => false), |
119 |
|
|
$smarty); |
120 |
|
|
$html_result .= "</select>\n"; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
if ($display_meridian && !$use_24_hours) { |
124 |
|
|
$html_result .= '<select name='; |
125 |
|
|
if (null !== $field_array) { |
126 |
|
|
$html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"'; |
127 |
|
|
} else { |
128 |
|
|
$html_result .= '"' . $prefix . 'Meridian"'; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
if (null !== $meridian_extra){ |
132 |
|
|
$html_result .= ' ' . $meridian_extra; |
133 |
|
|
} |
134 |
|
|
if (null !== $all_extra){ |
135 |
|
|
$html_result .= ' ' . $all_extra; |
136 |
|
|
} |
137 |
|
|
$html_result .= '>'."\n"; |
138 |
|
|
|
139 |
|
|
$html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'), |
140 |
|
|
'values' => array('am', 'pm'), |
141 |
|
|
'selected' => strtolower(strftime('%p', $time)), |
142 |
|
|
'print_result' => false), |
143 |
|
|
$smarty); |
144 |
|
|
$html_result .= "</select>\n"; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
print $html_result; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
/* vim: set expandtab: */ |
151 |
|
|
|
152 |
|
|
?> |