datepickerdate.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once ('HTML/QuickForm/date.php');
  4. /**
  5. * Form element to select a date and hour (with popup datepicker)
  6. */
  7. class HTML_QuickForm_datepickerdate extends HTML_QuickForm_date
  8. {
  9. /**
  10. * Constructor
  11. */
  12. function HTML_QuickForm_datepickerdate($elementName = null, $elementLabel = null, $attributes = null) {
  13. global $myMinYear, $myMaxYear;
  14. $js_form_name = $attributes['form_name'];
  15. unset($attributes['form_name']);
  16. HTML_QuickForm_element :: HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  17. $this->_persistantFreeze = true;
  18. $this->_appendName = true;
  19. $this->_type = 'datepicker';
  20. $popup_link = '<a href="javascript:openCalendar(\''.$js_form_name.'\',\''.$elementName.'\')"><img src="'.api_get_path(WEB_IMG_PATH).'calendar_select.gif" style="vertical-align:middle;" alt="Select Date" /></a>';
  21. $special_chars = array ('D', 'l', 'd', 'M', 'F', 'm', 'y', 'H', 'a', 'A', 's', 'i', 'h', 'g', ' ');
  22. foreach ($special_chars as $index => $char)
  23. {
  24. $popup_link = str_replace($char, "\\".$char, $popup_link);
  25. }
  26. $lang_code = api_get_language_isocode();
  27. // If translation not available in PEAR::HTML_QuickForm_date, add the Chamilo-translation
  28. if(! array_key_exists($lang_code,$this->_locale))
  29. {
  30. $this->_locale[$lang_code]['months_long'] = api_get_months_long();
  31. }
  32. $this->_options['format'] = 'dFY '.$popup_link;
  33. $this->_options['minYear'] = date('Y')-5;
  34. $this->_options['maxYear'] = date('Y')+10;
  35. $this->_options['language'] = $lang_code;
  36. //$this->_options['addEmptyOption'] = true;
  37. //$this->_options['emptyOptionValue'] = 0;
  38. //$this->_options['emptyOptionText'] = ' -- ';
  39. }
  40. /**
  41. * HTML code to display this datepicker
  42. */
  43. function toHtml()
  44. {
  45. $js = $this->getElementJS();
  46. return $js.parent :: toHtml();
  47. }
  48. /**
  49. * Get the necessary javascript for this datepicker
  50. */
  51. function getElementJS()
  52. {
  53. $js = '';
  54. if(!defined('DATEPICKER_JAVASCRIPT_INCLUDED'))
  55. {
  56. define('DATEPICKER_JAVASCRIPT_INCLUDED',1);
  57. $js = "\n";
  58. $js .= '<script src="';
  59. $js .= api_get_path(WEB_CODE_PATH).'inc/lib/formvalidator/Element/';
  60. $js .= 'tbl_change.js.php" type="text/javascript"></script>';
  61. $js .= "\n";
  62. }
  63. return $js;
  64. }
  65. /**
  66. * Export the date value in MySQL format
  67. * @return string YYYY-MM-DD HH:II:SS
  68. */
  69. function exportValue(&$submitValues, $assoc = false)
  70. {
  71. $values = parent::getValue();
  72. $y = $values['Y'][0];
  73. $m = $values['F'][0];
  74. $d = $values['d'][0];
  75. $m = $m < 10 ? '0'.$m : $m;
  76. $d = $d < 10 ? '0'.$d : $d;
  77. $datetime = $y.'-'.$m.'-'.$d;
  78. $result[$this->getName()]= $datetime;
  79. return $result;
  80. }
  81. /**
  82. * Sets an option to a value
  83. */
  84. function setLocalOption($name,$value)
  85. {
  86. $this->_options[$name] = $value;
  87. }
  88. }
  89. ?>