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

Source for file function.pnformdateinput.php

Documentation is available at function.pnformdateinput.php

  1. <?php
  2. /**
  3.  * Date input plugin
  4.  *
  5.  * @copyright (c) 2006, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: function.pnformdateinput.php 24425 2008-07-02 12:13:57Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @author Jorn Wildt
  10.  * @package Zikula_Template_Plugins
  11.  * @subpackage Functions
  12.  */
  13.  
  14. /** Make sure to use require_once() instead of Loader::requireOnce() since "function.pnformtextinput.php"
  15.  is loaded by Smarty (the base render class) with the use of require_once(). We do not want to
  16.  get in conflict with that.*/
  17. require_once('system/pnForm/plugins/function.pnformtextinput.php');
  18.  
  19.  
  20. /**
  21.  * Date input for pnForms
  22.  *
  23.  * The date input plugin is a text input plugin that only allows dates to be posted. The value
  24.  * returned from {@link pnForm::pnFormGetValues()} is although a string of the format 'YYYY-MM-DD'
  25.  * since this is the standard internal Zikula format for dates.
  26.  *
  27.  * You can also use all of the features from the pnFormTextInput plugin since the date input
  28.  * inherits from it.
  29.  *
  30.  * @package pnForm
  31.  * @subpackage Plugins
  32.  */
  33. {
  34.     /**
  35.      * Enable or disable input of time in addition to the date
  36.      * @var bool 
  37.      */
  38.     var $includeTime;
  39.     var $initDate;
  40.  
  41.     /**
  42.      * Default date value
  43.      *
  44.      * This parameter enables the input to be pre-filled with the current date or similar other well defined
  45.      * default values.
  46.      * You can set the default value to be one of the following:
  47.      * - now: current date and time
  48.      * - today: current date
  49.      * - monthstart: first day in current month
  50.      * - monthend: last day in current month
  51.      * - yearstart: first day in the year
  52.      * - yearend: last day in the year
  53.      * - custom: inital Date
  54.      */
  55.     var $defaultValue;
  56.  
  57.  
  58.     function getFilename()
  59.     {
  60.         return __FILE__// FIXME: may be found in smarty's data???
  61.     }
  62.  
  63.  
  64.     function create(&$render&$params)
  65.     {
  66.        $this->includeTime = (array_key_exists('includeTime'$params$params['includeTime'0);
  67.        $this->defaultValue = (array_key_exists('defaultValue'$params$params['defaultValue'null);
  68.        $this->initDate = (array_key_exists('initDate'$params$params['initDate'0);
  69.        $this->maxLength ($this->includeTime ? 18 12);
  70.        $params['width'($this->includeTime ? '10em' '8em');;
  71.        
  72.        parent::create($render$params);
  73.        
  74.        $this->cssClass .= ' date';
  75.     }
  76.  
  77.  
  78.     function render(&$render)
  79.     {
  80.         static $firstTime true;
  81.  
  82.         if (!empty($this->defaultValue&& !$render->pnFormIsPostBack())
  83.         {
  84.             $d strtolower($this->defaultValue);
  85.             $now getdate();
  86.             $date null;
  87.  
  88.             if ($d == 'now')
  89.             {
  90.                 $date time();
  91.             }
  92.             else if ($d == 'today')
  93.             {
  94.                 $date mktime(0,0,0$now['mon']$now['mday']$now['year']);
  95.             }
  96.             else if ($d == 'monthstart')
  97.             {
  98.                 $date mktime(0,0,0$now['mon']1$now['year']);
  99.             }
  100.             else if ($d == 'monthend')
  101.             {
  102.                 $daysInMonth date('t');
  103.                 $date mktime(0,0,0$now['mon']$daysInMonth$now['year']);
  104.             }
  105.             else if ($d == 'yearstart')
  106.             {
  107.                 $date mktime(0,0,011$now['year']);
  108.             }
  109.             else if ($d == 'yearend')
  110.             {
  111.                 $date mktime(0,0,01231$now['year']);
  112.             }
  113.             else if ($d == 'custom')
  114.             {
  115.                 $date strtotime($this->initDate);
  116.             }
  117.  
  118.             if ($date != null)
  119.                 $this->text DateUtil::getDatetime($date($this->includeTime _DATETIMEINPUT _DATEINPUT));
  120.             else
  121.                 $this->text 'Unknown default date';
  122.         }
  123.  
  124.         $result '<span class="date" style="white-space: nowrap">';
  125.  
  126.         $result .= parent::render($render);
  127.  
  128.         $txt _PNFORM_SELECTDATE;
  129.         $result .= " <img id=\"{$this->id}_img\" src=\"javascript/jscalendar/img.gif\" style=\"vertical-align: middle\" class=\"clickable\" alt=\"$txt\" /></span>";
  130.  
  131.         if ($firstTime)
  132.         {
  133.             $headers['javascript/jscalendar/calendar.js';
  134.             $lang SessionUtil::getVar('lang');
  135.             $lang substr($lang02);
  136.             $headers["javascript/jscalendar/lang/calendar-$lang.js";
  137.             $headers['javascript/jscalendar/calendar-setup.js';
  138.             PageUtil::addVar('stylesheet''javascript/jscalendar/calendar-win2k-cold-2.css');
  139.             PageUtil::addVar('javascript'$headers);
  140.         }
  141.         $firstTime false;
  142.         if($this->includeTime{
  143.             $this->initDate str_replace('-',','$this->initDate);
  144.             $result .= "<script type=\"text/javascript\">
  145.             Calendar.setup(
  146.                 {
  147.                     inputField : \"{$this->id}\",
  148.                     ifFormat : \"%Y-%m-%d %H:%M\",
  149.                     showsTime      :    true,
  150.                     timeFormat     :    \"24\",
  151.                     button : \"{$this->id}_img\",
  152.                     singleClick    :    false,
  153.                     firstDay: _DATEFIRSTWEEKDAY "
  154.                 });
  155.                 </script>";
  156.         else {
  157.             $result .= "<script type=\"text/javascript\">
  158.             Calendar.setup(
  159.                 {
  160.                     inputField : \"{$this->id}\",
  161.                     ifFormat : \"%Y-%m-%d\",
  162.                     button : \"{$this->id}_img\",
  163.                     firstDay: _DATEFIRSTWEEKDAY "
  164.                 }
  165.             );
  166.             </script>";
  167.         }
  168.         return $result;
  169.     }
  170.  
  171.  
  172.     function parseValue(&$render$text)
  173.     {
  174.       if (empty($text))
  175.           return null;
  176.       return $text;
  177.     }
  178.  
  179.  
  180.     function validate(&$render)
  181.     {
  182.         parent::validate($render);
  183.         if (!$this->isValid)
  184.             return;
  185.  
  186.         if (strlen($this->text0)
  187.         {
  188.             if ($this->includeTime)
  189.                 $dateValue DateUtil::parseUIDateTime($this->text);
  190.             else
  191.                 $dateValue DateUtil::parseUIDate($this->text);
  192.  
  193.             if ($dateValue == null)
  194.                 $this->setError(_NOTAVALIDDATE);
  195.         }
  196.     }
  197.  
  198.  
  199.     function formatValue(&$render$value)
  200.     {
  201.         return DateUtil::formatDatetime($value($this->includeTime _DATETIMEINPUT _DATEINPUT));
  202.     }
  203. }
  204.  
  205.  
  206. function smarty_function_pnformdateinput($params&$render)
  207. {
  208.     return $render->pnFormRegisterPlugin('pnFormDateInput'$params);
  209. }
  210.  
  211. ?>

Documentation generated on Fri, 18 Jul 2008 21:45:48 +0200 by phpDocumentor 1.4.1