Merge branch '1.10.x' of github.com:chamilo/chamilo-lms into 1.10.x

1.10.x
Yannick Warnier 11 years ago
commit 0d043192de
  1. 32
      main/announcements/announcements.php
  2. 7
      main/exercice/hotspot.class.php
  3. 4
      main/inc/lib/course.lib.php
  4. 26
      main/inc/lib/formvalidator/Rule/FileName.php
  5. 28
      main/inc/lib/formvalidator/Rule/MaxFileSize.php
  6. 29
      main/inc/lib/formvalidator/Rule/MimeType.php
  7. 27
      main/inc/lib/formvalidator/Rule/UploadFile.php
  8. 13
      main/inc/lib/pear/HTML/QuickForm.php
  9. 80
      main/inc/lib/pear/HTML/QuickForm/Renderer.php
  10. 2
      main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php
  11. 6
      main/inc/lib/pear/HTML/QuickForm/RuleRegistry.php
  12. 6
      main/inc/lib/pear/HTML/QuickForm/advmultiselect.php
  13. 73
      main/inc/lib/pear/HTML/QuickForm/file.php

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @author Frederik Vermeire <frederik.vermeire@pandora.be>, UGent Internship
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: code cleaning
@ -271,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',
@ -285,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',
@ -330,8 +336,6 @@ switch ($action) {
$form->addButtonSave(get_lang('ButtonPublishAnnouncement'));
$form->setDefaults($defaults);
$content = $form->return_form();
if ($form->validate()) {
$data = $form->getSubmitValues();
@ -357,7 +361,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 +405,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;
@ -404,6 +416,8 @@ switch ($action) {
} // end condition token
}
}
$content = $form->returnForm();
break;
}
@ -429,9 +443,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 '<div class="actions">';
if (in_array($action, array('add', 'modify','view'))) {

@ -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('<img src="../img/hotspots.png" />', get_lang('UploadJpgPicture')) );

@ -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'),

@ -0,0 +1,26 @@
<?php
/* For licensing terms, see /license.txt */
/** @author Julio Montoya */
/**
* Class HTML_QuickForm_Rule_FileName
*/
class HTML_QuickForm_Rule_FileName extends HTML_QuickForm_Rule
{
/**
* @param $value array Uploaded file info (from $_FILES)
* @param null $options
* @return bool
*/
public function validate($value, $options = null)
{
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) {
return is_uploaded_file($elementValue['tmp_name']);
} else {
return false;
}
}
}

@ -0,0 +1,28 @@
<?php
/* For licensing terms, see /license.txt */
/** @author Julio Montoya */
/**
* Class HTML_QuickForm_Rule_MaxFileSize
*/
class HTML_QuickForm_Rule_MaxFileSize extends HTML_QuickForm_Rule
{
/**
* @param $value array Uploaded file info (from $_FILES)
* @param null $options
* @return bool
*/
public function validate($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']));
}
}

@ -0,0 +1,29 @@
<?php
/* For licensing terms, see /license.txt */
/** @author Julio Montoya */
/**
* Class HTML_QuickForm_Rule_MimeType
*/
class HTML_QuickForm_Rule_MimeType extends HTML_QuickForm_Rule
{
/**
* 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
*/
public function validate($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
}

@ -0,0 +1,27 @@
<?php
/* For licensing terms, see /license.txt */
/** @author Julio Montoya */
/**
* Class HTML_QuickForm_Rule_UploadFile
*/
class HTML_QuickForm_Rule_UploadFile extends HTML_QuickForm_Rule
{
/**
* 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
*/
public function validate($elementValue, $regex)
{
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) {
return is_uploaded_file($elementValue['tmp_name']);
} else {
return false;
}
} // end func _ruleCheckFileName
}

@ -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'
);
}
}

@ -1,36 +1,36 @@
<?php
/* 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 <avb@php.net>
* @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 <avb@php.net>
* @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 <avb@php.net>
* @version Release: 3.2.11
* @since 3.0
* @category HTML
* @package HTML_QuickForm
* @author Alexey Borzov <avb@php.net>
* @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

@ -318,8 +318,8 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
} else {
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->.*<!-- END required -->([ \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('<!-- BEGIN error -->', '', $html);

@ -152,7 +152,11 @@ class HTML_QuickForm_RuleRegistry
'html' => '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];

@ -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("<!-- END label_{$key} -->", '', $strHtml);
}
}
// clean up useless label tags
if (strpos($strHtml, '{label_')) {
$strHtml = preg_replace('/\s*<!-- BEGIN label_(\S+) -->'.

@ -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
*

Loading…
Cancel
Save