changed git call from https to git readonly
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / plugins / function.html_select_time.php
1 <?php\r
2 /**\r
3  * Smarty plugin\r
4  * @package Smarty\r
5  * @subpackage plugins\r
6  */\r
7 \r
8 \r
9 /**\r
10  * Smarty {html_select_time} function plugin\r
11  *\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
17  * @param array\r
18  * @param Smarty\r
19  * @return string\r
20  * @uses smarty_make_timestamp()\r
21  */\r
22 function smarty_function_html_select_time($params, &$smarty)\r
23 {\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
27     $prefix             = "Time_";\r
28     $time               = time();\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
41     $all_extra          = null;\r
42     $hour_extra         = null;\r
43     $minute_extra       = null;\r
44     $second_extra       = null;\r
45     $meridian_extra     = null;\r
46 \r
47     extract($params);\r
48 \r
49     $time = smarty_make_timestamp($time);\r
50 \r
51     $html_result = '';\r
52 \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
61         } else {\r
62             $html_result .= '"' . $prefix . 'Hour"';\r
63         }\r
64         if (null !== $hour_extra){\r
65             $html_result .= ' ' . $hour_extra;\r
66         }\r
67         if (null !== $all_extra){\r
68             $html_result .= ' ' . $all_extra;\r
69         }\r
70         $html_result .= '>'."\n";\r
71         $html_result .= smarty_function_html_options(array('output'          => $hours,\r
72                                                            'values'          => $hours,\r
73                                                            'selected'      => strftime($hour_fmt, $time),\r
74                                                            'print_result' => false),\r
75                                                      $smarty);\r
76         $html_result .= "</select>\n";\r
77     }\r
78 \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
87         } else {\r
88             $html_result .= '"' . $prefix . 'Minute"';\r
89         }\r
90         if (null !== $minute_extra){\r
91             $html_result .= ' ' . $minute_extra;\r
92         }\r
93         if (null !== $all_extra){\r
94             $html_result .= ' ' . $all_extra;\r
95         }\r
96         $html_result .= '>'."\n";\r
97         \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
102                                                      $smarty);\r
103         $html_result .= "</select>\n";\r
104     }\r
105 \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
114         } else {\r
115             $html_result .= '"' . $prefix . 'Second"';\r
116         }\r
117         \r
118         if (null !== $second_extra){\r
119             $html_result .= ' ' . $second_extra;\r
120         }\r
121         if (null !== $all_extra){\r
122             $html_result .= ' ' . $all_extra;\r
123         }\r
124         $html_result .= '>'."\n";\r
125         \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
130                                                      $smarty);\r
131         $html_result .= "</select>\n";\r
132     }\r
133 \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
138         } else {\r
139             $html_result .= '"' . $prefix . 'Meridian"';\r
140         }\r
141         \r
142         if (null !== $meridian_extra){\r
143             $html_result .= ' ' . $meridian_extra;\r
144         }\r
145         if (null !== $all_extra){\r
146             $html_result .= ' ' . $all_extra;\r
147         }\r
148         $html_result .= '>'."\n";\r
149         \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
154                                                      $smarty);\r
155         $html_result .= "</select>\n";\r
156     }\r
157 \r
158     return $html_result;\r
159 }\r
160 \r
161 /* vim: set expandtab: */\r
162 \r
163 ?>\r