MDL-21940 removing the old custom exception handling from nonajax code too + redirect...
[moodle.git] / mod / feedback / view.php
CommitLineData
84973212 1<?php
c70ad9f7 2
84973212 3/**
4 * the first page to view the feedback
5 *
6 * @author Andreas Grabs
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package feedback
9 */
10require_once("../../config.php");
11require_once("lib.php");
12
13$id = required_param('id', PARAM_INT);
14$courseid = optional_param('courseid', false, PARAM_INT);
15
16// $SESSION->feedback->current_tab = 'view';
17$current_tab = 'view';
18
19if (! $cm = get_coursemodule_from_id('feedback', $id)) {
20 print_error('invalidcoursemodule');
21}
22
23if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
24 print_error('coursemisconf');
25}
26
27if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
28 print_error('invalidcoursemodule');
29}
30
31$capabilities = feedback_load_capabilities($cm->id);
32
8001d6e7
AG
33if(isset($CFG->feedback_allowfullanonymous)
34 AND $CFG->feedback_allowfullanonymous
35 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
84973212 36 $capabilities->complete = true;
37}
38
39//check whether the feedback is located and! started from the mainsite
40if($course->id == SITEID AND !$courseid) {
41 $courseid = SITEID;
42}
43
44//check whether the feedback is mapped to the given courseid
45if($course->id == SITEID AND !$capabilities->edititems) {
46 if($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
47 if(!$DB->get_record('feedback_sitecourse_map', array('feedbackid'=>$feedback->id, 'courseid'=>$courseid))){
48 print_error('invalidcoursemodule');
da329996 49 }
50 }
84973212 51}
d4b1d58c 52
84973212 53if($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
54 if($course->id == SITEID) {
55 require_login($course->id, true);
56 }else {
57 require_login($course->id, true, $cm);
da329996 58 }
84973212 59} else {
60 if($course->id == SITEID) {
61 require_course_login($course, true);
62 }else {
63 require_course_login($course, true, $cm);
c70ad9f7 64 }
84973212 65}
66
67//check whether the given courseid exists
68if($courseid AND $courseid != SITEID) {
69 if($course2 = $DB->get_record('course', array('id'=>$courseid))){
70 require_course_login($course2); //this overwrites the object $course :-(
71 $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
72 }else {
73 print_error('invalidcourseid');
c70ad9f7 74 }
84973212 75}
76
77if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
78 add_to_log($course->id, 'feedback', 'view', 'view.php?id='.$cm->id, $feedback->id,$cm->id);
79}
80
81/// Print the page header
82$strfeedbacks = get_string("modulenameplural", "feedback");
83$strfeedback = get_string("modulename", "feedback");
84
a6855934 85$PAGE->set_url('/mod/feedback/view.php', array('id'=>$cm->id, 'do_show'=>'view'));
84973212 86$PAGE->set_title(format_string($feedback->name));
84973212 87echo $OUTPUT->header();
88
89//ishidden check.
90//feedback in courses
91if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $course->id != SITEID) {
92 notice(get_string("activityiscurrentlyhidden"));
93}
94
95//ishidden check.
96//feedback on mainsite
97if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $courseid == SITEID) {
98 notice(get_string("activityiscurrentlyhidden"));
99}
100
101/// Print the main part of the page
102///////////////////////////////////////////////////////////////////////////
103///////////////////////////////////////////////////////////////////////////
104///////////////////////////////////////////////////////////////////////////
105
106/// print the tabs
107include('tabs.php');
108
109echo $OUTPUT->heading(format_text($feedback->name));
110
111echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
112$options = (object)array('noclean'=>true);
113echo format_module_intro('feedback', $feedback, $cm->id);
114echo $OUTPUT->box_end();
115
116if($capabilities->edititems) {
117 echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
118 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
119 echo format_text($feedback->page_after_submit);
120 echo $OUTPUT->box_end();
121}
c70ad9f7 122
84973212 123if( (intval($feedback->publish_stats) == 1) AND ( $capabilities->viewanalysepage) AND !( $capabilities->viewreports) ) {
124 if($multiple_count = $DB->count_records('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
125 echo '<div class="mdl-align"><a href="'.htmlspecialchars('analysis.php?id=' . $id . '&courseid='.$courseid).'">';
126 echo get_string('completed_feedbacks', 'feedback').'</a>';
127 echo '</div>';
c70ad9f7 128 }
84973212 129}
130echo '<p>';
c70ad9f7 131
84973212 132//####### mapcourse-start
133if($capabilities->mapcourse) {
134 if($feedback->course == SITEID) {
135 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
136 echo '<div class="mdl-align">';
137 echo '<form action="mapcourse.php" method="get">';
138 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
139 echo '<input type="hidden" name="id" value="'.$id.'" />';
140 echo '<button type="submit">'.get_string('mapcourses', 'feedback').'</button>';
4bcc5118 141 echo $OUTPUT->help_icon('mapcourse', '', 'feedback', true);
84973212 142 echo '</form>';
143 echo '<br />';
144 echo '</div>';
145 echo $OUTPUT->box_end();
da329996 146 }
84973212 147}
148//####### mapcourse-end
da329996 149
84973212 150//####### completed-start
151if($capabilities->complete) {
d4b1d58c 152 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
84973212 153 //check, whether the feedback is open (timeopen, timeclose)
154 $checktime = time();
155 if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
156 echo $OUTPUT->box_start('generalbox boxaligncenter');
157 echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
158 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
d4b1d58c 159 echo $OUTPUT->box_end();
84973212 160 echo $OUTPUT->footer();
161 exit;
c70ad9f7 162 }
d4b1d58c 163
84973212 164 //check multiple Submit
165 $feedback_can_submit = true;
166 if($feedback->multiple_submit == 0 ) {
167 if(feedback_is_already_submitted($feedback->id, $courseid)) {
168 $feedback_can_submit = false;
c70ad9f7 169 }
170 }
84973212 171 if($feedback_can_submit) {
172 //if the user is not known so we cannot save the values temporarly
173 if(!isset($USER->username) OR $USER->username == 'guest') {
174 $completefile = 'complete_guest.php';
175 $guestid = sesskey();
176 }else {
177 $completefile = 'complete.php';
178 $guestid = false;
c70ad9f7 179 }
84973212 180 if($feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, $guestid)) {
181 if($startpage = feedback_get_page_to_continue($feedback->id, $courseid, $guestid)) {
182 echo '<a href="'.htmlspecialchars($completefile.'?id='.$id.'&gopage='.$startpage.'&courseid='.$courseid).'">'.get_string('continue_the_form', 'feedback').'</a>';
c70ad9f7 183 }else {
84973212 184 echo '<a href="'.htmlspecialchars($completefile.'?id='.$id.'&gopage=0&courseid='.$courseid).'">'.get_string('continue_the_form', 'feedback').'</a>';
c70ad9f7 185 }
186 }else {
84973212 187 echo '<a href="'.htmlspecialchars($completefile.'?id='.$id.'&gopage=0&courseid='.$courseid).'">'.get_string('complete_the_form', 'feedback').'</a>';
188 }
189 }else {
190 echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>';
191 if($courseid) {
192 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
193 }else {
194 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
c70ad9f7 195 }
c70ad9f7 196 }
84973212 197 echo $OUTPUT->box_end();
198}
199//####### completed-end
200echo "</p>";
c70ad9f7 201
84973212 202/// Finish the page
203///////////////////////////////////////////////////////////////////////////
204///////////////////////////////////////////////////////////////////////////
205///////////////////////////////////////////////////////////////////////////
c70ad9f7 206
84973212 207echo $OUTPUT->footer();
c70ad9f7 208