return false;
}
+ /**
+ * Get draft files of a form element
+ * This is a protected method which will be used only inside moodleforms
+ *
+ * @global object $USER
+ * @param string $elname name of element
+ * @return array
+ */
+ protected function get_draft_files($elname) {
+ global $USER;
+
+ if (!$this->is_submitted()) {
+ return false;
+ }
+
+ $element = $this->_form->getElement($elname);
+
+ if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) {
+ $values = $this->_form->exportValues($elname);
+ if (empty($values[$elname])) {
+ return false;
+ }
+ $draftid = $values[$elname];
+ $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)) {
+ return null;
+ }
+ return $files;
+ }
+ return null;
+ }
+
/**
* Dispose form element draft files
*
// New local package upload
$maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
$mform->setMaxFileSize($maxbytes);
- $mform->addElement('file', 'packagefile', get_string('package','scorm'));
+ $mform->addElement('filepicker', 'packagefile', get_string('package','scorm'));
$mform->disabledIf('packagefile', 'scormtype', 'noteq', SCORM_TYPE_LOCAL);
//-------------------------------------------------------------------------------
}
function validation($data, $files) {
+ global $CFG;
$errors = parent::validation($data, $files);
$type = $data['scormtype'];
if (!empty($data['update'])) {
//ok, not required
- } else if (empty($files['packagefile'])) {
+ } else if (empty($data['packagefile'])) {
$errors['packagefile'] = get_string('required');
} else {
+ $files = $this->get_draft_files('packagefile');
+ if (count($files)<1) {
+ $errors['packagefile'] = get_string('required');
+ }
+ $file = reset($files);
+ $filename = $CFG->dataroot.'/temp/scormimport/scrom_'.time();
+ make_upload_directory('temp/scormimport');
+ $file->copy_content_to($filename);
+
$packer = get_file_packer('application/zip');
- $filelist = $packer->list_files($files['packagefile']);
+ $filelist = $packer->list_files($filename);
if (!is_array($filelist)) {
$errors['packagefile'] = 'Incorrect file package - not an archive'; //TODO: localise
} else {
$errors['packagefile'] = 'Incorrect file package - missing imsmanifest.xml or AICC structure'; //TODO: localise
}
}
+ unlink($filename);
}
} else if ($type === SCORM_TYPE_EXTERNAL) {