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 * prints the form to edit a dedicated item
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
25 require_once("../../config.php");
26 require_once("lib.php");
28 feedback_init_feedback_session();
30 $cmid = required_param('cmid', PARAM_INT
);
31 $typ = optional_param('typ', false, PARAM_ALPHA
);
32 $id = optional_param('id', false, PARAM_INT
);
33 $action = optional_param('action', false, PARAM_ALPHA
);
35 $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cmid));
38 redirect($editurl->out(false));
41 $url = new moodle_url('/mod/feedback/edit_item.php', array('cmid'=>$cmid));
43 $url->param('typ', $typ);
46 $url->param('id', $id);
50 // set up some general variables
53 if (($formdata = data_submitted()) AND !confirm_sesskey()) {
54 print_error('invalidsesskey');
57 if (! $cm = get_coursemodule_from_id('feedback', $cmid)) {
58 print_error('invalidcoursemodule');
61 if (! $course = $DB->get_record("course", array("id"=>$cm->course
))) {
62 print_error('coursemisconf');
65 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance
))) {
66 print_error('invalidcoursemodule');
69 $context = context_module
::instance($cm->id
);
71 require_login($course, true, $cm);
73 require_capability('mod/feedback:edititems', $context);
75 //if the typ is pagebreak so the item will be saved directly
76 if ($typ == 'pagebreak') {
77 feedback_create_pagebreak($feedback->id
);
78 redirect($editurl->out(false));
82 //get the existing item or create it
83 // $formdata->itemid = isset($formdata->itemid) ? $formdata->itemid : NULL;
84 if ($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) {
87 $item = new stdClass();
91 print_error('typemissing', 'feedback', $editurl->out(false));
97 require_once($CFG->dirroot
.'/mod/feedback/item/'.$typ.'/lib.php');
99 $itemobj = feedback_get_item_class($typ);
101 $itemobj->build_editform($item, $feedback, $cm);
103 if ($itemobj->is_cancelled()) {
104 redirect($editurl->out(false));
107 if ($itemobj->get_data()) {
108 if ($item = $itemobj->save_item()) {
109 feedback_move_item($item, $item->position
);
110 redirect($editurl->out(false));
114 ////////////////////////////////////////////////////////////////////////////////////
115 /// Print the page header
116 $strfeedbacks = get_string("modulenameplural", "feedback");
117 $strfeedback = get_string("modulename", "feedback");
120 $PAGE->navbar
->add(get_string('edit_item', 'feedback'));
122 $PAGE->navbar
->add(get_string('add_item', 'feedback'));
124 $PAGE->set_heading(format_string($course->fullname
));
125 $PAGE->set_title(format_string($feedback->name
));
126 echo $OUTPUT->header();
128 // Print the main part of the page.
129 echo $OUTPUT->heading(format_string($feedback->name
));
138 $itemobj->show_editform();
141 $PAGE->requires
->js('/mod/feedback/feedback.js');
142 $PAGE->requires
->js_function_call('set_item_focus', Array('id_itemname'));
146 ///////////////////////////////////////////////////////////////////////////
147 ///////////////////////////////////////////////////////////////////////////
148 ///////////////////////////////////////////////////////////////////////////
150 echo $OUTPUT->footer();