Merge branch 'MDL-32249-21' of github.com:srynot4sale/moodle into MOODLE_21_STABLE
[moodle.git] / course / delete.php
blob906f7b7155b1320b8d3c2d01fba0e0a3c4617efc
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 $coursecontext = get_context_instance(CONTEXT_COURSE, $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' => get_context_instance(CONTEXT_COURSE, $course->id)));
36 $categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $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 . ")";
51 echo $OUTPUT->confirm($message, "delete.php?id=$course->id&delete=".md5($course->timemodified), "category.php?id=$course->category");
53 echo $OUTPUT->footer();
54 exit;
57 if ($delete != md5($course->timemodified)) {
58 print_error("invalidmd5");
61 if (!confirm_sesskey()) {
62 print_error('confirmsesskeybad', 'error');
65 // OK checks done, delete the course now.
67 add_to_log(SITEID, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
69 $strdeletingcourse = get_string("deletingcourse", "", $courseshortname);
71 $PAGE->navbar->add($strdeletingcourse);
72 $PAGE->set_title("$site->shortname: $strdeletingcourse");
73 $PAGE->set_heading($site->fullname);
74 echo $OUTPUT->header();
75 echo $OUTPUT->heading($strdeletingcourse);
77 delete_course($course);
78 fix_course_sortorder(); //update course count in catagories
80 echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
82 echo $OUTPUT->continue_button("category.php?id=$course->category");
84 echo $OUTPUT->footer();