CompareDate.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Alexey Borzov <avb@php.net> |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Compare.php 6184 2005-09-07 10:08:17Z bmol $
  20. /**
  21. * @package chamilo.library
  22. */
  23. /**
  24. * Code
  25. */
  26. require_once 'HTML/QuickForm/Rule.php';
  27. /**
  28. * Rule to compare two form fields
  29. *
  30. * The most common usage for this is to ensure that the password
  31. * confirmation field matches the password field
  32. *
  33. * @access public
  34. * @package HTML_QuickForm
  35. * @version $Revision: 6184 $
  36. */
  37. class HTML_QuickForm_Rule_CompareDate extends HTML_QuickForm_Rule
  38. {
  39. /**
  40. * Possible operators to use
  41. * @var array
  42. * @access private
  43. */
  44. /*var $_operators = array(
  45. 'eq' => '==',
  46. 'neq' => '!=',
  47. 'gt' => '>',
  48. 'gte' => '>=',
  49. 'lt' => '<',
  50. 'lte' => '<='
  51. );*/
  52. /**
  53. * Returns the operator to use for comparing the values
  54. *
  55. * @access private
  56. * @param string operator name
  57. * @return string operator to use for validation
  58. */
  59. /*function _findOperator($name)
  60. {
  61. if (empty($name)) {
  62. return '==';
  63. } elseif (isset($this->_operators[$name])) {
  64. return $this->_operators[$name];
  65. } elseif (in_array($name, $this->_operators)) {
  66. return $name;
  67. } else {
  68. return '==';
  69. }
  70. }*/
  71. function validate($values, $options)
  72. {
  73. $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\'] );');
  74. return $compareFn($values[0], $values[1]);
  75. }
  76. }