Merge branch 'MDL-38542_23' of git://github.com/timhunt/moodle into MOODLE_23_STABLE
[moodle.git] / mod / feedback / delete_item.php
blob31cc3c0faa9150e07b81430292d0f72d5958cb2b
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * deletes an item of the feedback
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package feedback
25 require_once("../../config.php");
26 require_once("lib.php");
27 require_once('delete_item_form.php');
29 $id = required_param('id', PARAM_INT);
30 $deleteitem = required_param('deleteitem', PARAM_INT);
32 $PAGE->set_url('/mod/feedback/delete_item.php', array('id'=>$id, 'deleteitem'=>$deleteitem));
34 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
35 print_error('invalidcoursemodule');
38 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
39 print_error('coursemisconf');
42 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
43 print_error('invalidcoursemodule');
46 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
47 print_error('badcontext');
50 require_login($course, true, $cm);
52 require_capability('mod/feedback:edititems', $context);
54 $mform = new mod_feedback_delete_item_form();
55 $newformdata = array('id'=>$id,
56 'deleteitem'=>$deleteitem,
57 'confirmdelete'=>'1');
58 $mform->set_data($newformdata);
59 $formdata = $mform->get_data();
61 if ($mform->is_cancelled()) {
62 redirect('edit.php?id='.$id);
65 if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) {
66 feedback_delete_item($formdata->deleteitem);
67 redirect('edit.php?id=' . $id);
71 /// Print the page header
72 $strfeedbacks = get_string("modulenameplural", "feedback");
73 $strfeedback = get_string("modulename", "feedback");
75 $PAGE->navbar->add(get_string('delete_item', 'feedback'));
76 $PAGE->set_heading(format_string($course->fullname));
77 $PAGE->set_title(format_string($feedback->name));
78 echo $OUTPUT->header();
80 /// Print the main part of the page
81 ///////////////////////////////////////////////////////////////////////////
82 ///////////////////////////////////////////////////////////////////////////
83 ///////////////////////////////////////////////////////////////////////////
84 echo $OUTPUT->heading(format_text($feedback->name));
85 echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
86 echo $OUTPUT->heading(get_string('confirmdeleteitem', 'feedback'));
87 print_string('relateditemsdeleted', 'feedback');
88 $mform->display();
89 echo $OUTPUT->box_end();
91 echo $OUTPUT->footer();