MDL-81717 h5p: Improve robustness content type fetching
[moodle.git] / mod / feedback / edit_item.php
blobcbc88b076f960cb9935c4f65215380da43cf2b3c
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 * 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);
31 if (!$itemid) {
32 $cmid = required_param('cmid', PARAM_INT);
33 $typ = required_param('typ', PARAM_ALPHA);
36 if ($itemid) {
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));
40 $typ = $item->typ;
41 } else {
42 $item = null;
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));
55 $PAGE->set_url($url);
57 // If the typ is pagebreak so the item will be saved directly.
58 if (!$item->id && $typ === 'pagebreak') {
59 require_sesskey();
60 feedback_create_pagebreak($feedback->id);
61 redirect($editurl->out(false));
62 exit;
65 //get the existing item or create it
66 if (!$typ) {
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()) {
74 redirect($editurl);
75 exit;
77 if ($itemobj->get_data()) {
78 if ($item = $itemobj->save_item()) {
79 feedback_move_item($item, $item->position);
80 redirect($editurl);
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')));
91 if ($item->id) {
92 $PAGE->navbar->add(get_string('edit_item', 'feedback'));
93 } else {
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,
100 "description" => ''
102 echo $OUTPUT->header();
104 /// print the tabs
105 $current_tab = 'edit';
106 $id = $cm->id;
108 //print errormsg
109 if (isset($error)) {
110 echo $error;
112 $itemobj->show_editform();
114 /// Finish the page
115 ///////////////////////////////////////////////////////////////////////////
116 ///////////////////////////////////////////////////////////////////////////
117 ///////////////////////////////////////////////////////////////////////////
119 echo $OUTPUT->footer();