2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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 $PAGE->set_url('/course/delete.php', array('id' => $id));
32 $PAGE->set_context(context_system
::instance());
35 $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST
);
36 $coursecontext = context_course
::instance($course->id
);
38 if ((int)$SITE->id
=== (int)$course->id ||
!can_delete_course($id)) {
39 // Can not delete frontpage or don't have permission to delete the course.
40 print_error('cannotdeletecourse');
43 $courseshortname = format_string($course->shortname
, true, array('context' => $coursecontext));
44 $coursefullname = format_string($course->fullname
, true, array('context' => $coursecontext));
45 $categoryurl = new moodle_url('/course/management.php', array('categoryid' => $course->category
));
47 navigation_node
::override_active_url(new moodle_url('/course/management.php'));
49 // Check if we've got confirmation.
50 if ($delete === md5($course->timemodified
)) {
51 // We do - time to delete the course.
54 $strdeletingcourse = get_string("deletingcourse", "", $courseshortname);
56 $PAGE->navbar
->add($strdeletingcourse);
57 $PAGE->set_title("$SITE->shortname: $strdeletingcourse");
58 $PAGE->set_heading($SITE->fullname
);
60 echo $OUTPUT->header();
61 echo $OUTPUT->heading($strdeletingcourse);
62 // We do this here because it spits out feedback as it goes.
63 delete_course($course);
64 echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
65 // Update course count in categories.
66 fix_course_sortorder();
67 echo $OUTPUT->continue_button($categoryurl);
68 echo $OUTPUT->footer();
69 exit; // We must exit here!!!
72 $strdeletecheck = get_string("deletecheck", "", $courseshortname);
73 $strdeletecoursecheck = get_string("deletecoursecheck");
74 $message = "{$strdeletecoursecheck}<br /><br />{$coursefullname} ({$courseshortname})";
76 $continueurl = new moodle_url('/course/delete.php', array('id' => $course->id
, 'delete' => md5($course->timemodified
)));
78 $PAGE->navbar
->add($strdeletecheck);
79 $PAGE->set_title("$SITE->shortname: $strdeletecheck");
80 $PAGE->set_heading($SITE->fullname
);
81 echo $OUTPUT->header();
82 echo $OUTPUT->confirm($message, $continueurl, $categoryurl);
83 echo $OUTPUT->footer();