Merge branch 'wip-MDL-39456-m24' of git://github.com/samhemelryk/moodle into MOODLE_2...
[moodle.git] / course / delete.php
bloba47822bf3d695de6e5692699ad0e1db7b59d5ca2
1 <?php
2 // Admin-only code to delete a course utterly
4 require_once(dirname(__FILE__) . '/../config.php');
5 require_once($CFG->dirroot . '/course/lib.php');
7 $id = required_param('id', PARAM_INT); // course id
8 $delete = optional_param('delete', '', PARAM_ALPHANUM); // delete confirmation hash
10 $PAGE->set_url('/course/delete.php', array('id' => $id));
11 $PAGE->set_context(context_system::instance());
12 require_login();
14 $site = get_site();
16 $strdeletecourse = get_string("deletecourse");
17 $stradministration = get_string("administration");
18 $strcategories = get_string("categories");
20 if (! $course = $DB->get_record("course", array("id"=>$id))) {
21 print_error("invalidcourseid");
23 if ($site->id == $course->id) {
24 // can not delete frontpage!
25 print_error("invalidcourseid");
28 $coursecontext = context_course::instance($course->id);
30 if (!can_delete_course($id)) {
31 print_error('cannotdeletecourse');
34 $category = $DB->get_record("course_categories", array("id"=>$course->category));
35 $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
36 $categoryname = format_string($category->name, true, array('context' => context_coursecat::instance($category->id)));
38 $PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php/'));
39 $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
40 $PAGE->navbar->add($categoryname, new moodle_url('/course/category.php', array('id'=>$course->category)));
41 if (! $delete) {
42 $strdeletecheck = get_string("deletecheck", "", $courseshortname);
43 $strdeletecoursecheck = get_string("deletecoursecheck");
45 $PAGE->navbar->add($strdeletecheck);
46 $PAGE->set_title("$site->shortname: $strdeletecheck");
47 $PAGE->set_heading($site->fullname);
48 echo $OUTPUT->header();
50 $message = "$strdeletecoursecheck<br /><br />" . format_string($course->fullname, true, array('context' => $coursecontext)) . " (" . $courseshortname . ")";
52 echo $OUTPUT->confirm($message, "delete.php?id=$course->id&delete=".md5($course->timemodified), "category.php?id=$course->category");
54 echo $OUTPUT->footer();
55 exit;
58 if ($delete != md5($course->timemodified)) {
59 print_error("invalidmd5");
62 if (!confirm_sesskey()) {
63 print_error('confirmsesskeybad', 'error');
66 // OK checks done, delete the course now.
68 add_to_log(SITEID, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
70 $strdeletingcourse = get_string("deletingcourse", "", $courseshortname);
72 $PAGE->navbar->add($strdeletingcourse);
73 $PAGE->set_title("$site->shortname: $strdeletingcourse");
74 $PAGE->set_heading($site->fullname);
75 echo $OUTPUT->header();
76 echo $OUTPUT->heading($strdeletingcourse);
78 delete_course($course);
79 fix_course_sortorder(); //update course count in catagories
81 echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
83 echo $OUTPUT->continue_button("category.php?id=$course->category");
85 echo $OUTPUT->footer();