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