} $criterion = null; if ($criterionid > 0 && !($criterion = $DB->get_record('gradingform_rubric_criteria', array('id' => $criterionid)))) { print_error(get_string('invalidcourseid', 'mod_emarking')); } // Get the course module for the emarking, to build the emarking url $urlemarking = new moodle_url('/mod/emarking/kanban.php', array('id' => $cm->id, 'criterion' => $criterionid)); $context = context_module::instance($cm->id); // Check that user is logued in the course require_login($course->id); if (isguestuser()) { die; } // Check if user has an editingteacher role require_capability('mod/emarking:grade', $context); $useristeacher = emarking_user_is_teacher($course->id); if ($useristeacher || is_siteadmin($USER)) { $emarking->anonymous = false; } // Page navigation and URL settings $PAGE->set_url($urlemarking); $PAGE->set_context($context); $PAGE->set_course($course); $PAGE->set_pagelayout('incourse'); $PAGE->set_cm($cm); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('emarking', 'mod_emarking')); // Show header and heading echo $OUTPUT->header(); echo $OUTPUT->heading_with_help(get_string('emarking', 'mod_emarking'), 'annotatesubmission', 'mod_emarking'); // Navigation tabs
/** * Serves the files from the emarking file areas * * @package mod_emarking * @category files * * @param stdClass $course the course object * @param stdClass $cm the course module object * @param stdClass $context the emarking's context * @param string $filearea the name of the file area * @param array $args extra arguments (itemid, path) * @param bool $forcedownload whether or not force download * @param array $options additional options affecting the file serving */ function emarking_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options = array()) { global $DB, $CFG, $USER; require_once $CFG->dirroot . '/mod/emarking/locallib.php'; require_login(); $filename = array_pop($args); $arg0 = array_pop($args); $contextcategory = context_coursecat::instance($course->category); $contextcourse = context_course::instance($course->id); $examid = 0; // Security! if ($filearea === 'exams') { if (!has_capability('mod/emarking:downloadexam', $contextcategory) && !($CFG->emarking_teachercandownload && has_capability('mod/emarking:downloadexam', $contextcourse))) { send_file_not_found(); } $sesskey = required_param('sesskey', PARAM_ALPHANUM); $token = optional_param('token', 0, PARAM_INT); // Validate session key if ($sesskey != $USER->sesskey) { send_file_not_found(); } if ($token > 9999) { $examid = $_SESSION[$USER->sesskey . 'examid']; } // A token was sent to validate download if ($token > 9999) { if ($_SESSION[$USER->sesskey . 'smstoken'] === $token) { $now = new DateTime(); $tokendate = new DateTime(); $tokendate->setTimestamp($_SESSION[$USER->sesskey . 'smsdate']); $diff = $now->diff($tokendate); if ($diff->i > 5) { send_file_not_found(); } } else { send_file_not_found(); } } elseif ($token > 0) { send_file_not_found(); } } if ($filearea === 'pages') { $parts = explode('-', $filename); if (count($parts) != 3) { send_file_not_found(); } if (!($parts[0] === intval($parts[0]) . "") || !($parts[1] === intval($parts[1]) . "")) { send_file_not_found(); } $subparts = explode('.', $parts[2]); $isanonymous = substr($subparts[0], -strlen('_a')) === '_a'; $imageuser = intval($parts[0]); $usercangrade = has_capability('mod/emarking:grade', $context); $bothenrolled = is_enrolled($contextcourse) && is_enrolled($contextcourse, $imageuser); if ($USER->id != $imageuser && !$usercangrade && !$isanonymous && !is_siteadmin($USER) && !$bothenrolled) { send_file_not_found(); } } if ($filearea === 'response') { $parts = explode('_', $filename); if (count($parts) != 3) { send_file_not_found(); } if (!($parts[0] === "response") || !($parts[1] === intval($parts[1]) . "")) { send_file_not_found(); } $subparts = explode('.', $parts[2]); $studentid = intval($subparts[0]); $emarkingid = intval($parts[1]); if (!($emarking = $DB->get_record('emarking', array('id' => $emarkingid)))) { send_file_not_found(); } $useristeacher = emarking_user_is_teacher($emarking->course); if ($studentid != $USER->id && !is_siteadmin($USER) && !$useristeacher) { send_file_not_found(); } } $fs = get_file_storage(); /* * Check if this module is part of crowd module linking. */ if ($markermap = $DB->get_record('emarking_markers', array('activityid' => $cm->instance))) { //(Its linked) if ($markermap->masteractivity != $cm->instance) { //This is a child soreplace the context for the parent's $parentcm = get_coursemodule_from_instance("emarking", $markermap->masteractivity); $context = context_module::instance($parentcm->id); $arg0 = $markermap->masteractivity; } } //echo $context->id."..".$filearea."..".$arg0;die(); if (!($file = $fs->get_file($context->id, 'mod_emarking', $filearea, $arg0, '/', $filename))) { //submission .pdf hay que cambiar al nombre del png user-curso-pag.png echo "File really not found"; send_file_not_found(); } if ($examid > 0) { if (!($exam = $DB->get_record('emarking_exams', array('id' => $examid)))) { echo "Exam not found"; send_file_not_found(); } $exam->status = EMARKING_EXAM_SENT_TO_PRINT; $DB->update_record('emarking_exams', $exam); } send_file($file, $filename); }