forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.php
87 lines (60 loc) · 3.21 KB
/
delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php // $Id$
// Admin-only code to delete a course utterly
require_once("../config.php");
$id = required_param('id', PARAM_INT); // course id
$delete = optional_param('delete', '', PARAM_ALPHANUM); // delete confirmation hash
require_login();
if (!can_delete_course($id)) {
print_error('cannotdeletecourse');
}
if (!$site = get_site()) {
print_error("siteisnotdefined", 'debug');
}
$strdeletecourse = get_string("deletecourse");
$stradministration = get_string("administration");
$strcategories = get_string("categories");
if (! $course = get_record("course", "id", $id)) {
print_error("invalidcourseid");
}
$category = get_record("course_categories", "id", $course->category);
$navlinks = array();
if (! $delete) {
$strdeletecheck = get_string("deletecheck", "", $course->shortname);
$strdeletecoursecheck = get_string("deletecoursecheck");
$navlinks[] = array('name' => $stradministration, 'link' => "../$CFG->admin/index.php", 'type' => 'misc');
$navlinks[] = array('name' => $strcategories, 'link' => "index.php", 'type' => 'misc');
$navlinks[] = array('name' => $category->name, 'link' => "category.php?id=$course->category", 'type' => 'misc');
$navlinks[] = array('name' => $strdeletecheck, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$site->shortname: $strdeletecheck", $site->fullname, $navigation);
notice_yesno("$strdeletecoursecheck<br /><br />" . format_string($course->fullname) .
" (" . format_string($course->shortname) . ")",
"delete.php?id=$course->id&delete=".md5($course->timemodified)."&sesskey=$USER->sesskey",
"category.php?id=$course->category");
print_footer($course);
exit;
}
if ($delete != md5($course->timemodified)) {
print_error("invalidmd5");
}
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', 'error');
}
// OK checks done, delete the course now.
add_to_log(SITEID, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
$strdeletingcourse = get_string("deletingcourse", "", format_string($course->shortname));
$navlinks[] = array('name' => $stradministration, 'link' => "../$CFG->admin/index.php", 'type' => 'misc');
$navlinks[] = array('name' => $strcategories, 'link' => "index.php", 'type' => 'misc');
$navlinks[] = array('name' => $category->name, 'link' => "category.php?id=$course->category", 'type' => 'misc');
$navlinks[] = array('name' => $strdeletingcourse, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$site->shortname: $strdeletingcourse", $site->fullname, $navigation);
print_heading($strdeletingcourse);
delete_course($course->id);
fix_course_sortorder(); //update course count in catagories
// MDL-9983
events_trigger('course_deleted', $course);
print_heading( get_string("deletedcourse", "", format_string($course->shortname)) );
print_continue("category.php?id=$course->category");
print_footer();
?>