CompareDate.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. function validate($values, $options)
  40. {
  41. if (!is_array($values[0]) && !is_array($values[1])) {
  42. return api_strtotime($values[0]) < api_strtotime($values[1]);
  43. } else {
  44. $compareFn = create_function(
  45. '$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\'] );'
  46. );
  47. return $compareFn($values[0], $values[1]);
  48. }
  49. }
  50. }