This commit is contained in:
Xes
2025-08-14 22:37:50 +02:00
parent fb6d5d5926
commit 3641e93527
9156 changed files with 1813532 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
/**
* Rule for HTML_QuickForm to display a CAPTCHA image
*
* This package requires the use of a PHP session.
*
* PHP versions 4 and 5
*
* @category HTML
* @package HTML_QuickForm_CAPTCHA
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2006-2008 by Philippe Jausions / 11abacus
* @license http://www.opensource.org/licenses/bsd-license.php New BSD
* @version CVS: $Id: CAPTCHA.php,v 1.1 2008/04/26 23:27:30 jausions Exp $
* @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA
*/
/**
* Rule to compare a field with a CAPTCHA image
*
* @category HTML
* @package HTML_QuickForm_CAPTCHA
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2006-2008 by Philippe Jausions / 11abacus
* @license http://www.opensource.org/licenses/bsd-license.php New BSD
* @version Release: 0.3.0
* @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA
*/
class HTML_QuickForm_Rule_CAPTCHA extends HTML_QuickForm_Rule
{
/**
* Validates the data entered matches the CAPTCHA image that was
* displayed
*
* @param string $value data to validate
* @param HTML_QuickForm_CAPTCHA_Common $captcha element to check against
*
* @return boolean TRUE if valid, FALSE otherwise
* @access public
* @static
*/
function validate($value, $captcha)
{
return ($value == $captcha->getValue());
}
}

View File

@@ -0,0 +1,119 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Validates values using callback functions or methods
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Callback.php,v 1.9 2009/04/04 21:34:04 avb Exp $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Validates values using callback functions or methods
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Callback extends HTML_QuickForm_Rule
{
/**
* Array of callbacks
*
* Array is in the format:
* $_data['rulename'] = array('functionname', 'classname');
* If the callback is not a method, then the class name is not set.
*
* @var array
* @access private
*/
var $_data = array();
/**
* Whether to use BC mode for specific rules
*
* Previous versions of QF passed element's name as a first parameter
* to validation functions, but not to validation methods. This behaviour
* is emulated if you are using 'function' as rule type when registering.
*
* @var array
* @access private
*/
var $_BCMode = array();
/**
* Validates a value using a callback
*
* @param string $value Value to be checked
* @param mixed $options Options for callback
* @access public
* @return boolean true if value is valid
*/
function validate($value, $options = null)
{
if (isset($this->_data[$this->name])) {
$callback = $this->_data[$this->name];
if (isset($callback[1])) {
return call_user_func(array($callback[1], $callback[0]), $value, $options);
} elseif ($this->_BCMode[$this->name]) {
return $callback[0]('', $value, $options);
} else {
return $callback[0]($value, $options);
}
} elseif (is_callable($options)) {
return call_user_func($options, $value);
} else {
return true;
}
} // end func validate
/**
* Adds new callbacks to the callbacks list
*
* @param string $name Name of rule
* @param string $callback Name of function or method
* @param string $class Name of class containing the method
* @param bool $BCMode Backwards compatibility mode
* @access public
*/
function addData($name, $callback, $class = null, $BCMode = false)
{
if (!empty($class)) {
$this->_data[$name] = array($callback, $class);
} else {
$this->_data[$name] = array($callback);
}
$this->_BCMode[$name] = $BCMode;
} // end func addData
function getValidationScript($options = null)
{
if (isset($this->_data[$this->name])) {
$callback = $this->_data[$this->name][0];
$params = ($this->_BCMode[$this->name]? "'', {jsVar}": '{jsVar}') .
(isset($options)? ", '{$options}'": '');
} else {
$callback = is_array($options)? $options[1]: $options;
$params = '{jsVar}';
}
return array('', "{jsVar} != '' && !{$callback}({$params})");
} // end func getValidationScript
} // end class HTML_QuickForm_Rule_Callback
?>

View File

@@ -0,0 +1,127 @@
<?php
/**
* Rule to compare two form fields
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Alexey Borzov <avb@php.net>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Compare.php,v 1.7 2009/04/04 21:34:04 avb Exp $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Rule to compare two form fields
*
* The most common usage for this is to ensure that the password
* confirmation field matches the password field
*
* @category HTML
* @package HTML_QuickForm
* @author Alexey Borzov <avb@php.net>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule
{
/**
* Possible operators to use
* @var array
* @access private
*/
public $_operators = array(
'eq' => '===',
'neq' => '!==',
'gt' => '>',
'gte' => '>=',
'lt' => '<',
'lte' => '<=',
'==' => '===',
'!=' => '!=='
);
/**
* Returns the operator to use for comparing the values
*
* @access private
* @param string operator name
* @return string operator to use for validation
*/
public function _findOperator($name)
{
$name = trim($name);
if (empty($name)) {
return '===';
} elseif (isset($this->_operators[$name])) {
return $this->_operators[$name];
} elseif (in_array($name, $this->_operators)) {
return $name;
} else {
return '===';
}
}
/**
* @param array $values
* @param string $operator
* @return mixed
*/
public function validate($values, $operator = null)
{
$operator = $this->_findOperator($operator);
$a = $values[0];
$b = $values[1];
if ('===' != $operator && '!==' != $operator) {
$a = floatval($a);
$b = floatval($b);
} else {
$a = strval($a);
$b = strval($b);
}
switch ($operator) {
case '===':
return $a === $b;
break;
case '!==':
return $a !== $b;
break;
case '>':
return $a > $b;
break;
case '>=':
return $a >= $b;
break;
case '<':
return $a < $b;
break;
case '<=':
return $a <= $b;
break;
}
}
public function getValidationScript($operator = null)
{
$operator = $this->_findOperator($operator);
if ('===' != $operator && '!==' != $operator) {
$check = "!(Number({jsVar}[0]) {$operator} Number({jsVar}[1]))";
} else {
$check = "!(String({jsVar}[0]) {$operator} String({jsVar}[1]))";
}
return array('', "'' != {jsVar}[0] && {$check}");
}
}

View File

@@ -0,0 +1,47 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Alexey Borzov <avb@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Compare.php 6184 2005-09-07 10:08:17Z bmol $
/**
* @package chamilo.library
*/
/**
* Rule to compare two form fields
*
* The most common usage for this is to ensure that the password
* confirmation field matches the password field
*
* @access public
* @package HTML_QuickForm
* @version $Revision: 6184 $
*/
class HTML_QuickForm_Rule_CompareDate extends HTML_QuickForm_Rule
{
function validate($values, $options)
{
if (!is_array($values[0]) && !is_array($values[1])) {
return api_strtotime($values[0]) < api_strtotime($values[1]);
} else {
$compareFn = create_function(
'$a, $b', 'return mktime($a[\'H\'],$a[\'i\'],0,$a[\'M\'],$a[\'d\'],$a[\'Y\']) <= mktime($b[\'H\'],$b[\'i\'],0,$b[\'M\'],$b[\'d\'],$b[\'Y\'] );'
);
return $compareFn($values[0], $values[1]);
}
}
}

View File

@@ -0,0 +1,20 @@
<?php
/* For licensing terms, see /license.txt */
/**
* QuickForm rule to check a date
* @package chamilo.include
*/
class Html_Quickform_Rule_Date extends HTML_QuickForm_Rule
{
/**
* Function to check a date
* @see HTML_QuickForm_Rule
* @param array $date An array with keys F (month), d (day) and Y (year)
* @return boolean True if date is valid
*/
function validate($date, $options)
{
$compareDate = create_function('$a', 'return checkdate($a[\'M\'],$a[\'d\'],$a[\'Y\']);');
return $compareDate($date);
}
}

View File

@@ -0,0 +1,68 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Email validation rule
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Email.php,v 1.7 2009/04/04 21:34:04 avb Exp $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Email validation rule
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
{
var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
/**
* Validates an email address
*
* @param string $email Email address
* @param boolean $checkDomain True if dns check should be performed
* @access public
* @return boolean true if email is valid
*/
function validate($email, $checkDomain = false)
{
// Fix for bug #10799: add 'D' modifier to regex
if (preg_match($this->regex . 'D', $email)) {
if ($checkDomain && function_exists('checkdnsrr')) {
$tokens = explode('@', $email);
if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
return true;
}
return false;
}
return true;
}
return false;
} // end func validate
function getValidationScript($options = null)
{
return array(" var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
} // end func getValidationScript
} // end class HTML_QuickForm_Rule_Email
?>

View File

@@ -0,0 +1,25 @@
<?php
/* For licensing terms, see /license.txt */
/**
* QuickForm rule to check a text field has a minimum of X chars
* @package chamilo.include
*/
class Html_Quickform_Rule_MinText extends HTML_QuickForm_Rule
{
/**
* Function to check a text field has a minimum of X chars
* @see HTML_QuickForm_Rule
* @param string $text A text
* @param int $count The minimum number of characters that the text should contain
* @return boolean True if text has the minimum number of chars required
*/
public function validate($text, $count)
{
$checkMinText = function($a, $b) {
return strlen(utf8_decode($a)) >= $b;
};
return $checkMinText($text, $count);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Required elements validation
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Required.php,v 1.6 2009/04/04 21:34:04 avb Exp $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Required elements validation
*
* @category HTML
* @package HTML_QuickForm
* @author Yannick Warnier <yannick.warnier@beeznest.com>
* @version Based on release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_QuestionType extends HTML_QuickForm_Rule
{
/**
* Checks if a value is one of the accepted question types
*
* @param string $value Value to check
* @param mixed $options Not used yet
* @access public
* @return boolean true if value is not empty
*/
public function validate($value, $options = null)
{
// It seems this is a file.
if (in_array($value, preg_split('/:/', QUESTION_TYPES))) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Checks that the length of value is within range
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Range.php,v 1.8 2009/04/04 21:34:04 avb Exp $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Checks that the length of value is within range
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
{
/**
* Validates a value using a range comparison
*
* @param string $value Value to be checked
* @param mixed $options Int for length, array for range
* @access public
* @return boolean true if value is valid
*/
public function validate($value, $options)
{
$length = api_strlen($value);
switch ($this->name) {
case 'min_numeric_length':
return (float) $value >= $options;
case 'max_numeric_length':
return (float) $value <= $options;
case 'minlength':
return $length >= $options;
case 'maxlength':
return $length <= $options;
default:
return $length >= $options[0] && $length <= $options[1];
}
}
public function getValidationScript($options = null)
{
switch ($this->name) {
case 'minlength':
$test = '{jsVar}.length < '.$options;
break;
case 'maxlength':
$test = '{jsVar}.length > '.$options;
break;
default:
$test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
}
return array('', "{jsVar} != '' && {$test}");
}
}

View File

@@ -0,0 +1,99 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Validates values using regular expressions
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Regex.php,v 1.6 2009/04/04 21:34:04 avb Exp $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Validates values using regular expressions
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Regex extends HTML_QuickForm_Rule
{
/**
* Array of regular expressions
*
* Array is in the format:
* $_data['rulename'] = 'pattern';
*
* @var array
* @access private
*/
public $_data = array(
'lettersonly' => '/^[a-zA-Z]+$/',
'alphanumeric' => '/^[a-zA-Z0-9]+$/',
'numeric' => '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/',
'nopunctuation' => '/^[^().\/\*\^\?#!@$%+=,\"\'><~\[\]{}]+$/',
'nonzero' => '/^-?[1-9][0-9]*/',
);
/**
* Validates a value using a regular expression
*
* @param string $value Value to be checked
* @param string $regex Regular expression
* @access public
* @return boolean true if value is valid
*/
public function validate($value, $regex = null)
{
// Fix for bug #10799: add 'D' modifier to regex
if (isset($this->_data[$this->name])) {
if (!preg_match($this->_data[$this->name] . 'D', $value)) {
return false;
}
} else {
if (!preg_match($regex . 'D', $value)) {
return false;
}
}
return true;
} // end func validate
/**
* Adds new regular expressions to the list
*
* @param string $name Name of rule
* @param string $pattern Regular expression pattern
* @access public
*/
function addData($name, $pattern)
{
$this->_data[$name] = $pattern;
} // end func addData
function getValidationScript($options = null)
{
$regex = isset($this->_data[$this->name]) ? $this->_data[$this->name] : $options;
// bug #12376, converting unicode escapes and stripping 'u' modifier
if ($pos = strpos($regex, 'u', strrpos($regex, '/'))) {
$regex = substr($regex, 0, $pos) . substr($regex, $pos + 1);
$regex = preg_replace('/(?<!\\\\)(?>\\\\\\\\)*\\\\x{([a-fA-F0-9]+)}/', '\\u$1', $regex);
}
return array(" var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Required elements validation
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Required.php,v 1.6 2009/04/04 21:34:04 avb Exp $
* @link http://pear.php.net/package/HTML_QuickForm
*/
/**
* Required elements validation
*
* @category HTML
* @package HTML_QuickForm
* @author Bertrand Mansion <bmansion@mamasam.com>
* @version Release: 3.2.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Required extends HTML_QuickForm_Rule
{
/**
* Checks if an element is empty
*
* @param string $value Value to check
* @param mixed $options Not used yet
* @access public
* @return boolean true if value is not empty
*/
public function validate($value, $options = null)
{
// It seems this is a file.
if (is_array($value)) {
if (isset($value['name']) &&
isset($value['type']) &&
isset($value['tmp_name']) &&
isset($value['size']) &&
isset($value['error'])
){
if (empty($value['tmp_name'])) {
return false;
}
}
} else {
if ((string)$value == '') {
return false;
}
}
return true;
}
public function getValidationScript($options = null)
{
return array('', "{jsVar} == ''");
}
}

View File

@@ -0,0 +1,6 @@
<html>
<head>
</head>
<body>
</body>
</html>