]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Smarty/plugins/function.html_select_time.php
Release 6.5.0
[Github/sugarcrm.git] / include / Smarty / plugins / function.html_select_time.php
1 <?php
2
3 /*
4
5 Modification information for LGPL compliance
6
7 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
8
9 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
10
11 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
12
13 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3  tags and updated the build system 
14
15 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
16
17 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
18
19 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
20
21 r10971 - 2006-01-12 14:58:30 -0800 (Thu, 12 Jan 2006) - chris - Bug 4128: updating Smarty templates to 2.6.11, a version supposedly that plays better with PHP 5.1
22
23 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
24
25
26 */
27
28
29 /**
30  * Smarty plugin
31  * @package Smarty
32  * @subpackage plugins
33  */
34
35
36 /**
37  * Smarty {html_select_time} function plugin
38  *
39  * Type:     function<br>
40  * Name:     html_select_time<br>
41  * Purpose:  Prints the dropdowns for time selection
42  * @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time}
43  *          (Smarty online manual)
44  * @author Roberto Berto <roberto@berto.net>
45  * @credits Monte Ohrt <monte AT ohrt DOT com>
46  * @param array
47  * @param Smarty
48  * @return string
49  * @uses smarty_make_timestamp()
50  */
51 function smarty_function_html_select_time($params, &$smarty)
52 {
53     require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
54     require_once $smarty->_get_plugin_filepath('function','html_options');
55     /* Default values. */
56     $prefix             = "Time_";
57     $time               = time();
58     $display_hours      = true;
59     $display_minutes    = true;
60     $display_seconds    = true;
61     $display_meridian   = true;
62     $use_24_hours       = true;
63     $minute_interval    = 1;
64     $second_interval    = 1;
65     /* Should the select boxes be part of an array when returned from PHP?
66        e.g. setting it to "birthday", would create "birthday[Hour]",
67        "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".
68        Can be combined with prefix. */
69     $field_array        = null;
70     $all_extra          = null;
71     $hour_extra         = null;
72     $minute_extra       = null;
73     $second_extra       = null;
74     $meridian_extra     = null;
75
76     foreach ($params as $_key=>$_value) {
77         switch ($_key) {
78             case 'prefix':
79             case 'time':
80             case 'field_array':
81             case 'all_extra':
82             case 'hour_extra':
83             case 'minute_extra':
84             case 'second_extra':
85             case 'meridian_extra':
86                 $$_key = (string)$_value;
87                 break;
88
89             case 'display_hours':
90             case 'display_minutes':
91             case 'display_seconds':
92             case 'display_meridian':
93             case 'use_24_hours':
94                 $$_key = (bool)$_value;
95                 break;
96
97             case 'minute_interval':
98             case 'second_interval':
99                 $$_key = (int)$_value;
100                 break;
101
102             default:
103                 $smarty->trigger_error("[html_select_time] unknown parameter $_key", E_USER_WARNING);
104         }
105     }
106
107     $time = smarty_make_timestamp($time);
108
109     $html_result = '';
110
111     if ($display_hours) {
112         $hours       = $use_24_hours ? range(0, 23) : range(1, 12);
113         $hour_fmt = $use_24_hours ? '%H' : '%I';
114         for ($i = 0, $for_max = count($hours); $i < $for_max; $i++)
115             $hours[$i] = sprintf('%02d', $hours[$i]);
116         $html_result .= '<select name=';
117         if (null !== $field_array) {
118             $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
119         } else {
120             $html_result .= '"' . $prefix . 'Hour"';
121         }
122         if (null !== $hour_extra){
123             $html_result .= ' ' . $hour_extra;
124         }
125         if (null !== $all_extra){
126             $html_result .= ' ' . $all_extra;
127         }
128         $html_result .= '>'."\n";
129         $html_result .= smarty_function_html_options(array('output'          => $hours,
130                                                            'values'          => $hours,
131                                                            'selected'      => strftime($hour_fmt, $time),
132                                                            'print_result' => false),
133                                                      $smarty);
134         $html_result .= "</select>\n";
135     }
136
137     if ($display_minutes) {
138         $all_minutes = range(0, 59);
139         for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+= $minute_interval)
140             $minutes[] = sprintf('%02d', $all_minutes[$i]);
141         $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);
142         $html_result .= '<select name=';
143         if (null !== $field_array) {
144             $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
145         } else {
146             $html_result .= '"' . $prefix . 'Minute"';
147         }
148         if (null !== $minute_extra){
149             $html_result .= ' ' . $minute_extra;
150         }
151         if (null !== $all_extra){
152             $html_result .= ' ' . $all_extra;
153         }
154         $html_result .= '>'."\n";
155         
156         $html_result .= smarty_function_html_options(array('output'          => $minutes,
157                                                            'values'          => $minutes,
158                                                            'selected'      => $selected,
159                                                            'print_result' => false),
160                                                      $smarty);
161         $html_result .= "</select>\n";
162     }
163
164     if ($display_seconds) {
165         $all_seconds = range(0, 59);
166         for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+= $second_interval)
167             $seconds[] = sprintf('%02d', $all_seconds[$i]);
168         $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);
169         $html_result .= '<select name=';
170         if (null !== $field_array) {
171             $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
172         } else {
173             $html_result .= '"' . $prefix . 'Second"';
174         }
175         
176         if (null !== $second_extra){
177             $html_result .= ' ' . $second_extra;
178         }
179         if (null !== $all_extra){
180             $html_result .= ' ' . $all_extra;
181         }
182         $html_result .= '>'."\n";
183         
184         $html_result .= smarty_function_html_options(array('output'          => $seconds,
185                                                            'values'          => $seconds,
186                                                            'selected'      => $selected,
187                                                            'print_result' => false),
188                                                      $smarty);
189         $html_result .= "</select>\n";
190     }
191
192     if ($display_meridian && !$use_24_hours) {
193         $html_result .= '<select name=';
194         if (null !== $field_array) {
195             $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
196         } else {
197             $html_result .= '"' . $prefix . 'Meridian"';
198         }
199         
200         if (null !== $meridian_extra){
201             $html_result .= ' ' . $meridian_extra;
202         }
203         if (null !== $all_extra){
204             $html_result .= ' ' . $all_extra;
205         }
206         $html_result .= '>'."\n";
207         
208         $html_result .= smarty_function_html_options(array('output'          => array('AM', 'PM'),
209                                                            'values'          => array('am', 'pm'),
210                                                            'selected'      => strtolower(strftime('%p', $time)),
211                                                            'print_result' => false),
212                                                      $smarty);
213         $html_result .= "</select>\n";
214     }
215
216     return $html_result;
217 }
218
219 /* vim: set expandtab: */
220
221 ?>