2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * the first page to view the feedback
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
24 require_once("../../config.php");
25 require_once("lib.php");
27 $id = required_param('id', PARAM_INT);
28 $courseid = optional_param('courseid', false, PARAM_INT);
30 $current_tab = 'view';
32 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
33 print_error('invalidcoursemodule');
36 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
37 print_error('coursemisconf');
40 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
41 print_error('invalidcoursemodule');
44 $context = context_module::instance($cm->id);
46 $feedback_complete_cap = false;
48 if (has_capability('mod/feedback:complete', $context)) {
49 $feedback_complete_cap = true;
52 if (isset($CFG->feedback_allowfullanonymous)
53 AND $CFG->feedback_allowfullanonymous
54 AND $course->id == SITEID
55 AND (!$courseid OR $courseid == SITEID)
56 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
57 $feedback_complete_cap = true;
60 //check whether the feedback is located and! started from the mainsite
61 if ($course->id == SITEID AND !$courseid) {
65 //check whether the feedback is mapped to the given courseid
66 if ($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)) {
70 print_error('invalidcoursemodule');
75 if ($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
76 if ($course->id == SITEID) {
77 require_login($course, true);
79 require_login($course, true, $cm);
82 if ($course->id == SITEID) {
83 require_course_login($course, true);
85 require_course_login($course, true, $cm);
89 //check whether the given courseid exists
90 if ($courseid AND $courseid != SITEID) {
91 if ($course2 = $DB->get_record('course', array('id'=>$courseid))) {
92 require_course_login($course2); //this overwrites the object $course :-(
93 $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
95 print_error('invalidcourseid');
99 if ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
100 add_to_log($course->id, 'feedback', 'view', 'view.php?id='.$cm->id, $feedback->id, $cm->id);
103 /// Print the page header
104 $strfeedbacks = get_string("modulenameplural", "feedback");
105 $strfeedback = get_string("modulename", "feedback");
107 if ($course->id == SITEID) {
108 $PAGE->set_context($context);
109 $PAGE->set_cm($cm, $course); // set's up global $COURSE
110 $PAGE->set_pagelayout('incourse');
112 $PAGE->set_url('/mod/feedback/view.php', array('id'=>$cm->id, 'do_show'=>'view'));
113 $PAGE->set_title(format_string($feedback->name));
114 $PAGE->set_heading(format_string($course->fullname));
115 echo $OUTPUT->header();
118 //feedback in courses
119 $cap_viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context);
120 if ((empty($cm->visible) and !$cap_viewhiddenactivities) AND $course->id != SITEID) {
121 notice(get_string("activityiscurrentlyhidden"));
125 //feedback on mainsite
126 if ((empty($cm->visible) and !$cap_viewhiddenactivities) AND $courseid == SITEID) {
127 notice(get_string("activityiscurrentlyhidden"));
130 /// Print the main part of the page
131 ///////////////////////////////////////////////////////////////////////////
132 ///////////////////////////////////////////////////////////////////////////
133 ///////////////////////////////////////////////////////////////////////////
138 $previewimg = $OUTPUT->pix_icon('t/preview', get_string('preview'));
139 $previewlnk = '<a href="'.$CFG->wwwroot.'/mod/feedback/print.php?id='.$id.'">'.$previewimg.'</a>';
141 echo $OUTPUT->heading(format_text($feedback->name.' '.$previewlnk));
143 //show some infos to the feedback
144 if (has_capability('mod/feedback:edititems', $context)) {
146 $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id, true);
147 $mygroupid = groups_get_activity_group($cm);
149 echo $OUTPUT->box_start('boxaligncenter boxwidthwide');
150 echo $groupselect.'<div class="clearer"> </div>';
151 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid);
152 echo $OUTPUT->box_start('feedback_info');
153 echo '<span class="feedback_info">';
154 echo get_string('completed_feedbacks', 'feedback').': ';
156 echo '<span class="feedback_info_value">';
157 echo $completedscount;
159 echo $OUTPUT->box_end();
161 $params = array('feedback'=>$feedback->id, 'hasvalue'=>1);
162 $itemscount = $DB->count_records('feedback_item', $params);
163 echo $OUTPUT->box_start('feedback_info');
164 echo '<span class="feedback_info">';
165 echo get_string('questions', 'feedback').': ';
167 echo '<span class="feedback_info_value">';
170 echo $OUTPUT->box_end();
172 if ($feedback->timeopen) {
173 echo $OUTPUT->box_start('feedback_info');
174 echo '<span class="feedback_info">';
175 echo get_string('feedbackopen', 'feedback').': ';
177 echo '<span class="feedback_info_value">';
178 echo userdate($feedback->timeopen);
180 echo $OUTPUT->box_end();
182 if ($feedback->timeclose) {
183 echo $OUTPUT->box_start('feedback_info');
184 echo '<span class="feedback_info">';
185 echo get_string('feedbackclose', 'feedback').': ';
187 echo '<span class="feedback_info_value">';
188 echo userdate($feedback->timeclose);
190 echo $OUTPUT->box_end();
192 echo $OUTPUT->box_end();
195 if (has_capability('mod/feedback:edititems', $context)) {
196 echo $OUTPUT->heading(get_string('description', 'feedback'), 4);
198 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
199 $options = (object)array('noclean'=>true);
200 echo format_module_intro('feedback', $feedback, $cm->id);
201 echo $OUTPUT->box_end();
203 if (has_capability('mod/feedback:edititems', $context)) {
204 require_once($CFG->libdir . '/filelib.php');
206 $page_after_submit_output = file_rewrite_pluginfile_urls($feedback->page_after_submit,
213 echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
214 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
215 echo format_text($page_after_submit_output,
216 $feedback->page_after_submitformat,
217 array('overflowdiv'=>true));
219 echo $OUTPUT->box_end();
222 if ( (intval($feedback->publish_stats) == 1) AND
223 ( has_capability('mod/feedback:viewanalysepage', $context)) AND
224 !( has_capability('mod/feedback:viewreports', $context)) ) {
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);
230 echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
231 echo get_string('completed_feedbacks', 'feedback').'</a>';
236 //####### mapcourse-start
237 if (has_capability('mod/feedback:mapcourse', $context)) {
238 if ($feedback->course == SITEID) {
239 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
240 echo '<div class="mdl-align">';
241 echo '<form action="mapcourse.php" method="get">';
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>';
246 echo $OUTPUT->help_icon('mapcourse', 'feedback');
251 echo $OUTPUT->box_end();
254 //####### mapcourse-end
256 //####### completed-start
257 if ($feedback_complete_cap) {
258 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
259 //check, whether the feedback is open (timeopen, timeclose)
261 if (($feedback->timeopen > $checktime) OR
262 ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
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);
266 echo $OUTPUT->box_end();
267 echo $OUTPUT->footer();
271 //check multiple Submit
272 $feedback_can_submit = true;
273 if ($feedback->multiple_submit == 0 ) {
274 if (feedback_is_already_submitted($feedback->id, $courseid)) {
275 $feedback_can_submit = false;
278 if ($feedback_can_submit) {
279 //if the user is not known so we cannot save the values temporarly
280 if (!isloggedin() or isguestuser()) {
281 $completefile = 'complete_guest.php';
282 $guestid = sesskey();
284 $completefile = 'complete.php';
287 $url_params = array('id'=>$id, 'courseid'=>$courseid, 'gopage'=>0);
288 $completeurl = new moodle_url('/mod/feedback/'.$completefile, $url_params);
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)) {
293 $completeurl->param('gopage', $startpage);
295 echo '<a href="'.$completeurl->out().'">'.get_string('continue_the_form', 'feedback').'</a>';
297 echo '<a href="'.$completeurl->out().'">'.get_string('complete_the_form', 'feedback').'</a>';
300 echo '<h2><font color="red">';
301 echo get_string('this_feedback_is_already_submitted', 'feedback');
304 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
306 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
309 echo $OUTPUT->box_end();
311 //####### completed-end
314 ///////////////////////////////////////////////////////////////////////////
315 ///////////////////////////////////////////////////////////////////////////
316 ///////////////////////////////////////////////////////////////////////////
318 echo $OUTPUT->footer();