X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2Fsmarty%2Fplugins%2Ffunction.html_select_time.php;fp=WEB-INF%2Flib%2Fsmarty%2Fplugins%2Ffunction.html_select_time.php;h=ddde4f5ac638fb488afaafd3c2ac83509de5323a;hb=9a23a8c0a51b7ec38a96f525484134f3cb85dc7e;hp=0000000000000000000000000000000000000000;hpb=098a79f0819ebb89b7d48df4a6b154af4560f68e;p=timetracker.git diff --git a/WEB-INF/lib/smarty/plugins/function.html_select_time.php b/WEB-INF/lib/smarty/plugins/function.html_select_time.php new file mode 100644 index 00000000..ddde4f5a --- /dev/null +++ b/WEB-INF/lib/smarty/plugins/function.html_select_time.php @@ -0,0 +1,194 @@ + + * Name: html_select_time
+ * Purpose: Prints the dropdowns for time selection + * + * @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time} + * (Smarty online manual) + * @author Roberto Berto + * @credits Monte Ohrt + * @param array $params parameters + * @param object $template template object + * @return string + * @uses smarty_make_timestamp() + */ +function smarty_function_html_select_time($params, $template) +{ + require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); + require_once(SMARTY_PLUGINS_DIR . 'function.html_options.php'); + + /* Default values. */ + $prefix = "Time_"; + $time = time(); + $display_hours = true; + $display_minutes = true; + $display_seconds = true; + $display_meridian = true; + $use_24_hours = true; + $minute_interval = 1; + $second_interval = 1; + /* Should the select boxes be part of an array when returned from PHP? + e.g. setting it to "birthday", would create "birthday[Hour]", + "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]". + Can be combined with prefix. */ + $field_array = null; + $all_extra = null; + $hour_extra = null; + $minute_extra = null; + $second_extra = null; + $meridian_extra = null; + + foreach ($params as $_key => $_value) { + switch ($_key) { + case 'prefix': + case 'time': + case 'field_array': + case 'all_extra': + case 'hour_extra': + case 'minute_extra': + case 'second_extra': + case 'meridian_extra': + $$_key = (string)$_value; + break; + + case 'display_hours': + case 'display_minutes': + case 'display_seconds': + case 'display_meridian': + case 'use_24_hours': + $$_key = (bool)$_value; + break; + + case 'minute_interval': + case 'second_interval': + $$_key = (int)$_value; + break; + + default: + trigger_error("[html_select_time] unknown parameter $_key", E_USER_WARNING); + } + } + + $time = smarty_make_timestamp($time); + + $html_result = ''; + + if ($display_hours) { + $hours = $use_24_hours ? range(0, 23) : range(1, 12); + $hour_fmt = $use_24_hours ? '%H' : '%I'; + for ($i = 0, $for_max = count($hours); $i < $for_max; $i++) + $hours[$i] = sprintf('%02d', $hours[$i]); + $html_result .= '\n"; + } + + if ($display_minutes) { + $all_minutes = range(0, 59); + for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i += $minute_interval) + $minutes[] = sprintf('%02d', $all_minutes[$i]); + $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval); + $html_result .= '\n"; + } + + if ($display_seconds) { + $all_seconds = range(0, 59); + for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i += $second_interval) + $seconds[] = sprintf('%02d', $all_seconds[$i]); + $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval); + $html_result .= '\n"; + } + + if ($display_meridian && !$use_24_hours) { + $html_result .= '\n"; + } + + return $html_result; +} + +?> \ No newline at end of file