From e157a6508589b29bba4dedcbfd5b53bafc349903 Mon Sep 17 00:00:00 2001 From: messju Date: Wed, 10 Dec 2003 16:43:39 +0000 Subject: [PATCH] added day_empty, month_empty, year_empty and all_empty attributes to pass an undefined date use {html_select_date time="--" ...} --- NEWS | 2 ++ libs/plugins/function.html_select_date.php | 35 ++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index bd4b8d96..7a954f4a 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - add day_empty, month_empty, year_empty and all_empty attributes to + html_select_date (messju) - add table of explanation for {if} qualifiers in docs (boots) - fix bug when comparing array-keys to "selected" in html_options and html_checkboxes (messju) diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php index 4f694095..61d4d634 100644 --- a/libs/plugins/function.html_select_date.php +++ b/libs/plugins/function.html_select_date.php @@ -68,10 +68,14 @@ function smarty_function_html_select_date($params, &$smarty) $year_extra = null; /* Order in which to display the fields. "D" -> day, "M" -> month, "Y" -> year. */ - $field_order = 'MDY'; + $field_order = 'MDY'; /* String printed between the different fields. */ $field_separator = "\n"; $time = time(); + $all_empty = null; + $day_empty = null; + $month_empty = null; + $year_empty = null; foreach ($params as $_key=>$_value) { switch ($_key) { @@ -93,9 +97,17 @@ function smarty_function_html_select_date($params, &$smarty) case 'field_order': case 'field_separator': case 'month_value_format': + case 'month_empty': + case 'day_empty': + case 'year_empty': $$_key = (string)$_value; break; - + + case 'all_empty': + $$_key = (string)$_value; + $day_empty = $month_empty = $year_empty = $all_empty; + break; + case 'display_days': case 'display_months': case 'display_years': @@ -107,7 +119,7 @@ function smarty_function_html_select_date($params, &$smarty) } // If $time is not in format yyyy-mm-dd - if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $time)) { + if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $time) && $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 @@ -139,7 +151,10 @@ function smarty_function_html_select_date($params, &$smarty) if ($display_months) { $month_names = array(); $month_values = array(); - + if(isset($month_empty)) { + $month_names[''] = $month_empty; + $month_values[''] = ''; + } 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)); @@ -173,6 +188,10 @@ function smarty_function_html_select_date($params, &$smarty) if ($display_days) { $days = array(); + if (isset($day_empty)) { + $days[''] = $day_empty; + $day_values[''] = ''; + } for ($i = 1; $i <= 31; $i++) { $days[] = sprintf($day_format, $i); $day_values[] = sprintf($day_value_format, $i); @@ -222,7 +241,11 @@ function smarty_function_html_select_date($params, &$smarty) if ($reverse_years) { rsort($years, SORT_NUMERIC); } - + $yearvals = $years; + if(isset($year_empty)) { + array_unshift($years, $year_empty); + array_unshift($yearvals, ''); + } $year_result .= '