MDL-41438 core renderer: additional patch to remove .main definition from all core...
[moodle.git] / mod / feedback / view.php
CommitLineData
84973212 1<?php
9c5bc7a5
AG
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/>.
c70ad9f7 16
84973212 17/**
18 * the first page to view the feedback
19 *
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package feedback
23 */
24require_once("../../config.php");
25require_once("lib.php");
26
27$id = required_param('id', PARAM_INT);
28$courseid = optional_param('courseid', false, PARAM_INT);
29
84973212 30$current_tab = 'view';
31
32if (! $cm = get_coursemodule_from_id('feedback', $id)) {
33 print_error('invalidcoursemodule');
34}
35
36if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
37 print_error('coursemisconf');
38}
39
40if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
41 print_error('invalidcoursemodule');
42}
43
2c979976 44$context = context_module::instance($cm->id);
c987dbad
AG
45
46$feedback_complete_cap = false;
47
9c5bc7a5 48if (has_capability('mod/feedback:complete', $context)) {
c987dbad
AG
49 $feedback_complete_cap = true;
50}
84973212 51
9c5bc7a5 52if (isset($CFG->feedback_allowfullanonymous)
8001d6e7 53 AND $CFG->feedback_allowfullanonymous
8d8e6694
AG
54 AND $course->id == SITEID
55 AND (!$courseid OR $courseid == SITEID)
8001d6e7 56 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
c987dbad 57 $feedback_complete_cap = true;
84973212 58}
59
60//check whether the feedback is located and! started from the mainsite
9c5bc7a5 61if ($course->id == SITEID AND !$courseid) {
84973212 62 $courseid = SITEID;
63}
64
65//check whether the feedback is mapped to the given courseid
9c5bc7a5
AG
66if ($course->id == SITEID AND !has_capability('mod/feedback:edititems', $context)) {
67 if ($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
68 $params = array('feedbackid'=>$feedback->id, 'courseid'=>$courseid);
69 if (!$DB->get_record('feedback_sitecourse_map', $params)) {
84973212 70 print_error('invalidcoursemodule');
da329996 71 }
72 }
84973212 73}
d4b1d58c 74
9c5bc7a5
AG
75if ($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
76 if ($course->id == SITEID) {
cdbea7ee 77 require_login($course, true);
9c5bc7a5 78 } else {
cdbea7ee 79 require_login($course, true, $cm);
da329996 80 }
84973212 81} else {
9c5bc7a5 82 if ($course->id == SITEID) {
84973212 83 require_course_login($course, true);
9c5bc7a5 84 } else {
84973212 85 require_course_login($course, true, $cm);
c70ad9f7 86 }
84973212 87}
88
89//check whether the given courseid exists
9c5bc7a5
AG
90if ($courseid AND $courseid != SITEID) {
91 if ($course2 = $DB->get_record('course', array('id'=>$courseid))) {
84973212 92 require_course_login($course2); //this overwrites the object $course :-(
93 $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
9c5bc7a5 94 } else {
84973212 95 print_error('invalidcourseid');
c70ad9f7 96 }
84973212 97}
98
9c5bc7a5
AG
99if ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
100 add_to_log($course->id, 'feedback', 'view', 'view.php?id='.$cm->id, $feedback->id, $cm->id);
84973212 101}
102
103/// Print the page header
104$strfeedbacks = get_string("modulenameplural", "feedback");
105$strfeedback = get_string("modulename", "feedback");
106
9c5bc7a5 107if ($course->id == SITEID) {
2ad5d2ef 108 $PAGE->set_context($context);
7620725f
AG
109 $PAGE->set_cm($cm, $course); // set's up global $COURSE
110 $PAGE->set_pagelayout('incourse');
111}
a6855934 112$PAGE->set_url('/mod/feedback/view.php', array('id'=>$cm->id, 'do_show'=>'view'));
84973212 113$PAGE->set_title(format_string($feedback->name));
9d092aa9 114$PAGE->set_heading(format_string($course->fullname));
84973212 115echo $OUTPUT->header();
116
117//ishidden check.
118//feedback in courses
9c5bc7a5
AG
119$cap_viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context);
120if ((empty($cm->visible) and !$cap_viewhiddenactivities) AND $course->id != SITEID) {
84973212 121 notice(get_string("activityiscurrentlyhidden"));
122}
123
124//ishidden check.
125//feedback on mainsite
9c5bc7a5 126if ((empty($cm->visible) and !$cap_viewhiddenactivities) AND $courseid == SITEID) {
84973212 127 notice(get_string("activityiscurrentlyhidden"));
128}
129
130/// Print the main part of the page
131///////////////////////////////////////////////////////////////////////////
132///////////////////////////////////////////////////////////////////////////
133///////////////////////////////////////////////////////////////////////////
134
135/// print the tabs
9c5bc7a5 136require('tabs.php');
84973212 137
38b5a5e2
AG
138$previewimg = $OUTPUT->pix_icon('t/preview', get_string('preview'));
139$previewlnk = '<a href="'.$CFG->wwwroot.'/mod/feedback/print.php?id='.$id.'">'.$previewimg.'</a>';
84973212 140
38b5a5e2
AG
141echo $OUTPUT->heading(format_text($feedback->name.' '.$previewlnk));
142
143//show some infos to the feedback
9c5bc7a5 144if (has_capability('mod/feedback:edititems', $context)) {
38b5a5e2 145 //get the groupid
9c5bc7a5 146 $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id, true);
38b5a5e2
AG
147 $mygroupid = groups_get_activity_group($cm);
148
149 echo $OUTPUT->box_start('boxaligncenter boxwidthwide');
150 echo $groupselect.'<div class="clearer">&nbsp;</div>';
151 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid);
152 echo $OUTPUT->box_start('feedback_info');
9c5bc7a5
AG
153 echo '<span class="feedback_info">';
154 echo get_string('completed_feedbacks', 'feedback').': ';
155 echo '</span>';
156 echo '<span class="feedback_info_value">';
157 echo $completedscount;
158 echo '</span>';
38b5a5e2 159 echo $OUTPUT->box_end();
9c5bc7a5
AG
160
161 $params = array('feedback'=>$feedback->id, 'hasvalue'=>1);
162 $itemscount = $DB->count_records('feedback_item', $params);
38b5a5e2 163 echo $OUTPUT->box_start('feedback_info');
9c5bc7a5
AG
164 echo '<span class="feedback_info">';
165 echo get_string('questions', 'feedback').': ';
166 echo '</span>';
167 echo '<span class="feedback_info_value">';
168 echo $itemscount;
169 echo '</span>';
38b5a5e2 170 echo $OUTPUT->box_end();
2396a414 171
9c5bc7a5 172 if ($feedback->timeopen) {
38b5a5e2 173 echo $OUTPUT->box_start('feedback_info');
9c5bc7a5
AG
174 echo '<span class="feedback_info">';
175 echo get_string('feedbackopen', 'feedback').': ';
176 echo '</span>';
177 echo '<span class="feedback_info_value">';
178 echo userdate($feedback->timeopen);
179 echo '</span>';
38b5a5e2
AG
180 echo $OUTPUT->box_end();
181 }
9c5bc7a5 182 if ($feedback->timeclose) {
38b5a5e2 183 echo $OUTPUT->box_start('feedback_info');
9c5bc7a5 184 echo '<span class="feedback_info">';
9b108a86 185 echo get_string('feedbackclose', 'feedback').': ';
9c5bc7a5
AG
186 echo '</span>';
187 echo '<span class="feedback_info_value">';
188 echo userdate($feedback->timeclose);
189 echo '</span>';
38b5a5e2
AG
190 echo $OUTPUT->box_end();
191 }
192 echo $OUTPUT->box_end();
193}
194
9c5bc7a5 195if (has_capability('mod/feedback:edititems', $context)) {
38b5a5e2
AG
196 echo $OUTPUT->heading(get_string('description', 'feedback'), 4);
197}
84973212 198echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
199$options = (object)array('noclean'=>true);
200echo format_module_intro('feedback', $feedback, $cm->id);
201echo $OUTPUT->box_end();
202
9c5bc7a5 203if (has_capability('mod/feedback:edititems', $context)) {
abd2899c
AG
204 require_once($CFG->libdir . '/filelib.php');
205
206 $page_after_submit_output = file_rewrite_pluginfile_urls($feedback->page_after_submit,
207 'pluginfile.php',
208 $context->id,
209 'mod_feedback',
210 'page_after_submit',
211 0);
212
84973212 213 echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
214 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
abd2899c 215 echo format_text($page_after_submit_output,
9c5bc7a5
AG
216 $feedback->page_after_submitformat,
217 array('overflowdiv'=>true));
218
84973212 219 echo $OUTPUT->box_end();
220}
c70ad9f7 221
9c5bc7a5 222if ( (intval($feedback->publish_stats) == 1) AND
2396a414 223 ( has_capability('mod/feedback:viewanalysepage', $context)) AND
c987dbad 224 !( has_capability('mod/feedback:viewreports', $context)) ) {
9c5bc7a5
AG
225
226 $params = array('userid'=>$USER->id, 'feedback'=>$feedback->id);
227 if ($multiple_count = $DB->count_records('feedback_tracking', $params)) {
228 $url_params = array('id'=>$id, 'courseid'=>$courseid);
229 $analysisurl = new moodle_url('/mod/feedback/analysis.php', $url_params);
5dee2210 230 echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
84973212 231 echo get_string('completed_feedbacks', 'feedback').'</a>';
232 echo '</div>';
c70ad9f7 233 }
84973212 234}
c70ad9f7 235
84973212 236//####### mapcourse-start
9c5bc7a5
AG
237if (has_capability('mod/feedback:mapcourse', $context)) {
238 if ($feedback->course == SITEID) {
84973212 239 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
240 echo '<div class="mdl-align">';
241 echo '<form action="mapcourse.php" method="get">';
9d092aa9 242 echo '<fieldset>';
84973212 243 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
244 echo '<input type="hidden" name="id" value="'.$id.'" />';
245 echo '<button type="submit">'.get_string('mapcourses', 'feedback').'</button>';
e8790d59 246 echo $OUTPUT->help_icon('mapcourse', 'feedback');
9d092aa9 247 echo '</fieldset>';
84973212 248 echo '</form>';
249 echo '<br />';
250 echo '</div>';
251 echo $OUTPUT->box_end();
da329996 252 }
84973212 253}
254//####### mapcourse-end
da329996 255
84973212 256//####### completed-start
9c5bc7a5 257if ($feedback_complete_cap) {
d4b1d58c 258 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
84973212 259 //check, whether the feedback is open (timeopen, timeclose)
260 $checktime = time();
9c5bc7a5
AG
261 if (($feedback->timeopen > $checktime) OR
262 ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
263
264 echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
265 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
d4b1d58c 266 echo $OUTPUT->box_end();
84973212 267 echo $OUTPUT->footer();
268 exit;
c70ad9f7 269 }
d4b1d58c 270
84973212 271 //check multiple Submit
272 $feedback_can_submit = true;
9c5bc7a5
AG
273 if ($feedback->multiple_submit == 0 ) {
274 if (feedback_is_already_submitted($feedback->id, $courseid)) {
84973212 275 $feedback_can_submit = false;
c70ad9f7 276 }
277 }
9c5bc7a5 278 if ($feedback_can_submit) {
84973212 279 //if the user is not known so we cannot save the values temporarly
9c5bc7a5 280 if (!isloggedin() or isguestuser()) {
84973212 281 $completefile = 'complete_guest.php';
282 $guestid = sesskey();
9c5bc7a5 283 } else {
84973212 284 $completefile = 'complete.php';
285 $guestid = false;
c70ad9f7 286 }
9c5bc7a5
AG
287 $url_params = array('id'=>$id, 'courseid'=>$courseid, 'gopage'=>0);
288 $completeurl = new moodle_url('/mod/feedback/'.$completefile, $url_params);
2396a414 289
9c5bc7a5
AG
290 $feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, $guestid);
291 if ($feedbackcompletedtmp) {
292 if ($startpage = feedback_get_page_to_continue($feedback->id, $courseid, $guestid)) {
5dee2210 293 $completeurl->param('gopage', $startpage);
c70ad9f7 294 }
5dee2210 295 echo '<a href="'.$completeurl->out().'">'.get_string('continue_the_form', 'feedback').'</a>';
9c5bc7a5 296 } else {
5dee2210 297 echo '<a href="'.$completeurl->out().'">'.get_string('complete_the_form', 'feedback').'</a>';
84973212 298 }
9c5bc7a5
AG
299 } else {
300 echo '<h2><font color="red">';
301 echo get_string('this_feedback_is_already_submitted', 'feedback');
302 echo '</font></h2>';
303 if ($courseid) {
84973212 304 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
9c5bc7a5 305 } else {
84973212 306 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
c70ad9f7 307 }
c70ad9f7 308 }
84973212 309 echo $OUTPUT->box_end();
310}
311//####### completed-end
c70ad9f7 312
84973212 313/// Finish the page
314///////////////////////////////////////////////////////////////////////////
315///////////////////////////////////////////////////////////////////////////
316///////////////////////////////////////////////////////////////////////////
c70ad9f7 317
84973212 318echo $OUTPUT->footer();
c70ad9f7 319