MDL-23927 improved guest handling
[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
c987dbad
AG
31if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
32 print_error('badcontext');
33}
34
35$feedback_complete_cap = false;
36
37if(has_capability('mod/feedback:complete', $context)) {
38 $feedback_complete_cap = true;
39}
84973212 40
8001d6e7
AG
41if(isset($CFG->feedback_allowfullanonymous)
42 AND $CFG->feedback_allowfullanonymous
43 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
c987dbad 44 $feedback_complete_cap = true;
84973212 45}
46
47//check whether the feedback is located and! started from the mainsite
48if($course->id == SITEID AND !$courseid) {
49 $courseid = SITEID;
50}
51
52//check whether the feedback is mapped to the given courseid
c987dbad 53if($course->id == SITEID AND !has_capability('mod/feedback:edititems', $context)) {
84973212 54 if($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
55 if(!$DB->get_record('feedback_sitecourse_map', array('feedbackid'=>$feedback->id, 'courseid'=>$courseid))){
56 print_error('invalidcoursemodule');
da329996 57 }
58 }
84973212 59}
d4b1d58c 60
84973212 61if($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
62 if($course->id == SITEID) {
63 require_login($course->id, true);
64 }else {
65 require_login($course->id, true, $cm);
da329996 66 }
84973212 67} else {
68 if($course->id == SITEID) {
69 require_course_login($course, true);
70 }else {
71 require_course_login($course, true, $cm);
c70ad9f7 72 }
84973212 73}
74
75//check whether the given courseid exists
76if($courseid AND $courseid != SITEID) {
77 if($course2 = $DB->get_record('course', array('id'=>$courseid))){
78 require_course_login($course2); //this overwrites the object $course :-(
79 $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
80 }else {
81 print_error('invalidcourseid');
c70ad9f7 82 }
84973212 83}
84
85if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
86 add_to_log($course->id, 'feedback', 'view', 'view.php?id='.$cm->id, $feedback->id,$cm->id);
87}
88
89/// Print the page header
90$strfeedbacks = get_string("modulenameplural", "feedback");
91$strfeedback = get_string("modulename", "feedback");
92
7620725f 93if($course->id == SITEID) {
2ad5d2ef 94 $PAGE->set_context($context);
7620725f
AG
95 $PAGE->set_cm($cm, $course); // set's up global $COURSE
96 $PAGE->set_pagelayout('incourse');
97}
a6855934 98$PAGE->set_url('/mod/feedback/view.php', array('id'=>$cm->id, 'do_show'=>'view'));
84973212 99$PAGE->set_title(format_string($feedback->name));
9d092aa9 100$PAGE->set_heading(format_string($course->fullname));
84973212 101echo $OUTPUT->header();
102
103//ishidden check.
104//feedback in courses
c987dbad 105if ((empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) AND $course->id != SITEID) {
84973212 106 notice(get_string("activityiscurrentlyhidden"));
107}
108
109//ishidden check.
110//feedback on mainsite
c987dbad 111if ((empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) AND $courseid == SITEID) {
84973212 112 notice(get_string("activityiscurrentlyhidden"));
113}
114
115/// Print the main part of the page
116///////////////////////////////////////////////////////////////////////////
117///////////////////////////////////////////////////////////////////////////
118///////////////////////////////////////////////////////////////////////////
119
120/// print the tabs
121include('tabs.php');
122
38b5a5e2
AG
123$previewimg = $OUTPUT->pix_icon('t/preview', get_string('preview'));
124$previewlnk = '<a href="'.$CFG->wwwroot.'/mod/feedback/print.php?id='.$id.'">'.$previewimg.'</a>';
84973212 125
38b5a5e2
AG
126echo $OUTPUT->heading(format_text($feedback->name.' '.$previewlnk));
127
128//show some infos to the feedback
129if(has_capability('mod/feedback:edititems', $context)) {
130 //get the groupid
131 $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/view.php?id=' . $cm->id, true);
132 $mygroupid = groups_get_activity_group($cm);
133
134 echo $OUTPUT->box_start('boxaligncenter boxwidthwide');
135 echo $groupselect.'<div class="clearer">&nbsp;</div>';
136 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid);
137 echo $OUTPUT->box_start('feedback_info');
138 echo '<span class="feedback_info">'.get_string('completed_feedbacks', 'feedback').': </span><span class="feedback_info_value">'.$completedscount. '</span>';
139 echo $OUTPUT->box_end();
140 $itemscount = $DB->count_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1));
141 echo $OUTPUT->box_start('feedback_info');
142 echo '<span class="feedback_info">'.get_string('questions', 'feedback').': </span><span class="feedback_info_value">' .$itemscount. '</span>';
143 echo $OUTPUT->box_end();
2396a414 144
38b5a5e2
AG
145 if($feedback->timeopen) {
146 echo $OUTPUT->box_start('feedback_info');
147 echo '<span class="feedback_info">'.get_string('feedbackopen', 'feedback').': </span><span class="feedback_info_value">' .UserDate($feedback->timeopen). '</span>';
148 echo $OUTPUT->box_end();
149 }
150 if($feedback->timeclose) {
151 echo $OUTPUT->box_start('feedback_info');
152 echo '<span class="feedback_info">'.get_string('timeclose', 'feedback').': </span><span class="feedback_info_value">' .UserDate($feedback->timeclose). '</span>';
153 echo $OUTPUT->box_end();
154 }
155 echo $OUTPUT->box_end();
156}
157
158if(has_capability('mod/feedback:edititems', $context)) {
159 echo $OUTPUT->heading(get_string('description', 'feedback'), 4);
160}
84973212 161echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
162$options = (object)array('noclean'=>true);
163echo format_module_intro('feedback', $feedback, $cm->id);
164echo $OUTPUT->box_end();
165
c987dbad 166if(has_capability('mod/feedback:edititems', $context)) {
84973212 167 echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
168 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
169 echo format_text($feedback->page_after_submit);
170 echo $OUTPUT->box_end();
171}
c70ad9f7 172
2396a414
PS
173if( (intval($feedback->publish_stats) == 1) AND
174 ( has_capability('mod/feedback:viewanalysepage', $context)) AND
c987dbad 175 !( has_capability('mod/feedback:viewreports', $context)) ) {
84973212 176 if($multiple_count = $DB->count_records('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
5dee2210
AG
177 $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
178 echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
84973212 179 echo get_string('completed_feedbacks', 'feedback').'</a>';
180 echo '</div>';
c70ad9f7 181 }
84973212 182}
cf6c33cb 183// echo '<p>';
c70ad9f7 184
84973212 185//####### mapcourse-start
6a471fe0 186if(has_capability('mod/feedback:mapcourse', $context)) {
84973212 187 if($feedback->course == SITEID) {
188 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
189 echo '<div class="mdl-align">';
190 echo '<form action="mapcourse.php" method="get">';
9d092aa9 191 echo '<fieldset>';
84973212 192 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
193 echo '<input type="hidden" name="id" value="'.$id.'" />';
194 echo '<button type="submit">'.get_string('mapcourses', 'feedback').'</button>';
e8790d59 195 echo $OUTPUT->help_icon('mapcourse', 'feedback');
9d092aa9 196 echo '</fieldset>';
84973212 197 echo '</form>';
198 echo '<br />';
199 echo '</div>';
200 echo $OUTPUT->box_end();
da329996 201 }
84973212 202}
203//####### mapcourse-end
da329996 204
84973212 205//####### completed-start
c987dbad 206if($feedback_complete_cap) {
d4b1d58c 207 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
84973212 208 //check, whether the feedback is open (timeopen, timeclose)
209 $checktime = time();
210 if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
84973212 211 echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
212 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
d4b1d58c 213 echo $OUTPUT->box_end();
84973212 214 echo $OUTPUT->footer();
215 exit;
c70ad9f7 216 }
d4b1d58c 217
84973212 218 //check multiple Submit
219 $feedback_can_submit = true;
220 if($feedback->multiple_submit == 0 ) {
221 if(feedback_is_already_submitted($feedback->id, $courseid)) {
222 $feedback_can_submit = false;
c70ad9f7 223 }
224 }
84973212 225 if($feedback_can_submit) {
226 //if the user is not known so we cannot save the values temporarly
2396a414 227 if(!isloggedin() or isguestuser()) {
84973212 228 $completefile = 'complete_guest.php';
229 $guestid = sesskey();
230 }else {
231 $completefile = 'complete.php';
232 $guestid = false;
c70ad9f7 233 }
5dee2210 234 $completeurl = new moodle_url('/mod/feedback/'.$completefile, array('id'=>$id, 'courseid'=>$courseid, 'gopage'=>0));
2396a414 235
84973212 236 if($feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, $guestid)) {
237 if($startpage = feedback_get_page_to_continue($feedback->id, $courseid, $guestid)) {
5dee2210 238 $completeurl->param('gopage', $startpage);
c70ad9f7 239 }
5dee2210 240 echo '<a href="'.$completeurl->out().'">'.get_string('continue_the_form', 'feedback').'</a>';
c70ad9f7 241 }else {
5dee2210 242 echo '<a href="'.$completeurl->out().'">'.get_string('complete_the_form', 'feedback').'</a>';
84973212 243 }
244 }else {
245 echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>';
246 if($courseid) {
247 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
248 }else {
249 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
c70ad9f7 250 }
c70ad9f7 251 }
84973212 252 echo $OUTPUT->box_end();
253}
254//####### completed-end
cf6c33cb 255// echo "</p>";
c70ad9f7 256
84973212 257/// Finish the page
258///////////////////////////////////////////////////////////////////////////
259///////////////////////////////////////////////////////////////////////////
260///////////////////////////////////////////////////////////////////////////
c70ad9f7 261
84973212 262echo $OUTPUT->footer();
c70ad9f7 263