datepickerdate.php 3.9 KB

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