From 2c2e4b1c0b8a3f6ec32dd672833f7d1751bb35d3 Mon Sep 17 00:00:00 2001 From: andrey Date: Fri, 31 Aug 2001 03:32:51 +0000 Subject: [PATCH] - compile_id support - new options for html_select_date --- NEWS | 3 + Smarty.addons.php | 157 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 131 insertions(+), 29 deletions(-) diff --git a/NEWS b/NEWS index 401dbd79..14b05438 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ + - added many more options to html_select_date. (Alexander Skwar, Andrei) + - added support for generating different compiled templates from the same + source template. (Hans-Peter Oeri, Andrei) - modified Smarty to pass itself to insert functions as the second parameter. (Andrei) - modified Smarty to pass itself to prefilter functions as the second diff --git a/Smarty.addons.php b/Smarty.addons.php index 031dc23d..98bf5d8b 100644 --- a/Smarty.addons.php +++ b/Smarty.addons.php @@ -260,22 +260,46 @@ function smarty_func_html_options() function smarty_func_html_select_date() { /* Default values. */ - $prefix = "Date_"; - $time = time(); - $start_year = strftime("%Y"); - $end_year = $start_year; - $display_days = true; - $display_months = true; - $display_years = true; - $month_format = "%B"; - $day_format = "%02d"; - $year_as_text = false; + $prefix = "Date_"; + $time = time(); + $start_year = strftime("%Y"); + $end_year = $start_year; + $display_days = true; + $display_months = true; + $display_years = true; + $month_format = "%B"; + $day_format = "%02d"; + $year_as_text = false; + /* Display years in reverse order? Ie. 2000,1999,.... */ + $reverse_years = false; + /* Should the select boxes be part of an array when returned from PHP? + e.g. setting it to "birthday", would create "birthday[Day]", + "birthday[Month]" & "birthday[Year]". Can be combined with prefix */ + $field_array = null; + /* tags. + If not set, uses default dropdown. */ + $day_size = null; + $month_size = null; + $year_size = null; + /* Unparsed attributes common to *ALL* the tags. + An example might be in the template: all_extra ='class ="foo"'. */ + $all_extra = null; + /* Separate attributes for the tags. */ + $day_extra = null; + $month_extra = null; + $year_extra = null; + /* Order in which to display the fields. + "D" -> day, "M" -> month, "Y" -> year. */ + $field_order = 'MDY'; + /* String printed between the different fields. */ + $field_separator = "\n"; extract(func_get_arg(0)); $time = smarty_make_timestamp($time); + $field_order = strtoupper($field_order); - $html_result = ""; + $html_result = $month_result = $day_result = $year_result = ""; if ($display_months) { $month_names = array(); @@ -283,12 +307,27 @@ function smarty_func_html_select_date() for ($i = 1; $i <= 12; $i++) $month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)); - $html_result .= '\n"; + $month_result .= ''; } if ($display_days) { @@ -296,29 +335,89 @@ function smarty_func_html_select_date() for ($i = 0; $i < count($days); $i++) $days[$i] = sprintf($day_format, $days[$i]); - $html_result .= '\n"; + $day_result .= ''; } if ($display_years) { - if ($year_as_text) { - $html_result .= ''; + if (null !== $field_array){ + $year_name = $field_array . '[' . $prefix . 'Year]'; } else { - $years = range($start_year, $end_year); + $year_name = $prefix . 'Year'; + } + if ($year_as_text) { + $year_result .= ''."\n"; - $html_result .= smarty_func_html_options(array('output' => $years, + $year_result .= '\n"; + $year_result .= ''; } } + // Loop thru the field_order field + for ($i = 0; $i <= 2; $i++){ + $c = substr($field_order, $i, 1); + switch ($c){ + case 'D': + $html_result .= $day_result; + break; + + case 'M': + $html_result .= $month_result; + break; + + case 'Y': + $html_result .= $year_result; + break; + } + // Add the field seperator + $html_result .= $field_separator; + } + print $html_result; }