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
|
2011-09-04 10:37:39 +02:00
|
|
|
* @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-09-04 10:37:39 +02:00
|
|
|
*
|
2011-08-30 22:50:55 +02:00
|
|
|
* Deals with date and time. Overridden to handle date-houronly as a transform
|
2011-09-04 10:37:39 +02:00
|
|
|
*
|
|
|
|
* 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')
|
|
|
|
);
|
2011-09-04 10:37:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* (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
|
2011-10-18 18:33:41 +02:00
|
|
|
elseif (($obj = DateTime::createFromFormat($this->attrs['dataformat'], $value)))
|
2011-09-04 10:37:39 +02:00
|
|
|
{
|
|
|
|
$valid = $obj->format($this->attrs['dataformat']);
|
|
|
|
}
|
2011-10-18 18:33:41 +02:00
|
|
|
// Null is acceptable also
|
|
|
|
elseif ($value !== null)
|
2011-09-04 10:37:39 +02:00
|
|
|
{
|
|
|
|
// this is not really a user error, but one of the clientside engine
|
2011-10-18 18:33:41 +02:00
|
|
|
self::set_validation_error($form_name,lang("'%1' is not a valid date !!!", $value).' '.$this->dataformat);
|
2011-09-04 10:37:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-30 22:50:55 +02:00
|
|
|
}
|
|
|
|
new jscalendar();
|