Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/delete.php
Go to the documentation of this file.
00001 <?php
00002       // Admin-only code to delete a course utterly
00003 
00004     require_once(dirname(__FILE__) . '/../config.php');
00005     require_once($CFG->dirroot . '/course/lib.php');
00006 
00007     $id     = required_param('id', PARAM_INT);              // course id
00008     $delete = optional_param('delete', '', PARAM_ALPHANUM); // delete confirmation hash
00009 
00010     $PAGE->set_url('/course/delete.php', array('id' => $id));
00011     $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
00012     require_login();
00013 
00014     $site = get_site();
00015 
00016     $strdeletecourse = get_string("deletecourse");
00017     $stradministration = get_string("administration");
00018     $strcategories = get_string("categories");
00019 
00020     if (! $course = $DB->get_record("course", array("id"=>$id))) {
00021         print_error("invalidcourseid", 'error', '', $id);
00022     }
00023     if ($site->id == $course->id) {
00024         // can not delete frontpage!
00025         print_error("invalidcourseid", 'error', '', $id);
00026     }
00027 
00028     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00029 
00030     if (!can_delete_course($id)) {
00031         print_error('cannotdeletecourse');
00032     }
00033 
00034     $category = $DB->get_record("course_categories", array("id"=>$course->category));
00035     $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
00036     $categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id)));
00037 
00038     $PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php/'));
00039     $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
00040     $PAGE->navbar->add($categoryname, new moodle_url('/course/category.php', array('id'=>$course->category)));
00041     if (! $delete) {
00042         $strdeletecheck = get_string("deletecheck", "", $courseshortname);
00043         $strdeletecoursecheck = get_string("deletecoursecheck");
00044 
00045         $PAGE->navbar->add($strdeletecheck);
00046         $PAGE->set_title("$site->shortname: $strdeletecheck");
00047         $PAGE->set_heading($site->fullname);
00048         echo $OUTPUT->header();
00049 
00050         $message = "$strdeletecoursecheck<br /><br />" . format_string($course->fullname, true, array('context' => $coursecontext)) .  " (" . $courseshortname . ")";
00051 
00052         echo $OUTPUT->confirm($message, "delete.php?id=$course->id&delete=".md5($course->timemodified), "category.php?id=$course->category");
00053 
00054         echo $OUTPUT->footer();
00055         exit;
00056     }
00057 
00058     if ($delete != md5($course->timemodified)) {
00059         print_error("invalidmd5");
00060     }
00061 
00062     if (!confirm_sesskey()) {
00063         print_error('confirmsesskeybad', 'error');
00064     }
00065 
00066     // OK checks done, delete the course now.
00067 
00068     add_to_log(SITEID, "course", "delete", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
00069 
00070     $strdeletingcourse = get_string("deletingcourse", "", $courseshortname);
00071 
00072     $PAGE->navbar->add($strdeletingcourse);
00073     $PAGE->set_title("$site->shortname: $strdeletingcourse");
00074     $PAGE->set_heading($site->fullname);
00075     echo $OUTPUT->header();
00076     echo $OUTPUT->heading($strdeletingcourse);
00077 
00078     delete_course($course);
00079     fix_course_sortorder(); //update course count in catagories
00080 
00081     echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) );
00082 
00083     echo $OUTPUT->continue_button("category.php?id=$course->category");
00084 
00085     echo $OUTPUT->footer();
00086 
00087 
 All Data Structures Namespaces Files Functions Variables Enumerations