MDL-40918 mod_lti: replaced 'view' and 'view all' add_to_log calls with events
[moodle.git] / mod / feedback / edit_item.php
bloba15b7acecf31eb753023fad92c8a031b763a0aa1
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 feedback
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));
37 if (!$typ) {
38 redirect($editurl->out(false));
41 $url = new moodle_url('/mod/feedback/edit_item.php', array('cmid'=>$cmid));
42 if ($typ !== false) {
43 $url->param('typ', $typ);
45 if ($id !== false) {
46 $url->param('id', $id);
48 $PAGE->set_url($url);
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));
79 exit;
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))) {
85 $typ = $item->typ;
86 } else {
87 $item = new stdClass();
88 $item->id = null;
89 $item->position = -1;
90 if (!$typ) {
91 print_error('typemissing', 'feedback', $editurl->out(false));
93 $item->typ = $typ;
94 $item->options = '';
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));
105 exit;
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");
119 if ($item->id) {
120 $PAGE->navbar->add(get_string('edit_item', 'feedback'));
121 } else {
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));
131 /// print the tabs
132 require('tabs.php');
134 //print errormsg
135 if (isset($error)) {
136 echo $error;
138 $itemobj->show_editform();
140 if ($typ!='label') {
141 $PAGE->requires->js('/mod/feedback/feedback.js');
142 $PAGE->requires->js_function_call('set_item_focus', Array('id_itemname'));
145 /// Finish the page
146 ///////////////////////////////////////////////////////////////////////////
147 ///////////////////////////////////////////////////////////////////////////
148 ///////////////////////////////////////////////////////////////////////////
150 echo $OUTPUT->footer();