2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * drops records from feedback_sitecourse_map
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
25 require_once("../../config.php");
26 require_once($CFG->dirroot
.'/mod/feedback/lib.php');
28 $id = required_param('id', PARAM_INT
);
29 $cmapid = required_param('cmapid', PARAM_INT
);
31 $url = new moodle_url('/mod/feedback/unmapcourse.php', array('id'=>$id));
33 $url->param('cmapid', $cmapid);
37 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
38 print_error('invalidcoursemodule');
41 if (! $course = $DB->get_record("course", array("id"=>$cm->course
))) {
42 print_error('coursemisconf');
45 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance
))) {
46 print_error('invalidcoursemodule');
49 if (!$context = get_context_instance(CONTEXT_MODULE
, $cm->id
)) {
50 print_error('badcontext');
53 require_capability('mod/feedback:mapcourse', $context);
55 // cleanup all lost entries after deleting courses or feedbacks
56 feedback_clean_up_sitecourse_map();
58 if ($DB->delete_records('feedback_sitecourse_map', array('id'=>$cmapid))) {
59 $mapurl = new moodle_url('/mod/feedback/mapcourse.php', array('id'=>$id));
60 redirect ($mapurl->out(false));
62 print_error('cannotunmap', 'feedback');