mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
added day_empty, month_empty, year_empty and all_empty attributes
to pass an undefined date use {html_select_date time="--" ...}
This commit is contained in:
2
NEWS
2
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)
|
||||
|
@@ -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 .= '<select name="' . $year_name . '"';
|
||||
if (null !== $year_size){
|
||||
$year_result .= ' size="' . $year_size . '"';
|
||||
@@ -235,7 +258,7 @@ function smarty_function_html_select_date($params, &$smarty)
|
||||
}
|
||||
$year_result .= '>'."\n";
|
||||
$year_result .= smarty_function_html_options(array('output' => $years,
|
||||
'values' => $years,
|
||||
'values' => $yearvals,
|
||||
'selected' => $time[0],
|
||||
'print_result' => false),
|
||||
$smarty);
|
||||
|
Reference in New Issue
Block a user