Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-44585 grade_import: Restrict the accepted types in the gradebook …

…import
  • Loading branch information...
commit 7ae964bf89f97b6594a6cb881299f4ae613f0345 1 parent 872f4e2
@leblangi leblangi authored
View
3  grade/import/csv/index.php
@@ -74,7 +74,8 @@
}
// Set up the import form.
-$mform = new grade_import_form(null, array('includeseparator'=>true, 'verbosescales'=>true));
+$mform = new grade_import_form(null, array('includeseparator' => true, 'verbosescales' => true, 'acceptedtypes' =>
+ array('.csv', '.txt')));
// If the csv file hasn't been imported yet then look for a form submission or
// show the initial submission form.
View
12 grade/import/grade_import_form.php
@@ -38,8 +38,16 @@ function definition (){
$mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
$mform->setType('id', PARAM_INT);
$mform->addElement('header', 'general', get_string('importfile', 'grades'));
- // file upload
- $mform->addElement('filepicker', 'userfile', get_string('file'));
+
+ // Restrict the possible upload file types.
+ if (!empty($features['acceptedtypes'])) {
+ $acceptedtypes = $features['acceptedtypes'];
+ } else {
+ $acceptedtypes = '*';
+ }
+
+ // File upload.
+ $mform->addElement('filepicker', 'userfile', get_string('file'), null, array('accepted_types' => $acceptedtypes));
$mform->addRule('userfile', null, 'required');
$encodings = core_text::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
View
17 grade/import/xml/grade_import_form.php
@@ -27,6 +27,12 @@ function definition () {
$mform =& $this->_form;
+ if (isset($this->_customdata)) {
+ $features = $this->_customdata;
+ } else {
+ $features = array();
+ }
+
// course id needs to be passed for auth purposes
$mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
$mform->setType('id', PARAM_INT);
@@ -36,8 +42,15 @@ function definition () {
$mform->addElement('advcheckbox', 'feedback', get_string('importfeedback', 'grades'));
$mform->setDefault('feedback', 0);
- // file upload
- $mform->addElement('filepicker', 'userfile', get_string('file'));
+ // Restrict the possible upload file types.
+ if (!empty($features['acceptedtypes'])) {
+ $acceptedtypes = $features['acceptedtypes'];
+ } else {
+ $acceptedtypes = '*';
+ }
+
+ // File upload.
+ $mform->addElement('filepicker', 'userfile', get_string('file'), null, array('accepted_types' => $acceptedtypes));
$mform->disabledIf('userfile', 'url', 'noteq', '');
$mform->addElement('text', 'url', get_string('fileurl', 'gradeimport_xml'), 'size="80"');
View
2  grade/import/xml/index.php
@@ -41,7 +41,7 @@
$CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context);
}
-$mform = new grade_import_form();
+$mform = new grade_import_form(null, array('acceptedtypes' => array('.xml')));
if ($data = $mform->get_data()) {
// Large files are likely to take their time and memory. Let PHP know

0 comments on commit 7ae964b

Please sign in to comment.
Something went wrong with that request. Please try again.