datepicker_old.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_datepicker extends HTML_QuickForm_date
  8. {
  9. /**
  10. * Constructor
  11. */
  12. public function HTML_QuickForm_datepicker($elementName = null, $elementLabel = null, $attributes = null, $optionIncrement = null)
  13. {
  14. $js_form_name = api_get_unique_id();
  15. HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  16. $this->_persistantFreeze = true;
  17. $this->_appendName = true;
  18. $this->_type = 'datepicker';
  19. $popup_link = '<a href="javascript:openCalendar(\''.$js_form_name.'\',\''.$elementName.'\')">
  20. <img src="'.api_get_path(WEB_IMG_PATH).'calendar_select.gif" style="vertical-align:middle;" alt="Select Date" /></a>';
  21. $hour_minute_devider = get_lang("HourMinuteDivider");
  22. $special_chars = array('D', 'l', 'd', 'M', 'F', 'm', 'y', 'H', 'a', 'A', 's', 'i', 'h', 'g', ' ');
  23. foreach ($special_chars as $char) {
  24. $popup_link = str_replace($char, "\\".$char, $popup_link);
  25. $hour_minute_devider = str_replace($char, "\\".$char, $hour_minute_devider);
  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.' H '.$hour_minute_devider.' i';
  33. $this->_options['minYear'] = date('Y')-5;
  34. $this->_options['maxYear'] = date('Y')+10;
  35. $this->_options['language'] = $lang_code;
  36. if (isset($optionIncrement)) {
  37. $this->_options['optionIncrement']['i'] = intval($optionIncrement);
  38. }
  39. }
  40. /**
  41. * HTML code to display this datepicker
  42. */
  43. public 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. define('DATEPICKER_JAVASCRIPT_INCLUDED', 1);
  56. $js = "\n";
  57. $js .= '<script src="';
  58. $js .= api_get_path(WEB_CODE_PATH).'inc/lib/formvalidator/Element/';
  59. $js .= 'tbl_change.js.php" type="text/javascript"></script>';
  60. $js .= "\n";
  61. }
  62. return $js;
  63. }
  64. /**
  65. * Export the date value in MySQL format
  66. * @param array
  67. * @param bool
  68. * @return string YYYY-MM-DD HH:II:SS
  69. */
  70. function exportValue(&$submitValues, $assoc = false)
  71. {
  72. $values = parent::getValue();
  73. $y = $values['Y'][0];
  74. $m = $values['F'][0];
  75. $d = $values['d'][0];
  76. $h = $values['H'][0];
  77. $i = $values['i'][0];
  78. $m = $m < 10 ? '0'.$m : $m;
  79. $d = $d < 10 ? '0'.$d : $d;
  80. $h = $h < 10 ? '0'.$h : $h;
  81. $i = $i < 10 ? '0'.$i : $i;
  82. $datetime = $y.'-'.$m.'-'.$d.' '.$h.':'.$i.':00';
  83. $result[$this->getName()]= $datetime;
  84. return $result;
  85. }
  86. /**
  87. * Sets an option to a value
  88. */
  89. function setLocalOption($name,$value)
  90. {
  91. $this->_options[$name] = $value;
  92. }
  93. }