Merge branch 'MDL-27053-dev-code-warning' of git://github.com/mudrd8mz/moodle
[moodle.git] / course / delete.php
blobc0a60ca88726b07fb95fe6e5b8bfd688292260f8
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(get_context_instance(CONTEXT_SYSTEM));
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", 'error', '', $id);
23 if ($site->id == $course->id) {
24 // can not delete frontpage!
25 print_error("invalidcourseid", 'error', '', $id);
28 if (!can_delete_course($id)) {
29 print_error('cannotdeletecourse');
32 $category = $DB->get_record("course_categories", array("id"=>$course->category));
34 $PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php/'));
35 $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
36 $PAGE->navbar->add($category->name, new moodle_url('/course/category.php', array('id'=>$course->category)));
37 if (! $delete) {
38 $strdeletecheck = get_string("deletecheck", "", $course->shortname);
39 $strdeletecoursecheck = get_string("deletecoursecheck");
41 $PAGE->navbar->add($strdeletecheck);
42 $PAGE->set_title("$site->shortname: $strdeletecheck");
43 $PAGE->set_heading($site->fullname);
44 echo $OUTPUT->header();
46 $message = "$strdeletecoursecheck<br /><br />" . format_string($course->fullname) . " (" . format_string($course->shortname) . ")";
47 echo $OUTPUT->confirm($message, "delete.php?id=$course->id&delete=".md5($course->timemodified), "category.php?id=$course->category");
49 echo $OUTPUT->footer();
50 exit;
53 if ($delete != md5($course->timemodified)) {
54 print_error("invalidmd5");
57 if (!confirm_sesskey()) {
58 print_error('confirmsesskeybad', 'error');
61 // OK checks done, delete the course now.
63 add_to_log(SITEID, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
65 $strdeletingcourse = get_string("deletingcourse", "", format_string($course->shortname));
67 $PAGE->navbar->add($strdeletingcourse);
68 $PAGE->set_title("$site->shortname: $strdeletingcourse");
69 $PAGE->set_heading($site->fullname);
70 echo $OUTPUT->header();
71 echo $OUTPUT->heading($strdeletingcourse);
73 delete_course($course);
74 fix_course_sortorder(); //update course count in catagories
76 echo $OUTPUT->heading( get_string("deletedcourse", "", format_string($course->shortname)) );
78 echo $OUTPUT->continue_button("category.php?id=$course->category");
80 echo $OUTPUT->footer();