MDL-49622 behat: better handling of profile and tags
[moodle.git] / course / delete.php
blob31d48176d405422fddc3433cec9f7065b158d831
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(dirname(__FILE__) . '/../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 // We do this here because it spits out feedback as it goes.
65 delete_course($course);
66 echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
67 // Update course count in categories.
68 fix_course_sortorder();
69 echo $OUTPUT->continue_button($categoryurl);
70 echo $OUTPUT->footer();
71 exit; // We must exit here!!!
74 $strdeletecheck = get_string("deletecheck", "", $courseshortname);
75 $strdeletecoursecheck = get_string("deletecoursecheck");
76 $message = "{$strdeletecoursecheck}<br /><br />{$coursefullname} ({$courseshortname})";
78 $continueurl = new moodle_url('/course/delete.php', array('id' => $course->id, 'delete' => md5($course->timemodified)));
80 $PAGE->navbar->add($strdeletecheck);
81 $PAGE->set_title("$SITE->shortname: $strdeletecheck");
82 $PAGE->set_heading($SITE->fullname);
83 echo $OUTPUT->header();
84 echo $OUTPUT->confirm($message, $continueurl, $categoryurl);
85 echo $OUTPUT->footer();
86 exit;