|
From: Erin S. <ebu...@us...> - 2003-10-30 03:34:39
|
Update of /cvsroot/squirrelmail/smdoc/lib/input
In directory sc8-pr-cvs1:/tmp/cvs-serv30497
Added Files:
input.checkbox.php input.cookie.php input.dropdown.php
input.form.php input.lib.php input.querystring.php
input.radio.php input.session.php input.textarea.php
input.textbox.php
Log Message:
My simplified implementations of several input classes
used for form building.
--- NEW FILE ---
<?php
/*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This file is an addition/modification to the
* Framework for Object Orientated Web Development (Foowd).
*
* $Id: input.checkbox.php,v 1.1 2003/10/30 03:34:36 ebullient Exp $
*/
require_once(INPUT_DIR . 'input.lib.php');
/**
* Input checkbox class.
*
* This class defines an input checkbox, it handles value persistancy, and
* displaying the object.
*
* @package smdoc/input
*/
class input_checkbox extends input_base
{
/**
* Whether the checkbox is checked.
*
* @type bool
*/
var $checked;
/**
* The checkboxes caption.
*
* @type str
*/
var $caption;
/**
* Constructs a new checkbox object.
*
* @param str name The name of the checkbox.
* @param bool checked The initial checkbox state.
* @param str caption The caption to display by the checkbox.
*/
function input_checkbox($name, $checked = FALSE, $caption = NULL)
{
$this->caption = $caption;
$this->name = $name;
$this->regex = NULL;
$this->required = FALSE;
$this->value = NULL;
if ( sqGetGlobalVar($name, $new_value, SQ_FORM) )
{
$this->wasSet = TRUE;
$this->wasValid = TRUE;
$this->checked = TRUE;
}
elseif ( $checked && count($_POST) == 0)
$this->checked = TRUE;
else
$this->checked = FALSE;
}
/**
* Sets the value of the checkbox.
*
* @param bool value The value to set the checkbox to.
* @return bool TRUE on success.
*/
function set($value)
{
if (is_bool($value))
{
$this->checked = $value;
return TRUE;
}
return FALSE;
}
/**
* Display the checkbox.
*/
function display($class = NULL, $id = NULL)
{
$type = 'type="checkbox" ';
$name = 'name="'.$this->name.'" ';
$id = 'id="'.(( $id == NULL ) ? $this->name : $id ).'" ';
$title = ( $this->caption == NULL ) ? '' : 'title="'.$this->caption.'" ';
$class = ( $class == NULL ) ? '' : 'class="'.$class.'" ';
$checked = ( $this->checked ) ? 'checked ' : '';
echo '<input '.$type.$name.$id.$title.$class.$checked.'/>';
}
}
--- NEW FILE ---
<?php
/*
Copyright 2003, Paul James
This file is part of the Framework for Object Orientated Web Development (Foowd).
Foowd is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Foowd is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foowd; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
input.cookie.php
Cookie input object
*/
if (!defined('COOKIE_EXPIRE')) define('COOKIE_EXPIRE', 31536000);
if (!defined('COOKIE_PATH')) define('COOKIE_PATH', '');
if (!defined('COOKIE_DOMAIN')) define('COOKIE_DOMAIN', '');
if (!defined('COOKIE_SECURE')) define('COOKIE_SECURE', '');
/**
* Input cookie class.
*
* This class defines an input cookie, it handles input validation, and setting
* and retrieving the cookies value.
*
* @package Foowd/Input
* @class input_cookie
* @author Paul James
*/
class input_cookie {
/**
* The name of the cookie object.
*
* @type str
*/
var $name;
/**
* The value of the cookie.
*
* @type str
*/
var $value = NULL;
/**
* The regular expression used to validate the cookies value.
*
* @type str
*/
var $regex = NULL;
/**
* How long til the cookie expires in seconds.
*
* @type int
*/
var $expire;
/**
* The path the cookie is valid for.
*
* @type str
*/
var $path;
/**
* The domain the cookie is valid for.
*
* @type str
*/
var $domain;
/**
* Whether the cookie should only be sent over secure HTTP.
*
* @type bool
*/
var $secure;
/**
* Constructs a new cookie object.
*
* @param str name The name of the querystring object.
* @param str regex The validation regular expression.
* @param str value The initial contents value.
* @param int expire How long til the cookie expires in seconds.
* @param str path The path the cookie is valid for.
* @param str domain The domain the cookie is valid for.
* @param bool secure Whether the cookie should only be sent over secure HTTP.
*/
function input_cookie($name, $regex = NULL, $value = NULL, $expire = COOKIE_EXPIRE, $path = COOKIE_PATH, $domain = COOKIE_DOMAIN, $secure = COOKIE_SECURE) {
$this->name = $name;
$this->regex = $regex;
$this->expire = $expire;
$this->path = $path;
$this->domain = $domain;
$this->secure = $secure;
if (isset($_COOKIE[$name]) && ($this->regex == NULL || preg_match($this->regex, $_COOKIE[$name]))) {
if (get_magic_quotes_gpc()) {
$this->value = stripslashes($_COOKIE[$name]);
} else {
$this->value = $_COOKIE[$name];
}
}
if (!isset($this->value)) {
$this->value = $value;
}
}
/**
* Sets the value of the cookie object.
*
* @param str value The value to set the cookie to.
* @return bool TRUE on success.
*/
function set($value){
if ($this->regex == NULL || preg_match($this->regex, $value)) {
if (get_magic_quotes_gpc()) $value = stripslashes($value);
$this->value = $value;
if ($this->expire == 0) {
$expire = 0;
} else {
$expire = time() + $this->expire;
}
return setcookie($this->name, $this->value, $expire, $this->path, $this->domain, $this->secure);
} else {
return FALSE;
}
}
/**
* Delete the cookie from the client.
*
* @return bool TRUE on success.
*/
function delete(){
return setcookie($this->name, $this->value, time() - 3600, $this->path, $this->domain, $this->secure);
}
}
?>
--- NEW FILE ---
<?php
/*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This file is an addition to the Framework for Object Orientated Web Development (Foowd).
*
* It provides methods for managing groups and tracking permissions to
* consolidate operations using groups without using the groups class.
*
* $Id: input.dropdown.php,v 1.1 2003/10/30 03:34:36 ebullient Exp $
*/
require_once(INPUT_DIR . 'input.lib.php');
/**
* Dropdown list class.
*
* This class defines a dropdown listbox, it handles input validation, value
* persistancy, and displaying the object.
*
* @package smdoc/input
*/
class input_dropdown extends input_base
{
/**
* The dropdown lists caption.
*
* @type str
*/
var $caption;
/**
* Array of list items.
*
* @type array
*/
var $items;
/**
* Dropdown list allows multiple selection.
*
* @type bool
*/
var $multiple;
/**
* Constructs a new dropdown list object.
*
* @param str name The name of the dropdown list.
* @param str value The initial selected item.
* @param array items List of items to choose from
* @param str caption The caption to display by the dropdown list.
* @param bool multiple Dropdown list allows multiple selection.
*/
function input_dropdown($name, $value = NULL, $items = NULL, $caption = NULL, $multiple = FALSE)
{
$this->items = $items;
$this->caption = $caption;
$this->multiple = $multiple;
parent::input_base($name, NULL, $value);
}
/**
* Sets the value of the dropdown list.
*
* @param str value The item to select in the dropdown list.
* @return bool TRUE on success.
*/
function set($value)
{
if ( is_array($value) )
{
if ( $multiple )
{
foreach($value as $val)
{
if ( !array_key_exists($val, $this->items) )
return FALSE;
}
$this->value = $value;
return TRUE;
}
else
{
if ( isset($value[0]) )
return $this->set($value[0]); // recurse for single value
}
}
else
{
if ( is_numeric($value) )
$value = intval($value);
if ( isset($this->items[$value]) )
{
if ( $this->multiple )
$this->value[] = $value;
else
$this->value = $value;
return TRUE;
}
}
return FALSE;
}
/**
* Display the dropdown list.
*/
function display() {
echo $this->caption, ' <select name="', $this->name;
if ($this->multiple) {
echo '[]" multiple="multiple';
}
echo '" size="', $this->height, '" class="', $this->class, '">';
foreach ($this->items as $value => $item) {
echo '<option value="', $value, '"';
if ($this->multiple && is_array($this->value)) {
if (in_array($value, $this->value)) echo ' selected="selected"';
} else {
if ($this->value == $value) echo ' selected="selected"';
}
echo '>', $item, '</option>';
}
echo '</select>';
}
}
--- NEW FILE ---
<?php
/*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This file is an addition/modification to the
* Framework for Object Orientated Web Development (Foowd).
*
* $Id: input.form.php,v 1.1 2003/10/30 03:34:36 ebullient Exp $
*/
require_once(INPUT_DIR . 'input.lib.php');
define('FORM_DEFAULT_SUBMIT', _("Submit"));
define('FORM_DEFAULT_PREVIEW', _("Preview"));
define('FORM_DEFAULT_RESET', _("Reset"));
define('FORM_DEFAULT_CANCEL', _("Cancel"));
/**
* Input form class.
* Replacement for FOOWD input_form
*
* This class defines an input form and has methods for adding form objects to
* the form, displaying the form, and requesting the forms state.
*
* @package smdoc/input
*/
class input_form
{
/**
* The name of the form.
*
* @type str
*/
var $name;
/**
* URI for form to submit to.
*
* @type str
*/
var $location;
/**
* The submit method to use: SQ_POST or SQ_GET
*
* @type int
*/
var $method;
/**
* Caption of the submit button.
*
* @type str
*/
var $submit;
/**
* Cancel this action.
*
* @type str
*/
var $cancel;
/**
* Caption of the reset button.
*
* @type str
*/
var $reset;
/**
* Caption of the preview button.
*
* @type str
*/
var $preview;
/**
* Form objects in this form.
*
* @type array
*/
var $objects = array();
/**
* Constructs a new form object.
*
* @param str name The name of the form.
* @param str location URI for form to submit to.
* @param str method The submit method to use.
* @param str submit Caption of the submit button.
* @param str reset Caption of the reset button.
* @param str preview Caption of the preview button.
*/
function input_form($name, $location = NULL, $method = 'POST',
$submit = FORM_DEFAULT_SUBMIT,
$reset = FORM_DEFAULT_RESET,
$preview = NULL)
{
$this->name = $name;
if ($location == NULL)
{
$location = getURI();
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '')
$location .= '?'.$_SERVER['QUERY_STRING'];
}
if ( is_string($method) )
{
$method = ( $method == 'POST' ) ? SQ_POST : SQ_GET;
}
$this->location = $location;
$this->method = $method;
$this->submit = $submit;
$this->reset = $reset;
$this->preview = $preview;
}
/**
* Add a form object to the form.
*
* @param object object The form object to add.
* @return bool TRUE on success.
*/
function addObject(&$object)
{
if ( is_object($object) && isset($object->name) )
{
$this->objects[$object->name] = $object;
return TRUE;
}
return FALSE;
}
/**
* Has the form been submitted?
*
* @return bool TRUE if the form has been submitted.
*/
function submitted()
{
if ( sqGetGlobalVar($this->name.'_submit', $new_value, $this->method) )
return TRUE;
return FALSE;
}
/**
* Has the form been previewed?
*
* @return bool TRUE if the form has been previewed.
*/
function previewed()
{
if ( sqGetGlobalVar($this->name.'_preview', $new_value, $this->method) )
return TRUE;
return FALSE;
}
/**
* Display the form header. This method should be used in conjunction with
* {@link input_form::display_end} and requires the form objects within the
* form to be manually told to display themselves. This can be useful if you
* need finer granularity over the forms look without having to sub-class.
*/
function display_start($form_class = NULL)
{
$method = ( $this->method == SQ_POST ) ? 'POST' : 'GET';
$enctype = 'enctype="multipart/form-data" ';
$method = 'method="'.$method.'" ';
$action = 'action="'.$this->location.'" ';
$name = 'name="'.$this->name.'" ';
$class = ( $form_class == NULL ) ? '' : 'class="'.$form_class.'" ';
echo '<form '.$name.$action.$method.$enctype.$class.'>'."\n";
}
/**
* Display the form footer. See {@link input_form::display_start} for more.
*/
function display_buttons($button_class = NULL, $appendTypeToClass = FALSE)
{
// Only append type to class if a class is defined
if ( $button_class == NULL )
{
$appendTypeToClass = FALSE;
$class = '';
}
else
{
$class = 'class="'.$button_class;
$class .= $appendTypeToClass ? '' : '" ';
}
if ( $this->submit )
{
$button_class = $appendTypeToClass ? '_submit" ' : '';
$name = 'name="'.$this->name.'_submit" ';
echo '<input type="submit" '.$class.$button_class.$name.'value="'.$this->submit.'" />';
}
if ( $this->preview )
{
$button_class = $appendTypeToClass ? '_preview" ' : '';
$name = 'name="'.$this->name.'_preview" ';
echo '<input type="submit" '.$class.$button_class.$name.'value="'.$this->preview.'" />';
}
echo ' ';
if ( $this->reset )
{
$button_class = $appendTypeToClass ? '_reset" ' : '';
$name = 'name="'.$this->name.'_reset" ';
echo '<input type="reset" '.$class.$button_class.$name.'value="'.$this->reset.'" />';
}
$button_class = $appendTypeToClass ? '_cancel" ' : '';
$name = 'name="form_cancel" ';
echo '<input type="submit" '.$class.$button_class.$name.'value="'.FORM_DEFAULT_CANCEL.'" />';
}
function display_end()
{
echo '</form>'."\n";
}
}
--- NEW FILE ---
<?php
/*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This file is an addition/modification to the
* Framework for Object Orientated Web Development (Foowd).
*
* $Id: input.lib.php,v 1.1 2003/10/30 03:34:36 ebullient Exp $
*/
/*
* Clean up input
* -------------------------------------------------------------
* strip any tags added to the url from PHP_SELF.
* This fixes hand crafted url XXS expoits for any
* page that uses PHP_SELF as the FORM action
*
* Also, remove slashes from $_GET and $_POST vars if added
*/
$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
if (get_magic_quotes_gpc()) {
sqstripslashes($_GET);
sqstripslashes($_POST);
}
/**
* base input element class.
* Used to over-ride FOOWD elements.
*
*/
class input_base
{
/**
* The name of the element.
*
* @attribute str name
* @class input_base
*/
var $name;
/**
* The value of the element.
*
* @attribute str value
* @class input_base
*/
var $value;
/**
* The regular expression used to validate the objects contents.
*
* @attribute str regex
* @class input_base
*/
var $regex;
/**
* Whether the value was set by form submission
*
* @attribute bool wasSet
* @class input_base
*/
var $wasSet = FALSE;
/**
* Whether the value set by form submission was correct
*
* @attribute bool wasSet
* @class input_base
*/
var $wasValid = FALSE;
/**
* Whether or not element is required
*
* @attribute bool required
* @class input_base
*/
var $required;
/**
* Constructs a new base object.
*
* @constructor input_base
* @param str name The name of the form element.
* @param optional str regex The validation regular expression.
* @param optional str value The initial contents value.
* @param optional boolean required is item required
* @param optional constant method SQ_GET, SQ_POST, SQ_SESSION, etc.
*/
function input_base($name, $regex=NULL, $value=NULL, $required=FALSE, $method=SQ_FORM)
{
$this->name = $name;
$this->regex = $regex;
$this->required = $required;
if ( sqGetGlobalVar($name, $new_value, $method) )
{
$this->wasSet = TRUE;
$this->wasValid = $this->set($new_value);
}
if ( !$this->wasSet || !$this->wasValid )
$this->value = $value;
}
/**
* Sets the value of the object.
*
* @method set
* @param str value The value to set.
* @return bool TRUE on success.
*/
function set($value)
{
if ( ($value == NULL && !$this->required) ||
$this->regex == NULL ||
preg_match($this->regex, $value) )
{
$this->value = $value;
return TRUE;
}
return FALSE;
}
} // end input_base
/**
* recursively strip slashes from the values of an array
* From SquirrelMail 1.4.1 functions/global.php
*/
function sqstripslashes(&$array)
{
if(count($array) > 0)
{
foreach ($array as $index=>$value)
{
if (is_array($array[$index]))
sqstripslashes($array[$index]);
else
$array[$index] = stripslashes($value);
}
}
}
define('SQ_INORDER',0);
define('SQ_GET',1);
define('SQ_POST',2);
define('SQ_SESSION',3);
define('SQ_COOKIE',4);
define('SQ_SERVER',5);
define('SQ_FORM',6);
/**
* Search for the var $name in $_SESSION, $_POST, $_GET,
* $_COOKIE, or $_SERVER and set it in provided var.
* From SquirrelMail 1.4.1 functions/global.php
*
* If $search is not provided, or == SQ_INORDER, it will search
* $_SESSION, then $_POST, then $_GET. Otherwise,
* use one of the defined constants to look for
* a var in one place specifically.
*
* Note: $search is an int value equal to one of the
* constants defined above.
*
* example:
* sqgetGlobalVar('username',$username,SQ_SESSION);
* -- no quotes around last param!
*
* Returns FALSE if variable is not found.
* Returns TRUE if it is.
*/
function sqGetGlobalVar($name, &$value, $search = SQ_INORDER)
{
switch ($search)
{
/* we want the default case to be first here,
* so that if a valid value isn't specified,
* all three arrays will be searched.
*/
default:
case SQ_INORDER: // check session, post, get
case SQ_SESSION:
if( isset($_SESSION[$name]) ) {
$value = $_SESSION[$name];
return TRUE;
} elseif ( $search == SQ_SESSION ) {
break;
}
case SQ_FORM: // check post, get
case SQ_POST:
if( isset($_POST[$name]) ) {
$value = $_POST[$name];
return TRUE;
} elseif ( $search == SQ_POST ) {
break;
}
case SQ_GET:
if ( isset($_GET[$name]) ) {
$value = $_GET[$name];
return TRUE;
}
/* NO IF HERE. FOR SQ_INORDER CASE, EXIT after GET */
break;
case SQ_COOKIE:
if ( isset($_COOKIE[$name]) ) {
$value = $_COOKIE[$name];
return TRUE;
}
break;
case SQ_SERVER:
if ( isset($_SERVER[$name]) ) {
$value = $_SERVER[$name];
return TRUE;
}
break;
}
return FALSE;
}
--- NEW FILE ---
<?php
/*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This file is an addition/modification to the
* Framework for Object Orientated Web Development (Foowd).
*
* $Id: input.querystring.php,v 1.1 2003/10/30 03:34:36 ebullient Exp $
*/
require_once(INPUT_DIR . 'input.lib.php');
/**
* Input querystring class.
* Replacement for FOOWD input_querystring
*
* This class defines an input querystring, it handles input validation, value
* persistancy, and displaying the object.
*
* @package smdoc/input
*/
class input_querystring extends input_base
{
/**
* Constructs a new base object.
*
* @constructor input_querystring
* @param str name The name of the querystring object.
* @param optional str regex The validation regular expression.
* @param optional str value The initial contents value.
*/
function input_querystring($name, $regex = NULL, $value = NULL)
{
parent::input_base($name, $regex, $value, FALSE, SQ_GET);
}
}
--- NEW FILE ---
<?php
/*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This file is an addition to the Framework for Object Orientated Web Development (Foowd).
*
* It provides methods for managing groups and tracking permissions to
* consolidate operations using groups without using the groups class.
*
* $Id: input.radio.php,v 1.1 2003/10/30 03:34:36 ebullient Exp $
*/
require_once(INPUT_DIR . 'input.lib.php');
/**
* Input radio class.
*
* This class defines an input radio group, it handles input validation, value
* persistancy, and displaying the object.
*
* @package smdoc/input
*/
class input_radio extends input_base
{
/**
* The radio buttons in the radio group.
*
* @type array
*/
var $buttons;
/**
* Constructs a new radio group.
*
* @param str name The name of the radio.
* @param int value The initial value.
* @param array buttons The buttons in the radio object.
*/
function input_radio($name, $value = NULL, $buttons = NULL)
{
$this->buttons = $buttons;
parent::input_base($name, NULL, $value);
}
/**
* Sets the value of the radio group.
*
* @param str value The value to set the radio group to.
* @return bool TRUE on success.
*/
function set($value)
{
reset($this->buttons); // go to beginning of button array
if ( $value >= key($this->buttons) )
{
end($this->buttons); // go to end of button array
if ($value <= key($this->buttons))
{
$this->value = $value;
return TRUE;
}
}
return FALSE;
}
/**
* Display the radio group.
*/
function display($class = NULL, $id = NULL)
{
$type = 'type="radio" ';
$name = 'name="'.$this->name.'" ';
$class = ( $class == NULL ) ? '' : 'class="'.$class.'" ';
foreach ($this->buttons as $index => $button)
{
$id = 'id="'.(( $id == NULL ) ? $this->name : $id ).'_'.$index.'" ';
$title = 'title="'.$button.'" ';
$value = 'value="'.$index.'" ';
$checked = ( $index == $this->value ) ? 'checked' : '';
echo '<input '.$type.$name.$class.$id.$title.$value.$checked.'" />';
}
}
}
--- NEW FILE ---
<?php
/*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This file is an addition to the Framework for Object Orientated Web Development (Foowd).
*
* It provides methods for managing groups and tracking permissions to
* consolidate operations using groups without using the groups class.
*
* $Id: input.session.php,v 1.1 2003/10/30 03:34:36 ebullient Exp $
*/
require_once(INPUT_DIR . 'input.lib.php');
/**
* The SMdoc input_session class.
*
* Used to store/retrieve data from the session.
*
* @package smdoc/input
*/
class input_session extends input_base
{
/**
* Should/Is value base64 encoded in the session
*
* @var bool
* @access private
*/
var $base64;
/**
* Constructs a new textarea object.
*
* @param str name The name of the textarea.
* @param str regex The validation regular expression.
* @param str value The initial contents value.
* @param bool base64 Should the value be base64 encoded in the session.
*/
function input_session($name,
$regex = NULL,
$value = NULL,
$base64 = false)
{
$this->base64 = $base64;
parent::input_base($name, $regex, $value, FALSE, SQ_SESSION);
$this->refresh();
if ( $this->value == NULL && $value != NULL)
$this->set($value);
}
/**
* Refresh values from the session
*/
function refresh()
{
if ( !isset($_SESSION[$this->name]) )
return;
if ( $_SESSION[$this->name] == NULL || $_SESSION[$this->name] == '' )
$this->set(NULL, FALSE);
elseif ( $this->base64 )
$new_value = unserialize(base64_decode($_SESSION[$this->name]));
else
$new_value = $_SESSION[$this->name];
$this->set($new_value, FALSE);
}
/**
* Set the value for this object,
* also set value in session if set_in_session is true.
*
* @param str value The value to set.
* @param bool set_in_session Should value also be set in session
* @return bool TRUE on success.
*/
function set($value, $set_in_session = TRUE)
{
if (!$this->verifyData($value) )
return FALSE;
if ( $set_in_session ) {
if ( $this->base64 )
$_SESSION[$this->name] = base64_encode(serialize($value));
else
$_SESSION[$this->name] = $value;
}
$this->value = $value;
return TRUE;
}
/**
* Clear value from session.
*/
function remove()
{
unset($_SESSION[$this->name]);
$this->value = NULL;
}
/**
* Verify value against regex. Will recursively verify array elements.
*
* @access private
* @param str value The value to verify.
* @return bool TRUE if value is valid.
*/
function verifyData($value)
{
if ( $value == NULL || $this->regex == NULL )
return TRUE;
if ( !is_array($value) )
return preg_match($this->regex, $value);
if ( count($value) > 0 )
{
foreach( $value as $index => $val )
{
$ok = $this->verifyData($val);
if ( !$ok )
return FALSE;
}
}
return TRUE;
}
}
?>
--- NEW FILE ---
<?php
/*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This file is an addition to the Framework for Object Orientated Web Development (Foowd).
*
* It provides methods for managing groups and tracking permissions to
* consolidate operations using groups without using the groups class.
*
* $Id: input.textarea.php,v 1.1 2003/10/30 03:34:36 ebullient Exp $
*/
require_once(INPUT_DIR . 'input.lib.php');
if (!defined('INPUT_TEXTAREA_WIDTH_MIN')) define('INPUT_TEXTAREA_WIDTH_MIN', 20);
if (!defined('INPUT_TEXTAREA_WIDTH_MAX')) define('INPUT_TEXTAREA_WIDTH_MAX', 80);
if (!defined('INPUT_TEXTAREA_HEIGHT_MIN')) define('INPUT_TEXTAREA_HEIGHT_MIN', 4);
if (!defined('INPUT_TEXTAREA_HEIGHT_MAX')) define('INPUT_TEXTAREA_HEIGHT_MAX', 20);
/**
* Input textarea class.
*
* This class defines an input textarea, it handles input validation, value
* persistancy, and displaying the object.
*
* @package smdoc/input
*/
class input_textarea extends input_base
{
/**
* The textareas caption.
*
* @type str
*/
var $caption;
/**
* Constructs a new textarea object.
*
* @param str name The name of the textarea.
* @param str regex The validation regular expression.
* @param str value The initial contents value.
* @param str caption The caption to display by the textarea.
*/
function input_textarea($name, $regex = NULL, $value = NULL, $caption = NULL)
{
$this->caption = $caption;
parent::input_base($name, $regex, $value, FALSE);
}
/**
* Display the textarea.
*/
function display($class = NULL, $width = NULL, $height = NULL)
{
$maxlength = getRegexLength($this->regex, INPUT_TEXTAREA_WIDTH_MAX);
if ( $width == NULL )
$width = ($maxlength == 0) ? INPUT_TEXTAREA_WIDTH_MAX : (int) ($maxlength / 2);
if ( $width > INPUT_TEXTAREA_WIDTH_MAX )
$width = INPUT_TEXTAREA_WIDTH_MAX;
elseif ( $width < INPUT_TEXTAREA_WIDTH_MIN )
$width = INPUT_TEXTAREA_WIDTH_MIN;
if ( $height == NULL )
$height = ($maxlength == 0) ? INPUT_TEXTAREA_HEIGHT_MAX : (int) ($maxlength / 10);
if ( $height > INPUT_TEXTAREA_HEIGHT_MAX )
$height = INPUT_TEXTAREA_HEIGHT_MAX;
elseif ( $height < INPUT_TEXTAREA_HEIGHT_MIN )
$height = INPUT_TEXTAREA_HEIGHT_MIN;
$name = 'name="'.$this->name.'" ';
$value = 'value="'.htmlentities($this->value).'" ';
$width = 'cols="'.$width.'" ';
$height = 'rows="'.$height.'" ';
$class = ( $class == NULL ) ? '' : 'class="'.$class.'" ';
$maxlength = ( $maxlength == 0 ) ? '' : 'maxlength="'.$maxlength.'" ';
echo '<textarea '.$name.$width.$height.$class.'wrap="virtual" >'."\n"
.htmlentities($this->value)."\n"
.'</textarea>'."\n";
}
}
?>
--- NEW FILE ---
<?php
/*
* Copyright (c) 1999-2003 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This file is an addition to the Framework for Object Orientated Web Development (Foowd).
*
* It provides methods for managing groups and tracking permissions to
* consolidate operations using groups without using the groups class.
*
* $Id: input.textbox.php,v 1.1 2003/10/30 03:34:36 ebullient Exp $
*/
require_once(INPUT_DIR . 'input.lib.php');
if (!defined('INPUT_TEXTBOX_SIZE_MIN')) define('INPUT_TEXTBOX_SIZE_MIN', 4);
if (!defined('INPUT_TEXTBOX_SIZE_MAX')) define('INPUT_TEXTBOX_SIZE_MAX', 50);
/**
* Input textbox class.
*
* This class defines an input textbox, it handles input validation, value
* persistancy, and displaying the object.
*
* @package smdoc/input
*/
class input_textbox extends input_base
{
/**
* The textboxes caption.
*
* @type str
*/
var $caption;
/**
* The textbox type.
*
* @type str
*/
var $type;
/**
* Constructs a new textbox object.
*
* @param str name The name of the textbox.
* @param str regex The validation regular expression.
* @param str value The initial contents value.
* @param str caption The caption to display by the textbox.
* @param bool required Whether the texbox is allowed to contain no value.
*/
function input_textbox($name, $regex = NULL, $value = NULL, $caption = NULL, $required = TRUE)
{
$this->type = 'textbox';
$this->caption = $caption;
parent::input_base($name, $regex, $value, $required);
}
/**
* Display the textbox.
*/
function display($class = NULL, $size = NULL)
{
$maxlength = getRegexLength($this->regex, 16);
if ( $size == NULL )
$size = ($maxlength == 0) ? INPUT_TEXTBOX_SIZE_MAX : $maxlength;
if ( $size > INPUT_TEXTBOX_SIZE_MAX )
$size = INPUT_TEXTBOX_SIZE_MAX;
elseif ( $size < INPUT_TEXTBOX_SIZE_MIN )
$size = INPUT_TEXTBOX_SIZE_MIN;
if ($this->required && ( !$this->wasSet || !$this->wasValid ) )
$class .= 'error';
$type = 'type='.$this->type.'" ';
$name = 'name="'.$this->name.'" ';
$value = 'value="'.htmlentities($this->value).'" ';
$size = 'size='.$size.'" ';
$class = ( $class == NULL ) ? '' : 'class="'.$class.'" ';
$maxlength = ( $maxlength == 0 ) ? '' : 'maxlength="'.$maxlength.'" ';
$required = ( $this->required ) ? ' *' : '';
echo '<input '.$type.$name.$value.$size.$maxlength.$class.'" />'.$required;
}
}
//----------- input_password ---------------------------------------------------
/**
* Input password textbox class.
*
* This class defines an input password textbox. It differs from the standard
* textbox by hiding the input of the user.
*
* @package smdoc/input
*/
class input_passwordbox extends input_textbox
{
/**
* Textbox to verify contents against
*
* @type object
*/
var $verify;
/**
* Constructs a new passwordbox object.
*
* @param str name The name of the textbox.
* @param str regex The validation regular expression.
* @param str value The initial contents value.
* @param str caption The caption to display by the textbox.
* @param bool required Whether the texbox is allowed to contain no value.
* @param object optional Textbox to verify contents against - value of this box
* must match value of other box (e.g. password verify)
*/
function input_passwordbox($name, $regex = NULL, $value = NULL, $caption = NULL,
$verify = NULL, $required = TRUE)
{
$this->verify = $verify;
parent::input_textbox($name, $regex, $value, $caption, $required);
$this->type='password';
}
/**
* Sets the value of the object.
*
* @method set
* @param str value The value to set.
* @return bool TRUE on success.
*/
function set($value)
{
if ( $this->verify && $value == $this->verify->value )
return parent::set($value);
return FALSE;
}
}
//------------ input_hiddenbox --------------------------------------------------
/**
* Input hidden textbox class.
*
* This class defines an input hidden textbox. It differs from the standard
* textbox by no being visible to the user and thus not accepting user input.
*
* @package smdoc/input
*/
class input_hiddenbox extends input_textbox
{
/**
* Constructs a new passwordbox object.
*
* @param str name The name of the textbox.
* @param str regex The validation regular expression.
* @param str value The initial contents value.
* @param str caption The caption to display by the textbox.
* @param bool required Whether the texbox is allowed to contain no value.
*/
function input_hiddenbox($name, $regex = NULL, $value = NULL, $required = TRUE)
{
parent::input_textbox($name, $regex, $value, NULL, $required);
$this->type='hidden';
}
/**
* Display the hidden textbox.
*/
function display()
{
$type = 'type="'.$this->type.'" ';
$name = 'name="'.$this->name.'" ';
$value = 'value="'.htmlentities($this->value).'" ';
echo '<input '.$type.$name.$value.'" />';
}
}
?>
|