5ba165baca134d4d739458e52313a83187d04948
[moodle.git] / course / delete.php
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 (!isadmin()) {
12         error("You must be an administrator to use this page.");
13     }
15     if (!$site = get_site()) {
16         error("Site not found!");
17     }
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)");
25     }
27     $category = get_record("course_categories", "id", $course->category);
29     if (! $delete) {
30         $strdeletecheck = get_string("deletecheck", "", $course->shortname);
31         $strdeletecoursecheck = get_string("deletecoursecheck");
33         
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> -> ".
38                      "$strdeletecheck");
40         notice_yesno("$strdeletecoursecheck<br /><br />$course->fullname ($course->shortname)", 
41                      "delete.php?id=$course->id&amp;delete=".md5($course->timemodified)."&amp;sesskey=$USER->sesskey", 
42                      "category.php?id=$course->category");
44         print_footer($course);
45         exit;
46     }
48     if ($delete != md5($course->timemodified)) {
49         error("The check variable was wrong - try again");
50     }
52     if (!confirm_sesskey()) {
53         error(get_string('confirmsesskeybad', 'error'));
54     }
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");
77     print_footer();
79 ?>