diff --git a/lib/classes/filetypes.php b/lib/classes/filetypes.php index cd91993f6cd..3b0be4b591b 100644 --- a/lib/classes/filetypes.php +++ b/lib/classes/filetypes.php @@ -127,6 +127,7 @@ abstract class core_filetypes { 'ico' => array('type' => 'image/vnd.microsoft.icon', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'), 'ics' => array('type' => 'text/calendar', 'icon' => 'text'), + 'imscc' => array('type' => 'application/zip', 'icon' => 'archive', 'string' => 'archive'), 'isf' => array('type' => 'application/inspiration', 'icon' => 'isf'), 'ist' => array('type' => 'application/inspiration.template', 'icon' => 'isf'), 'java' => array('type' => 'text/plain', 'icon' => 'sourcecode'), diff --git a/mod/imscp/mod_form.php b/mod/imscp/mod_form.php index d93baf90add..a8a0eabb394 100644 --- a/mod/imscp/mod_form.php +++ b/mod/imscp/mod_form.php @@ -59,7 +59,9 @@ class mod_imscp_mod_form extends moodleform_mod { // IMS-CP file upload. $mform->addElement('header', 'content', get_string('contentheader', 'imscp')); $mform->setExpanded('content', true); - $mform->addElement('filepicker', 'package', get_string('packagefile', 'imscp')); + + $mform->addElement('filepicker', 'package', get_string('packagefile', 'imscp'), null, + ['accepted_types' => ['application/zip', '.imscc']]); $options = array('-1' => get_string('all'), '0' => get_string('no'), '1' => '1', '2' => '2', '5' => '5', '10' => '10', '20' => '20'); @@ -78,27 +80,15 @@ class mod_imscp_mod_form extends moodleform_mod { * @param array $files */ public function validation($data, $files) { - global $USER; - if ($errors = parent::validation($data, $files)) { return $errors; } - $usercontext = context_user::instance($USER->id); - $fs = get_file_storage(); - - if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['package'], 'id', false)) { + if (!$this->get_draft_files('package')) { if (!$this->current->instance) { $errors['package'] = get_string('required'); return $errors; } - } else { - $file = reset($files); - if ($file->get_mimetype() != 'application/zip') { - $errors['package'] = get_string('invalidfiletype', 'error', '', $file); - // Better delete current file, it is not usable anyway. - $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['package']); - } } return $errors;