datepicker.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // $Id: datepicker.php 20456 2009-05-10 17:27:44Z ivantcholakov $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004-2005 Dokeos S.A.
  7. Copyright (c) Bart Mollet, Hogeschool Gent
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. require_once ('HTML/QuickForm/date.php');
  20. /**
  21. * Form element to select a date and hour (with popup datepicker)
  22. */
  23. class HTML_QuickForm_datepicker extends HTML_QuickForm_date
  24. {
  25. /**
  26. * Constructor
  27. */
  28. function HTML_QuickForm_datepicker($elementName = null, $elementLabel = null, $attributes = null)
  29. {
  30. global $language_interface;
  31. $js_form_name = $attributes['form_name'];
  32. unset($attributes['form_name']);
  33. HTML_QuickForm_element :: HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  34. $this->_persistantFreeze = true;
  35. $this->_appendName = true;
  36. $this->_type = 'datepicker';
  37. $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>';
  38. $special_chars = array ('D', 'l', 'd', 'M', 'F', 'm', 'y', 'H', 'a', 'A', 's', 'i', 'h', 'g', ' ');
  39. $hour_minute_devider = get_lang("HourMinuteDivider");
  40. foreach ($special_chars as $index => $char)
  41. {
  42. $popup_link = str_replace($char, "\\".$char, $popup_link);
  43. $hour_minute_devider = str_replace($char, "\\".$char, $hour_minute_devider);
  44. }
  45. @ $editor_lang = Database :: get_language_isocode($language_interface);
  46. if (empty ($editor_lang) )
  47. {
  48. //if there was no valid iso-code, use the english one
  49. $editor_lang = 'en';
  50. }
  51. // If translation not available in PEAR::HTML_QuickForm_date, add the Dokeos-translation
  52. if(! array_key_exists($editor_lang,$this->_locale))
  53. {
  54. $this->_locale[$editor_lang]['months_long'] = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
  55. }
  56. $this->_options['format'] = 'dFY '.$popup_link.' H '.$hour_minute_devider.' i';
  57. $this->_options['minYear'] = date('Y')-7;
  58. $this->_options['maxYear'] = date('Y')+15;
  59. $this->_options['language'] = $editor_lang;
  60. //$this->_options['addEmptyOption'] = true;
  61. //$this->_options['emptyOptionValue'] = 0;
  62. //$this->_options['emptyOptionText'] = ' -- ';
  63. }
  64. /**
  65. * HTML code to display this datepicker
  66. */
  67. function toHtml()
  68. {
  69. $js = $this->getElementJS();
  70. return $js.parent :: toHtml();
  71. }
  72. /**
  73. * Get the necessary javascript for this datepicker
  74. */
  75. function getElementJS()
  76. {
  77. $js = '';
  78. if(!defined('DATEPICKER_JAVASCRIPT_INCLUDED'))
  79. {
  80. define('DATEPICKER_JAVASCRIPT_INCLUDED',1);
  81. $js = "\n";
  82. $js .= '<script src="';
  83. $js .= api_get_path(WEB_CODE_PATH).'inc/lib/formvalidator/Element/';
  84. $js .= 'tbl_change.js.php" type="text/javascript"></script>';
  85. $js .= "\n";
  86. }
  87. return $js;
  88. }
  89. /**
  90. * Export the date value in MySQL format
  91. * @return string YYYY-MM-DD HH:II:SS
  92. */
  93. function exportValue()
  94. {
  95. $values = parent::getValue();
  96. $y = $values['Y'][0];
  97. $m = $values['F'][0];
  98. $d = $values['d'][0];
  99. $h = $values['H'][0];
  100. $i = $values['i'][0];
  101. $m = $m < 10 ? '0'.$m : $m;
  102. $d = $d < 10 ? '0'.$d : $d;
  103. $h = $h < 10 ? '0'.$h : $h;
  104. $i = $i < 10 ? '0'.$i : $i;
  105. $datetime = $y.'-'.$m.'-'.$d.' '.$h.':'.$i.':00';
  106. $result[$this->getName()]= $datetime;
  107. return $result;
  108. }
  109. /**
  110. * Sets an option to a value
  111. */
  112. function setLocalOption($name,$value)
  113. {
  114. $this->_options[$name] = $value;
  115. }
  116. }
  117. ?>