CompareDate.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. * Rule to compare two form fields
  25. *
  26. * The most common usage for this is to ensure that the password
  27. * confirmation field matches the password field
  28. *
  29. * @access public
  30. * @package HTML_QuickForm
  31. * @version $Revision: 6184 $
  32. */
  33. class HTML_QuickForm_Rule_CompareDate extends HTML_QuickForm_Rule
  34. {
  35. function validate($values, $options)
  36. {
  37. if (!is_array($values[0]) && !is_array($values[1])) {
  38. return api_strtotime($values[0]) < api_strtotime($values[1]);
  39. } else {
  40. $compareFn = create_function(
  41. '$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\'] );'
  42. );
  43. return $compareFn($values[0], $values[1]);
  44. }
  45. }
  46. }