MDL-63303 message: add functions to message_repository.js
[moodle.git] / course / delete.php
blobdef41a6b7cc2770988d5ac5bcf3e0855e5d583ad
1 <?php
2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
17 /**
18 * Admin-only code to delete a course utterly.
20 * @package core_course
21 * @copyright 2002 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__ . '/../config.php');
26 require_once($CFG->dirroot . '/course/lib.php');
28 $id = required_param('id', PARAM_INT); // Course ID.
29 $delete = optional_param('delete', '', PARAM_ALPHANUM); // Confirmation hash.
31 $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
32 $coursecontext = context_course::instance($course->id);
34 require_login();
36 if ($SITE->id == $course->id || !can_delete_course($id)) {
37 // Can not delete frontpage or don't have permission to delete the course.
38 print_error('cannotdeletecourse');
41 $categorycontext = context_coursecat::instance($course->category);
42 $PAGE->set_url('/course/delete.php', array('id' => $id));
43 $PAGE->set_context($categorycontext);
44 $PAGE->set_pagelayout('admin');
45 navigation_node::override_active_url(new moodle_url('/course/management.php', array('categoryid'=>$course->category)));
47 $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
48 $coursefullname = format_string($course->fullname, true, array('context' => $coursecontext));
49 $categoryurl = new moodle_url('/course/management.php', array('categoryid' => $course->category));
51 // Check if we've got confirmation.
52 if ($delete === md5($course->timemodified)) {
53 // We do - time to delete the course.
54 require_sesskey();
56 $strdeletingcourse = get_string("deletingcourse", "", $courseshortname);
58 $PAGE->navbar->add($strdeletingcourse);
59 $PAGE->set_title("$SITE->shortname: $strdeletingcourse");
60 $PAGE->set_heading($SITE->fullname);
62 echo $OUTPUT->header();
63 echo $OUTPUT->heading($strdeletingcourse);
64 // This might take a while. Raise the execution time limit.
65 core_php_time_limit::raise();
66 // We do this here because it spits out feedback as it goes.
67 delete_course($course);
68 echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
69 // Update course count in categories.
70 fix_course_sortorder();
71 echo $OUTPUT->continue_button($categoryurl);
72 echo $OUTPUT->footer();
73 exit; // We must exit here!!!
76 $strdeletecheck = get_string("deletecheck", "", $courseshortname);
77 $strdeletecoursecheck = get_string("deletecoursecheck");
78 $message = "{$strdeletecoursecheck}<br /><br />{$coursefullname} ({$courseshortname})";
80 $continueurl = new moodle_url('/course/delete.php', array('id' => $course->id, 'delete' => md5($course->timemodified)));
81 $continuebutton = new single_button($continueurl, get_string('delete'), 'post');
83 $PAGE->navbar->add($strdeletecheck);
84 $PAGE->set_title("$SITE->shortname: $strdeletecheck");
85 $PAGE->set_heading($SITE->fullname);
86 echo $OUTPUT->header();
87 echo $OUTPUT->confirm($message, $continuebutton, $categoryurl);
88 echo $OUTPUT->footer();
89 exit;