Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

date-field.inc.php

Go to the documentation of this file.
00001 <?php
00010 class DateField extends AbstractField
00011 {
00012     public $beginYear = '';
00013     public $endYear = '';
00014 
00021     public function __construct($name, Form &$parentForm, array $attribs = array())
00022     {
00023         parent::__construct($name, $parentForm, $attribs);
00024         $this->value = 'now';
00025     }
00026 
00030     public function drawInput()
00031     {
00032         $day = getdate(strtotime($this->value));
00033 
00034         # Day
00035         echo "<select name='{$this->name}_day'>";
00036 
00037         for($i = 1; $i <= 31; $i++)
00038             echo "\t<option value='$i'", $day['mday'] == $i ? ' selected="selected">' : '>',
00039                 $i, "</option>\n";
00040         
00041         echo "</select> ";
00042 
00043 
00044         # Month
00045         $monNames = array(
00046             1 => 'Jan',
00047             2 => 'Feb',
00048             3 => 'Mar',
00049             4 => 'Apr',
00050             5 => 'May',
00051             6 => 'Jun',
00052             7 => 'Jul',
00053             8 => 'Aug',
00054             9 => 'Sep',
00055             10 => 'Oct',
00056             11 => 'Nov',
00057             12 => 'Dec'
00058         );
00059 
00060         echo "<select name='{$this->name}_mon'>";
00061 
00062         for($i = 1; $i <= 12; $i++)
00063         {
00064             echo "\t<option value='$i'", $day['mon'] == $i ? ' selected="selected">' : '>',
00065                 $monNames[$i], "</option>\n";
00066         }
00067 
00068         echo "</select>\n";
00069 
00070         # Year
00071         $today = getdate();
00072 
00073         //generate our years...
00074         if (!$this->endYear)
00075             $this->endYear = max($today['year'] + 3, $day['year'] + 3);
00076 
00077         if (!$this->beginYear)
00078             $this->beginYear = $day['year'] - 2;
00079 
00080         echo "<select name='{$this->name}_year'>\n";
00081         
00082         for($i = $this->beginYear; $i <= $this->endYear; $i++)
00083         {
00084             echo "\t<option value='$i'", $day['year'] == $i ? ' selected="selected">' : '>',
00085                 $i, "</option>\n";
00086         }
00087 
00088         echo "</select>\n";
00089     }
00090 
00091 
00095     public function setDataFromRequest()
00096     {
00097         $this->value = $_REQUEST["{$this->name}_year"] . '-' . $_REQUEST["{$this->name}_mon"] . '-' . $_REQUEST["{$this->name}_day"];
00098     }
00099 }
00100 ?>

Generated on Fri Oct 27 12:26:39 2006 for BaseJumper by doxygen 1.3.9.1