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