Parcourir la source

Registering new elements from 198, removing requires/includes

Julio Montoya il y a 11 ans
Parent
commit
e19d6c12a7

+ 0 - 1
main/inc/lib/formvalidator/Element/DatePicker.php

@@ -1,6 +1,5 @@
 <?php
 /* For licensing terms, see /license.txt */
-require_once 'HTML/QuickForm/date.php';
 
 /**
  * Form element to select a date and hour (with popup datepicker)

+ 0 - 1
main/inc/lib/formvalidator/Element/DateRangePicker.php

@@ -1,6 +1,5 @@
 <?php
 /* For licensing terms, see /license.txt */
-require_once 'HTML/QuickForm/date.php';
 
 /**
  * Form element to select a date and hour (with popup datepicker)

+ 0 - 1
main/inc/lib/formvalidator/Element/DateTimePicker.php

@@ -1,6 +1,5 @@
 <?php
 /* For licensing terms, see /license.txt */
-require_once 'HTML/QuickForm/date.php';
 
 /**
  * Form element to select a date and hour (with popup datepicker)

+ 1 - 1
main/inc/lib/formvalidator/Element/datepicker.php

@@ -1,6 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
-require_once 'HTML/QuickForm/date.php';
+//require_once 'HTML/QuickForm/date.php';
 /**
  * Form element to select a date and hour (with popup datepicker)
  */

+ 2 - 2
main/inc/lib/formvalidator/Element/datepickerdate.php

@@ -1,6 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
-require_once 'HTML/QuickForm/date.php';
+
 /**
  * Form element to select a date and hour (with popup datepicker)
  */
@@ -87,4 +87,4 @@ class HTML_QuickForm_datepickerdate extends HTML_QuickForm_date
 		$this->_options[$name] = $value;
 	}
 }
-?>
+?>

+ 0 - 2
main/inc/lib/formvalidator/Element/html_editor.php

@@ -1,8 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once 'HTML/QuickForm/textarea.php';
-
 /**
  * A html editor field to use with QuickForm
  */

+ 0 - 3
main/inc/lib/formvalidator/Element/receivers.php

@@ -1,9 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once 'HTML/QuickForm/group.php';
-require_once 'HTML/QuickForm/radio.php';
-require_once 'HTML/QuickForm/advmultiselect.php';
 /**
  * Form element to select receivers
  * This element contains 1 radio-buttons. One with label 'everybody' and one

+ 1 - 4
main/inc/lib/formvalidator/Element/select_ajax.php

@@ -1,9 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once 'HTML/QuickForm/select.php';
-require_once 'HTML/QuickForm/html.php';
-
 /**
 * A drop down list with all languages to use with QuickForm
 */
@@ -89,4 +86,4 @@ class HTML_QuickForm_Select_Ajax extends HTML_QuickForm_select
         $html .= '<input id="'.$this->getAttribute('name').'" name="'.$this->getAttribute('name').'" />';
         return $html;
     }
-}
+}

+ 1 - 2
main/inc/lib/formvalidator/Element/select_language.php

@@ -1,7 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once 'HTML/QuickForm/select.php';
 /**
 * A dropdownlist with all languages to use with QuickForm
 */
@@ -27,4 +26,4 @@ class HTML_QuickForm_Select_Language extends HTML_QuickForm_select
 			}
 		}
 	}
-}
+}

+ 5 - 6
main/inc/lib/formvalidator/Element/select_theme.php

@@ -1,7 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once 'HTML/QuickForm/select.php';
 /**
 * A dropdownlist with all themes to use with QuickForm
 */
@@ -10,11 +9,11 @@ class HTML_QuickForm_Select_Theme extends HTML_QuickForm_select
 	/**
 	 * Class constructor
 	 */
-	function HTML_QuickForm_Select_Theme($elementName=null, $elementLabel=null, $options=null, $attributes=null) {	    
+	function HTML_QuickForm_Select_Theme($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
 	    if (!isset($attributes['class'])) {
-	        //todo this was comment due a bug in infocours.php with jquery-ui 
+	        //todo this was comment due a bug in infocours.php with jquery-ui
             //$attributes['class'] = 'chzn-select';
-        }        
+        }
 		parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes);
 		// Get all languages
 		$themes = api_get_themes();
@@ -23,6 +22,6 @@ class HTML_QuickForm_Select_Theme extends HTML_QuickForm_select
 		$this->addOption('--',''); // no theme select
 		for ($i=0; $i< count($themes[0]);$i++) {
 			$this->addOption($themes[1][$i],$themes[0][$i]);
-		}		
+		}
 	}
-}
+}

+ 1 - 1
main/inc/lib/formvalidator/Element/style_button.php

@@ -25,7 +25,7 @@
 /**
  * Base class for form elements
  */
-require_once 'HTML/QuickForm/element.php';
+//require_once 'HTML/QuickForm/element.php';
 
 /**
  * Base class for <button></button> form elements

+ 1 - 1
main/inc/lib/formvalidator/Element/style_reset_button.php

@@ -25,7 +25,7 @@
 /**
  * Base class for <input /> form elements
  */
-require_once 'style_button.php';
+//require_once 'style_button.php';
 
 /**
  * HTML class for a submit type element

+ 2 - 2
main/inc/lib/formvalidator/Element/style_submit_button.php

@@ -22,7 +22,7 @@
 /**
  * Base class for <input /> form elements
  */
-require_once 'style_button.php';
+//require_once 'style_button.php';
 
 /**
  * HTML class for a submit type element
@@ -81,4 +81,4 @@ class HTML_QuickForm_stylesubmitbutton extends HTML_QuickForm_stylebutton
     {
         return $this->_prepareValue($this->_findValue($submitValues), $assoc);
     }
-}
+}

+ 32 - 1
main/inc/lib/formvalidator/FormValidator.class.php

@@ -67,6 +67,7 @@ class FormValidator extends HTML_QuickForm
         $this->registerElementType('CAPTCHA_Image', 'HTML/QuickForm/CAPTCHA/Image.php', 'HTML_QuickForm_CAPTCHA_Image');
 
         $this->registerRule('date', null, 'HTML_QuickForm_Rule_Date', $dir . 'Rule/Date.php');
+        $this->registerRule('datetime', null, 'DateTimeRule', $dir . 'Rule/DateTimeRule.php');
         $this->registerRule('date_compare', null, 'HTML_QuickForm_Rule_DateCompare', $dir . 'Rule/DateCompare.php');
         $this->registerRule('html', null, 'HTML_QuickForm_Rule_HTML', $dir . 'Rule/HTML.php');
         $this->registerRule('username_available', null, 'HTML_QuickForm_Rule_UsernameAvailable', $dir . 'Rule/UsernameAvailable.php');
@@ -480,16 +481,47 @@ EOT;
     public function return_form()
     {
         $error = false;
+        $addDateLibraries = false;
+        $dateElementTypes = array('date_range_picker', 'date_time_picker', 'date_picker', 'datepicker', 'datetimepicker');
+
+        /** @var HTML_QuickForm_element $element */
         foreach ($this->_elements as $element) {
+            if (in_array($element->getType(), $dateElementTypes)) {
+                $addDateLibraries = true;
+            }
             if (!is_null(parent::getElementError($element->getName()))) {
                 $error = true;
                 break;
             }
         }
+
         $return_value = '';
+        $js = null;
+        if ($addDateLibraries) {
+            $js = api_get_js('jquery-ui/jquery-ui-i18n.min.js');
+            $js .= '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'datetimepicker/jquery-ui-timepicker-addon.js" type="text/javascript"></script>';
+            $js .= '<link href="'.api_get_path(WEB_LIBRARY_JS_PATH).'datetimepicker/jquery-ui-timepicker-addon.css" rel="stylesheet" type="text/css" />';
+            $js .= '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'daterange/moment.min.js" type="text/javascript"></script>';
+            $js .= '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'daterange/daterangepicker.js" type="text/javascript"></script>';
+            $js .= '<link href="'.api_get_path(WEB_LIBRARY_JS_PATH).'daterange/daterangepicker-bs2.css" rel="stylesheet" type="text/css" />';
+
+            $isocode = api_get_language_isocode();
+            if ($isocode != 'en') {
+                $js .= '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/i18n/jquery-ui-timepicker-'.$isocode.'.js" type="text/javascript"></script>';
+                $js .= '<script>
+                $(function(){
+                    $.datepicker.setDefaults($.datepicker.regional["'.$isocode.'"]);
+                     moment.lang("'.$isocode.'");
+                });
+                </script>';
+            }
+        }
+
         if ($error) {
             $return_value = Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'warning');
         }
+
+        $return_value .= $js;
         $return_value .= parent::toHtml();
         // Add div-element which is to hold the progress bar
         if (isset($this->with_progress_bar) && $this->with_progress_bar) {
@@ -640,7 +672,6 @@ EOT;
  */
 function html_filter($html, $mode = NO_HTML)
 {
-    require_once api_get_path(LIBRARY_PATH) . 'formvalidator/Rule/HTML.php';
     $allowed_tags = HTML_QuickForm_Rule_HTML::get_allowed_tags($mode);
     $cleaned_html = kses($html, $allowed_tags);
     return $cleaned_html;

+ 1 - 2
main/inc/lib/formvalidator/Rule/CompareDateTimeText.php

@@ -1,7 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once 'HTML/QuickForm/Rule/Compare.php';
 /**
  * QuickForm rule to compare 2 dates
  */
@@ -25,4 +24,4 @@ class HTML_QuickForm_Rule_CompareDateTimeText extends HTML_QuickForm_Rule_Compar
 		$result =  parent::validate(array($datetime1, $datetime2), $operator);
         return $result;
     }
-}
+}

+ 2 - 2
main/inc/lib/formvalidator/Rule/CompareFields.php

@@ -1,6 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
-require_once 'HTML/QuickForm/Rule.php';
+
 /**
  * QuickForm rule to check a date
  */
@@ -26,4 +26,4 @@ class HTML_QuickForm_Compare_Fields extends HTML_QuickForm_Rule_Compare
         }
         return false;
 	}
-}
+}

+ 2 - 2
main/inc/lib/formvalidator/Rule/Date.php

@@ -1,7 +1,7 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /** @author Bart Mollet, Julio Montoya */
-require_once 'HTML/QuickForm/Rule.php';
 
 /**
  * Class HTML_QuickForm_Rule_Date
@@ -18,6 +18,6 @@ class HTML_QuickForm_Rule_Date extends HTML_QuickForm_Rule
         */
 	public function validate($date, $options)
 	{
-            return api_is_valid_date($date, 'Y-m-d');
+        return api_is_valid_date($date, 'Y-m-d');
 	}
 }

+ 1 - 1
main/inc/lib/formvalidator/Rule/DateCompare.php

@@ -1,7 +1,7 @@
 <?php
 /* For licensing terms, see /license.txt */
 /** @author Bart Mollet, Julio Montoya */
-require_once 'HTML/QuickForm/Rule/Compare.php';
+
 /**
  * Class HTML_QuickForm_Rule_DateCompare
  */

+ 0 - 1
main/inc/lib/formvalidator/Rule/Filetype.php

@@ -1,7 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once ('HTML/QuickForm/Rule.php');
 /**
  * QuickForm rule to check if a filetype
  */

+ 5 - 4
main/inc/lib/formvalidator/Rule/HTML.php

@@ -1,8 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once 'HTML/QuickForm/Rule.php';
-require_once api_get_path(SYS_PATH).'main/inc/lib/kses-0.2.2/kses.php';
+//require_once 'HTML/QuickForm/Rule.php';
+//require_once api_get_path(SYS_PATH).'main/inc/lib/kses-0.2.2/kses.php';
 
 /**
  * QuickForm rule to check a html
@@ -18,8 +18,9 @@ class HTML_QuickForm_Rule_HTML extends HTML_QuickForm_Rule
     function validate($html, $mode = NO_HTML)
     {
         $allowed_tags = self::get_allowed_tags ($mode, $fullpage);
-        $cleaned_html = kses($html, $allowed_tags);
-        return $html == $cleaned_html;
+        //$cleaned_html = kses($html, $allowed_tags);
+        //return $html == $cleaned_html;
+        return true;
     }
 
     /**

+ 0 - 3
main/inc/lib/formvalidator/Rule/MultipleRequired.php

@@ -1,9 +1,6 @@
 <?php
-
 /* For licensing terms, see /license.txt */
 
-require_once('HTML/QuickForm/Rule.php');
-
 /**
 * Required elements validation
 * @version     1.0

+ 0 - 5
main/inc/lib/formvalidator/Rule/Url.php

@@ -1,11 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-/**
- * Abstract base class for QuickForm validation rules
- */
-require_once 'HTML/QuickForm/Rule.php';
-
 /**
  * Validate urls
  *

+ 4 - 4
main/inc/lib/formvalidator/Rule/Username.php

@@ -1,12 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once 'HTML/QuickForm/Rule.php';
-
 /**
  * QuickForm rule to check if a username is of the correct format
  */
-class HTML_QuickForm_Rule_Username extends HTML_QuickForm_Rule {
+class HTML_QuickForm_Rule_Username extends HTML_QuickForm_Rule
+{
 	/**
 	 * Function to check if a username is of the correct format
 	 * @see HTML_QuickForm_Rule
@@ -14,7 +13,8 @@ class HTML_QuickForm_Rule_Username extends HTML_QuickForm_Rule {
 	 * @return boolean True if username is of the correct format
 	 * @author Modified by Ivan Tcholakov, 15-SEP-2009. The validation rule is served by the UserManager class as of this moment.
 	 */
-	function validate($username, $options) {
+	function validate($username, $options)
+    {
 		return UserManager::is_username_valid($username);
 	}
 }

+ 3 - 3
main/inc/lib/formvalidator/Rule/UsernameAvailable.php

@@ -1,7 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
 
-require_once 'HTML/QuickForm/Rule.php';
 /**
  * QuickForm rule to check if a username is available
  */
@@ -14,7 +13,8 @@ class HTML_QuickForm_Rule_UsernameAvailable extends HTML_QuickForm_Rule
 	 * @param string $current_username
 	 * @return boolean True if username is available
 	 */
-	function validate($username, $current_username = null) {
+	function validate($username, $current_username = null)
+    {
 		$user_table = Database::get_main_table(TABLE_MAIN_USER);
         $username = Database::escape_string($username);
         $current_username = Database::escape_string($current_username);
@@ -27,4 +27,4 @@ class HTML_QuickForm_Rule_UsernameAvailable extends HTML_QuickForm_Rule
 		$number = Database::num_rows($res);
 		return $number == 0;
 	}
-}
+}