MDL-73912 templates: Proper type value for back to user menu button
[moodle.git] / mod / feedback / edit.php
blobaf956c27a2f5d8b127aa253f80d95a867f1b9eac
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 the feedback items such moving, deleting and so on
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 $id = required_param('id', PARAM_INT);
32 if (($formdata = data_submitted()) AND !confirm_sesskey()) {
33 print_error('invalidsesskey');
36 $switchitemrequired = optional_param('switchitemrequired', false, PARAM_INT);
37 $deleteitem = optional_param('deleteitem', false, PARAM_INT);
39 list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
41 $context = context_module::instance($cm->id);
42 require_login($course, false, $cm);
43 require_capability('mod/feedback:edititems', $context);
44 $feedback = $PAGE->activityrecord;
45 $feedbackstructure = new mod_feedback_structure($feedback, $cm);
46 $url = new moodle_url('/mod/feedback/edit.php', ['id' => $cm->id]);
48 if ($switchitemrequired) {
49 require_sesskey();
50 $items = $feedbackstructure->get_items();
51 if (isset($items[$switchitemrequired])) {
52 feedback_switch_item_required($items[$switchitemrequired]);
54 redirect($url);
57 if ($deleteitem) {
58 require_sesskey();
59 $items = $feedbackstructure->get_items();
60 if (isset($items[$deleteitem])) {
61 feedback_delete_item($deleteitem);
63 redirect($url);
66 // Process the create template form.
67 $cancreatetemplates = has_capability('mod/feedback:createprivatetemplate', $context) ||
68 has_capability('mod/feedback:createpublictemplate', $context);
70 //Get the feedbackitems
71 $lastposition = 0;
72 $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
73 if (is_array($feedbackitems)) {
74 $feedbackitems = array_values($feedbackitems);
75 if (count($feedbackitems) > 0) {
76 $lastitem = $feedbackitems[count($feedbackitems)-1];
77 $lastposition = $lastitem->position;
78 } else {
79 $lastposition = 0;
82 $lastposition++;
84 $PAGE->set_url($url);
85 $PAGE->set_heading($course->fullname);
86 $PAGE->set_title($feedback->name);
87 $actionbar = new \mod_feedback\output\edit_action_bar($cm->id, $url, $lastposition);
88 $PAGE->activityheader->set_attrs([
89 'hidecompletion' => true,
90 'description' => ''
91 ]);
92 $PAGE->add_body_class('limitedwidth');
94 //Adding the javascript module for the items dragdrop.
95 if (count($feedbackitems) > 1) {
96 $PAGE->requires->strings_for_js(array(
97 'pluginname',
98 'move_item',
99 'position',
100 ), 'feedback');
101 $PAGE->requires->yui_module('moodle-mod_feedback-dragdrop', 'M.mod_feedback.init_dragdrop',
102 array(array('cmid' => $cm->id)));
105 echo $OUTPUT->header();
106 /** @var \mod_feedback\output\renderer $renderer */
107 $renderer = $PAGE->get_renderer('mod_feedback');
108 echo $renderer->main_action_bar($actionbar);
109 $form = new mod_feedback_complete_form(mod_feedback_complete_form::MODE_EDIT,
110 $feedbackstructure, 'feedback_edit_form');
111 echo '<div id="feedback_dragarea">'; // The container for the dragging area.
112 $form->display();
113 echo '</div>';
115 if ($cancreatetemplates) {
116 echo $renderer->create_template_form($id);
119 echo $OUTPUT->footer();