From 41acfabcf17716632775e81144035b2b70379809 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Mar 2015 12:40:38 +0100 Subject: [PATCH] Add new form layout LAYOUT_BOX_NO_LABEL used in the login page. --- main/admin/user_add.php | 2 +- main/css/base.css | 6 +- main/document/document.php | 16 +- main/glossary/glossary_form.class.php | 2 +- main/glossary/index.php | 2 +- main/inc/lib/course.lib.php | 15 +- .../lib/formvalidator/Element/DatePicker.php | 2 +- .../formvalidator/Element/DatePickerDate.php | 87 ------- .../formvalidator/Element/DateRangePicker.php | 2 +- .../formvalidator/Element/DateTimePicker.php | 2 +- .../lib/formvalidator/Element/HtmlEditor.php | 4 +- main/inc/lib/formvalidator/Element/Number.php | 2 +- .../formvalidator/Element/calendar_popup.php | 3 + .../formvalidator/Element/style_button.php | 220 ------------------ .../Element/style_reset_button.php | 84 ------- .../Element/style_submit_button.php | 91 ++++++-- .../lib/formvalidator/FormValidator.class.php | 89 ++++--- main/inc/lib/pear/HTML/QuickForm.php | 3 +- main/inc/lib/pear/HTML/QuickForm/CAPTCHA.php | 2 +- .../pear/HTML/QuickForm/Renderer/Default.php | 73 ++++-- .../pear/HTML/QuickForm/advmultiselect.php | 17 +- main/inc/lib/pear/HTML/QuickForm/button.php | 48 ++++ main/inc/lib/pear/HTML/QuickForm/checkbox.php | 2 +- main/inc/lib/pear/HTML/QuickForm/element.php | 51 +++- main/inc/lib/pear/HTML/QuickForm/email.php | 2 +- main/inc/lib/pear/HTML/QuickForm/file.php | 2 +- main/inc/lib/pear/HTML/QuickForm/group.php | 2 +- main/inc/lib/pear/HTML/QuickForm/hidden.php | 2 +- .../lib/pear/HTML/QuickForm/hiddenselect.php | 2 +- main/inc/lib/pear/HTML/QuickForm/image.php | 2 +- main/inc/lib/pear/HTML/QuickForm/input.php | 12 +- main/inc/lib/pear/HTML/QuickForm/link.php | 2 +- main/inc/lib/pear/HTML/QuickForm/password.php | 35 +-- main/inc/lib/pear/HTML/QuickForm/radio.php | 5 +- main/inc/lib/pear/HTML/QuickForm/reset.php | 2 +- main/inc/lib/pear/HTML/QuickForm/select.php | 60 ++++- main/inc/lib/pear/HTML/QuickForm/submit.php | 2 +- main/inc/lib/pear/HTML/QuickForm/text.php | 105 ++++++--- main/inc/lib/userportal.lib.php | 77 +++--- 39 files changed, 537 insertions(+), 600 deletions(-) delete mode 100644 main/inc/lib/formvalidator/Element/DatePickerDate.php delete mode 100755 main/inc/lib/formvalidator/Element/style_button.php delete mode 100755 main/inc/lib/formvalidator/Element/style_reset_button.php diff --git a/main/admin/user_add.php b/main/admin/user_add.php index 7b64df8261..17a2d1eb71 100755 --- a/main/admin/user_add.php +++ b/main/admin/user_add.php @@ -275,7 +275,7 @@ $form->setDefaults($defaults); // Submit button $html_results_enabled[] = $form->createElement('button', 'submit', get_lang('Add'), 'plus', 'primary'); -$html_results_enabled[] = $form->createElement('button', 'submit_plus', get_lang('Add').'+'); +$html_results_enabled[] = $form->createElement('button', 'submit_plus', get_lang('Add').'+', 'plus', 'primary'); $form->addGroup($html_results_enabled); diff --git a/main/css/base.css b/main/css/base.css index 3d5c84f123..10f4d2c9ce 100755 --- a/main/css/base.css +++ b/main/css/base.css @@ -5484,4 +5484,8 @@ i.size-32.icon-new-work{ background-image: -o-linear-gradient(top, #3cb0fd, #3498db); background-image: linear-gradient(to bottom, #3cb0fd, #3498db); text-decoration: none; -} \ No newline at end of file +} + +.actions .form-inline { + display:inline-block; +} diff --git a/main/document/document.php b/main/document/document.php index 423716cfe9..8a7b1f98c6 100755 --- a/main/document/document.php +++ b/main/document/document.php @@ -1509,17 +1509,21 @@ if (!isset($folders) || $folders === false) { $actions = '
'; if (!$is_certificate_mode) { /* BUILD SEARCH FORM */ - $actions .= ''; - $form = new FormValidator('search_document', 'get', api_get_self().'?'.api_get_cidreq()); - $renderer = & $form->defaultRenderer(); - $renderer->setElementTemplate('{element} '); + + $form = new FormValidator( + 'search_document', + 'get', + api_get_self().'?'.api_get_cidreq(), + '', + array(), + FormValidator::LAYOUT_INLINE + ); $form->addText('keyword', '', false, array('class' => 'col-md-2')); $form->addElement('hidden', 'cidReq', api_get_course_id()); $form->addElement('hidden', 'id_session', api_get_session_id()); $form->addElement('hidden', 'gidReq', $groupId); $form->addButtonSearch(get_lang('Search')); - $actions .= $form->return_form(); - $actions .= ''; + $actions .= $form->returnForm(); } /* GO TO PARENT DIRECTORY */ diff --git a/main/glossary/glossary_form.class.php b/main/glossary/glossary_form.class.php index c61aa721bf..71cc453ce4 100755 --- a/main/glossary/glossary_form.class.php +++ b/main/glossary/glossary_form.class.php @@ -77,7 +77,7 @@ class GlossaryForm extends \FormValidator $this->addHeader($form_name); $this->addText('name', get_lang('TermName'), $required = true, array('class' => 'span3')); - $this->addHtmlEditor('description', get_lang('TermDefinition'), true, array('ToolbarSet' => 'Glossary', 'Width' => '90%', 'Height' => '300')); + $this->addHtmlEditor('description', get_lang('TermDefinition'), true, array('ToolbarSet' => 'Glossary', 'Height' => '300')); $this->addButton('save', get_lang('Save')); $this->setDefaults($defaults); diff --git a/main/glossary/index.php b/main/glossary/index.php index 2782e3e573..ae355bf8c2 100755 --- a/main/glossary/index.php +++ b/main/glossary/index.php @@ -134,7 +134,7 @@ if (api_is_allowed_to_edit(null, true)) { $form->addElement('hidden', 'glossary_id'); $form->addElement('text', 'glossary_title', get_lang('TermName'),array('size'=>'80')); //$form->applyFilter('glossary_title', 'html_filter'); - $form->addElement('html_editor', 'glossary_comment', get_lang('TermDefinition'), null, array('ToolbarSet' => 'Glossary', 'Width' => '90%', 'Height' => '300')); + $form->addElement('html_editor', 'glossary_comment', get_lang('TermDefinition'), null, array('ToolbarSet' => 'Glossary', 'Height' => '300')); $element = $form->addElement('text', 'insert_date', get_lang('CreationDate'),array('size'=>'100')); $element->freeze(); $element = $form->addElement('text', 'update_date', get_lang('UpdateDate'),array('size'=>'100')); diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 4ca487b466..f15b5470f6 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3299,7 +3299,7 @@ class CourseManager $notifications = isset($params['notifications']) ? $params['notifications'] : null; $html.= $params['title']. $notifications; $html.=''; - + return $html; } @@ -5321,8 +5321,13 @@ class CourseManager $result[$content['value']] = $content['content']; } - $group = $form->addElement('advmultiselect', 'users', get_lang('Users'), $result, - array('select_all_checkbox' => true)); + $form->addElement( + 'advmultiselect', + 'users', + get_lang('Users'), + $result, + array('select_all_checkbox' => true) + ); } /** @@ -5344,7 +5349,7 @@ class CourseManager $result[$content['value']] = $content['content']; } - $group = $form->addElement('advmultiselect', 'users', get_lang('Users'), $result); + $form->addElement('advmultiselect', 'users', get_lang('Users'), $result); } /** @@ -5375,7 +5380,7 @@ class CourseManager ) { // $to_already_selected is the array containing the groups (and users) that are already selected $user_label = ($this_group['userNb'] > 0) ? get_lang('Users') : get_lang('LowerCaseUser'); $user_disabled = ($this_group['userNb'] > 0) ? "" : "disabled=disabled"; - $result [] = array( + $result[] = array( 'disabled' => $user_disabled, 'value' => "GROUP:" . $this_group['id'], 'content' => "G: " . $this_group['name'] . " - " . $this_group['userNb'] . " " . $user_label diff --git a/main/inc/lib/formvalidator/Element/DatePicker.php b/main/inc/lib/formvalidator/Element/DatePicker.php index 7b87aed88e..c89a173492 100755 --- a/main/inc/lib/formvalidator/Element/DatePicker.php +++ b/main/inc/lib/formvalidator/Element/DatePicker.php @@ -20,7 +20,7 @@ class DatePicker extends HTML_QuickForm_text } $attributes['class'] = 'form-control'; - HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->_appendName = true; $this->_type = 'date_picker'; } diff --git a/main/inc/lib/formvalidator/Element/DatePickerDate.php b/main/inc/lib/formvalidator/Element/DatePickerDate.php deleted file mode 100644 index 3327ebc5b6..0000000000 --- a/main/inc/lib/formvalidator/Element/DatePickerDate.php +++ /dev/null @@ -1,87 +0,0 @@ -_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 $char) { - $popup_link = str_replace($char, "\\".$char, $popup_link); - } - $lang_code = api_get_language_isocode(); - // If translation not available in PEAR::HTML_QuickForm_date, add the Chamilo-translation - if (! array_key_exists($lang_code,$this->_locale)) { - $this->_locale[$lang_code]['months_long'] = api_get_months_long(); - } - $this->_options['format'] = 'dFY '.$popup_link; - $this->_options['minYear'] = date('Y')-5; - $this->_options['maxYear'] = date('Y')+10; - $this->_options['language'] = $lang_code; - } - - /** - * 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(&$submitValues, $assoc = false) - { - $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; - } - /** - * Sets an option to a value - */ - function setLocalOption($name,$value) - { - $this->_options[$name] = $value; - } -} diff --git a/main/inc/lib/formvalidator/Element/DateRangePicker.php b/main/inc/lib/formvalidator/Element/DateRangePicker.php index cd5feef9ad..13a7db89f1 100755 --- a/main/inc/lib/formvalidator/Element/DateRangePicker.php +++ b/main/inc/lib/formvalidator/Element/DateRangePicker.php @@ -15,7 +15,7 @@ class DateRangePicker extends HTML_QuickForm_text $attributes['id'] = $elementName; } $attributes['class'] = 'form-control'; - HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->_appendName = true; $this->_type = 'date_range_picker'; } diff --git a/main/inc/lib/formvalidator/Element/DateTimePicker.php b/main/inc/lib/formvalidator/Element/DateTimePicker.php index a0bf717a2b..34e5fadc63 100755 --- a/main/inc/lib/formvalidator/Element/DateTimePicker.php +++ b/main/inc/lib/formvalidator/Element/DateTimePicker.php @@ -15,7 +15,7 @@ class DateTimePicker extends HTML_QuickForm_text $attributes['id'] = $elementName; } $attributes['class'] = 'form-control'; - HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->_appendName = true; $this->_type = 'date_time_picker'; } diff --git a/main/inc/lib/formvalidator/Element/HtmlEditor.php b/main/inc/lib/formvalidator/Element/HtmlEditor.php index 0b47341a4c..ddf73654ae 100644 --- a/main/inc/lib/formvalidator/Element/HtmlEditor.php +++ b/main/inc/lib/formvalidator/Element/HtmlEditor.php @@ -24,7 +24,7 @@ class HtmlEditor extends HTML_QuickForm_textarea * @param array $config Optional configuration settings for the online editor. * @return bool */ - public function HtmlEditor( + public function __construct( $name = null, $elementLabel = null, $attributes = null, @@ -34,7 +34,7 @@ class HtmlEditor extends HTML_QuickForm_textarea return false; } - HTML_QuickForm_element :: HTML_QuickForm_element($name, $elementLabel, $attributes); + parent::__construct($name, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_type = 'html_editor'; diff --git a/main/inc/lib/formvalidator/Element/Number.php b/main/inc/lib/formvalidator/Element/Number.php index 77945ddcd5..aa231a2fed 100644 --- a/main/inc/lib/formvalidator/Element/Number.php +++ b/main/inc/lib/formvalidator/Element/Number.php @@ -22,7 +22,7 @@ class Number extends HTML_QuickForm_text $attributes['type'] = 'number'; $attributes['class'] = 'form-control'; - HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->_appendName = true; $this->_type = 'number'; } diff --git a/main/inc/lib/formvalidator/Element/calendar_popup.php b/main/inc/lib/formvalidator/Element/calendar_popup.php index 2ada117a6f..8b141184e5 100755 --- a/main/inc/lib/formvalidator/Element/calendar_popup.php +++ b/main/inc/lib/formvalidator/Element/calendar_popup.php @@ -1,5 +1,8 @@ form elements - * - * PHP versions 4 and 5 - * - * LICENSE: This source file is subject to version 3.01 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_01.txt If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. - * - * @category HTML - * @package HTML_QuickForm - * @author Adam Daniel - * @author Bertrand Mansion - * @copyright 2001-2007 The PHP Group - * @license http://www.php.net/license/3_01.txt PHP License 3.01 - * @version CVS: $Id: input.php 17344 2008-12-17 08:55:29Z Scara84 $ - * @link http://pear.php.net/package/HTML_QuickForm - */ - -/** - * Base class for form elements - * - * @category HTML - * @package HTML_QuickForm - * @author Hans De Bisschop - * @abstract - */ -class HTML_QuickForm_style_button extends HTML_QuickForm_element -{ - // {{{ constructor - /** - * Class constructor - * - * @param string Input field name attribute - * @param mixed Label(s) for the input field - * @param mixed Either a typical HTML attribute string or an associative array - * @since 1.0 - * @access public - * @return void - */ - function HTML_QuickForm_style_button($elementName=null, $elementLabel=null, $attributes=null) - { - $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); - - } //end constructor - - // }}} - // {{{ setType() - - /** - * Sets the element type - * - * @param string $type Element type - * @since 1.0 - * @access public - * @return void - */ - - - /* Returns an HTML formatted attribute string - * @param array $attributes - * @return string - * @access private - */ - function _getAttrString($attributes) { - $strAttr = ''; - if (is_array($attributes)) { - foreach ($attributes as $key => $value) { - if ($key != 'value') $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"'; - } - } - return $strAttr; - } // end func _getAttrString - - - function setType($type) - { - $this->_type = $type; - $this->updateAttributes(array('type'=>$type)); - } // end func setType - - // }}} - // {{{ setName() - - /** - * Sets the input field name - * - * @param string $name Input field name attribute - * @since 1.0 - * @access public - * @return void - */ - function setName($name) - { - $this->updateAttributes(array('name'=>$name)); - } //end func setName - - // }}} - // {{{ getName() - - /** - * Returns the element name - * - * @since 1.0 - * @access public - * @return string - */ - function getName() - { - return $this->getAttribute('name'); - } //end func getName - - // }}} - // {{{ setValue() - - /** - * Sets the value of the form element - * - * @param string $value Default value of the form element - * @since 1.0 - * @access public - * @return void - */ - function setValue($value) - { - $this->updateAttributes(array('value'=>$value)); - } // end func setValue - - // }}} - // {{{ getValue() - - /** - * Returns the value of the form element - * - * @since 1.0 - * @access public - * @return string - */ - function getValue() - { - //return $this->getAttribute('value'); - return $this->_attributes['value']; - } // end func getValue - - // }}} - // {{{ toHtml() - - /** - * Returns the input field in HTML - * - * @since 1.0 - * @access public - * @return string - */ - function toHtml() { - if ($this->_flagFrozen) { - return $this->getFrozenHtml(); - } else { - //Adding the btn class - if (isset($this->_attributes['class'])) { - $this->_attributes['class'] = 'btn '.$this->_attributes['class']; - } - return $this->_getTabs().''; - } - } //end func toHtml - - // }}} - // {{{ onQuickFormEvent() - - /** - * Called by HTML_QuickForm whenever form event is made on this element - * - * @param string $event Name of event - * @param mixed $arg event arguments - * @param object &$caller calling object - * @since 1.0 - * @access public - * @return void - * @throws - */ - function onQuickFormEvent($event, $arg, &$caller) - { - // do not use submit values for button-type elements - $type = $this->getType(); - if (('updateValue' != $event) || - ('submit' != $type && 'reset' != $type && 'button' != $type)) { - parent::onQuickFormEvent($event, $arg, $caller); - } else { - $value = $this->_findValue($caller->_constantValues); - if (null === $value) { - $value = $this->_findValue($caller->_defaultValues); - } - if (null !== $value) { - $this->setValue($value); - } - } - return true; - } // end func onQuickFormEvent - - // }}} - // {{{ exportValue() - - /** - * We don't need values from button-type elements (except submit) and files - */ - function exportValue(&$submitValues, $assoc = false) - { - $type = $this->getType(); - if ('reset' == $type || 'button' == $type) { - return null; - } else { - return parent::exportValue($submitValues, $assoc); - } - } -} // end class HTML_QuickForm_element diff --git a/main/inc/lib/formvalidator/Element/style_reset_button.php b/main/inc/lib/formvalidator/Element/style_reset_button.php deleted file mode 100755 index 160e8084fa..0000000000 --- a/main/inc/lib/formvalidator/Element/style_reset_button.php +++ /dev/null @@ -1,84 +0,0 @@ - - * @author Bertrand Mansion - * @copyright 2001-2007 The PHP Group - * @license http://www.php.net/license/3_01.txt PHP License 3.01 - * @version CVS: $Id: submit.php 17344 2008-12-17 08:55:29Z Scara84 $ - * @link http://pear.php.net/package/HTML_QuickForm - */ - -/** - * HTML class for a submit type element - * - * @category HTML - * @package HTML_QuickForm - * @author Adam Daniel - * @author Bertrand Mansion - * @version Release: 3.2.10 - * @since 1.0 - */ -class HTML_QuickForm_styleresetbutton extends HTML_QuickForm_style_button -{ - // {{{ constructor - - /** - * Class constructor - * - * @param string Input field name attribute - * @param string Input field value - * @param mixed Either a typical HTML attribute string or an associative array - * @since 1.0 - * @access public - * @return void - */ - function HTML_QuickForm_styleresetbutton($elementName=null, $value=null, $attributes=null) - { - HTML_QuickForm_style_button::HTML_QuickForm_style_button($elementName, null, $attributes, $value); - $this->setValue($value); - $this->setType('reset'); - } //end constructor - - // }}} - // {{{ freeze() - - /** - * Freeze the element so that only its value is returned - * - * @access public - * @return void - */ - function freeze() - { - return false; - } //end func freeze - - // }}} - // {{{ exportValue() - - /** - * Only return the value if it is found within $submitValues (i.e. if - * this particular submit button was clicked) - */ - function exportValue(&$submitValues, $assoc = false) - { - return $this->_prepareValue($this->_findValue($submitValues), $assoc); - } - - // }}} -} //end class HTML_QuickForm_submit -?> diff --git a/main/inc/lib/formvalidator/Element/style_submit_button.php b/main/inc/lib/formvalidator/Element/style_submit_button.php index 91d6bda972..5ad51c3d71 100755 --- a/main/inc/lib/formvalidator/Element/style_submit_button.php +++ b/main/inc/lib/formvalidator/Element/style_submit_button.php @@ -32,10 +32,8 @@ * @version Release: 3.2.10 * @since 1.0 */ -class HTML_QuickForm_style_submit_button extends HTML_QuickForm_style_button +class HTML_QuickForm_style_submit_button extends HTML_QuickForm_input { - // {{{ constructor - /** * Class constructor * @@ -46,7 +44,8 @@ class HTML_QuickForm_style_submit_button extends HTML_QuickForm_style_button * @access public * @return void */ - function HTML_QuickForm_style_submit_button($elementName = null, $value = null, $attributes = null, $img = null) { + public function __construct($elementName = null, $value = null, $attributes = null, $img = null) + { if (empty($attributes)) { $attributes = array(); } @@ -56,10 +55,10 @@ class HTML_QuickForm_style_submit_button extends HTML_QuickForm_style_button $attributes['class'] = 'btn'; } } - HTML_QuickForm_style_button::HTML_QuickForm_style_button($elementName, null, $attributes, $value, $img); + parent::__construct($elementName, null, $attributes, $value, $img); $this->setValue($value); $this->setType('submit'); - } //end constructor + } /** * Freeze the element so that only its value is returned @@ -67,19 +66,83 @@ class HTML_QuickForm_style_submit_button extends HTML_QuickForm_style_button * @access public * @return void */ - function freeze() { + public function freeze() + { return false; - } //end func freeze - - // }}} - // {{{ exportValue() + } /** * Only return the value if it is found within $submitValues (i.e. if * this particular submit button was clicked) */ - function exportValue(&$submitValues, $assoc = false) { + public function exportValue(&$submitValues, $assoc = false) + { return $this->_prepareValue($this->_findValue($submitValues), $assoc); } - // }}} -} //end class HTML_QuickForm_submit + + /** + * @return string + */ + public function toHtml() + { + if ($this->_flagFrozen) { + return $this->getFrozenHtml(); + } else { + //Adding the btn class + if (isset($this->_attributes['class'])) { + $this->_attributes['class'] = 'btn '.$this->_attributes['class']; + } + return ''; + } + } + + /** + * Called by HTML_QuickForm whenever form event is made on this element + * + * @param string $event Name of event + * @param mixed $arg event arguments + * @param object &$caller calling object + * @since 1.0 + * @access public + * @return void + * @throws + */ + public function onQuickFormEvent($event, $arg, &$caller) + { + // do not use submit values for button-type elements + $type = $this->getType(); + if (('updateValue' != $event) || + ('submit' != $type && 'reset' != $type && 'button' != $type)) { + parent::onQuickFormEvent($event, $arg, $caller); + } else { + $value = $this->_findValue($caller->_constantValues); + if (null === $value) { + $value = $this->_findValue($caller->_defaultValues); + } + if (null !== $value) { + $this->setValue($value); + } + } + + return true; + } + + /** + * Returns an HTML formatted attribute string + * @param array $attributes + * @return string + * @access private + */ + public function _getAttrString($attributes) + { + $strAttr = ''; + if (is_array($attributes)) { + foreach ($attributes as $key => $value) { + if ($key != 'value') $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"'; + } + } + + return $strAttr; + } + +} diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 9b689a1943..9050abc388 100755 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -9,7 +9,11 @@ class FormValidator extends HTML_QuickForm { const LAYOUT_HORIZONTAL = 'horizontal'; const LAYOUT_INLINE = 'inline'; + const LAYOUT_BOX = 'box'; + const LAYOUT_BOX_NO_LABEL = 'box-no-label'; + public $with_progress_bar = false; + private $layout; /** * Constructor @@ -27,7 +31,7 @@ class FormValidator extends HTML_QuickForm $method = 'post', $action = '', $target = '', - $attributes = null, + $attributes = array(), $layout = self::LAYOUT_HORIZONTAL, $trackSubmit = true ) { @@ -40,11 +44,14 @@ class FormValidator extends HTML_QuickForm $layout = 'inline'; } + $this->setLayout($layout); + switch ($layout) { case self::LAYOUT_HORIZONTAL: $attributes['class'] = 'form-horizontal'; break; case self::LAYOUT_INLINE: + case self::LAYOUT_BOX: $attributes['class'] = 'form-inline'; break; } @@ -82,7 +89,7 @@ class FormValidator extends HTML_QuickForm $elementTemplate = ' {label} {element} '; $renderer->setElementTemplate($elementTemplate); } else { - $renderer->setElementTemplate($this->getElementTemplate()); + $renderer->setElementTemplate($this->getDefaultElementTemplate()); // Display a gray div in the buttons $templateSimple = '
{label} {element}
'; @@ -135,7 +142,7 @@ EOT; /** * @return string */ - public function getElementTemplate() + public function getDefaultElementTemplate() { return '
@@ -144,6 +151,7 @@ EOT; {label}
+ {icon} {element} @@ -162,6 +170,23 @@ EOT;
'; } + /** + * @return string + */ + public function getLayout() + { + return $this->layout; + } + + /** + * @param string $layout + */ + public function setLayout($layout) + { + $this->layout = $layout; + } + + /** * Adds a text field to the form. * A trim-filter is attached to the field. @@ -606,11 +631,13 @@ EOT; * @param string $label The label for the form-element * @param bool $required (optional) Is the form-element required (default=true) * @param bool $fullPage (optional) When it is true, the editor loads completed html code for a full page. - * @param array $config (optional) Configuration settings for the online editor. + * @param array $config (optional) Configuration settings for the online editor. */ public function addHtmlEditor($name, $label, $required = true, $fullPage = false, $config = array()) { - $this->addElement('html_editor', $name, $label, 'rows="15" cols="80"', $config); + $config['rows'] = isset($config['rows']) ? $config['rows'] : 15; + $config['cols'] = isset($config['cols']) ? $config['cols'] : 80; + $this->addElement('html_editor', $name, $label, $config); $this->applyFilter($name, 'trim'); if ($required) { $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); @@ -731,30 +758,16 @@ EOT; */ public function display() { - echo $this->return_form(); + echo $this->returnForm(); } /** * Returns the HTML code of the form. - * If an element in the form didn't validate, an error message is showed - * asking the user to complete the form. - * * @return string $return_value HTML code of the form - * - * @author Patrick Cool , Ghent University, august 2006 - * @author Julio Montoya */ - public function return_form() + public function returnForm() { $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 (!is_null(parent::getElementError($element->getName()))) { @@ -762,22 +775,40 @@ EOT; break; } } - $return_value = ''; + $returnValue = ''; $js = null; if ($error) { - $return_value = Display::return_message(get_lang('FormHasErrorsPleaseComplete'), - 'warning'); + $returnValue = Display::return_message( + get_lang('FormHasErrorsPleaseComplete'), + 'warning' + ); } - $return_value .= $js; - $return_value .= parent::toHtml(); + $returnValue .= $js; + $returnValue .= parent::toHtml(); // Add div-element which is to hold the progress bar if (isset($this->with_progress_bar) && $this->with_progress_bar) { - $return_value .= '
'; + $returnValue .= '
'; } - return $return_value; + return $returnValue; + } + + /** + * Returns the HTML code of the form. + * If an element in the form didn't validate, an error message is showed + * asking the user to complete the form. + * + * @return string $return_value HTML code of the form + * + * @author Patrick Cool , Ghent University, august 2006 + * @author Julio Montoya + * @deprecated use returnForm() + */ + public function return_form() + { + return $this->returnForm(); } /** @@ -866,7 +897,7 @@ EOT; } /** - * @return null + * @return HTML_QuickForm_Renderer_Default */ public static function getDefaultRenderer() { diff --git a/main/inc/lib/pear/HTML/QuickForm.php b/main/inc/lib/pear/HTML/QuickForm.php index 2bfb0424b7..4c4bd55797 100755 --- a/main/inc/lib/pear/HTML/QuickForm.php +++ b/main/inc/lib/pear/HTML/QuickForm.php @@ -1761,7 +1761,8 @@ class HTML_QuickForm extends HTML_Common * @since 1.0 * @access public */ - function toHtml ($in_data = null) { + public function toHtml($in_data = null) + { if (!is_null($in_data)) { $this->addElement('html', $in_data); } diff --git a/main/inc/lib/pear/HTML/QuickForm/CAPTCHA.php b/main/inc/lib/pear/HTML/QuickForm/CAPTCHA.php index 2ba7abe414..32658beded 100755 --- a/main/inc/lib/pear/HTML/QuickForm/CAPTCHA.php +++ b/main/inc/lib/pear/HTML/QuickForm/CAPTCHA.php @@ -115,7 +115,7 @@ class HTML_QuickForm_CAPTCHA extends HTML_QuickForm_input function HTML_QuickForm_CAPTCHA($elementName = null, $elementLabel = null, $options = null, $attributes = null) { - HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->setType('CAPTCHA_'.$this->_CAPTCHA_driver); if (is_array($options)) { diff --git a/main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php b/main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php index 95ef44ba3d..e876a4b41f 100755 --- a/main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php +++ b/main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php @@ -36,6 +36,8 @@ */ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer { + private $form; + /** * The HTML of the form * @var string @@ -174,10 +176,30 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer */ function startForm(&$form) { + $this->setForm($form); + $this->_html = ''; $this->_hiddenHtml = ''; + } + + /** + * @return FormValidator + */ + public function getForm() + { + return $this->form; + } + + /** + * @param mixed $form + */ + public function setForm($form) + { + $this->form = $form; } // end func startForm + + /** * Called when visiting a form, after processing all form elements * Adds required note, form attributes, validation javascript and form content. @@ -228,51 +250,63 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer /** * Helper method for renderElement * - * @param string Element name - * @param mixed Element label (if using an array of labels, you should set the appropriate template) + * @param HTML_QuickForm_element $element * @param bool Whether an element is required - * @param string Error message associated with the element - * @param string Label for ID + * @param string $required Error message associated with the element + * @param string $error Label for ID * @access private * @see renderElement() * @return string Html for element */ - function _prepareTemplate($name, $label, $required, $error, $labelForId = '') + private function _prepareTemplate(HTML_QuickForm_element $element, $required, $error) { + $name = $element->getName(); + $label = $element->getLabel(); + $labelForId = $element->getLabelFor(); + $icon = $element->getIconToHtml(); + if (is_array($label)) { $nameLabel = array_shift($label); } else { $nameLabel = $label; } - if (!empty($labelForId)) { - $labelFor = 'for="' . $labelForId . '"'; - } else { - $labelFor = ''; - } + + $labelFor = !empty($labelForId) ? 'for="' . $labelForId . '"' : ''; + if (isset($this->_templates[$name])) { + // Custom template $html = str_replace('{label}', $nameLabel, $this->_templates[$name]); - $html = str_replace('{label-for}', $labelFor, $html); } else { - $html = str_replace('{label}', $nameLabel, $this->_elementTemplate); - $html = str_replace('{label-for}', $labelFor, $html); + if (method_exists($element, 'getTemplate')) { + $template = $element->getTemplate($this->getForm()->getLayout()); + } else { + $template = $this->getForm()->getDefaultElementTemplate(); + } + $html = str_replace('{label}', $nameLabel, $template); + // Default template + //$html = str_replace('{label}', $nameLabel, $this->_elementTemplate); } + $html = str_replace('{label-for}', $labelFor, $html); + $html = str_replace('{icon}', $icon, $html); + if ($required) { $html = str_replace('', '', $html); $html = str_replace('', '', $html); } else { $html = preg_replace("/([ \t\n\r]*)?.*([ \t\n\r]*)?/isU", '', $html); } + if (isset($error)) { $html = str_replace('{error}', $error, $html); $html = str_replace('{error_class}', 'error has-error', $html); $html = str_replace('', '', $html); $html = str_replace('', '', $html); } else { - $html = str_replace('{error_class}', '', $html); + $html = str_replace('{error_class}', '', $html); $html = preg_replace("/([ \t\n\r]*)?.*([ \t\n\r]*)?/isU", '', $html); } if (is_array($label)) { - foreach($label as $key => $text) { + foreach ($label as $key => $text) { $key = is_int($key)? $key + 2: $key; $html = str_replace("{label_{$key}}", $text, $html); $html = str_replace("", '', $html); @@ -282,6 +316,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer if (strpos($html, '{label_')) { $html = preg_replace('/\s*.*\s*/is', '', $html); } + return $html; } // end func _prepareTemplate @@ -299,11 +334,9 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer { if (!$this->_inGroup) { $html = $this->_prepareTemplate( - $element->getName(), - $element->getLabel(), + $element, $required, - $error, - $element->getLabelFor() + $error ); $this->_html .= str_replace('{element}', $element->toHtml(), $html); @@ -360,7 +393,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer function startGroup(&$group, $required, $error) { $name = $group->getName(); - $this->_groupTemplate = $this->_prepareTemplate($name, $group->getLabel(), $required, $error); + $this->_groupTemplate = $this->_prepareTemplate($group, $required, $error); $this->_groupElementTemplate = empty($this->_groupTemplates[$name])? '': $this->_groupTemplates[$name]; $this->_groupWrap = empty($this->_groupWraps[$name])? '': $this->_groupWraps[$name]; $this->_groupElements = array(); diff --git a/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php b/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php index ff4fa28eab..d532ea10db 100755 --- a/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php +++ b/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php @@ -533,15 +533,12 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select } else { $this->_elementTemplate = ' {javascript} - -{label_2} - {label_3} - - {unselected} - {add}{remove} - {selected} - - + +
{label_2} {unselected}
+
{add}{remove}
+
+{label_3}{selected}
+ '; } if ($js == false) { @@ -1010,9 +1007,11 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select if ($this->selectAllCheckBox) { $strHtml .= ' +
+
'; } diff --git a/main/inc/lib/pear/HTML/QuickForm/button.php b/main/inc/lib/pear/HTML/QuickForm/button.php index 88de0be852..073a6bfbdd 100755 --- a/main/inc/lib/pear/HTML/QuickForm/button.php +++ b/main/inc/lib/pear/HTML/QuickForm/button.php @@ -196,4 +196,52 @@ class HTML_QuickForm_button extends HTML_QuickForm_input { return false; } + + /** + * @param string $layout + * + * @return string + */ + public function getTemplate($layout) + { + switch ($layout) { + case FormValidator::LAYOUT_INLINE: + return ' + {element} + '; + break; + case FormValidator::LAYOUT_HORIZONTAL: + return ' +
+ +
+ {icon} + {element} + + +

{label_2}

+ + + + {error} + +
+
+ + {label_3} + +
+
'; + break; + case FormValidator::LAYOUT_BOX: + case FormValidator::LAYOUT_BOX_NO_LABEL: + return ' + {element} + '; + break; + } + } } diff --git a/main/inc/lib/pear/HTML/QuickForm/checkbox.php b/main/inc/lib/pear/HTML/QuickForm/checkbox.php index cb517ac2c3..25f9255439 100755 --- a/main/inc/lib/pear/HTML/QuickForm/checkbox.php +++ b/main/inc/lib/pear/HTML/QuickForm/checkbox.php @@ -68,7 +68,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input $text = '', $attributes = null ) { - HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_text = $text; $this->setType('checkbox'); diff --git a/main/inc/lib/pear/HTML/QuickForm/element.php b/main/inc/lib/pear/HTML/QuickForm/element.php index cbd07b09d3..f6ae171960 100755 --- a/main/inc/lib/pear/HTML/QuickForm/element.php +++ b/main/inc/lib/pear/HTML/QuickForm/element.php @@ -37,6 +37,9 @@ */ class HTML_QuickForm_element extends HTML_Common { + private $layout; + private $icon; + // {{{ properties /** @@ -88,7 +91,7 @@ class HTML_QuickForm_element extends HTML_Common * @access public * @return void */ - function HTML_QuickForm_element($elementName = null, $elementLabel = null, $attributes = null) + public function __construct($elementName = null, $elementLabel = null, $attributes = null) { parent::__construct($attributes); if (isset($elementName)) { @@ -109,6 +112,46 @@ class HTML_QuickForm_element extends HTML_Common } } + /** + * @return string + */ + public function getLayout() + { + return $this->layout; + } + + /** + * @param string $layout + */ + public function setLayout($layout) + { + $this->layout = $layout; + } + + /** + * @return string + */ + public function getIcon() + { + return $this->icon; + } + + /** + * @return string + */ + public function getIconToHtml() + { + return $this->icon; + } + + /** + * @param mixed $icon + */ + public function setIcon($icon) + { + $this->icon = $icon; + } + /** * Returns the current API version * @@ -238,7 +281,7 @@ class HTML_QuickForm_element extends HTML_Common * @access public * @return string */ - function getFrozenHtml() + public function getFrozenHtml() { $value = $this->getValue(); // Modified by Ivan Tcholakov, 16-MAR-2010. @@ -284,7 +327,7 @@ class HTML_QuickForm_element extends HTML_Common * @access public * @return bool */ - function isFrozen() + public function isFrozen() { return $this->_flagFrozen; } // end func isFrozen @@ -318,7 +361,7 @@ class HTML_QuickForm_element extends HTML_Common * @access public * @return void */ - function setLabel($label, $labelFor = null) + public function setLabel($label, $labelFor = null) { $this->_label = $label; if (!empty($labelFor)) { diff --git a/main/inc/lib/pear/HTML/QuickForm/email.php b/main/inc/lib/pear/HTML/QuickForm/email.php index 9239abc388..0386ec860d 100755 --- a/main/inc/lib/pear/HTML/QuickForm/email.php +++ b/main/inc/lib/pear/HTML/QuickForm/email.php @@ -28,7 +28,7 @@ class HTML_QuickForm_email extends HTML_QuickForm_input */ function HTML_QuickForm_email($elementName=null, $elementLabel=null, $attributes=null) { - HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->setType('email'); } //end constructor diff --git a/main/inc/lib/pear/HTML/QuickForm/file.php b/main/inc/lib/pear/HTML/QuickForm/file.php index 57192f1de9..fbe915ae5b 100755 --- a/main/inc/lib/pear/HTML/QuickForm/file.php +++ b/main/inc/lib/pear/HTML/QuickForm/file.php @@ -67,7 +67,7 @@ class HTML_QuickForm_file extends HTML_QuickForm_input */ function HTML_QuickForm_file($elementName=null, $elementLabel=null, $attributes=null) { - HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->setType('file'); } //end constructor diff --git a/main/inc/lib/pear/HTML/QuickForm/group.php b/main/inc/lib/pear/HTML/QuickForm/group.php index 57bc1c7db9..72622b7012 100755 --- a/main/inc/lib/pear/HTML/QuickForm/group.php +++ b/main/inc/lib/pear/HTML/QuickForm/group.php @@ -91,7 +91,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element * @access public * @return void */ - function HTML_QuickForm_group($elementName=null, $elementLabel=null, $elements=null, $separator=null, $appendName = true) + public function __construct($elementName=null, $elementLabel=null, $elements=null, $separator=null, $appendName = true) { parent::__construct($elementName, $elementLabel); $this->_type = 'group'; diff --git a/main/inc/lib/pear/HTML/QuickForm/hidden.php b/main/inc/lib/pear/HTML/QuickForm/hidden.php index 05b8fb1784..dc665139a1 100755 --- a/main/inc/lib/pear/HTML/QuickForm/hidden.php +++ b/main/inc/lib/pear/HTML/QuickForm/hidden.php @@ -49,7 +49,7 @@ class HTML_QuickForm_hidden extends HTML_QuickForm_input */ public function HTML_QuickForm_hidden($elementName = null, $value = '', $attributes = null) { - HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes); + parent::__construct($elementName, null, $attributes); $this->setType('hidden'); $this->setValue($value); } //end constructor diff --git a/main/inc/lib/pear/HTML/QuickForm/hiddenselect.php b/main/inc/lib/pear/HTML/QuickForm/hiddenselect.php index f0a58efc25..13b80bd667 100755 --- a/main/inc/lib/pear/HTML/QuickForm/hiddenselect.php +++ b/main/inc/lib/pear/HTML/QuickForm/hiddenselect.php @@ -53,7 +53,7 @@ class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select */ function HTML_QuickForm_hiddenselect($elementName=null, $elementLabel=null, $options=null, $attributes=null) { - HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_type = 'hiddenselect'; if (isset($options)) { diff --git a/main/inc/lib/pear/HTML/QuickForm/image.php b/main/inc/lib/pear/HTML/QuickForm/image.php index 34c4f7215b..a538b21789 100755 --- a/main/inc/lib/pear/HTML/QuickForm/image.php +++ b/main/inc/lib/pear/HTML/QuickForm/image.php @@ -49,7 +49,7 @@ class HTML_QuickForm_image extends HTML_QuickForm_input */ function HTML_QuickForm_image($elementName=null, $src='', $attributes=null) { - HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes); + parent::__construct($elementName, null, $attributes); $this->setType('image'); $this->setSource($src); } // end class constructor diff --git a/main/inc/lib/pear/HTML/QuickForm/input.php b/main/inc/lib/pear/HTML/QuickForm/input.php index c41786f511..26eec635e6 100755 --- a/main/inc/lib/pear/HTML/QuickForm/input.php +++ b/main/inc/lib/pear/HTML/QuickForm/input.php @@ -47,9 +47,9 @@ class HTML_QuickForm_input extends HTML_QuickForm_element * @access public * @return void */ - function HTML_QuickForm_input($elementName=null, $elementLabel=null, $attributes=null) + public function __construct($elementName=null, $elementLabel=null, $attributes=null) { - $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); } //end constructor // }}} @@ -195,4 +195,12 @@ class HTML_QuickForm_input extends HTML_QuickForm_element return parent::exportValue($submitValues, $assoc); } } + + /** + * @param string $layout + */ + public function getTemplate($layout) + { + + } } diff --git a/main/inc/lib/pear/HTML/QuickForm/link.php b/main/inc/lib/pear/HTML/QuickForm/link.php index 379d62489f..6c2a0d21b9 100755 --- a/main/inc/lib/pear/HTML/QuickForm/link.php +++ b/main/inc/lib/pear/HTML/QuickForm/link.php @@ -62,7 +62,7 @@ class HTML_QuickForm_link extends HTML_QuickForm_static */ function HTML_QuickForm_link($elementName=null, $elementLabel=null, $href=null, $text=null, $attributes=null) { - HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->_persistantFreeze = false; $this->_type = 'link'; $this->setHref($href); diff --git a/main/inc/lib/pear/HTML/QuickForm/password.php b/main/inc/lib/pear/HTML/QuickForm/password.php index 511ec95c6d..15b1c07b46 100755 --- a/main/inc/lib/pear/HTML/QuickForm/password.php +++ b/main/inc/lib/pear/HTML/QuickForm/password.php @@ -32,7 +32,7 @@ * @version Release: 3.2.11 * @since 1.0 */ -class HTML_QuickForm_password extends HTML_QuickForm_input +class HTML_QuickForm_password extends HTML_QuickForm_text { // {{{ constructor @@ -48,15 +48,12 @@ class HTML_QuickForm_password extends HTML_QuickForm_input * @return void * @throws */ - function HTML_QuickForm_password($elementName=null, $elementLabel=null, $attributes=null) + public function __construct($elementName=null, $elementLabel=null, $attributes=null) { $attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'form-control'; - HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); $this->setType('password'); - } //end constructor - - // }}} - // {{{ setSize() + } /** * Sets size of password element @@ -66,13 +63,10 @@ class HTML_QuickForm_password extends HTML_QuickForm_input * @access public * @return void */ - function setSize($size) + public function setSize($size) { $this->updateAttributes(array('size'=>$size)); - } //end func setSize - - // }}} - // {{{ setMaxlength() + } /** * Sets maxlength of password element @@ -82,13 +76,10 @@ class HTML_QuickForm_password extends HTML_QuickForm_input * @access public * @return void */ - function setMaxlength($maxlength) + public function setMaxlength($maxlength) { $this->updateAttributes(array('maxlength'=>$maxlength)); - } //end func setMaxlength - - // }}} - // {{{ getFrozenHtml() + } /** * Returns the value of field without HTML tags (in this case, value is changed to a mask) @@ -98,14 +89,10 @@ class HTML_QuickForm_password extends HTML_QuickForm_input * @return string * @throws */ - function getFrozenHtml() + public function getFrozenHtml() { $value = $this->getValue(); return ('' != $value? '**********': ' ') . $this->_getPersistantData(); - } //end func getFrozenHtml - - // }}} - -} //end class HTML_QuickForm_password -?> + } +} diff --git a/main/inc/lib/pear/HTML/QuickForm/radio.php b/main/inc/lib/pear/HTML/QuickForm/radio.php index f53ff975f3..0458758615 100755 --- a/main/inc/lib/pear/HTML/QuickForm/radio.php +++ b/main/inc/lib/pear/HTML/QuickForm/radio.php @@ -34,7 +34,6 @@ */ class HTML_QuickForm_radio extends HTML_QuickForm_input { - /** * Radio display text * @var string @@ -55,14 +54,14 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input * @access public * @return void */ - public function HTML_QuickForm_radio( + public function __construct( $elementName = null, $elementLabel = null, $text = null, $value = null, $attributes = null ) { - $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); + parent::__construct($elementName, $elementLabel, $attributes); if (isset($value)) { $this->setValue($value); } diff --git a/main/inc/lib/pear/HTML/QuickForm/reset.php b/main/inc/lib/pear/HTML/QuickForm/reset.php index c08b9fb785..119fb1b4a5 100755 --- a/main/inc/lib/pear/HTML/QuickForm/reset.php +++ b/main/inc/lib/pear/HTML/QuickForm/reset.php @@ -49,7 +49,7 @@ class HTML_QuickForm_reset extends HTML_QuickForm_input */ function HTML_QuickForm_reset($elementName=null, $value=null, $attributes=null) { - HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes); + parent::__construct($elementName, null, $attributes); $this->setValue($value); $this->setType('reset'); } //end constructor diff --git a/main/inc/lib/pear/HTML/QuickForm/select.php b/main/inc/lib/pear/HTML/QuickForm/select.php index 0da1450cc8..80d85d6590 100755 --- a/main/inc/lib/pear/HTML/QuickForm/select.php +++ b/main/inc/lib/pear/HTML/QuickForm/select.php @@ -645,6 +645,60 @@ class HTML_QuickForm_select extends HTML_QuickForm_element } } - // }}} -} //end class HTML_QuickForm_select -?> + /** + * @param string $layout + * + * @return string + */ + public function getTemplate($layout) + { + /*$size = $this->getInputSize(); + $size = empty($size) ? '8' : $size;*/ + + switch ($layout) { + case FormValidator::LAYOUT_INLINE: + return ' +
+ + {element} +
'; + break; + case FormValidator::LAYOUT_HORIZONTAL: + return ' +
+ +
+ {icon} + {element} + + +

{label_2}

+ + + + {error} + +
+
+ + {label_3} + +
+
'; + break; + case FormValidator::LAYOUT_BOX_NO_LABEL: + return ' +
+ {icon} + {element} +
'; + break; + } + } +} diff --git a/main/inc/lib/pear/HTML/QuickForm/submit.php b/main/inc/lib/pear/HTML/QuickForm/submit.php index 320d9ca555..801917fae1 100755 --- a/main/inc/lib/pear/HTML/QuickForm/submit.php +++ b/main/inc/lib/pear/HTML/QuickForm/submit.php @@ -48,7 +48,7 @@ class HTML_QuickForm_submit extends HTML_QuickForm_input */ public function __construct($elementName=null, $value=null, $attributes=null) { - HTML_QuickForm_input::HTML_QuickForm_input($elementName, null, $attributes); + parent::__construct($elementName, null, $attributes); $this->setValue($value); $this->setType('submit'); } //end constructor diff --git a/main/inc/lib/pear/HTML/QuickForm/text.php b/main/inc/lib/pear/HTML/QuickForm/text.php index 9c1f44defa..e47261b827 100755 --- a/main/inc/lib/pear/HTML/QuickForm/text.php +++ b/main/inc/lib/pear/HTML/QuickForm/text.php @@ -1,5 +1,4 @@ setInputSize($inputSize); + $icon = isset($attributes['icon']) ? $attributes['icon'] : null; + $this->setIcon($icon); + if (!empty($inputSize)) { unset($attributes['input-size']); } + if (!empty($icon)) { + unset($attributes['icon']); + } + parent::__construct($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->setType('text'); $renderer = FormValidator::getDefaultRenderer(); - $renderer->setElementTemplate($this->getTemplate(), $elementName); + //$renderer->setElementTemplate($this->getTemplate(), $elementName); + } + + /** + * Show an icon at the left side of an input + * @return string + */ + public function getIconToHtml() + { + $icon = $this->getIcon(); + + if (empty($icon)) { + return ''; + } + + return ' +
+ +
'; } /** + * @param string $layout + * * @return string */ - public function getTemplate() + public function getTemplate($layout) { $size = $this->getInputSize(); $size = empty($size) ? '8' : $size; - return ' -
- -
+ switch ($layout) { + case FormValidator::LAYOUT_INLINE: + return ' +
+ {element} - - -

{label_2}

- - - - {error} - -
-
- - {label_3} - -
-
'; +
'; + break; + case FormValidator::LAYOUT_HORIZONTAL: + return ' +
+ +
+ {icon} + {element} + + +

{label_2}

+ + + + {error} + +
+
+ + {label_3} + +
+
'; + break; + case FormValidator::LAYOUT_BOX_NO_LABEL: + return ' +
+ {icon} + {element} +
'; + break; + } } - /** * @return null */ diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 11156d7653..05035d4d9e 100755 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -694,33 +694,29 @@ class IndexManager * Adds a form to let users login * @version 1.1 */ - function display_login_form() + public function display_login_form() { + $form = new FormValidator( + 'formLogin', + 'POST', + null, + null, + null, + FormValidator::LAYOUT_BOX_NO_LABEL + ); + + $form->addText('login', get_lang('UserName'), true, array('id' => 'login', 'autofocus' => 'autofocus', 'icon' => 'user')); + $form->addElement('password', 'password', get_lang('Pass'), array('id' => 'password', 'icon' => 'lock')); - $form = new FormValidator('formLogin', 'POST', null, null, null, FormValidator::LAYOUT_INLINE); - $form->addElement('label',get_lang('UserName')); - $form->addHtml('
'); - $form->addHtml('
'); - $form->addElement('input', 'login','', array('id' => 'login', 'class' => 'form-control autocapitalize_off', 'autofocus' => 'autofocus')); - $form->addHtml('
'); - $form->addElement('label',get_lang('Pass')); - $form->addHtml('
'); - $form->addHtml('
'); - $form->addElement('password', 'password','', array('id' => 'password', 'class' => 'form-control')); - $form->addHtml('
'); global $_configuration; // Captcha $allowCaptcha = isset($_configuration['allow_captcha']) ? $_configuration['allow_captcha'] : false; if ($allowCaptcha) { - $useCaptcha = isset($_SESSION['loginFailed']) ? $_SESSION['loginFailed'] : null; - if ($useCaptcha) { - $ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha'; - $options = array( 'width' => 250, 'height' => 90, @@ -737,20 +733,18 @@ class IndexManager // Minimum options using all defaults (including defaults for Image_Text): //$options = array('callback' => 'qfcaptcha_image.php'); - $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options); + $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options); $form->addElement('static', null, null, get_lang('ClickOnTheImageForANewOne')); $form->addElement('text', 'captcha', get_lang('EnterTheLettersYouSee')); $form->addRule('captcha', get_lang('EnterTheCharactersYouReadInTheImage'), 'required', null, 'client'); - $form->addRule('captcha', get_lang('TheTextYouEnteredDoesNotMatchThePicture'), 'CAPTCHA', $captcha_question); } } - $form->addHtml(''); - $html = $form->return_form(); + $form->addButton('submitAuth', get_lang('LoginEnter'), null, 'primary', null, 'btn-block'); + + $html = $form->returnForm(); // The validation is located in the local.inc /*if ($form->validate()) { // Prevent re-use of the same CAPTCHA phrase @@ -761,10 +755,16 @@ class IndexManager include_once 'main/auth/openid/login.php'; $html .= '
'.openid_form().'
'; } + return $html; } - function return_search_block() { + /** + * @todo use FormValidator + * @return string + */ + public function return_search_block() + { $html = ''; if (api_get_setting('search_enabled') == 'true') { $search_btn = get_lang('Search'); @@ -775,10 +775,14 @@ class IndexManager
'; $html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block'); } + return $html; } - function return_classes_block() + /** + * @return string + */ + public function return_classes_block() { $html = ''; if (api_get_setting('show_groups_to_users') == 'true') { @@ -793,7 +797,10 @@ class IndexManager } } if (api_is_platform_admin()) { - $classes .= Display::tag('li', Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add')); + $classes .= Display::tag( + 'li', + Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add') + ); } if (!empty($classes)) { $classes = Display::tag('ul', $classes, array('class'=>'nav nav-pills nav-stacked')); @@ -803,18 +810,6 @@ class IndexManager return $html; } - function return_reservation_block() { - $html = ''; - $booking_content = null; - if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) { - $booking_content .=''; - $html .= self::show_right_block(get_lang('Booking'), $booking_content, 'reservation_block'); - } - return $html; - } - /** * @return null|string */ @@ -849,7 +844,10 @@ class IndexManager return $html; } - function return_profile_block() + /** + * @return null|string|void + */ + public function return_profile_block() { global $_configuration; $user_id = api_get_user_id(); @@ -899,7 +897,8 @@ class IndexManager return $html; } - function return_navigation_links() { + public function return_navigation_links() + { $html = ''; // Deleting the myprofile link.