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)
* @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
* @author Andrei Zmievski
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. */
// 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
// 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];
$html_result = $month_result = $day_result = $year_result = "";
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 .= '<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 .= '>'. "\n";
'values' => $month_values,
'selected' => $month_values[$time[1]- 1],
'print_result' => false),
$month_result .= '</select>';
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;
'print_result' => false),
$day_result .= '</select>';
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);
$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 .= '>'. "\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
$html_result .= $field_separator;
/* vim: set expandtab: */
|