Ejemplo n.º 1
0
$PAGE->set_cm($cm);
$PAGE->set_pagelayout('incourse');
$PAGE->set_title(get_string('emarking', 'mod_emarking'));
$PAGE->navbar->add(get_string('uploadanswers', 'mod_emarking'));
// Options for uploading the zip file within the form
$options = array('subdirs' => 0, 'maxbytes' => get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $course->maxbytes), 'maxfiles' => 1, 'accepted_types' => '.zip', 'return_types' => FILE_INTERNAL);
$mform = new mod_emarking_upload_form(null, array('coursemoduleid' => $cmid, 'emarkingid' => $emarking->id, 'options' => $options));
// If the user cancelled the form, redirect to activity
if ($mform->is_cancelled()) {
    redirect($urlemarking);
} else {
    if ($mform->get_data()) {
        // Save uploaded file in Moodle filesystem and check
        $fs = get_file_storage();
        $fs->delete_area_files($context->id, 'mod_emarking', 'upload', $emarking->id);
        $file = $mform->save_stored_file('assignment_file', $context->id, 'mod_emarking', 'upload', $emarking->id, '/', emarking_clean_filename($mform->get_new_filename('assignment_file')));
        // Validate that file was correctly uploaded
        if (!$file) {
            print_error("Could not upload file");
        }
        // Check that the file is a zip
        if ($file->get_mimetype() !== 'application/zip') {
            echo $OUTPUT->header();
            echo $OUTPUT->box_start('generalbox');
            echo $OUTPUT->heading(get_string('error'));
            echo $OUTPUT->error_text(get_string('fileisnotzip', 'mod_emarking'));
            echo $OUTPUT->continue_button($urlemarking);
            echo $OUTPUT->box_end();
            echo $OUTPUT->footer();
            die;
        }