delete.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // Delete its feedbacks
  47. foreach ($feedbacks as $feedback) {
  48. // Deletes feedback from gradeimporter_feedback table and removes its associated files
  49. delete_feedback($feedback);
  50. // Recalculates gradeimporter instance grade without this feedback
  51. gradeimporter_update_grades($submission, $feedback->studentid);
  52. }
  53. // Delete submission
  54. $DB->delete_records('gradeimporter_submission', array('id' => $submission->id));
  55. // Print page and redirects to submission page after 5 seconds
  56. $PAGE->set_title($submission->name);
  57. $PAGE->set_heading($course->fullname);
  58. $PAGE->set_context($context);
  59. $viewlink = new moodle_url("/mod/gradeimporter/view.php", array('id' => $cmid, 'edit' => 1));
  60. echo $OUTPUT->header("refresh:5;url=$viewlink");
  61. echo "<p>".get_string('deletesubmissiondata', 'gradeimporter', $submission->name)."</p>";
  62. echo "<p>".get_string('deletefeedbacksdata', 'gradeimporter', count($feedbacks))."</p>";
  63. echo "<p>".get_string('redirect5s', 'gradeimporter')."<a href=\"$viewlink\">".get_string('here', 'gradeimporter')."</p>";
  64. echo $OUTPUT->footer();