. require_once('../../../../config.php'); require_once('submission_functions.php'); // Get Params to correctly load page $cmid = required_param('cmid', PARAM_INT); $subid = required_param('subid', PARAM_INT); $gradeimporterid = optional_param('id', 0, PARAM_INT); // Get course module and $course to check capability $cm = get_coursemodule_from_id('gradeimporter', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); // Gets context to check capability $context = context_module::instance($cm->id); // Sets Page URL $url = new moodle_url('/mod/gradeimporter/forms/submission/delete.php', array('cmid' => $cm->id, 'subid' => $subid)); if (!empty($gradeimporterid)) { $url->param('id', $gradeimporterid); } $PAGE->set_url($url); // Check if its teacher opening the page require_login ($course, false, $cm); require_capability('mod/gradeimporter:edit', $context); // Get globals global $DB; // Get submission $submission = $DB->get_record('gradeimporter_submission', array('id' => $subid, 'gradeimporterid' => $gradeimporterid)); // If submission doesn't exist, throw error if (!$submission) { throw new moodle_exception(get_string('submissionnotfound', 'gradeimporter', $subid)); } // Get feedbacks associated with it $feedbacks = $DB->get_records('gradeimporter_feedback', array('submissionid' => $subid)); // Delete its feedbacks foreach ($feedbacks as $feedback) { // Deletes feedback from gradeimporter_feedback table and removes its associated files delete_feedback($feedback); // Recalculates gradeimporter instance grade without this feedback gradeimporter_update_grades($submission, $feedback->studentid); } // Delete submission $DB->delete_records('gradeimporter_submission', array('id' => $submission->id)); // If there are no more submission that go to the gradebook, reset it for this gradeimporter instance if (!$DB->get_records('gradeimporter_submission', array('gradebook' => 1))) { gradeimporter_grade_item_update($submission, 'reset'); } // Print page and redirects to submission page after 5 seconds $PAGE->set_title($submission->name); $PAGE->set_heading($course->fullname); $PAGE->set_context($context); $viewlink = new moodle_url("/mod/gradeimporter/view.php", array('id' => $cmid, 'edit' => 1)); echo $OUTPUT->header("refresh:5;url=$viewlink"); echo "

".get_string('deletesubmissiondata', 'gradeimporter', $submission->name)."

"; echo "

".get_string('deletefeedbacksdata', 'gradeimporter', count($feedbacks))."

"; echo "

".get_string('redirect5s', 'gradeimporter')." ".get_string('here', 'gradeimporter')."

"; echo $OUTPUT->footer();