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
22 * @package mod_feedback
25 require_once("../../config.php");
26 require_once("lib.php");
28 feedback_init_feedback_session();
30 $itemid = optional_param('id', false, PARAM_INT
);
32 $cmid = required_param('cmid', PARAM_INT
);
33 $typ = required_param('typ', PARAM_ALPHA
);
37 $item = $DB->get_record('feedback_item', array('id' => $itemid), '*', MUST_EXIST
);
38 list($course, $cm) = get_course_and_cm_from_instance($item->feedback
, 'feedback');
39 $url = new moodle_url('/mod/feedback/edit_item.php', array('id' => $itemid));
43 list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'feedback');
44 $url = new moodle_url('/mod/feedback/edit_item.php', array('cmid' => $cm->id
, 'typ' => $typ));
45 $item = (object)['id' => null, 'position' => -1, 'typ' => $typ, 'options' => ''];
48 require_login($course, true, $cm);
49 $context = context_module
::instance($cm->id
);
50 require_capability('mod/feedback:edititems', $context);
51 $feedback = $PAGE->activityrecord
;
53 $editurl = new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id
));
57 // If the typ is pagebreak so the item will be saved directly.
58 if (!$item->id
&& $typ === 'pagebreak') {
60 feedback_create_pagebreak($feedback->id
);
61 redirect($editurl->out(false));
65 //get the existing item or create it
67 throw new \
moodle_exception('typemissing', 'feedback', $editurl->out(false));
70 $itemobj = feedback_get_item_class($typ);
71 $itemobj->build_editform($item, $feedback, $cm);
73 if ($itemobj->is_cancelled()) {
77 if ($itemobj->get_data()) {
78 if ($item = $itemobj->save_item()) {
79 feedback_move_item($item, $item->position
);
84 ////////////////////////////////////////////////////////////////////////////////////
85 /// Print the page header
86 $strfeedbacks = get_string("modulenameplural", "feedback");
87 $strfeedback = get_string("modulename", "feedback");
89 navigation_node
::override_active_url(new moodle_url('/mod/feedback/edit.php',
90 array('id' => $cm->id
, 'do_show' => 'edit')));
92 $PAGE->navbar
->add(get_string('edit_item', 'feedback'));
94 $PAGE->navbar
->add(get_string('add_item', 'feedback'));
96 $PAGE->set_heading($course->fullname
);
97 $PAGE->set_title($feedback->name
);
98 $PAGE->activityheader
->set_attrs([
99 "hidecompletion" => true,
102 echo $OUTPUT->header();
105 $current_tab = 'edit';
112 $itemobj->show_editform();
115 ///////////////////////////////////////////////////////////////////////////
116 ///////////////////////////////////////////////////////////////////////////
117 ///////////////////////////////////////////////////////////////////////////
119 echo $OUTPUT->footer();