Source for file datefield.php

Documentation is available at datefield.php

  1. <?php
  2. /**
  3. * textfield form widget designed to contain dates
  4. *
  5. @author    Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage FormsLibrary
  11. */
  12.  
  13. /** Load ancillary functions */
  14. require_once 'inc/typeinfo.php';
  15.  
  16. /** parent object */
  17. require_once 'field.php';
  18. /** Date/Time classes */
  19. require_once 'inc/date.php';
  20.  
  21. /**
  22. * textfield form widget designed to contain dates
  23. *
  24. @package    Bumblebee
  25. @subpackage FormsLibrary
  26. */
  27. class DateField extends Field {
  28.   /** @var SimpleDate   date value  */
  29.   var $date;
  30.   /** @var boolean      date can be changed  */
  31.   var $editableOutput=1;
  32.  
  33.   /**
  34.   *  Create a new datefield object
  35.   *
  36.   * @param string $name   the name of the field (db name, and html field name
  37.   * @param string $longname  long name to be used in the label of the field in display
  38.   * @param string $description  used in the html title or longdesc for the field
  39.   */
  40.   function DateField($name$longname=""$description=""{
  41.     parent::Field($name$longname$description);
  42.     //$this->DEBUG=10;
  43.     $this->date = new SimpleDate(0);
  44.   }
  45.  
  46.   function displayInTable($cols=3{
  47.     $errorclass ($this->isValid ? "" "class='inputerror'");
  48.     $t "<tr $errorclass><td>$this->longname</td>\n"
  49.         ."<td title='$this->description'>";
  50.     $t .= $this->getdisplay();
  51.     $t .= "</td>\n";
  52.     for ($i=0$i<$cols-2$i++{
  53.       $t .= '<td></td>';
  54.     }
  55.     $t .= '</tr>';
  56.     return $t;
  57.   }
  58.  
  59.  
  60.   /**
  61.   * Generate the complete html representation of the field
  62.   *
  63.   * @return string html presentation
  64.   */
  65.   function getdisplay({
  66.     $t '';
  67.     if ($this->editable && $this->editableOutput && $this->hidden{
  68.       $t .= $this->selectable();
  69.     else {
  70.       if (!$this->hidden$t .= xssqw($this->value);
  71.       $t .= $this->hidden();
  72.     }
  73.     if ($this->duplicateName{
  74.       $t .= "<input type='hiddenname='$this->duplicateName"
  75.              ."value='".xssqw($this->value)."' />";
  76.     }
  77.     return $t;
  78.   }
  79.  
  80.  
  81.  
  82.   /**
  83.   * Generate the html representation of the field in a textfield
  84.   *
  85.   * @return string html presentation
  86.   */
  87.   function selectable({
  88.     $t  "<input type='textname='$this->namebase$this->name"
  89.         ."value='".xssqw($this->date->dateString())."' ";
  90.     $t .= (isset($this->attr['size']"size='".$this->attr['size']."' " "");
  91.     $t .= (isset($this->attr['maxlength']"maxlength='".$this->attr['maxlength']."' " "");
  92.     $t .= "/>";
  93.     return $t;
  94.   }
  95.  
  96.   function hidden({
  97.     return "<input type='hiddenname='$this->namebase$this->name"
  98.            ."value='".xssqw($this->value)."' />";
  99.   }
  100.  
  101.  
  102.   /**
  103.   * Set the date (and value)
  104.   *
  105.   * @param SimpleDate $time 
  106.   */
  107.   function setDate($date{
  108.     $this->date = new SimpleDate($date);
  109.     $this->value = $this->date->dateString();
  110. //     $this->set($this->time->timeString());
  111.   }
  112.  
  113.   /**
  114.   * overload the parent's update method so that local calculations can be performed
  115.   *
  116.   * @param array $data html_name => value pairs
  117.   *
  118.   * @return boolean the value was updated
  119.   */
  120.   function update($data{
  121.     if (parent::update($data)) {
  122.       $this->setDate($this->value);
  123.     }
  124.     return $this->changed;
  125.   }
  126.  
  127.   /**
  128.   *  isValid test (extend Field::isValid), looking at whether the string parsed OK
  129.   * @return boolean data is valid
  130.   */
  131.   function isValid({
  132.     parent::isValid();
  133.     $this->isValid = $this->isValid && $this->date->isValid;
  134.     return $this->isValid;
  135.   }
  136.  
  137. }
  138.  
  139. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:14 +0000 by phpDocumentor 1.3.0