moodle/course/delete.php

87 lines
2.9 KiB
PHP
Raw Normal View History

2004-09-12 12:21:27 +00:00
<?php // $Id$
// Admin-only code to delete a course utterly
2005-05-16 19:38:21 +00:00
require_once("../config.php");
$id = required_param('id',PARAM_INT); // course id
$delete = optional_param('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");
$strcategories = get_string("categories");
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect (can't find it)");
}
$category = get_record("course_categories", "id", $course->category);
if (! $delete) {
2002-08-04 02:10:00 +00:00
$strdeletecheck = get_string("deletecheck", "", $course->shortname);
$strdeletecoursecheck = get_string("deletecoursecheck");
2005-05-16 19:38:21 +00:00
print_header("$site->shortname: $strdeletecheck", $site->fullname,
2003-08-09 02:10:05 +00:00
"<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
"<a href=\"index.php\">$strcategories</a> -> ".
"<a href=\"category.php?id=$course->category\">$category->name</a> -> ".
2003-08-09 02:10:05 +00:00
"$strdeletecheck");
2004-09-12 12:21:27 +00:00
notice_yesno("$strdeletecoursecheck<br /><br />$course->fullname ($course->shortname)",
"delete.php?id=$course->id&amp;delete=".md5($course->timemodified)."&amp;sesskey=$USER->sesskey",
2003-08-09 02:10:05 +00:00
"category.php?id=$course->category");
exit;
}
if ($delete != md5($course->timemodified)) {
error("The check variable was wrong - try again");
}
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
}
// OK checks done, delete the course now.
2005-03-14 02:39:39 +00:00
add_to_log(SITEID, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
$strdeletingcourse = get_string("deletingcourse", "", $course->shortname);
2005-05-16 19:38:21 +00:00
print_header("$site->shortname: $strdeletingcourse", $site->fullname,
2003-08-09 02:10:05 +00:00
"<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> ".
"<a href=\"index.php\">$strcategories</a> -> ".
"<a href=\"category.php?id=$course->category\">$category->name</a> -> ".
2003-08-09 02:10:05 +00:00
"$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.");
}
if (!fulldelete($CFG->dataroot.'/'.$course->id)) {
notify("An error occurred while deleting the course files.");
}
2002-08-04 02:10:00 +00:00
print_heading( get_string("deletedcourse", "", $course->shortname) );
2003-08-09 02:10:05 +00:00
print_continue("category.php?id=$course->category");
print_footer();
?>