diff --git a/main/inc/lib/formvalidator/Element/datepickerdate.php b/main/inc/lib/formvalidator/Element/datepickerdate.php new file mode 100644 index 0000000000..879cb60238 --- /dev/null +++ b/main/inc/lib/formvalidator/Element/datepickerdate.php @@ -0,0 +1,109 @@ +_persistantFreeze = true; + $this->_appendName = true; + $this->_type = 'datepicker'; + $popup_link = 'Select Date'; + $special_chars = array ('D', 'l', 'd', 'M', 'F', 'm', 'y', 'H', 'a', 'A', 's', 'i', 'h', 'g', ' '); + foreach ($special_chars as $index => $char) + { + $popup_link = str_replace($char, "\\".$char, $popup_link); + } + @ $editor_lang = Database :: get_language_isocode($language_interface); + if (empty ($editor_lang) ) + { + //if there was no valid iso-code, use the english one + $editor_lang = 'en'; + } + // If translation not available in PEAR::HTML_QuickForm_date, add the Dokeos-translation + if(! array_key_exists($editor_lang,$this->_locale)) + { + $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")); + } + $this->_options['format'] = 'dFY '.$popup_link; + $this->_options['minYear'] = date('Y')-1; + $this->_options['maxYear'] = date('Y')+5; + $this->_options['language'] = $editor_lang; + //$this->_options['addEmptyOption'] = true; + //$this->_options['emptyOptionValue'] = 0; + //$this->_options['emptyOptionText'] = ' -- '; + } + /** + * HTML code to display this datepicker + */ + function toHtml() + { + $js = $this->getElementJS(); + return $js.parent :: toHtml(); + } + /** + * Get the necessary javascript for this datepicker + */ + function getElementJS() + { + $js = ''; + if(!defined('DATEPICKER_JAVASCRIPT_INCLUDED')) + { + define('DATEPICKER_JAVASCRIPT_INCLUDED',1); + $js = "\n"; + $js .= ''; + $js .= "\n"; + } + return $js; + } + /** + * Export the date value in MySQL format + * @return string YYYY-MM-DD HH:II:SS + */ + function exportValue() + { + $values = parent::getValue(); + $y = $values['Y'][0]; + $m = $values['F'][0]; + $d = $values['d'][0]; + $m = $m < 10 ? '0'.$m : $m; + $d = $d < 10 ? '0'.$d : $d; + $datetime = $y.'-'.$m.'-'.$d; + $result[$this->getName()]= $datetime; + return $result; + } +} +?> \ No newline at end of file diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index e8d9ad3c6b..044c1ecdfc 100644 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -55,6 +55,7 @@ class FormValidator extends HTML_QuickForm $dir = dirname(__FILE__).'/'; $this->registerElementType('html_editor', $dir.'Element/html_editor.php', 'HTML_QuickForm_html_editor'); $this->registerElementType('datepicker', $dir.'Element/datepicker.php', 'HTML_QuickForm_datepicker'); + $this->registerElementType('datepickerdate', $dir.'Element/datepickerdate.php', 'HTML_QuickForm_datepickerdate'); $this->registerElementType('receivers', $dir.'Element/receivers.php', 'HTML_QuickForm_receivers'); $this->registerElementType('select_language', $dir.'Element/select_language.php', 'HTML_QuickForm_Select_Language'); $this->registerElementType('select_theme', $dir.'Element/select_theme.php', 'HTML_QuickForm_Select_Theme'); @@ -176,6 +177,18 @@ EOT; $this->addRule($name, get_lang('InvalidDate'), 'date'); } + /** + * Add a datepickerdate element to the form + * A rule is added to check if the date is a valid one + * @param string $label The label for the form-element + * @param string $name The element name + */ + function add_datepickerdate($name,$label) + { + $this->addElement('datepickerdate', $name, $label, array ('form_name' => $this->getAttribute('name'))); + $this->addRule($name, get_lang('InvalidDate'), 'date'); + } + /** * Add a timewindow element to the form. * 2 datepicker elements are added and a rule to check if the first date is