示例#1
0
        error("Course is misconfigured");
    }
} else {
    if (!($assignment = get_record("assignment", "id", $a))) {
        error("Course module is incorrect");
    }
    if (!($course = get_record("course", "id", $assignment->course))) {
        error("Course is misconfigured");
    }
    if (!($cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id))) {
        error("Course Module ID was incorrect");
    }
}
require_login($course->id, false, $cm);
require_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id));
$testform = new testcase_form(count_records('assignment_oj_tests', 'assignment', $assignment->id));
if ($testform->is_cancelled()) {
    redirect($CFG->wwwroot . '/mod/assignment/view.php?id=' . $id);
} else {
    if ($fromform = $testform->get_data()) {
        delete_records('assignment_oj_tests', 'assignment', $assignment->id);
        for ($i = 0; $i < $fromform->boundary_repeats; $i++) {
            if (emptycase($fromform, $i)) {
                continue;
            }
            if (isset($fromform->usefile[$i])) {
                $testcase->usefile = $fromform->usefile[$i];
            }
            if (isset($fromform->input[$i]) && isset($fromform->output[$i])) {
                $testcase->input = $fromform->input[$i];
                $testcase->output = $fromform->output[$i];
        print_error('invalidid', 'assignment');
    }
    if (!($course = $DB->get_record("course", array("id" => $assignment->course)))) {
        print_error('coursemisconf', 'assignment');
    }
    if (!($cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id))) {
        print_error('invalidcoursemodule');
    }
    $url->param('a', $a);
}
$PAGE->set_url($url);
require_login($course, true, $cm);
global $context;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/assignment:grade', $context);
$testform = new testcase_form($DB->count_records('assignment_oj_testcases', array('assignment' => $assignment->id)));
if ($testform->is_cancelled()) {
    redirect($CFG->wwwroot . '/mod/assignment/view.php?id=' . $id);
} else {
    if ($fromform = $testform->get_data()) {
        for ($i = 0; $i < $fromform->boundary_repeats; $i++) {
            if (emptycase($fromform, $i)) {
                if ($fromform->caseid[$i] != -1) {
                    $DB->delete_records('assignment_oj_testcases', array('id' => $fromform->caseid[$i]));
                    $fs = get_file_storage();
                    $fs->delete_area_files($context->id, 'mod_assignment', 'onlinejudge_input', $fromform->caseid[$i]);
                    $fs->delete_area_files($context->id, 'mod_assignment', 'onlinejudge_output', $fromform->caseid[$i]);
                }
                continue;
            }
            if (isset($fromform->usefile[$i])) {