egroupware/etemplate/inc/class.etemplate_widget_date.inc.php

85 lines
2.9 KiB
PHP
Raw Normal View History

2011-08-30 22:50:55 +02:00
<?php
/**
* EGroupware - eTemplate serverside date widget
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker@outdoor-training.de>
* @copyright 2002-11 by RalfBecker@outdoor-training.de
2011-08-30 22:50:55 +02:00
* @author Nathan Gray
* @copyright 2011 Nathan Gray
* @version $Id$
*/
/**
* eTemplate date widget
*
2011-08-30 22:50:55 +02:00
* Deals with date and time. Overridden to handle date-houronly as a transform
*
* Supported attributes: dataformat[,mode]
* dataformat: '' = timestamps or automatic conversation, or eg. 'Y-m-d H:i:s' for 2002-12-31 23:59:59
* mode: &1 = year is int-input not selectbox, &2 = show a [Today] button, (html-UI always uses jscal and dont care for &1+&2)
* &4 = 1min steps for time (default is 5min, with fallback to 1min if value is not in 5min-steps),
* &8 = dont show time for readonly and type date-time if time is 0:00,
* &16 = prefix r/o display with dow
* &32 = prefix r/o display with week-number
* &64 = prefix r/o display with weeknumber and dow
* &128 = no icon to trigger popup, click into input trigers it, also removing the separators to save space
*
* @todo validation of date-duration
2011-08-30 22:50:55 +02:00
*/
class etemplate_widget_date extends etemplate_widget_transformer
{
protected static $transformation = array(
'type' => array('date-houronly' => 'select-hour')
);
/**
* (Array of) comma-separated list of legacy options to automatically replace when parsing with set_attrs
*
* @var string|array
*/
protected $legacy_options = 'dataformat,mode';
/**
* Validate input
*
* @param string $cname current namespace
* @param array $content
* @param array &$validated=array() validated content
* @return boolean true if no validation error, false otherwise
*/
public function validate($cname, array $content, &$validated=array())
{
if (!$this->is_readonly($cname) && $this->type != 'date-since') // date-since is always readonly
{
$form_name = self::form_name($cname, $this->id);
$value = self::get_array($content, $form_name);
$valid =& self::get_array($validated, $form_name, true);
if ((string)$value === '' && $this->attrs['needed'])
{
self::set_validation_error($form_name,lang('Field must not be empty !!!'));
}
elseif (empty($this->attrs['dataformat'])) // integer timestamp
{
$valid = (int)$value;
}
// string with formatting letters like for php's date() method
elseif (($obs = DateTime::createFromFormat($this->attrs['dataformat'], $value)))
{
$valid = $obj->format($this->attrs['dataformat']);
}
else
{
// this is not really a user error, but one of the clientside engine
self::set_validation_error($name,lang("'%1' is not a valid date !!!", $value).' '.$this->dataformat);
}
}
}
2011-08-30 22:50:55 +02:00
}
new jscalendar();