From ba286e78974e6dea351194ec73fbe04de73324d1 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 7 Jul 2015 09:03:56 +0200 Subject: [PATCH 1/3] Minor - format code. --- main/announcements/announcements.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index 02103bc30a..716d0e58ce 100755 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -1,5 +1,6 @@ , UGent Internship * @author Patrick Cool , Ghent University: code cleaning @@ -330,7 +331,7 @@ switch ($action) { $form->addButtonSave(get_lang('ButtonPublishAnnouncement')); $form->setDefaults($defaults); - $content = $form->return_form(); + $content = $form->returnForm(); if ($form->validate()) { $data = $form->getSubmitValues(); @@ -357,7 +358,12 @@ switch ($action) { if ($_POST['email_ann'] && empty($_POST['onlyThoseMails'])) { AnnouncementManager::send_email($id, $sendToUsersInSession); } - Display::addFlash(Display::return_message(get_lang('AnnouncementModified'), 'success')); + Display::addFlash( + Display::return_message( + get_lang('AnnouncementModified'), + 'success' + ) + ); header('Location: '.$homeUrl); exit; } @@ -396,7 +402,10 @@ switch ($action) { /* MAIL FUNCTION */ if (isset($data['email_ann']) && $data['email_ann']) { - AnnouncementManager::send_email($insert_id, $sendToUsersInSession); + AnnouncementManager::send_email( + $insert_id, + $sendToUsersInSession + ); } header('Location: '.$homeUrl); exit; @@ -429,9 +438,9 @@ if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') { // Actions $show_actions = false; -if ((api_is_allowed_to_edit(false,true) OR - (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) and - (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') +if ((api_is_allowed_to_edit(false,true) || + (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) && + (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') ) { echo '
'; if (in_array($action, array('add', 'modify','view'))) { From 0c713278130c37ee5d299cad7e4fb09a7a5d2ab5 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 7 Jul 2015 10:03:53 +0200 Subject: [PATCH 2/3] Fix error in multi select see #7713 --- main/announcements/announcements.php | 13 ++- main/inc/lib/course.lib.php | 4 +- main/inc/lib/pear/HTML/QuickForm.php | 13 ++- main/inc/lib/pear/HTML/QuickForm/Renderer.php | 80 +++++++++---------- .../pear/HTML/QuickForm/Renderer/Default.php | 2 +- .../pear/HTML/QuickForm/advmultiselect.php | 6 +- 6 files changed, 64 insertions(+), 54 deletions(-) diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index 716d0e58ce..542f39f23c 100755 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -272,10 +272,13 @@ switch ($action) { } } - CourseManager::addUserGroupMultiSelect($form, array()); + $element = CourseManager::addUserGroupMultiSelect($form, array()); + $form->setRequired($element); + if (!isset($announcement_to_modify)) { $announcement_to_modify = ''; } + $form->addElement( 'checkbox', 'email_ann', @@ -286,7 +289,9 @@ switch ($action) { if (!isset($announcement_to_modify)) { $announcement_to_modify = ""; } - CourseManager::addGroupMultiSelect($form, $group_id, array()); + $element = CourseManager::addGroupMultiSelect($form, $group_id, array()); + $form->setRequired($element); + $form->addElement( 'checkbox', 'email_ann', @@ -331,8 +336,6 @@ switch ($action) { $form->addButtonSave(get_lang('ButtonPublishAnnouncement')); $form->setDefaults($defaults); - $content = $form->returnForm(); - if ($form->validate()) { $data = $form->getSubmitValues(); @@ -413,6 +416,8 @@ switch ($action) { } // end condition token } } + + $content = $form->returnForm(); break; } diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 2ad72bb09b..def6312e80 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -5165,6 +5165,8 @@ class CourseManager /** * @param FormValidator $form * @param array $to_already_selected + * + * @param HTML_QuickForm_element */ public static function addUserGroupMultiSelect(&$form, $to_already_selected) { @@ -5177,7 +5179,7 @@ class CourseManager $result[$content['value']] = $content['content']; } - $form->addElement( + return $form->addElement( 'advmultiselect', 'users', get_lang('Users'), diff --git a/main/inc/lib/pear/HTML/QuickForm.php b/main/inc/lib/pear/HTML/QuickForm.php index 58b5787687..9718d2716d 100755 --- a/main/inc/lib/pear/HTML/QuickForm.php +++ b/main/inc/lib/pear/HTML/QuickForm.php @@ -1427,7 +1427,6 @@ class HTML_QuickForm extends HTML_Common function isRuleRegistered($name, $autoRegister = false) { return true; - var_dump($name); if (is_scalar($name) && isset($GLOBALS['_HTML_QuickForm_registered_rules'][$name])) { return true; } elseif (!$autoRegister) { @@ -1575,6 +1574,7 @@ class HTML_QuickForm extends HTML_Common foreach ($this->_rules as $target => $rules) { $submitValue = $this->getSubmitValue($target); + foreach ($rules as $rule) { if ((isset($rule['group']) && isset($this->_errors[$rule['group']])) || isset($this->_errors[$target])) { @@ -1620,7 +1620,9 @@ class HTML_QuickForm extends HTML_Common } elseif (is_array($submitValue) && !isset($rule['howmany'])) { $result = $registry->validate($rule['type'], $submitValue, $rule['format'], true); } else { + $result = $registry->validate($rule['type'], $submitValue, $rule['format'], false); + } if (!$result || (!empty($rule['howmany']) && $rule['howmany'] > (int)$result)) { @@ -1738,7 +1740,7 @@ class HTML_QuickForm extends HTML_Common $element =& $this->_elements[$key]; $elementName = $element->getName(); $required = ($this->isElementRequired($elementName) && !$element->isFrozen()); - $error = $this->getElementError($elementName); + $error = $this->getElementError($elementName); $element->accept($renderer, $required, $error); } $renderer->finishForm($this); @@ -1783,6 +1785,7 @@ class HTML_QuickForm extends HTML_Common } $renderer =& $this->defaultRenderer(); $this->accept($renderer); + return $renderer->toHtml(); } // end func toHtml @@ -2078,7 +2081,11 @@ class HTML_QuickForm extends HTML_Common */ public function setRequired(HTML_QuickForm_element $element) { - $this->addRule($element->getName(), get_lang('ThisFieldIsRequired'), 'required'); + $this->addRule( + $element->getName(), + get_lang('ThisFieldIsRequired'), + 'required' + ); } } diff --git a/main/inc/lib/pear/HTML/QuickForm/Renderer.php b/main/inc/lib/pear/HTML/QuickForm/Renderer.php index 5a224d650d..3b5b13a9f7 100755 --- a/main/inc/lib/pear/HTML/QuickForm/Renderer.php +++ b/main/inc/lib/pear/HTML/QuickForm/Renderer.php @@ -1,36 +1,36 @@ - * @copyright 2001-2009 The PHP Group - * @license http://www.php.net/license/3_01.txt PHP License 3.01 - * @version CVS: $Id$ - * @link http://pear.php.net/package/HTML_QuickForm - */ +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * An abstract base class for QuickForm renderers + * + * 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 Alexey Borzov + * @copyright 2001-2009 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id$ + * @link http://pear.php.net/package/HTML_QuickForm + */ /** * An abstract base class for QuickForm renderers * * The class implements a Visitor design pattern * - * @category HTML - * @package HTML_QuickForm - * @author Alexey Borzov - * @version Release: 3.2.11 - * @since 3.0 + * @category HTML + * @package HTML_QuickForm + * @author Alexey Borzov + * @version Release: 3.2.11 + * @since 3.0 * @abstract */ class HTML_QuickForm_Renderer @@ -47,7 +47,7 @@ class HTML_QuickForm_Renderer /** * Called when visiting a form, before processing any form elements * - * @param HTML_QuickForm a form being visited + * @param HTML_QuickForm a form being visited * @access public * @return void * @abstract @@ -60,7 +60,7 @@ class HTML_QuickForm_Renderer /** * Called when visiting a form, after processing all form elements * - * @param HTML_QuickForm a form being visited + * @param HTML_QuickForm a form being visited * @access public * @return void * @abstract @@ -73,7 +73,7 @@ class HTML_QuickForm_Renderer /** * Called when visiting a header element * - * @param HTML_QuickForm_header a header element being visited + * @param HTML_QuickForm_header a header element being visited * @access public * @return void * @abstract @@ -86,9 +86,9 @@ class HTML_QuickForm_Renderer /** * Called when visiting an element * - * @param HTML_QuickForm_element form element being visited - * @param bool Whether an element is required - * @param string An error message associated with an element + * @param HTML_QuickForm_element form element being visited + * @param bool Whether an element is required + * @param string An error message associated with an element * @access public * @return void * @abstract @@ -101,7 +101,7 @@ class HTML_QuickForm_Renderer /** * Called when visiting a hidden element * - * @param HTML_QuickForm_element a hidden element being visited + * @param HTML_QuickForm_element a hidden element being visited * @access public * @return void * @abstract @@ -114,10 +114,10 @@ class HTML_QuickForm_Renderer /** * Called when visiting a raw HTML/text pseudo-element * - * Only implemented in Default renderer. Usage of 'html' elements is - * discouraged, templates should be used instead. + * Only implemented in Default renderer. Usage of 'html' elements is + * discouraged, templates should be used instead. * - * @param HTML_QuickForm_html a 'raw html' element being visited + * @param HTML_QuickForm_html a 'raw html' element being visited * @access public * @return void * @abstract @@ -130,9 +130,9 @@ class HTML_QuickForm_Renderer /** * Called when visiting a group, before processing any group elements * - * @param HTML_QuickForm_group A group being visited - * @param bool Whether a group is required - * @param string An error message associated with a group + * @param HTML_QuickForm_group A group being visited + * @param bool Whether a group is required + * @param string An error message associated with a group * @access public * @return void * @abstract @@ -145,7 +145,7 @@ class HTML_QuickForm_Renderer /** * Called when visiting a group, after processing all group elements * - * @param HTML_QuickForm_group A group being visited + * @param HTML_QuickForm_group A group being visited * @access public * @return void * @abstract diff --git a/main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php b/main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php index 57cf2db288..d9ed910628 100755 --- a/main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php +++ b/main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php @@ -318,8 +318,8 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer } 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); diff --git a/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php b/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php index c602f8b7cb..a2e8153e66 100755 --- a/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php +++ b/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php @@ -305,11 +305,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select if (is_null($this->_tableAttributes)) { $this->updateAttributes(array('class' => 'col-md-4')); } else { - /* - if (is_null($this->_tableAttributes)) { - // default table layout - $attr = array('border' => '0', 'cellpadding' => '10', 'cellspacing' => '0');*/ - //} else { $attr = array('class' => $this->_tableAttributes); $this->_removeAttr('class', $this->_attributes); } @@ -989,6 +984,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $strHtml = str_replace("", '', $strHtml); } } + // clean up useless label tags if (strpos($strHtml, '{label_')) { $strHtml = preg_replace('/\s*'. From dfdc842b8f9351dc0eb8a08509793d71c73c87e4 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 7 Jul 2015 12:29:18 +0200 Subject: [PATCH 3/3] Fix file rules. Needs to reload autoload. --- main/exercice/hotspot.class.php | 7 +- main/inc/lib/formvalidator/Rule/FileName.php | 26 +++++++ .../lib/formvalidator/Rule/MaxFileSize.php | 28 +++++++ main/inc/lib/formvalidator/Rule/MimeType.php | 29 ++++++++ .../inc/lib/formvalidator/Rule/UploadFile.php | 27 +++++++ .../lib/pear/HTML/QuickForm/RuleRegistry.php | 6 +- main/inc/lib/pear/HTML/QuickForm/file.php | 73 +------------------ 7 files changed, 121 insertions(+), 75 deletions(-) create mode 100644 main/inc/lib/formvalidator/Rule/FileName.php create mode 100644 main/inc/lib/formvalidator/Rule/MaxFileSize.php create mode 100644 main/inc/lib/formvalidator/Rule/MimeType.php create mode 100644 main/inc/lib/formvalidator/Rule/UploadFile.php diff --git a/main/exercice/hotspot.class.php b/main/exercice/hotspot.class.php index 24c18433bb..4d78418350 100755 --- a/main/exercice/hotspot.class.php +++ b/main/exercice/hotspot.class.php @@ -25,10 +25,13 @@ class HotSpot extends Question { } - function createForm (&$form, $fck_config=0) + /** + * @param FormValidator $form + * @param int $fck_config + */ + public function createForm (&$form, $fck_config=0) { parent::createForm($form, $fck_config); - global $text, $class; if (!isset($_GET['editQuestion'])) { $form->addElement('file','imageUpload',array('', get_lang('UploadJpgPicture')) ); diff --git a/main/inc/lib/formvalidator/Rule/FileName.php b/main/inc/lib/formvalidator/Rule/FileName.php new file mode 100644 index 0000000000..68b83f40c7 --- /dev/null +++ b/main/inc/lib/formvalidator/Rule/FileName.php @@ -0,0 +1,26 @@ += @filesize($elementValue['tmp_name'])); + } +} diff --git a/main/inc/lib/formvalidator/Rule/MimeType.php b/main/inc/lib/formvalidator/Rule/MimeType.php new file mode 100644 index 0000000000..c92c997785 --- /dev/null +++ b/main/inc/lib/formvalidator/Rule/MimeType.php @@ -0,0 +1,29 @@ + 'HTML_QuickForm_Rule_HTML', 'CAPTCHA' => 'HTML_QuickForm_Rule_CAPTCHA', 'date' => 'HTML_QuickForm_Rule_Date', - 'compare_datetime_text' => 'HTML_QuickForm_Rule_CompareDateTimeText' + 'compare_datetime_text' => 'HTML_QuickForm_Rule_CompareDateTimeText', + 'uploadedfile' => 'HTML_QuickForm_Rule_UploadFile', + 'maxfilesize', 'HTML_QuickForm_Rule_MaxFileSize', + 'mimetype', 'HTML_QuickForm_Rule_MimeType', + 'filename', 'HTML_QuickForm_Rule_FileName' ); $class = $rules[$ruleName]; diff --git a/main/inc/lib/pear/HTML/QuickForm/file.php b/main/inc/lib/pear/HTML/QuickForm/file.php index fbe915ae5b..d112fa5d8c 100755 --- a/main/inc/lib/pear/HTML/QuickForm/file.php +++ b/main/inc/lib/pear/HTML/QuickForm/file.php @@ -23,14 +23,6 @@ * @link http://pear.php.net/package/HTML_QuickForm */ -// register file-related rules -if (class_exists('HTML_QuickForm')) { - HTML_QuickForm::registerRule('uploadedfile', 'callback', '_ruleIsUploadedFile', 'HTML_QuickForm_file'); - HTML_QuickForm::registerRule('maxfilesize', 'callback', '_ruleCheckMaxFileSize', 'HTML_QuickForm_file'); - HTML_QuickForm::registerRule('mimetype', 'callback', '_ruleCheckMimeType', 'HTML_QuickForm_file'); - HTML_QuickForm::registerRule('filename', 'callback', '_ruleCheckFileName', 'HTML_QuickForm_file'); -} - /** * HTML class for a file upload field * @@ -221,6 +213,7 @@ class HTML_QuickForm_file extends HTML_QuickForm_input return HTML_QuickForm_file::_ruleIsUploadedFile($this->_value); } // end func isUploadedFile + // }}} // {{{ _ruleIsUploadedFile() @@ -244,70 +237,6 @@ class HTML_QuickForm_file extends HTML_QuickForm_input // }}} // {{{ _ruleCheckMaxFileSize() - /** - * Checks that the file does not exceed the max file size - * - * @param array Uploaded file info (from $_FILES) - * @param int Max file size - * @access private - * @return bool true if filesize is lower than maxsize, false otherwise - */ - function _ruleCheckMaxFileSize($elementValue, $maxSize) - { - if (!empty($elementValue['error']) && - (UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error'])) { - return false; - } - if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { - return true; - } - return ($maxSize >= @filesize($elementValue['tmp_name'])); - } // end func _ruleCheckMaxFileSize - - // }}} - // {{{ _ruleCheckMimeType() - - /** - * Checks if the given element contains an uploaded file of the right mime type - * - * @param array Uploaded file info (from $_FILES) - * @param mixed Mime Type (can be an array of allowed types) - * @access private - * @return bool true if mimetype is correct, false otherwise - */ - function _ruleCheckMimeType($elementValue, $mimeType) - { - if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { - return true; - } - if (is_array($mimeType)) { - return in_array($elementValue['type'], $mimeType); - } - return $elementValue['type'] == $mimeType; - } // end func _ruleCheckMimeType - - // }}} - // {{{ _ruleCheckFileName() - - /** - * Checks if the given element contains an uploaded file of the filename regex - * - * @param array Uploaded file info (from $_FILES) - * @param string Regular expression - * @access private - * @return bool true if name matches regex, false otherwise - */ - function _ruleCheckFileName($elementValue, $regex) - { - if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { - return true; - } - return (bool)preg_match($regex, $elementValue['name']); - } // end func _ruleCheckFileName - - // }}} - // {{{ _findValue() - /** * Tries to find the element value from the values array *