Source for file function.html_select_date.php
Documentation is available at function.html_select_date.php
* Smarty {html_select_date} plugin
* Name: html_select_date<br>
* Purpose: Prints the dropdowns for date selection.
* - 1.1 added support for +/- N syntax for begin
* 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)
* - 1.3.1 added support for choosing format for
* day values (Marcus Bointon)
* - 1.3.2 support negative timestamps, force year
* dropdown to include given date unless explicitly set (Monte)
* - 1.3.4 fix behaviour of 0000-00-00 00:00:00 dates to match that
* of 0000-00-00 dates (cybot, boots)
* @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
* @author Andrei Zmievski
* @author Monte Ohrt <monte at ohrt dot com>
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
require_once $smarty->_get_plugin_filepath('function','html_options');
/* Write months as numbers by default GL */
$month_value_format =
"%m";
/* Write day values using this format MB */
$day_value_format =
"%d";
/* Display years in reverse order? Ie. 2000,1999,.... */
/* 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 */
/* <select size>'s of the different <select> tags.
If not set, uses default dropdown. */
/* Unparsed attributes common to *ALL* the <select>/<input> tags.
An example might be in the template: all_extra ='class ="foo"'. */
/* Separate attributes for the tags. */
/* Order in which to display the fields.
"D" -> day, "M" -> month, "Y" -> year. */
/* String printed between the different fields. */
foreach ($params as $_key=>
$_value) {
case 'month_value_format':
$
$_key = (string)
$_value;
$
$_key = (string)
$_value;
$day_empty =
$month_empty =
$year_empty =
$all_empty;
$smarty->trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
// negative timestamp, use date()
$time =
date('Y-m-d', $time);
// If $time is not in format yyyy-mm-dd
if (preg_match('/^(\d{0,4}-\d{0,2}-\d{0,2})/', $time, $found)) {
// use smarty_make_timestamp to get an unix timestamp and
// strftime to make yyyy-mm-dd
// Now split this in pieces, which later can be used to set the select
// make syntax "+N" or "-N" work with start_year and end_year
if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) {
$start_year =
strftime('%Y') +
$match[2];
$start_year =
strftime('%Y') -
$match[2];
if ($start_year >
$time[0] &&
!isset
($params['start_year'])) {
// force start year to include given date if not explicitly set
if($end_year <
$time[0] &&
!isset
($params['end_year'])) {
// force end year to include given date if not explicitly set
$html_result =
$month_result =
$day_result =
$year_result =
"";
$field_separator_count = -
1;
$field_separator_count++
;
if(isset
($month_empty)) {
$month_names[''] =
$month_empty;
for ($i =
1; $i <=
12; $i++
) {
$month_names[$i] =
strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
$month_values[$i] =
strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
$month_result .=
'<select name=';
if (null !==
$field_array){
$month_result .=
'"' .
$field_array .
'[' .
$prefix .
'Month]"';
$month_result .=
'"' .
$prefix .
'Month"';
if (null !==
$month_size){
$month_result .=
' size="' .
$month_size .
'"';
if (null !==
$month_extra){
$month_result .=
' ' .
$month_extra;
if (null !==
$all_extra){
$month_result .=
' ' .
$all_extra;
$month_result .=
$extra_attrs .
'>'.
"\n";
'values' =>
$month_values,
'selected' => (int)
$time[1] ?
strftime($month_value_format, mktime(0, 0, 0, (int)
$time[1], 1, 2000)) :
'',
'print_result' =>
false),
$month_result .=
'</select>';
$field_separator_count++
;
for ($i =
1; $i <=
31; $i++
) {
$days[] =
sprintf($day_format, $i);
$day_values[] =
sprintf($day_value_format, $i);
$day_result .=
'<select name=';
if (null !==
$field_array){
$day_result .=
'"' .
$field_array .
'[' .
$prefix .
'Day]"';
$day_result .=
'"' .
$prefix .
'Day"';
$day_result .=
' size="' .
$day_size .
'"';
if (null !==
$all_extra){
$day_result .=
' ' .
$all_extra;
if (null !==
$day_extra){
$day_result .=
' ' .
$day_extra;
$day_result .=
$extra_attrs .
'>'.
"\n";
'print_result' =>
false),
$day_result .=
'</select>';
$field_separator_count++
;
if (null !==
$field_array){
$year_name =
$field_array .
'[' .
$prefix .
'Year]';
$year_name =
$prefix .
'Year';
$year_result .=
'<input type="text" name="' .
$year_name .
'" value="' .
$time[0] .
'" size="4" maxlength="4"';
if (null !==
$all_extra){
$year_result .=
' ' .
$all_extra;
if (null !==
$year_extra){
$year_result .=
' ' .
$year_extra;
$years =
range((int)
$start_year, (int)
$end_year);
rsort($years, SORT_NUMERIC);
sort($years, SORT_NUMERIC);
$year_result .=
'<select name="' .
$year_name .
'"';
if (null !==
$year_size){
$year_result .=
' size="' .
$year_size .
'"';
if (null !==
$all_extra){
$year_result .=
' ' .
$all_extra;
if (null !==
$year_extra){
$year_result .=
' ' .
$year_extra;
$year_result .=
$extra_attrs .
'>'.
"\n";
'print_result' =>
false),
$year_result .=
'</select>';
// Loop thru the field_order field
for ($i =
0; $i <=
2; $i++
){
$c =
substr($field_order, $i, 1);
$html_result .=
$day_result;
$html_result .=
$month_result;
$html_result .=
$year_result;
// Add the field seperator
if($i <
$field_separator_count) {
$html_result .=
$field_separator;
/* vim: set expandtab: */
Documentation generated on Sun, 09 Mar 2008 23:52:02 -0300 by phpDocumentor 1.4.0