mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-16 11:41:19 +01:00
30ed6a8ab7
- added more server-side debuging: * etemplate_widget_template class can be called via url and displays parsed xml, eg: http://localhost/egroupware/etemplate/inc/class.etemplate_widget_template.inc.php?name=infolog.edit This is different from directly calling the xet file, as it show what got parsed and how: http://localhost/egroupware/infolog/templates/default/edit.xet * etemplate_new class can be called via url to render an arbitrary template, eg: http://localhost/egroupware/etemplate/inc/class.etemplate_new.inc.php?name=timesheet.edit Thought not all are already rendered correct, eg. infolog.edit is not: http://localhost/egroupware/etemplate/inc/class.etemplate_new.inc.php?name=infolog.edit
135 lines
4.4 KiB
PHP
135 lines
4.4 KiB
PHP
<?php
|
|
/**
|
|
* EGroupware - eTemplate serverside textbox 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
|
|
* @version $Id$
|
|
*/
|
|
|
|
/**
|
|
* eTemplate textbox widget with following sub-types:
|
|
* - textbox with optional multiline="true" and rows="123"
|
|
* - integer or int
|
|
* - float
|
|
* - hidden
|
|
* - colorpicker
|
|
* sub-types are either passed to constructor or set via 'type' attribute!
|
|
*/
|
|
class etemplate_widget_textbox extends etemplate_widget
|
|
{
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param string|XMLReader $xml string with xml or XMLReader positioned on the element to construct
|
|
* @throws egw_exception_wrong_parameter
|
|
*/
|
|
public function __construct($xml)
|
|
{
|
|
parent::__construct($xml);
|
|
|
|
// normalize types
|
|
if ($this->type !== 'textbox')
|
|
{
|
|
if ($this->type == 'int') $this->type = 'integer';
|
|
|
|
$this->attrs['type'] = $this->type;
|
|
$this->type = 'textbox';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Validate input
|
|
*
|
|
* Following attributes get checked:
|
|
* - needed: value must NOT be empty
|
|
* - min, max: int and float widget only
|
|
* - maxlength: maximum length of string (longer strings get truncated to allowed size)
|
|
* - preg: perl regular expression incl. delimiters (set by default for int, float and colorpicker)
|
|
* - int and float get casted to their type
|
|
*
|
|
* @param array $content
|
|
* @param array &$validated=array() validated content
|
|
* @param string $cname='' current namespace
|
|
* @return boolean true if no validation error, false otherwise
|
|
*/
|
|
public function validate(array $content, &$validated=array(), $cname = '')
|
|
{
|
|
$ok = true;
|
|
if (!$this->is_readonly($cname))
|
|
{
|
|
if (!isset($this->attrs['preg']))
|
|
{
|
|
switch($this->type)
|
|
{
|
|
case 'integer':
|
|
$this->attrs['preg'] = '/^-?[0-9]*$/';
|
|
break;
|
|
case 'float':
|
|
$this->attrs['preg'] = '/^-?[0-9]*[,.]?[0-9]*$/';
|
|
break;
|
|
case 'colorpicker':
|
|
$this->attrs['preg'] = '/^(#[0-9a-f]{6}|)$/i';
|
|
break;
|
|
}
|
|
}
|
|
$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 !!!'),'');
|
|
$ok = false;
|
|
}
|
|
if ((int) $this->attrs['maxlength'] > 0 && strlen($value) > (int) $this->attrs['maxlength'])
|
|
{
|
|
$value = substr($value,0,(int) $this->attrs['maxlength']);
|
|
}
|
|
if ($this->attrs['preg'] && !preg_match($this->attrs['preg'],$value))
|
|
{
|
|
switch($this->type)
|
|
{
|
|
case 'integer':
|
|
self::set_validation_error($form_name,lang("'%1' is not a valid integer !!!",$value),'');
|
|
break;
|
|
case 'float':
|
|
self::set_validation_error($form_name,lang("'%1' is not a valid floatingpoint number !!!",$value),'');
|
|
break;
|
|
default:
|
|
self::set_validation_error($form_name,lang("'%1' has an invalid format !!!",$value)/*." !preg_match('$this->attrs[preg]', '$value')"*/,'');
|
|
break;
|
|
}
|
|
$ok = false;
|
|
}
|
|
elseif ($this->type == 'integer' || $this->type == 'float') // cast int and float and check range
|
|
{
|
|
if ((string)$value !== '' || $this->attrs['needed']) // empty values are Ok if needed is not set
|
|
{
|
|
$value = $this->type == 'integer' ? (int) $value : (float) str_replace(',','.',$value); // allow for german (and maybe other) format
|
|
|
|
if (!empty($this->attrs['min']) && $value < $this->attrs['min'])
|
|
{
|
|
self::set_validation_error($form_name,lang("Value has to be at least '%1' !!!",$this->attrs['min']),'');
|
|
$value = $this->type == 'integer' ? (int) $this->attrs['min'] : (float) $this->attrs['min'];
|
|
$ok = false;
|
|
}
|
|
if (!empty($this->attrs['max']) && $value > $this->attrs['max'])
|
|
{
|
|
self::set_validation_error($form_name,lang("Value has to be at maximum '%1' !!!",$this->attrs['max']),'');
|
|
$value = $this->type == 'integer' ? (int) $this->attrs['max'] : (float) $this->attrs['max'];
|
|
$ok = false;
|
|
}
|
|
}
|
|
}
|
|
$valid = $value;
|
|
}
|
|
return parent::validate($content, $validated, $cname) && $ok;
|
|
}
|
|
}
|
|
etemplate_widget::registerWidget('etemplate_widget_textbox', array('textbox','int','integer','float','passwd','hidden','colorpicker')); |