MDL-67264 core_course: Begin set up for Activity chooser
[moodle.git] / course / delete.php
CommitLineData
58b45fd7 1<?php
5dc361e1
SH
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.
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
17/**
18 * Admin-only code to delete a course utterly.
19 *
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
23 */
24
1fcf0ca8 25require_once(__DIR__ . '/../config.php');
5dc361e1 26require_once($CFG->dirroot . '/course/lib.php');
2cd901a4 27require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
5dc361e1
SH
28
29$id = required_param('id', PARAM_INT); // Course ID.
30$delete = optional_param('delete', '', PARAM_ALPHANUM); // Confirmation hash.
31
5dc361e1
SH
32$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
33$coursecontext = context_course::instance($course->id);
34
d5814f4e
PS
35require_login();
36
37if ($SITE->id == $course->id || !can_delete_course($id)) {
5dc361e1
SH
38 // Can not delete frontpage or don't have permission to delete the course.
39 print_error('cannotdeletecourse');
40}
41
d5814f4e
PS
42$categorycontext = context_coursecat::instance($course->category);
43$PAGE->set_url('/course/delete.php', array('id' => $id));
44$PAGE->set_context($categorycontext);
45$PAGE->set_pagelayout('admin');
46navigation_node::override_active_url(new moodle_url('/course/management.php', array('categoryid'=>$course->category)));
47
5dc361e1
SH
48$courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
49$coursefullname = format_string($course->fullname, true, array('context' => $coursecontext));
50$categoryurl = new moodle_url('/course/management.php', array('categoryid' => $course->category));
51
5dc361e1
SH
52// Check if we've got confirmation.
53if ($delete === md5($course->timemodified)) {
54 // We do - time to delete the course.
55 require_sesskey();
56fcb59a 56
8ebbb06a 57 $strdeletingcourse = get_string("deletingcourse", "", $courseshortname);
2b25f2a0 58
0a122046 59 $PAGE->navbar->add($strdeletingcourse);
5dc361e1
SH
60 $PAGE->set_title("$SITE->shortname: $strdeletingcourse");
61 $PAGE->set_heading($SITE->fullname);
62
0a122046 63 echo $OUTPUT->header();
7c5286cd 64 echo $OUTPUT->heading($strdeletingcourse);
41d6a25a
JP
65 // This might take a while. Raise the execution time limit.
66 core_php_time_limit::raise();
af321e0f
SH
67 // We do this here because it spits out feedback as it goes.
68 delete_course($course);
8ebbb06a 69 echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
af321e0f
SH
70 // Update course count in categories.
71 fix_course_sortorder();
5dc361e1 72 echo $OUTPUT->continue_button($categoryurl);
d60c1124 73 echo $OUTPUT->footer();
af321e0f 74 exit; // We must exit here!!!
5dc361e1
SH
75}
76
77$strdeletecheck = get_string("deletecheck", "", $courseshortname);
58b45fd7 78
5dc361e1
SH
79$PAGE->navbar->add($strdeletecheck);
80$PAGE->set_title("$SITE->shortname: $strdeletecheck");
81$PAGE->set_heading($SITE->fullname);
82echo $OUTPUT->header();
2cd901a4
MP
83
84// Only let user delete this course if there is not an async backup in progress.
85if (!async_helper::is_async_pending($id, 'course', 'backup')) {
86 $strdeletecoursecheck = get_string("deletecoursecheck");
87 $message = "{$strdeletecoursecheck}<br /><br />{$coursefullname} ({$courseshortname})";
88
89 $continueurl = new moodle_url('/course/delete.php', array('id' => $course->id, 'delete' => md5($course->timemodified)));
90 $continuebutton = new single_button($continueurl, get_string('delete'), 'post');
91 echo $OUTPUT->confirm($message, $continuebutton, $categoryurl);
92} else {
93 // Async backup is pending, don't let user delete course.
94 echo $OUTPUT->notification(get_string('pendingasyncerror', 'backup'), 'error');
95 echo $OUTPUT->container(get_string('pendingasyncdeletedetail', 'backup'));
96 echo $OUTPUT->continue_button($categoryurl);
97}
98
5dc361e1 99echo $OUTPUT->footer();
65377780 100exit;