1 |
efrain |
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* prints the form to edit a dedicated item
|
|
|
19 |
*
|
|
|
20 |
* @author Andreas Grabs
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
22 |
* @package mod_feedback
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once("../../config.php");
|
|
|
26 |
require_once("lib.php");
|
|
|
27 |
|
|
|
28 |
feedback_init_feedback_session();
|
|
|
29 |
|
|
|
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);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
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' => ''];
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
require_login($course, true, $cm);
|
|
|
49 |
$context = context_module::instance($cm->id);
|
|
|
50 |
require_capability('mod/feedback:edititems', $context);
|
|
|
51 |
$feedback = $PAGE->activityrecord;
|
|
|
52 |
|
|
|
53 |
$editurl = new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id));
|
|
|
54 |
|
|
|
55 |
$PAGE->set_url($url);
|
|
|
56 |
|
|
|
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;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
//get the existing item or create it
|
|
|
66 |
if (!$typ) {
|
|
|
67 |
throw new \moodle_exception('typemissing', 'feedback', $editurl->out(false));
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
$itemobj = feedback_get_item_class($typ);
|
|
|
71 |
$itemobj->build_editform($item, $feedback, $cm);
|
|
|
72 |
|
|
|
73 |
if ($itemobj->is_cancelled()) {
|
|
|
74 |
redirect($editurl);
|
|
|
75 |
exit;
|
|
|
76 |
}
|
|
|
77 |
if ($itemobj->get_data()) {
|
|
|
78 |
if ($item = $itemobj->save_item()) {
|
|
|
79 |
feedback_move_item($item, $item->position);
|
|
|
80 |
redirect($editurl);
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
////////////////////////////////////////////////////////////////////////////////////
|
|
|
85 |
/// Print the page header
|
|
|
86 |
$strfeedbacks = get_string("modulenameplural", "feedback");
|
|
|
87 |
$strfeedback = get_string("modulename", "feedback");
|
|
|
88 |
|
|
|
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'));
|
|
|
95 |
}
|
|
|
96 |
$PAGE->set_heading($course->fullname);
|
|
|
97 |
$PAGE->set_title($feedback->name);
|
|
|
98 |
$PAGE->activityheader->set_attrs([
|
|
|
99 |
"hidecompletion" => true,
|
|
|
100 |
"description" => ''
|
|
|
101 |
]);
|
|
|
102 |
echo $OUTPUT->header();
|
|
|
103 |
|
|
|
104 |
/// print the tabs
|
|
|
105 |
$current_tab = 'edit';
|
|
|
106 |
$id = $cm->id;
|
|
|
107 |
|
|
|
108 |
//print errormsg
|
|
|
109 |
if (isset($error)) {
|
|
|
110 |
echo $error;
|
|
|
111 |
}
|
|
|
112 |
$itemobj->show_editform();
|
|
|
113 |
|
|
|
114 |
/// Finish the page
|
|
|
115 |
///////////////////////////////////////////////////////////////////////////
|
|
|
116 |
///////////////////////////////////////////////////////////////////////////
|
|
|
117 |
///////////////////////////////////////////////////////////////////////////
|
|
|
118 |
|
|
|
119 |
echo $OUTPUT->footer();
|