Ejemplo n.º 1
0
// Check that user is logged in and is not guest
require_login($course->id);
if (isguestuser()) {
    die;
}
// Set navigation parameters
$PAGE->set_url($url);
$PAGE->set_context($context);
$PAGE->set_course($course);
$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') {
Ejemplo n.º 2
0
require_login($course->id);
if (isguestuser()) {
    die;
}
$action = optional_param('action', 'view', PARAM_ALPHA);
$digitizedanswerid = optional_param('did', 0, PARAM_INT);
$usercanmanageanswersfiles = has_capability('mod/emarking:uploadexam', $context) || is_siteadmin();
// Set navigation parameters.
$PAGE->set_url($url);
$PAGE->set_context($context);
$PAGE->set_course($course);
$PAGE->set_cm($cm);
$PAGE->set_pagelayout('incourse');
$PAGE->set_title(get_string('emarking', 'mod_emarking'));
$PAGE->navbar->add(get_string('uploadanswers', 'mod_emarking'));
$mform = new mod_emarking_upload_form(null, array('coursemoduleid' => $cm->id, 'emarkingid' => $emarking->id));
// If the user cancelled the form, redirect to activity.
if ($mform->is_cancelled()) {
    redirect($urlemarking);
    die;
}
if ($mform->get_data()) {
    require_capability('mod/emarking:uploadexam', $context);
    // Save uploaded file in Moodle filesystem and check.
    $fs = get_file_storage();
    $fs->delete_area_files($context->id, 'mod_emarking', 'tmpupload');
    $itemid = $emarking->id;
    $filemimetypes = array('dummy', 'application/pdf', 'application/zip');
    $file = $mform->save_stored_file('assignment_file', $context->id, 'mod_emarking', 'tmpupload', $itemid, '/', emarking_clean_filename($mform->get_new_filename('assignment_file')));
    // Validate that file was correctly uploaded.
    if (!$file) {