2 // Admin-only code to delete a course utterly
4 require_once("../config.php");
6 $id = required_param('id', PARAM_INT
); // course id
7 $delete = optional_param('delete', '', PARAM_ALPHANUM
); // delete confirmation hash
11 require_capability('moodle/course:delete', get_context_instance(CONTEXT_SYSTEM
, SITEID
));
13 if (!$site = get_site()) {
14 error("Site not found!");
17 $strdeletecourse = get_string("deletecourse");
18 $stradministration = get_string("administration");
19 $strcategories = get_string("categories");
21 if (! $course = get_record("course", "id", $id)) {
22 error("Course ID was incorrect (can't find it)");
25 $category = get_record("course_categories", "id", $course->category
);
28 $strdeletecheck = get_string("deletecheck", "", $course->shortname
);
29 $strdeletecoursecheck = get_string("deletecoursecheck");
32 print_header("$site->shortname: $strdeletecheck", $site->fullname
,
33 "<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
34 "<a href=\"index.php\">$strcategories</a> -> ".
35 "<a href=\"category.php?id=$course->category\">$category->name</a> -> ".
38 notice_yesno("$strdeletecoursecheck<br /><br />$course->fullname ($course->shortname)",
39 "delete.php?id=$course->id&delete=".md5($course->timemodified
)."&sesskey=$USER->sesskey",
40 "category.php?id=$course->category");
42 print_footer($course);
46 if ($delete != md5($course->timemodified
)) {
47 error("The check variable was wrong - try again");
50 if (!confirm_sesskey()) {
51 error(get_string('confirmsesskeybad', 'error'));
54 // OK checks done, delete the course now.
56 add_to_log(SITEID
, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
58 $strdeletingcourse = get_string("deletingcourse", "", $course->shortname
);
60 print_header("$site->shortname: $strdeletingcourse", $site->fullname
,
61 "<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
62 "<a href=\"index.php\">$strcategories</a> -> ".
63 "<a href=\"category.php?id=$course->category\">$category->name</a> -> ".
64 "$strdeletingcourse");
66 print_heading($strdeletingcourse);
68 delete_course($course->id
);
69 fix_course_sortorder(); //update course count in catagories
71 print_heading( get_string("deletedcourse", "", $course->shortname
) );
73 print_continue("category.php?id=$course->category");