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