MDL-44585 grade_import: Restrict the accepted types in the gradebook import
This commit is contained in:
@@ -74,7 +74,8 @@ if ($id) {
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -38,8 +38,16 @@ class grade_import_form extends moodleform {
|
||||
$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 = textlib::get_encodings();
|
||||
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
|
||||
|
||||
@@ -27,6 +27,12 @@ class grade_import_form extends moodleform {
|
||||
|
||||
$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 @@ class grade_import_form extends moodleform {
|
||||
$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"');
|
||||
|
||||
@@ -41,7 +41,7 @@ if (!empty($CFG->gradepublishing)) {
|
||||
$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
|
||||
|
||||
Reference in New Issue
Block a user