+++ /dev/null
-<?php\r
-/**\r
- * Smarty plugin\r
- * @package Smarty\r
- * @subpackage plugins\r
- */\r
-\r
-/**\r
- * Smarty {html_select_date} plugin\r
- *\r
- * Type: function<br>\r
- * Name: html_select_date<br>\r
- * Purpose: Prints the dropdowns for date selection.\r
- *\r
- * ChangeLog:<br>\r
- * - 1.0 initial release\r
- * - 1.1 added support for +/- N syntax for begin\r
- * and end year values. (Monte)\r
- * - 1.2 added support for yyyy-mm-dd syntax for\r
- * time value. (Jan Rosier)\r
- * - 1.3 added support for choosing format for \r
- * month values (Gary Loescher)\r
- * - 1.3.1 added support for choosing format for\r
- * day values (Marcus Bointon)\r
- * @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}\r
- * (Smarty online manual)\r
- * @version 1.3\r
- * @author Andrei Zmievski\r
- * @param array\r
- * @param Smarty\r
- * @return string\r
- */\r
-function smarty_function_html_select_date($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 = "Date_";\r
- $start_year = strftime("%Y");\r
- $end_year = $start_year;\r
- $display_days = true;\r
- $display_months = true;\r
- $display_years = true;\r
- $month_format = "%B";\r
- /* Write months as numbers by default GL */\r
- $month_value_format = "%m";\r
- $day_format = "%02d";\r
- /* Write day values using this format MB */\r
- $day_value_format = "%d";\r
- $year_as_text = false;\r
- /* Display years in reverse order? Ie. 2000,1999,.... */\r
- $reverse_years = false;\r
- /* Should the select boxes be part of an array when returned from PHP?\r
- e.g. setting it to "birthday", would create "birthday[Day]",\r
- "birthday[Month]" & "birthday[Year]". Can be combined with prefix */\r
- $field_array = null;\r
- /* <select size>'s of the different <select> tags.\r
- If not set, uses default dropdown. */\r
- $day_size = null;\r
- $month_size = null;\r
- $year_size = null;\r
- /* Unparsed attributes common to *ALL* the <select>/<input> tags.\r
- An example might be in the template: all_extra ='class ="foo"'. */\r
- $all_extra = null;\r
- /* Separate attributes for the tags. */\r
- $day_extra = null;\r
- $month_extra = null;\r
- $year_extra = null;\r
- /* Order in which to display the fields.\r
- "D" -> day, "M" -> month, "Y" -> year. */\r
- $field_order = 'MDY';\r
- /* String printed between the different fields. */\r
- $field_separator = "\n";\r
- $time = time();\r
-\r
-\r
- extract($params);\r
-\r
- // If $time is not in format yyyy-mm-dd\r
- if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $time)) {\r
- // then $time is empty or unix timestamp or mysql timestamp\r
- // using smarty_make_timestamp to get an unix timestamp and\r
- // strftime to make yyyy-mm-dd\r
- $time = strftime('%Y-%m-%d', smarty_make_timestamp($time));\r
- }\r
- // Now split this in pieces, which later can be used to set the select\r
- $time = explode("-", $time);\r
- \r
- // make syntax "+N" or "-N" work with start_year and end_year\r
- if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {\r
- if ($match[1] == '+') {\r
- $end_year = strftime('%Y') + $match[2];\r
- } else {\r
- $end_year = strftime('%Y') - $match[2];\r
- }\r
- }\r
- if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) {\r
- if ($match[1] == '+') {\r
- $start_year = strftime('%Y') + $match[2];\r
- } else {\r
- $start_year = strftime('%Y') - $match[2];\r
- }\r
- }\r
- \r
- $field_order = strtoupper($field_order);\r
-\r
- $html_result = $month_result = $day_result = $year_result = "";\r
-\r
- if ($display_months) {\r
- $month_names = array();\r
- $month_values = array();\r
-\r
- for ($i = 1; $i <= 12; $i++) {\r
- $month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));\r
- $month_values[] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000));\r
- }\r
-\r
- $month_result .= '<select name=';\r
- if (null !== $field_array){\r
- $month_result .= '"' . $field_array . '[' . $prefix . 'Month]"';\r
- } else {\r
- $month_result .= '"' . $prefix . 'Month"';\r
- }\r
- if (null !== $month_size){\r
- $month_result .= ' size="' . $month_size . '"';\r
- }\r
- if (null !== $month_extra){\r
- $month_result .= ' ' . $month_extra;\r
- }\r
- if (null !== $all_extra){\r
- $month_result .= ' ' . $all_extra;\r
- }\r
- $month_result .= '>'."\n";\r
- \r
- $month_result .= smarty_function_html_options(array('output' => $month_names,\r
- 'values' => $month_values,\r
- 'selected' => $month_values[$time[1]-1],\r
- 'print_result' => false),\r
- $smarty);\r
- \r
- $month_result .= '</select>';\r
- }\r
-\r
- if ($display_days) {\r
- $days = array();\r
- for ($i = 1; $i <= 31; $i++) {\r
- $days[] = sprintf($day_format, $i);\r
- $day_values[] = sprintf($day_value_format, $i);\r
- }\r
-\r
- $day_result .= '<select name=';\r
- if (null !== $field_array){\r
- $day_result .= '"' . $field_array . '[' . $prefix . 'Day]"';\r
- } else {\r
- $day_result .= '"' . $prefix . 'Day"';\r
- }\r
- if (null !== $day_size){\r
- $day_result .= ' size="' . $day_size . '"';\r
- }\r
- if (null !== $all_extra){\r
- $day_result .= ' ' . $all_extra;\r
- }\r
- if (null !== $day_extra){\r
- $day_result .= ' ' . $day_extra;\r
- }\r
- $day_result .= '>'."\n";\r
- $day_result .= smarty_function_html_options(array('output' => $days,\r
- 'values' => $day_values,\r
- 'selected' => $time[2],\r
- 'print_result' => false),\r
- $smarty);\r
- $day_result .= '</select>';\r
- }\r
-\r
- if ($display_years) {\r
- if (null !== $field_array){\r
- $year_name = $field_array . '[' . $prefix . 'Year]';\r
- } else {\r
- $year_name = $prefix . 'Year';\r
- }\r
- if ($year_as_text) {\r
- $year_result .= '<input type="text" name="' . $year_name . '" value="' . $time[0] . '" size="4" maxlength="4"';\r
- if (null !== $all_extra){\r
- $year_result .= ' ' . $all_extra;\r
- }\r
- if (null !== $year_extra){\r
- $year_result .= ' ' . $year_extra;\r
- }\r
- $year_result .= '>';\r
- } else {\r
- $years = range((int)$start_year, (int)$end_year);\r
- if ($reverse_years) {\r
- rsort($years, SORT_NUMERIC);\r
- }\r
-\r
- $year_result .= '<select name="' . $year_name . '"';\r
- if (null !== $year_size){\r
- $year_result .= ' size="' . $year_size . '"';\r
- }\r
- if (null !== $all_extra){\r
- $year_result .= ' ' . $all_extra;\r
- }\r
- if (null !== $year_extra){\r
- $year_result .= ' ' . $year_extra;\r
- }\r
- $year_result .= '>'."\n";\r
- $year_result .= smarty_function_html_options(array('output' => $years,\r
- 'values' => $years,\r
- 'selected' => $time[0],\r
- 'print_result' => false),\r
- $smarty);\r
- $year_result .= '</select>';\r
- }\r
- }\r
-\r
- // Loop thru the field_order field\r
- for ($i = 0; $i <= 2; $i++){\r
- $c = substr($field_order, $i, 1);\r
- switch ($c){\r
- case 'D':\r
- $html_result .= $day_result;\r
- break;\r
-\r
- case 'M':\r
- $html_result .= $month_result;\r
- break;\r
-\r
- case 'Y':\r
- $html_result .= $year_result;\r
- break;\r
- }\r
- // Add the field seperator\r
- if($i != 2) {\r
- $html_result .= $field_separator;\r
- }\r
- }\r
-\r
- return $html_result;\r
-}\r
-\r
-/* vim: set expandtab: */\r
-\r
-?>\r