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 if (!can_delete_course($id)) {
12 error('You do not have the permission to delete this course.');
15 if (!$site = get_site()) {
16 error("Site not found!");
19 $strdeletecourse = get_string("deletecourse");
20 $stradministration = get_string("administration");
21 $strcategories = get_string("categories");
23 if (! $course = get_record("course", "id", $id)) {
24 error("Course ID was incorrect (can't find it)");
27 $category = get_record("course_categories", "id", $course->category
);
30 $strdeletecheck = get_string("deletecheck", "", $course->shortname
);
31 $strdeletecoursecheck = get_string("deletecoursecheck");
34 print_header("$site->shortname: $strdeletecheck", $site->fullname
,
35 "<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
36 "<a href=\"index.php\">$strcategories</a> -> ".
37 "<a href=\"category.php?id=$course->category\">$category->name</a> -> ".
40 notice_yesno("$strdeletecoursecheck<br /><br />$course->fullname ($course->shortname)",
41 "delete.php?id=$course->id&delete=".md5($course->timemodified
)."&sesskey=$USER->sesskey",
42 "category.php?id=$course->category");
44 print_footer($course);
48 if ($delete != md5($course->timemodified
)) {
49 error("The check variable was wrong - try again");
52 if (!confirm_sesskey()) {
53 error(get_string('confirmsesskeybad', 'error'));
56 // OK checks done, delete the course now.
58 add_to_log(SITEID
, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
60 $strdeletingcourse = get_string("deletingcourse", "", $course->shortname
);
62 print_header("$site->shortname: $strdeletingcourse", $site->fullname
,
63 "<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
64 "<a href=\"index.php\">$strcategories</a> -> ".
65 "<a href=\"category.php?id=$course->category\">$category->name</a> -> ".
66 "$strdeletingcourse");
68 print_heading($strdeletingcourse);
70 delete_course($course->id
);
71 fix_course_sortorder(); //update course count in catagories
73 print_heading( get_string("deletedcourse", "", $course->shortname
) );
75 print_continue("category.php?id=$course->category");