delete.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // This file is part of
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. require_once('../../../../config.php');
  17. require_once('submission_functions.php');
  18. // Get Params to correctly load page
  19. $cmid = required_param('cmid', PARAM_INT);
  20. $subid = required_param('subid', PARAM_INT);
  21. $gradeimporterid = optional_param('id', 0, PARAM_INT);
  22. // Get course module and $course to check capability
  23. $cm = get_coursemodule_from_id('gradeimporter', $cmid, 0, false, MUST_EXIST);
  24. $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  25. // Gets context to check capability
  26. $context = context_module::instance($cm->id);
  27. // Sets Page URL
  28. $url = new moodle_url('/mod/gradeimporter/forms/submission/delete.php', array('cmid' => $cm->id, 'subid' => $subid));
  29. if (!empty($gradeimporterid)) {
  30. $url->param('id', $gradeimporterid);
  31. }
  32. $PAGE->set_url($url);
  33. // Check if its teacher opening the page
  34. require_login ($course, false, $cm);
  35. require_capability('mod/gradeimporter:edit', $context);
  36. // Get globals
  37. global $DB;
  38. // Get submission
  39. $submission = $DB->get_record('gradeimporter_submission', array('id' => $subid, 'gradeimporterid' => $gradeimporterid));
  40. // If submission doesn't exist, throw error
  41. if (!$submission) {
  42. throw new moodle_exception(get_string('submissionnotfound', 'gradeimporter', $subid));
  43. }
  44. // Get feedbacks associated with it
  45. $feedbacks = $DB->get_records('gradeimporter_feedback', array('submissionid' => $subid));
  46. foreach ($feedbacks as $feedback) {
  47. // For each feedback, deletes its files and then delete it
  48. delete_feedback_files($feedback);
  49. $DB->delete_records('gradeimporter_feedback', array('id' => $feedback->id));
  50. }
  51. // Delete submission
  52. $DB->delete_records('gradeimporter_submission', array('id' => $submission->id));
  53. // Print page and redirects to submission page after 5 seconds
  54. $PAGE->set_title($submission->name);
  55. $PAGE->set_heading($course->fullname);
  56. $PAGE->set_context($context);
  57. $viewlink = new moodle_url('CFG->dirroot/mod/gradeimporter/view.php', array('id' => $cmid, 'edit' => 1));
  58. echo $OUTPUT->header("refresh:5;url=../../view.php?id=$cmid&edit=1");
  59. echo "<p>".get_string('deletesubmissiondata', 'gradeimporter', $submission->name)."</p>";
  60. echo "<p>".get_string('deletefeedbacksdata', 'gradeimporter', count($feedbacks))."</p>";
  61. echo "<p>".get_string('redirect5s', 'gradeimporter')."<a href=$viewlink>".get_string('here', 'gradeimporter')."</p>";
  62. echo $OUTPUT->footer();