00001 <?php
00022 function smarty_function_html_select_time($params, &$smarty)
00023 {
00024 require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
00025 require_once $smarty->_get_plugin_filepath('function','html_options');
00026
00027 $prefix = "Time_";
00028 $time = time();
00029 $display_hours = true;
00030 $display_minutes = true;
00031 $display_seconds = true;
00032 $display_meridian = true;
00033 $use_24_hours = true;
00034 $minute_interval = 1;
00035 $second_interval = 1;
00036
00037
00038
00039
00040 $field_array = null;
00041 $all_extra = null;
00042 $hour_extra = null;
00043 $minute_extra = null;
00044 $second_extra = null;
00045 $meridian_extra = null;
00046
00047 foreach ($params as $_key=>$_value) {
00048 switch ($_key) {
00049 case 'prefix':
00050 case 'time':
00051 case 'field_array':
00052 case 'all_extra':
00053 case 'hour_extra':
00054 case 'minute_extra':
00055 case 'second_extra':
00056 case 'meridian_extra':
00057 $$_key = (string)$_value;
00058 break;
00059
00060 case 'display_hours':
00061 case 'display_minutes':
00062 case 'display_seconds':
00063 case 'display_meridian':
00064 case 'use_24_hours':
00065 $$_key = (bool)$_value;
00066 break;
00067
00068 case 'minute_interval':
00069 case 'second_interval':
00070 $$_key = (int)$_value;
00071 break;
00072
00073 default:
00074 $smarty->trigger_error("[html_select_time] unknown parameter $_key", E_USER_WARNING);
00075 }
00076 }
00077
00078 $time = smarty_make_timestamp($time);
00079
00080 $html_result = '';
00081
00082 if ($display_hours) {
00083 $hours = $use_24_hours ? range(0, 23) : range(1, 12);
00084 $hour_fmt = $use_24_hours ? '%H' : '%I';
00085 for ($i = 0, $for_max = count($hours); $i < $for_max; $i++)
00086 $hours[$i] = sprintf('%02d', $hours[$i]);
00087 $html_result .= '<select name=';
00088 if (null !== $field_array) {
00089 $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
00090 } else {
00091 $html_result .= '"' . $prefix . 'Hour"';
00092 }
00093 if (null !== $hour_extra){
00094 $html_result .= ' ' . $hour_extra;
00095 }
00096 if (null !== $all_extra){
00097 $html_result .= ' ' . $all_extra;
00098 }
00099 $html_result .= '>'."\n";
00100 $html_result .= smarty_function_html_options(array('output' => $hours,
00101 'values' => $hours,
00102 'selected' => strftime($hour_fmt, $time),
00103 'print_result' => false),
00104 $smarty);
00105 $html_result .= "</select>\n";
00106 }
00107
00108 if ($display_minutes) {
00109 $all_minutes = range(0, 59);
00110 for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+= $minute_interval)
00111 $minutes[] = sprintf('%02d', $all_minutes[$i]);
00112 $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);
00113 $html_result .= '<select name=';
00114 if (null !== $field_array) {
00115 $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
00116 } else {
00117 $html_result .= '"' . $prefix . 'Minute"';
00118 }
00119 if (null !== $minute_extra){
00120 $html_result .= ' ' . $minute_extra;
00121 }
00122 if (null !== $all_extra){
00123 $html_result .= ' ' . $all_extra;
00124 }
00125 $html_result .= '>'."\n";
00126
00127 $html_result .= smarty_function_html_options(array('output' => $minutes,
00128 'values' => $minutes,
00129 'selected' => $selected,
00130 'print_result' => false),
00131 $smarty);
00132 $html_result .= "</select>\n";
00133 }
00134
00135 if ($display_seconds) {
00136 $all_seconds = range(0, 59);
00137 for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+= $second_interval)
00138 $seconds[] = sprintf('%02d', $all_seconds[$i]);
00139 $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);
00140 $html_result .= '<select name=';
00141 if (null !== $field_array) {
00142 $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
00143 } else {
00144 $html_result .= '"' . $prefix . 'Second"';
00145 }
00146
00147 if (null !== $second_extra){
00148 $html_result .= ' ' . $second_extra;
00149 }
00150 if (null !== $all_extra){
00151 $html_result .= ' ' . $all_extra;
00152 }
00153 $html_result .= '>'."\n";
00154
00155 $html_result .= smarty_function_html_options(array('output' => $seconds,
00156 'values' => $seconds,
00157 'selected' => $selected,
00158 'print_result' => false),
00159 $smarty);
00160 $html_result .= "</select>\n";
00161 }
00162
00163 if ($display_meridian && !$use_24_hours) {
00164 $html_result .= '<select name=';
00165 if (null !== $field_array) {
00166 $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
00167 } else {
00168 $html_result .= '"' . $prefix . 'Meridian"';
00169 }
00170
00171 if (null !== $meridian_extra){
00172 $html_result .= ' ' . $meridian_extra;
00173 }
00174 if (null !== $all_extra){
00175 $html_result .= ' ' . $all_extra;
00176 }
00177 $html_result .= '>'."\n";
00178
00179 $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'),
00180 'values' => array('am', 'pm'),
00181 'selected' => strtolower(strftime('%p', $time)),
00182 'print_result' => false),
00183 $smarty);
00184 $html_result .= "</select>\n";
00185 }
00186
00187 return $html_result;
00188 }
00189
00190
00191
00192 ?>