From 37fb48e0f52f1cf486677abe149e4b370d30ee44 Mon Sep 17 00:00:00 2001 From: vyshane Date: Wed, 11 Oct 2006 05:45:44 +0000 Subject: [PATCH] Merged from 1.7 --- course/rest.php | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/course/rest.php b/course/rest.php index 0c1948e00b..b837c95540 100644 --- a/course/rest.php +++ b/course/rest.php @@ -139,11 +139,39 @@ switch($_SERVER['REQUEST_METHOD']) { break; case 'resource': - if (!$mod = get_record('course_modules', 'id', $id, 'course', $course->id)) { - error_log('AJAX commands.php: Bad course module ID '.$id); + if (!$cm = get_record('course_modules', 'id', $id, 'course', $course->id)) { + error_log('AJAX rest.php: Bad course module ID '.$id); + die; + } + if (!$mod = get_record('modules', 'id', $cm->module)) { + error_log('AJAX rest.php: Bad module ID '.$cm->module); + die; + } + $mod->name = clean_param($mod->name, PARAM_SAFEDIR); // For safety + $modlib = "$CFG->dirroot/mod/$mod->name/lib.php"; + + if (file_exists($modlib)) { + include_once($modlib); + } else { + error_log("Ajax rest.php: This module is missing important code ($modlib)"); die; } - delete_course_module($id); + $deleteinstancefunction = $mod->name."_delete_instance"; + + // Run the module's cleanup funtion. + if (!$deleteinstancefunction($cm->instance)) { + error_log("Ajax rest.php: Could not delete the $mod->name (instance)"); + die; + } + // Remove the course_modules entry. + if (!delete_course_module($cm->id)) { + error_log("Ajax rest.php: Could not delete the $mod->modulename (coursemodule)"); + die; + } + + add_to_log($courseid, "course", "delete mod", + "view.php?id=$courseid", + "$mod->name $cm->instance", $cm->id); break; } break; -- 2.39.5