moodle/course/delete.php
2003-08-02 11:32:59 +00:00

86 lines
2.9 KiB
PHP

<?PHP // $Id$
// Admin-only code to delete a course utterly
require_once("../config.php");
optional_variable($id); // course id
optional_variable($delete); // delete confirmation
require_login();
if (!isadmin()) {
error("You must be an administrator to use this page.");
}
if (!$site = get_site()) {
error("Site not found!");
}
$strdeletecourse = get_string("deletecourse");
$stradministration = get_string("administration");
if (!$id) {
print_header("$site->shortname: $strdeletecourse", $site->fullname,
"<A HREF=\"../$CFG->admin/index.php\">$stradministration</A> -> $strdeletecourse");
if ($courses = get_courses()) {
print_heading(get_string("choosecourse"));
print_simple_box_start("CENTER");
foreach ($courses as $course) {
echo "<A HREF=\"delete.php?id=$course->id\">$course->fullname ($course->shortname)</A><BR>";
}
print_simple_box_end();
} else {
print_heading(get_string("nocoursesyet"));
print_continue("../$CFG->admin/index.php");
}
print_footer();
exit;
}
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect (can't find it)");
}
if (! $delete) {
$strdeletecheck = get_string("deletecheck", "", $course->shortname);
$strdeletecoursecheck = get_string("deletecoursecheck");
print_header("$site->shortname: $strdeletecheck", $site->fullname,
"<A HREF=\"../$CFG->admin/index.php\">$stradministration</A> ->
<A HREF=\"delete.php\">$strdeletecourse</A> -> $strdeletecheck");
notice_yesno("$strdeletecoursecheck<BR><BR>$course->fullname ($course->shortname)",
"delete.php?id=$course->id&delete=".md5($course->timemodified),
"delete.php");
exit;
}
if ($delete != md5($course->timemodified)) {
error("The check variable was wrong - try again");
}
// OK checks done, delete the course now.
$strdeletingcourse = get_string("deletingcourse", "", $course->shortname);
print_header("$site->shortname: $strdeletingcourse", $site->fullname,
"<A HREF=\"../$CFG->admin/index.php\">$stradministration</A> ->
<A HREF=\"delete.php\">$strdeletecourse</A> -> $strdeletingcourse");
print_heading($strdeletingcourse);
if (!remove_course_contents($course->id)) {
notify("An error occurred while deleting some of the course contents.");
}
if (!delete_records("course", "id", $course->id)) {
notify("An error occurred while deleting the main course record.");
}
print_heading( get_string("deletedcourse", "", $course->shortname) );
print_continue("delete.php");
print_footer();
?>