datepickerdate.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * @deprecated use class DatePicker
  12. */
  13. public function HTML_QuickForm_datepickerdate($elementName = null, $elementLabel = null, $attributes = null)
  14. {
  15. global $myMinYear, $myMaxYear;
  16. $js_form_name = $attributes['form_name'];
  17. unset($attributes['form_name']);
  18. HTML_QuickForm_element :: HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  19. $this->_persistantFreeze = true;
  20. $this->_appendName = true;
  21. $this->_type = 'datepicker';
  22. $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>';
  23. $special_chars = array ('D', 'l', 'd', 'M', 'F', 'm', 'y', 'H', 'a', 'A', 's', 'i', 'h', 'g', ' ');
  24. foreach ($special_chars as $char) {
  25. $popup_link = str_replace($char, "\\".$char, $popup_link);
  26. }
  27. $lang_code = api_get_language_isocode();
  28. // If translation not available in PEAR::HTML_QuickForm_date, add the Chamilo-translation
  29. if (! array_key_exists($lang_code,$this->_locale)) {
  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. }
  37. /**
  38. * HTML code to display this datepicker
  39. */
  40. function toHtml()
  41. {
  42. $js = $this->getElementJS();
  43. return $js.parent :: toHtml();
  44. }
  45. /**
  46. * Get the necessary javascript for this datepicker
  47. */
  48. function getElementJS()
  49. {
  50. $js = '';
  51. if(!defined('DATEPICKER_JAVASCRIPT_INCLUDED')) {
  52. define('DATEPICKER_JAVASCRIPT_INCLUDED', 1);
  53. $js = "\n";
  54. $js .= '<script src="';
  55. $js .= api_get_path(WEB_CODE_PATH).'inc/lib/formvalidator/Element/';
  56. $js .= 'tbl_change.js.php" type="text/javascript"></script>';
  57. $js .= "\n";
  58. }
  59. return $js;
  60. }
  61. /**
  62. * Export the date value in MySQL format
  63. * @return string YYYY-MM-DD HH:II:SS
  64. */
  65. function exportValue(&$submitValues, $assoc = false)
  66. {
  67. $values = parent::getValue();
  68. $y = $values['Y'][0];
  69. $m = $values['F'][0];
  70. $d = $values['d'][0];
  71. $m = $m < 10 ? '0'.$m : $m;
  72. $d = $d < 10 ? '0'.$d : $d;
  73. $datetime = $y.'-'.$m.'-'.$d;
  74. $result[$this->getName()]= $datetime;
  75. return $result;
  76. }
  77. /**
  78. * Sets an option to a value
  79. */
  80. function setLocalOption($name,$value)
  81. {
  82. $this->_options[$name] = $value;
  83. }
  84. }