Skip to content

Commit

Permalink
MDL-29512 Revert "MDL-25937 Froms Library: Added server side validati…
Browse files Browse the repository at this point in the history
…on for filepicker and filemanager"

This reverts commit b19539b.
  • Loading branch information
stronk7 committed Sep 25, 2011
1 parent 0a5afc0 commit 9c49600
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 50 deletions.
2 changes: 1 addition & 1 deletion grade/import/xml/grade_import_form.php
Expand Up @@ -32,6 +32,7 @@ function definition () {
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);


$mform->addElement('header', 'general', get_string('importfile', 'grades')); $mform->addElement('header', 'general', get_string('importfile', 'grades'));
$mform->disabledIf('url', 'userfile', 'noteq', '');


$mform->addElement('advcheckbox', 'feedback', get_string('importfeedback', 'grades')); $mform->addElement('advcheckbox', 'feedback', get_string('importfeedback', 'grades'));
$mform->setDefault('feedback', 0); $mform->setDefault('feedback', 0);
Expand All @@ -41,7 +42,6 @@ function definition () {
$mform->disabledIf('userfile', 'url', 'noteq', ''); $mform->disabledIf('userfile', 'url', 'noteq', '');


$mform->addElement('text', 'url', get_string('fileurl', 'gradeimport_xml'), 'size="80"'); $mform->addElement('text', 'url', get_string('fileurl', 'gradeimport_xml'), 'size="80"');
$mform->disabledIf('url', 'userfile', 'noteq', '');


if (!empty($CFG->gradepublishing)) { if (!empty($CFG->gradepublishing)) {
$mform->addElement('header', 'publishing', get_string('publishing', 'grades')); $mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
Expand Down
1 change: 0 additions & 1 deletion lib/form/filemanager.php
Expand Up @@ -45,7 +45,6 @@ function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $att
if (!empty($options['maxbytes'])) { if (!empty($options['maxbytes'])) {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']); $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
} }
$this->_type = 'filemanager';
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes); parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
} }


Expand Down
1 change: 0 additions & 1 deletion lib/form/filepicker.php
Expand Up @@ -29,7 +29,6 @@ function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attr
if (!empty($options['maxbytes'])) { if (!empty($options['maxbytes'])) {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']); $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
} }
$this->_type = 'filepicker';
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes); parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
} }


Expand Down
47 changes: 0 additions & 47 deletions lib/formslib.php
Expand Up @@ -339,43 +339,6 @@ function _validate_files(&$files) {
} }
} }


/**
* Internal method. Validates filepicker and filemanager files if they are
* set as required fields. Also, sets the error message if encountered one.
*
* @return bool/array with errors
*/
function _validate_draft_files() {
global $USER;
$mform =& $this->_form;

$errors = array();
//Go through all the required elements and make sure you hit filepicker or
//filemanager element.
foreach ($mform->_rules as $elementname => $rules) {
$elementtype = $mform->getElementType($elementname);
//If element is of type filepicker then do validation
if (($elementtype == 'filepicker') || ($elementtype == 'filemanager')){
//Check if rule defined is required rule
foreach ($rules as $rule) {
if ($rule['type'] == 'required') {
$draftid = (int)$mform->getSubmitValue($elementname);
$fs = get_file_storage();
$context = get_context_instance(CONTEXT_USER, $USER->id);
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
$errors[$elementname] = $rule['message'];
}
}
}
}
}
if (empty($errors)) {
return true;
} else {
return $errors;
}
}

/** /**
* Load in existing data as form defaults. Usually new entry defaults are stored directly in * Load in existing data as form defaults. Usually new entry defaults are stored directly in
* form definition (new entry form); this function is used to load in data where values * form definition (new entry form); this function is used to load in data where values
Expand Down Expand Up @@ -476,16 +439,6 @@ function validate_defined_fields($validateonnosubmit=false) {


$files = array(); $files = array();
$file_val = $this->_validate_files($files); $file_val = $this->_validate_files($files);
//check draft files for validation and flag them if required files
//are not in draft area.
$draftfilevalue = $this->_validate_draft_files();

if ($file_val !== true && $draftfilevalue !== true) {
$file_val = array_merge($file_val, $draftfilevalue);
} else if ($draftfilevalue !== true) {
$file_val = $draftfilevalue;
} //default is file_val, so no need to assign.

if ($file_val !== true) { if ($file_val !== true) {
if (!empty($file_val)) { if (!empty($file_val)) {
foreach ($file_val as $element=>$msg) { foreach ($file_val as $element=>$msg) {
Expand Down

0 comments on commit 9c49600

Please sign in to comment.