MDL-11328 Added the missing variable
[moodle-pu.git] / course / delete.php
blob02ed485bcae5026a9989bce3697502fda9246482
1 <?php // $Id$
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
9 require_login();
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);
28 $navlinks = array();
30 if (! $delete) {
31 $strdeletecheck = get_string("deletecheck", "", $course->shortname);
32 $strdeletecoursecheck = get_string("deletecoursecheck");
34 $navlinks[] = array('name' => $stradministration, 'link' => "../$CFG->admin/index.php", 'type' => 'misc');
35 $navlinks[] = array('name' => $strcategories, 'link' => "index.php", 'type' => 'misc');
36 $navlinks[] = array('name' => $category->name, 'link' => "category.php?id=$course->category", 'type' => 'misc');
37 $navlinks[] = array('name' => $strdeletecheck, 'link' => null, 'type' => 'misc');
38 $navigation = build_navigation($navlinks);
40 print_header("$site->shortname: $strdeletecheck", $site->fullname, $navigation);
42 notice_yesno("$strdeletecoursecheck<br /><br />" . format_string($course->fullname) .
43 " (" . format_string($course->shortname) . ")",
44 "delete.php?id=$course->id&amp;delete=".md5($course->timemodified)."&amp;sesskey=$USER->sesskey",
45 "category.php?id=$course->category");
47 print_footer($course);
48 exit;
51 if ($delete != md5($course->timemodified)) {
52 error("The check variable was wrong - try again");
55 if (!confirm_sesskey()) {
56 error(get_string('confirmsesskeybad', 'error'));
59 // OK checks done, delete the course now.
61 add_to_log(SITEID, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
63 $strdeletingcourse = get_string("deletingcourse", "", format_string($course->shortname));
65 $navlinks[] = array('name' => $stradministration, 'link' => "../$CFG->admin/index.php", 'type' => 'misc');
66 $navlinks[] = array('name' => $strcategories, 'link' => "index.php", 'type' => 'misc');
67 $navlinks[] = array('name' => $category->name, 'link' => "category.php?id=$course->category", 'type' => 'misc');
68 $navlinks[] = array('name' => $strdeletingcourse, 'link' => null, 'type' => 'misc');
69 $navigation = build_navigation($navlinks);
71 print_header("$site->shortname: $strdeletingcourse", $site->fullname, $navigation);
73 print_heading($strdeletingcourse);
75 delete_course($course->id);
76 fix_course_sortorder(); //update course count in catagories
78 // MDL-9983
79 events_trigger('course_deleted', $course);
81 print_heading( get_string("deletedcourse", "", format_string($course->shortname)) );
83 print_continue("category.php?id=$course->category");
85 print_footer();