+++ /dev/null
-<?php\r
-/**\r
- * Smarty plugin\r
- * @package Smarty\r
- * @subpackage plugins\r
- */\r
-\r
-\r
-/**\r
- * Smarty {html_select_time} function plugin\r
- *\r
- * Type: function<br>\r
- * Name: html_select_time<br>\r
- * Purpose: Prints the dropdowns for time selection\r
- * @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time}\r
- * (Smarty online manual)\r
- * @param array\r
- * @param Smarty\r
- * @return string\r
- * @uses smarty_make_timestamp()\r
- */\r
-function smarty_function_html_select_time($params, &$smarty)\r
-{\r
- require_once $smarty->_get_plugin_filepath('shared','make_timestamp');\r
- require_once $smarty->_get_plugin_filepath('function','html_options');\r
- /* Default values. */\r
- $prefix = "Time_";\r
- $time = time();\r
- $display_hours = true;\r
- $display_minutes = true;\r
- $display_seconds = true;\r
- $display_meridian = true;\r
- $use_24_hours = true;\r
- $minute_interval = 1;\r
- $second_interval = 1;\r
- /* Should the select boxes be part of an array when returned from PHP?\r
- e.g. setting it to "birthday", would create "birthday[Hour]",\r
- "birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".\r
- Can be combined with prefix. */\r
- $field_array = null;\r
- $all_extra = null;\r
- $hour_extra = null;\r
- $minute_extra = null;\r
- $second_extra = null;\r
- $meridian_extra = null;\r
-\r
- extract($params);\r
-\r
- $time = smarty_make_timestamp($time);\r
-\r
- $html_result = '';\r
-\r
- if ($display_hours) {\r
- $hours = $use_24_hours ? range(0, 23) : range(1, 12);\r
- $hour_fmt = $use_24_hours ? '%H' : '%I';\r
- for ($i = 0, $for_max = count($hours); $i < $for_max; $i++)\r
- $hours[$i] = sprintf('%02d', $hours[$i]);\r
- $html_result .= '<select name=';\r
- if (null !== $field_array) {\r
- $html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';\r
- } else {\r
- $html_result .= '"' . $prefix . 'Hour"';\r
- }\r
- if (null !== $hour_extra){\r
- $html_result .= ' ' . $hour_extra;\r
- }\r
- if (null !== $all_extra){\r
- $html_result .= ' ' . $all_extra;\r
- }\r
- $html_result .= '>'."\n";\r
- $html_result .= smarty_function_html_options(array('output' => $hours,\r
- 'values' => $hours,\r
- 'selected' => strftime($hour_fmt, $time),\r
- 'print_result' => false),\r
- $smarty);\r
- $html_result .= "</select>\n";\r
- }\r
-\r
- if ($display_minutes) {\r
- $all_minutes = range(0, 59);\r
- for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+= $minute_interval)\r
- $minutes[] = sprintf('%02d', $all_minutes[$i]);\r
- $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);\r
- $html_result .= '<select name=';\r
- if (null !== $field_array) {\r
- $html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';\r
- } else {\r
- $html_result .= '"' . $prefix . 'Minute"';\r
- }\r
- if (null !== $minute_extra){\r
- $html_result .= ' ' . $minute_extra;\r
- }\r
- if (null !== $all_extra){\r
- $html_result .= ' ' . $all_extra;\r
- }\r
- $html_result .= '>'."\n";\r
- \r
- $html_result .= smarty_function_html_options(array('output' => $minutes,\r
- 'values' => $minutes,\r
- 'selected' => $selected,\r
- 'print_result' => false),\r
- $smarty);\r
- $html_result .= "</select>\n";\r
- }\r
-\r
- if ($display_seconds) {\r
- $all_seconds = range(0, 59);\r
- for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+= $second_interval)\r
- $seconds[] = sprintf('%02d', $all_seconds[$i]);\r
- $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);\r
- $html_result .= '<select name=';\r
- if (null !== $field_array) {\r
- $html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';\r
- } else {\r
- $html_result .= '"' . $prefix . 'Second"';\r
- }\r
- \r
- if (null !== $second_extra){\r
- $html_result .= ' ' . $second_extra;\r
- }\r
- if (null !== $all_extra){\r
- $html_result .= ' ' . $all_extra;\r
- }\r
- $html_result .= '>'."\n";\r
- \r
- $html_result .= smarty_function_html_options(array('output' => $seconds,\r
- 'values' => $seconds,\r
- 'selected' => $selected,\r
- 'print_result' => false),\r
- $smarty);\r
- $html_result .= "</select>\n";\r
- }\r
-\r
- if ($display_meridian && !$use_24_hours) {\r
- $html_result .= '<select name=';\r
- if (null !== $field_array) {\r
- $html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';\r
- } else {\r
- $html_result .= '"' . $prefix . 'Meridian"';\r
- }\r
- \r
- if (null !== $meridian_extra){\r
- $html_result .= ' ' . $meridian_extra;\r
- }\r
- if (null !== $all_extra){\r
- $html_result .= ' ' . $all_extra;\r
- }\r
- $html_result .= '>'."\n";\r
- \r
- $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'),\r
- 'values' => array('am', 'pm'),\r
- 'selected' => strtolower(strftime('%p', $time)),\r
- 'print_result' => false),\r
- $smarty);\r
- $html_result .= "</select>\n";\r
- }\r
-\r
- return $html_result;\r
-}\r
-\r
-/* vim: set expandtab: */\r
-\r
-?>\r