forms
[ class tree: forms ] [ index: forms ] [ all elements ]

Source for file TimeTextInput.class.php

Documentation is available at TimeTextInput.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package    forms
  9.  * @subpackage items
  10.  */
  11. if!defined"CLASSPATH" ) )
  12. {
  13.   echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  14.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  15.   exit();
  16. }
  17.  
  18. if defined"LANG" ) )
  19. {
  20.    /**
  21.     * Including language specific messages.
  22.     */
  23.    require_once CLASSPATH."forms/items/TimeTextInput/".LANG.".inc.php";
  24.    /**
  25.     * Including language specific messages.
  26.     */
  27.    require_once CLASSPATH."core/lang_spec_values/".LANG.".inc.php";
  28. }
  29. else
  30. {
  31.    echo "<h3>You have to define the constant LANG!</h3>\n";
  32.    echo "Example for german: define( 'LANG', 'de' );\n";
  33.    exit();
  34. }
  35.  
  36.  
  37.  
  38. /**
  39.  *
  40.  */
  41. require_once CLASSPATH."forms/items/HTMLTextInput.class.php";
  42. /**
  43.  *
  44.  */
  45. include_once CLASSPATH."core/DateFormatter.class.php";
  46. /**
  47.  *
  48.  */
  49. include_once CLASSPATH."core/DateFormatter.class.php";
  50.  
  51.  
  52. /**
  53.  * A class to generate text input fields to fill in Dates.
  54.  *
  55.  * @package    forms
  56.  * @subpackage items
  57.  * @version    0.1.0
  58.  * @since      0.9.1.9
  59.  * @static
  60.  * @author     Daniel Plücken <daniel@debakel.net>
  61.  * @license    http://www.gnu.org/copyleft/lesser.html
  62.  *              GNU Lesser General Public License
  63.  * @copyright  Copyright (C) 2003 Daniel Plücken <daniel@debakel.net>
  64.  *
  65.  *  This library is free software; you can redistribute it and/or
  66.  *  modify it under the terms of the GNU Lesser General Public
  67.  *  License as published by the Free Software Foundation; either
  68.  *  version 2.1 of the License.
  69.  *
  70.  *  This library is distributed in the hope that it will be useful,
  71.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  72.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  73.  *  GNU Lesser General Public License for more details.
  74.  *
  75.  *  You should have received a copy of the GNU Lesser General
  76.  *  Public License along with this library; if not, write to the
  77.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  78.  *  Boston, MA 02111-1307 USA
  79.  */
  80. class TimeTextInput extends HTMLTextInput
  81. {
  82.    /**
  83.     * The template for how to interpret the date.
  84.     * The standardvalue follows ISO 8601.
  85.     *
  86.     * Valid chars are:
  87.     *  - a - Lowercase Ante meridiem and Post meridiem        - am or pm
  88.     *  - A - Uppercase Ante meridiem and Post meridiem        - AM or PM
  89.     *  - B - Swatch Internet time                             - 000 through 999
  90.     *  - g - 12-hour format of an hour without leading zeros  - 1 through 12
  91.     *  - G - 24-hour format of an hour without leading zeros  - 0 through 23
  92.     *  - h - 12-hour format of an hour with leading zeros     - 01 through 12
  93.     *  - H - 24-hour format of an hour with leading zeros     - 00 through 23
  94.     *  - i - Minutes with leading zeros                       - 00 to 59
  95.     *  - s - Seconds, with leading zeros                      - 00 through 59
  96.     *
  97.     *
  98.     * @access private
  99.     * @see    http://www.php.net/manual/en/function.date.php (under Time)
  100.     * @var    string $template_date_format 
  101.     */
  102.    var $template_date_format = "";
  103.  
  104.    /**
  105.     * Stores whether this object has been output already.
  106.     *
  107.     * @access private
  108.     * @var    integer $year 
  109.     */
  110.    var $first_output = true;
  111.  
  112.  
  113.    /**
  114.     * Constructor
  115.     *
  116.     * @version 1.0
  117.     * @since   1.0
  118.     * @author  Daniel Plücken <daniel@debakel.net>
  119.     * @access  public
  120.     * @param   string  $name   The value of the "name"-attribute of the text
  121.     *                           input field.
  122.     * @param   string  $value  The value of the "value"-attribute of the text
  123.     *                           input field.
  124.     * @param   integer $size   The value of the "size"-attribute of the text
  125.     *                           input field.
  126.     * @return  void 
  127.     */
  128.     function TimeTextInput$name  ""$value ""$size  )
  129.     {
  130.         $this->HTMLTextInput$name$value$size12 );
  131.         $this->setOnBlur"checkTextTime( this );" );
  132.     }
  133.  
  134.  
  135.  
  136.    /**
  137.     * Returns a javascript functions to validate the correctness of a time.
  138.     *
  139.     * @version 1.0
  140.     * @since   0.1.0
  141.     * @author  Daniel Plücken <daniel@debakel.net>
  142.     * @access  public
  143.     * @return  string 
  144.     */
  145.    function getJSFunctionsToCheckTime()
  146.    {
  147.       static $JSOutputted 0;
  148.  
  149.       if $JSOutputted )
  150.       {
  151.          $JSOutputted ++;
  152.  
  153.          $tmp_js_validate JS_REGEXP_VALID_TIME;
  154.          $tmp_js_msg_invalid JS_ERR_INVALID_TIME_MSG;
  155.  
  156.          $temp  =
  157. <<<JSCRIPT
  158.  
  159.  
  160.     <script language="javascript">
  161.     <!--
  162.  
  163.         function checkTextTime( inputItem )
  164.         {
  165.             if ( inputItem.value == "" )
  166.                return true;
  167.  
  168.             regExpress = /${tmp_js_validate}/;
  169.  
  170.             if ( !regExpress.test( inputItem.value ) )
  171.             {
  172.                 alert( unescape( '${tmp_js_msg_invalid}' ) );
  173.                 return false;
  174.             }
  175.  
  176.             return true;
  177.         }
  178.  
  179.     // -->
  180.     </script>
  181.  
  182.  
  183. JSCRIPT;
  184.  
  185.          return $temp;
  186.       }
  187.    }
  188.  
  189.  
  190.  
  191.    /**
  192.     * Returns the value of this item in ISO format.
  193.     *
  194.     * @version 1.0
  195.     * @since   0.1.0
  196.     * @author  Daniel Plücken <daniel@debakel.net>
  197.     * @access  public
  198.     * @return  string The value of this input in ISO format.
  199.     */
  200.     function getISOTime()
  201.     {
  202.         if preg_match"!^".ISOTIME."$!"$this->value ) )
  203.            return $this->value;
  204.         else
  205.         {
  206.            $str_lang LANG;
  207.            if !empty$this->template_date_format ) )
  208.               $str_template $this->template_date_format;
  209.            else
  210.            switch $str_lang )
  211.            {
  212.                 case "de":
  213.                      $str_template "H:i:s";
  214.                      break;
  215.                 case "en":
  216.                      $str_template "h:i:s a";
  217.                      break;
  218.                 default// ISO-Format
  219.                      $str_template "H:i:s";
  220.                      break;
  221.            }
  222.  
  223.            return date(
  224.                         "H:i:s",
  225.                         DateFormatter::str2time$this->value$str_template )
  226.                       );
  227.         }
  228.     }
  229.  
  230.  
  231.  
  232.    /**
  233.     * Returns a generated string based on the attributes of this object.
  234.     *
  235.     * @version 1.0
  236.     * @since   0.1.0
  237.     * @author  Daniel Plücken <daniel@debakel.net>
  238.     * @access  public
  239.     * @return  string 
  240.     */
  241.     function get()
  242.     {
  243.         $str_template "H:i:s";
  244.         if preg_match"!^".ISOTIME."$!"$this->value ) )
  245.         {
  246.             $str_lang LANG;
  247.             if !empty$this->template_date_format ) )
  248.                $str_template $this->template_date_format;
  249.             else
  250.             switch $str_lang )
  251.             {
  252.                 case "de":
  253.                      $str_template "H:i:s";
  254.                      break;
  255.                 case "en":
  256.                      $str_template "h:i:s a";
  257.                      break;
  258.                 default// ISO-Format
  259.                      $str_template "H:i:s";
  260.                      break;
  261.             }
  262.  
  263.             $tmp_arr explode":"$this->value );
  264.             $this->value date(
  265.                                  $str_template,
  266.                                  mktime(
  267.                                          $tmp_arr[0]$tmp_arr[1]$tmp_arr[2],
  268.                                          111970 // <- is extraneous
  269.                                        )
  270.                                );
  271.         }
  272.  
  273.         if $this->first_output )
  274.         {
  275.             if empty$this->other_attributes ) )
  276.                $this->other_attributes "timeTemplate=\"".$str_template."\"";
  277.             else
  278.                $this->other_attributes .= " timeTemplate=\"".$str_template."\"";
  279.  
  280.             $this->first_output false;
  281.         }
  282.  
  283.         return $this->getJSFunctionsToCheckTime()
  284.               .parent::get();
  285.     }
  286. // End of class TimeTextInput
  287.  
  288. ?>

Documentation generated on Thu, 05 Jun 2008 19:15:28 +0200 by phpDocumentor 1.4.1