tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Source for file form_field_datetime.class.php

Documentation is available at form_field_datetime.class.php

  1. <?php
  2.  
  3. /**
  4.  * Contains class Form_Field_Datetime
  5.  *
  6.  * @package tangra_lib
  7.  * @subpackage form
  8.  */
  9.  
  10. /**
  11.  *
  12.  */
  13. require_once(TANGRA_MAIN_DIR.'form/fields/text/form_field_text.class.php');
  14. /**
  15.  *
  16.  */
  17. require_once(TANGRA_MAIN_DIR.'nls/date.inc.php');
  18.  
  19. /**
  20.  * Represents text form field that accepts datetime values like 2008-04-20 18:33:21
  21.  *
  22.  * @package tangra_lib
  23.  * @subpackage form
  24.  */
  25.  
  26.     /**
  27.      * Constructoe
  28.      *
  29.      * @param string $name Name of the field
  30.      * @param boolean $required Is field required. Default is false
  31.      * @param integer $maxlength Maximum length of the text. Default is 10
  32.      * @param string $value Default value. Must be valid date in YYYY-MM-DD format or 0000-00-00
  33.      */
  34.     function __construct($name$required false$maxlength 19$value NULL{
  35.         if ($value{
  36.             if (!check_timestamp($value)) {
  37.                 throw new Tangra_Exception('Invalid datetime = '.$value);
  38.             }
  39.         }
  40.  
  41.         parent::__construct($name$required$maxlength ,$value);
  42.         $this->add_potential_error('invalid_datetime');
  43.     }
  44.  
  45.  
  46.     /**
  47.      * Checks for valid datetime
  48.      *
  49.      * @return boolean Returns true if check passed
  50.      * @internal
  51.      */
  52.     public function basic_check({
  53.         $has_errors parent::basic_check();
  54.  
  55.         if (!$has_errors{
  56.             if ($this->get_html_value(!= NULL and $this->get_html_value(!= ''{
  57.                 if (!check_timestamp($this->get_html_value())) {
  58.                     $this->set_error('invalid_datetime');
  59.                     $has_errors true;
  60.                 }
  61.             }
  62.         }
  63.  
  64.         return $has_errors;
  65.     }
  66. }