From 8cd857c3e4ebf01215180a890709f396ee96c81e Mon Sep 17 00:00:00 2001 From: mohrt Date: Tue, 21 May 2002 19:41:34 +0000 Subject: [PATCH] update html_select_date with month_value_format attribute for controlling the format of the month values. --- Config_File.class.php | 2 +- RESOURCES | 1 + docs/designers.sgml | 14 ++++- libs/Config_File.class.php | 2 +- libs/plugins/function.html_select_date.php | 70 ++++++++++++---------- plugins/function.html_select_date.php | 70 ++++++++++++---------- 6 files changed, 94 insertions(+), 65 deletions(-) diff --git a/Config_File.class.php b/Config_File.class.php index b60c1d62..e86d7014 100644 --- a/Config_File.class.php +++ b/Config_File.class.php @@ -3,7 +3,7 @@ /** * Config_File class. * - * @version 2.0.1 + * @version 2.1.1 * @author Andrei Zmievski * @access public * diff --git a/RESOURCES b/RESOURCES index 3977fa23..edf25559 100644 --- a/RESOURCES +++ b/RESOURCES @@ -2,6 +2,7 @@ Smarty Resources on the Web: (if you have something to add, e-mail monte at ispi dot net) Home Page: +http://smarty.php.net http://www.phpinsider.com/php/code/Smarty Tutorials: diff --git a/docs/designers.sgml b/docs/designers.sgml index eef0017d..e34ec955 100644 --- a/docs/designers.sgml +++ b/docs/designers.sgml @@ -131,7 +131,7 @@ {$Contacts[row].Phone} -<body bgcolr="{#bgcolor#}"> +<body bgcolor="{#bgcolor#}"> @@ -1253,8 +1253,8 @@ s m o k e r s a r e p. . . - Be careful when capturing {insert} output. If - you have caching turned on and you have {insert} + Be careful when capturing insert output. If + you have caching turned on and you have insert commands that you expect to run within cached content, do not capture this content. @@ -3289,6 +3289,14 @@ OUTPUT: \n string printed between different fields + + month_value_format + string + No + %m + strftime format of the month values, default is + %m for month numbers. + diff --git a/libs/Config_File.class.php b/libs/Config_File.class.php index b60c1d62..e86d7014 100644 --- a/libs/Config_File.class.php +++ b/libs/Config_File.class.php @@ -3,7 +3,7 @@ /** * Config_File class. * - * @version 2.0.1 + * @version 2.1.1 * @author Andrei Zmievski * @access public * diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php index 59717971..0324420e 100644 --- a/libs/plugins/function.html_select_date.php +++ b/libs/plugins/function.html_select_date.php @@ -4,7 +4,7 @@ * ------------------------------------------------------------- * Type: function * Name: html_select_date - * Version: 1.2 + * Version: 1.3 * Purpose: Prints the dropdowns for date selection. * Author: Andrei Zmievski * @@ -13,6 +13,8 @@ * and end year values. (Monte) * 1.2 added support for yyyy-mm-dd syntax for * time value. (Jan Rosier) + * 1.3 added support for choosing format for + * month values (Gary Loescher) * ------------------------------------------------------------- */ require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php'; @@ -27,6 +29,8 @@ function smarty_function_html_select_date($params, &$smarty) $display_months = true; $display_years = true; $month_format = "%B"; + /* Write months as numbers by default GL */ + $month_value_format = "%m"; $day_format = "%02d"; $year_as_text = false; /* Display years in reverse order? Ie. 2000,1999,.... */ @@ -53,43 +57,47 @@ function smarty_function_html_select_date($params, &$smarty) /* String printed between the different fields. */ $field_separator = "\n"; + extract($params); - // If $time is not in format yyyy-mm-dd - if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $time)) { - // then $time is empty or unix timestamp or mysql timestamp - // using smarty_make_timestamp to get an unix timestamp and - // strftime to make yyyy-mm-dd - $time = strftime('%Y-%m-%d', smarty_make_timestamp($time)); - } - // Now split this in pieces, which later can be used to set the select - $time = explode("-", $time); - - // make syntax "+N" or "-N" work with start_year and end_year - if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { - if ($match[1] == '+') { - $end_year = strftime('%Y') + $match[2]; - } else { - $end_year = strftime('%Y') - $match[2]; - } - } - if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) { - if ($match[1] == '+') { - $start_year = strftime('%Y') + $match[2]; - } else { - $start_year = strftime('%Y') - $match[2]; - } - } - + // If $time is not in format yyyy-mm-dd + if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $time)) { + // then $time is empty or unix timestamp or mysql timestamp + // using smarty_make_timestamp to get an unix timestamp and + // strftime to make yyyy-mm-dd + $time = strftime('%Y-%m-%d', smarty_make_timestamp($time)); + } + // Now split this in pieces, which later can be used to set the select + $time = explode("-", $time); + + // make syntax "+N" or "-N" work with start_year and end_year + if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { + if ($match[1] == '+') { + $end_year = strftime('%Y') + $match[2]; + } else { + $end_year = strftime('%Y') - $match[2]; + } + } + if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) { + if ($match[1] == '+') { + $start_year = strftime('%Y') + $match[2]; + } else { + $start_year = strftime('%Y') - $match[2]; + } + } + $field_order = strtoupper($field_order); $html_result = $month_result = $day_result = $year_result = ""; if ($display_months) { $month_names = array(); + $month_values = array(); - for ($i = 1; $i <= 12; $i++) + for ($i = 1; $i <= 12; $i++) { $month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)); + $month_values[] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000)); + } $month_result .= ''; } diff --git a/plugins/function.html_select_date.php b/plugins/function.html_select_date.php index 59717971..0324420e 100644 --- a/plugins/function.html_select_date.php +++ b/plugins/function.html_select_date.php @@ -4,7 +4,7 @@ * ------------------------------------------------------------- * Type: function * Name: html_select_date - * Version: 1.2 + * Version: 1.3 * Purpose: Prints the dropdowns for date selection. * Author: Andrei Zmievski * @@ -13,6 +13,8 @@ * and end year values. (Monte) * 1.2 added support for yyyy-mm-dd syntax for * time value. (Jan Rosier) + * 1.3 added support for choosing format for + * month values (Gary Loescher) * ------------------------------------------------------------- */ require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php'; @@ -27,6 +29,8 @@ function smarty_function_html_select_date($params, &$smarty) $display_months = true; $display_years = true; $month_format = "%B"; + /* Write months as numbers by default GL */ + $month_value_format = "%m"; $day_format = "%02d"; $year_as_text = false; /* Display years in reverse order? Ie. 2000,1999,.... */ @@ -53,43 +57,47 @@ function smarty_function_html_select_date($params, &$smarty) /* String printed between the different fields. */ $field_separator = "\n"; + extract($params); - // If $time is not in format yyyy-mm-dd - if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $time)) { - // then $time is empty or unix timestamp or mysql timestamp - // using smarty_make_timestamp to get an unix timestamp and - // strftime to make yyyy-mm-dd - $time = strftime('%Y-%m-%d', smarty_make_timestamp($time)); - } - // Now split this in pieces, which later can be used to set the select - $time = explode("-", $time); - - // make syntax "+N" or "-N" work with start_year and end_year - if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { - if ($match[1] == '+') { - $end_year = strftime('%Y') + $match[2]; - } else { - $end_year = strftime('%Y') - $match[2]; - } - } - if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) { - if ($match[1] == '+') { - $start_year = strftime('%Y') + $match[2]; - } else { - $start_year = strftime('%Y') - $match[2]; - } - } - + // If $time is not in format yyyy-mm-dd + if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $time)) { + // then $time is empty or unix timestamp or mysql timestamp + // using smarty_make_timestamp to get an unix timestamp and + // strftime to make yyyy-mm-dd + $time = strftime('%Y-%m-%d', smarty_make_timestamp($time)); + } + // Now split this in pieces, which later can be used to set the select + $time = explode("-", $time); + + // make syntax "+N" or "-N" work with start_year and end_year + if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { + if ($match[1] == '+') { + $end_year = strftime('%Y') + $match[2]; + } else { + $end_year = strftime('%Y') - $match[2]; + } + } + if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) { + if ($match[1] == '+') { + $start_year = strftime('%Y') + $match[2]; + } else { + $start_year = strftime('%Y') - $match[2]; + } + } + $field_order = strtoupper($field_order); $html_result = $month_result = $day_result = $year_result = ""; if ($display_months) { $month_names = array(); + $month_values = array(); - for ($i = 1; $i <= 12; $i++) + for ($i = 1; $i <= 12; $i++) { $month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)); + $month_values[] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000)); + } $month_result .= ''; }