Source for file BirthdayDateTextInput.class.php
Documentation is available at BirthdayDateTextInput.class.php
* For including this file you have to define the constant "CLASSPATH".
* Because every include in the framework depends on the CLASSPATH definition.
* The CLASSPATH means the relative path to the folder that contains the
echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
* Including language specific messages.
require_once CLASSPATH. "forms/items/BirthdayDateTextInput/". LANG. ".inc.php";
* Including language specific messages.
require_once CLASSPATH. "core/lang_spec_values/". LANG. ".inc.php";
echo "<h3>You have to define the constant LANG!</h3>\n";
echo "Example for german: define( 'LANG', 'de' );\n";
require_once CLASSPATH. "forms/items/HTMLTextInput.class.php";
require_once CLASSPATH. "html/JavaScript.class.php";
* A class to generate text input fields to fill in Dates.
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (C) 2003 Daniel Plücken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* The template for how to interpret the date.
* The standardvalue follows ISO 8601.
* @var string $template_date_format
* Stores the interpreted day
* Stores the interpreted month
* Stores the interpreted year
* Stores whether this object has been output already.
* @param string $name The value of the "name"-attribute of the text
* @param string $value The value of the "value"-attribute of the text
* @param integer $size The value of the "size"-attribute of the text
* @param string $str_date_template Sets the template how to display date
* in the text input. The rules follow
* the parameter rules of the
* @return BirthdayDateTextInput
* Interprets a given date on the basis of a template.
* @param string $str_date
* @param string $str_template
* @param boolean $store_format
* @return array The date interpreted in an array in index order: year,
if ( empty( $str_template ) )
if ( empty( $str_date ) )
{ $str_date = $this->value; }
$y_pos = strpos( $str_template, "y" );
$m_pos = strpos( $str_template, "m" );
$d_pos = strpos( $str_template, "d" );
$int_max = max( $y_pos, $d_pos, $m_pos );
$int_min = min( $y_pos, $d_pos, $m_pos );
$d_regexp_pos = $m_regexp_pos = $y_regexp_pos = 2;
$str_template = str_replace( ".", "\.", $str_template );
$str_template = str_replace( "d", "(\d{1,2})", $str_template );
$str_template = str_replace( "m", "(\d{1,2})", $str_template );
$str_template = str_replace( "y", "(\d{4,4})", $str_template );
preg_match( "!^". $str_template. "$!", $str_date, $matches_arr );
$this->day = $matches_arr[$d_regexp_pos];
$this->month = $matches_arr[$m_regexp_pos];
$this->year = $matches_arr[$y_regexp_pos];
$matches_arr[$y_regexp_pos],
$matches_arr[$m_regexp_pos],
$matches_arr[$d_regexp_pos]
* Returns the value of this item in ISO format.
* @return string The value of this input in ISO format.
return $tmp_arr[0]. "-". $tmp_arr[1]. "-". $tmp_arr[2];
* A overwritten method to forbid to set the maximal capacity of this special
{ die( "It is not allowed to set the maximum capacity of date input." ); }
* Makes a clone of this object an returns a reference to this clone.
* @param string $new_name
* @param string $selected_value
* Returns a javascript functions to validate the correctness of a date.
$tmp_js_msg_day_gt_29_in_feb_of_leap =
$tmp_js_msg_day_gt_28_in_feb_of_non_leap =
<script language="javascript">
function removeLeadingZeros( str )
while ( str.substr( 0, 1 ) == "0" )
str = str.substr( 1, str.length - 1 );
{ return ((y % 4 == 0) && ((y % 100!= 0) || (y % 400 == 0))); }
function checkTextDate( inputItem )
if ( inputItem.value == "" )
regExpress = /${ tmp_js_validate}/;
if ( !regExpress.test( inputItem.value ) )
alert( unescape( '${ tmp_js_msg_invalid}' ) );
var date_tokens = inputItem.value.split( "${ tmp_js_digit_separator}" );
day = parseInt( removeLeadingZeros( date_tokens[0] ) );
month = parseInt( removeLeadingZeros( date_tokens[1] ) );
year = parseInt( removeLeadingZeros( date_tokens[2] ) );
alert( unescape( '${ tmp_js_msg_day_zero}' ) );
alert( unescape( '${ tmp_js_msg_day_gt_31}' ) );
alert( unescape( '${ tmp_js_msg_month_zero}' ) );
alert( unescape( '${ tmp_js_msg_month_gt_twelve}' ) );
if ( isLeapYear( year ) && ( month == 2 ) && ( day > 29 ) )
alert( unescape ( '${ tmp_js_msg_day_gt_29_in_feb_of_leap}' ) );
if ( !isLeapYear( year ) && month == 2 && day > 28 )
alert( unescape( '${ tmp_js_msg_day_gt_28_in_feb_of_non_leap}' ) );
errMonth = "{ $GLOBALS["monthNames"][3]}";
errMonth = "{ $GLOBALS["monthNames"][5]}";
errMonth = "{ $GLOBALS["monthNames"][8]}";
errMonth = "{ $GLOBALS["monthNames"][10]}";
alert( unescape( '${ tmp_js_msg_day_gt_30}' ) );
day = ( day < 10 ) ? "0" + day : day;
month = ( month < 10 ) ? "0" + month : month;
var str_tmp = inputItem.getAttribute( "dateTemplate" );
var str_val = str_tmp.replace( /d/i, day );
str_val = str_val.replace( /m/i, month );
str_val = str_val.replace( /y/i, year );
inputItem.value = str_val;
* Returns a javascript to check if the given value is valid for this kind of
$outputstr = "checkTextDate( document."
* Generates the sourcecode to build this object and returns it.
$outputstr = "unset( \x24value );\n";
$outputstr .= "\x24value = \x24_REQUEST[\"". $this -> name. "\"]\n";
$outputstr .= "\x24input[] = new BirthdayDateTextInput(\n"
. " \"". $this -> name. "\",\n"
. " \"". $this -> size. "\"\n"
$outputstr .= !empty( $this -> value )
? "if( \x24value === \"\" )\n"
. " \x24input[count(\x24input)-1] "
. "-> setValue( \"". $this -> value. "\" );\n\n"
* Sets the template how to display date in the text input. The rules follow
* the parameter rules of the date()-function.
* @param string $str_date
if ( !empty( $str_date ) )
* Returns a generated string based on the attributes of this object.
parent::setOnBlur( "checkTextDate( this );". $this->blur );
} // END of class BirthdayDateTextInput
|