Esempio n. 1
0
if (!($course = $DB->get_record("course", array("id" => $exam->course)))) {
    print_error(get_string("invalidcourseid", "mod_emarking"));
    die;
}
$contextcat = context_coursecat::instance($course->category);
$contextcourse = context_course::instance($course->id);
$url = new moodle_url("/mod/emarking/print/download.php", array("examid" => $exam->id, "token" => $token, "sesskey" => $sesskey));
$PAGE->set_context($contextcourse);
$PAGE->set_url($url);
$coursecategoryurl = new moodle_url("/mod/emarking/print/printorders.php", array("category" => $course->category));
$courseurl = new moodle_url("/mod/emarking/print/exams.php", array("course" => $course->id));
// Validate capability in the category context.
if (!(has_capability("mod/emarking:downloadexam", $contextcat) || has_capability("mod/emarking:downloadexam", $contextcourse))) {
    $item = array("context" => $contextcourse, "objectid" => $exam->emarking);
    // Add to Moodle log so some auditing can be done.
    \mod_emarking\event\invalidaccessdownload_attempted::create($item)->trigger();
    echo json_encode(array("error" => get_string("invalidaccess", "mod_emarking")));
    die;
}
// Check the exam status to validate if it is already generated.
if ($exam->status < EMARKING_EXAM_PROCESSED) {
    echo json_encode(array('error' => get_string('error') . core_text::strtolower(' ' . get_string('exam', 'mod_emarking') . ' ' . get_string('examstatusbeingprocessed', 'mod_emarking'))));
    die;
}
// If a token was sent and it was not valid, log and die.
if ($token > 9999 && $_SESSION[$USER->sesskey . "smstoken"] !== $token) {
    $item = array("context" => $contextcourse, "objectid" => $exam->emarking);
    // Add to Moodle log so some auditing can be done.
    \mod_emarking\event\invalidtokendownload_attempted::create($item)->trigger();
    echo $OUTPUT->header();
    echo $OUTPUT->notification(get_string("eventinvalidtokengranted", "mod_emarking"), "notifyproblem");