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
22 * @package mod_feedback
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 // Trigger module viewed event.
100 $event = \mod_feedback\event\course_module_viewed
::create(array(
101 'objectid' => $feedback->id
,
102 'context' => $context,
103 'anonymous' => ($feedback->anonymous
== FEEDBACK_ANONYMOUS_YES
),
105 'anonymous' => $feedback->anonymous
// Deprecated.
108 $event->add_record_snapshot('course_modules', $cm);
109 $event->add_record_snapshot('course', $course);
110 $event->add_record_snapshot('feedback', $feedback);
113 /// Print the page header
114 $strfeedbacks = get_string("modulenameplural", "feedback");
115 $strfeedback = get_string("modulename", "feedback");
117 if ($course->id
== SITEID
) {
118 $PAGE->set_context($context);
119 $PAGE->set_cm($cm, $course); // set's up global $COURSE
120 $PAGE->set_pagelayout('incourse');
122 $PAGE->set_url('/mod/feedback/view.php', array('id'=>$cm->id
, 'do_show'=>'view'));
123 $PAGE->set_title($feedback->name
);
124 $PAGE->set_heading($course->fullname
);
125 echo $OUTPUT->header();
128 //feedback in courses
129 $cap_viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context);
130 if ((empty($cm->visible
) and !$cap_viewhiddenactivities) AND $course->id
!= SITEID
) {
131 notice(get_string("activityiscurrentlyhidden"));
135 //feedback on mainsite
136 if ((empty($cm->visible
) and !$cap_viewhiddenactivities) AND $courseid == SITEID
) {
137 notice(get_string("activityiscurrentlyhidden"));
140 /// Print the main part of the page
141 ///////////////////////////////////////////////////////////////////////////
142 ///////////////////////////////////////////////////////////////////////////
143 ///////////////////////////////////////////////////////////////////////////
145 $previewimg = $OUTPUT->pix_icon('t/preview', get_string('preview'));
146 $previewlnk = new moodle_url('/mod/feedback/print.php', array('id' => $id));
147 $preview = html_writer
::link($previewlnk, $previewimg);
149 echo $OUTPUT->heading(format_string($feedback->name
) . $preview);
154 //show some infos to the feedback
155 if (has_capability('mod/feedback:edititems', $context)) {
157 $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot
.'/mod/feedback/view.php?id='.$cm->id
, true);
158 $mygroupid = groups_get_activity_group($cm);
160 echo $OUTPUT->box_start('boxaligncenter boxwidthwide');
161 echo $groupselect.'<div class="clearer"> </div>';
162 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid);
163 echo $OUTPUT->box_start('feedback_info');
164 echo '<span class="feedback_info">';
165 echo get_string('completed_feedbacks', 'feedback').': ';
167 echo '<span class="feedback_info_value">';
168 echo $completedscount;
170 echo $OUTPUT->box_end();
172 $params = array('feedback'=>$feedback->id
, 'hasvalue'=>1);
173 $itemscount = $DB->count_records('feedback_item', $params);
174 echo $OUTPUT->box_start('feedback_info');
175 echo '<span class="feedback_info">';
176 echo get_string('questions', 'feedback').': ';
178 echo '<span class="feedback_info_value">';
181 echo $OUTPUT->box_end();
183 if ($feedback->timeopen
) {
184 echo $OUTPUT->box_start('feedback_info');
185 echo '<span class="feedback_info">';
186 echo get_string('feedbackopen', 'feedback').': ';
188 echo '<span class="feedback_info_value">';
189 echo userdate($feedback->timeopen
);
191 echo $OUTPUT->box_end();
193 if ($feedback->timeclose
) {
194 echo $OUTPUT->box_start('feedback_info');
195 echo '<span class="feedback_info">';
196 echo get_string('feedbackclose', 'feedback').': ';
198 echo '<span class="feedback_info_value">';
199 echo userdate($feedback->timeclose
);
201 echo $OUTPUT->box_end();
203 echo $OUTPUT->box_end();
206 if (has_capability('mod/feedback:edititems', $context)) {
207 echo $OUTPUT->heading(get_string('description', 'feedback'), 3);
209 echo $OUTPUT->box_start('generalbox boxwidthwide');
210 $options = (object)array('noclean'=>true);
211 echo format_module_intro('feedback', $feedback, $cm->id
);
212 echo $OUTPUT->box_end();
214 if (has_capability('mod/feedback:edititems', $context)) {
215 require_once($CFG->libdir
. '/filelib.php');
217 $page_after_submit_output = file_rewrite_pluginfile_urls($feedback->page_after_submit
,
224 echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 3);
225 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
226 echo format_text($page_after_submit_output,
227 $feedback->page_after_submitformat
,
228 array('overflowdiv'=>true));
230 echo $OUTPUT->box_end();
233 if ( (intval($feedback->publish_stats
) == 1) AND
234 ( has_capability('mod/feedback:viewanalysepage', $context)) AND
235 !( has_capability('mod/feedback:viewreports', $context)) ) {
237 $params = array('userid'=>$USER->id
, 'feedback'=>$feedback->id
);
238 if ($multiple_count = $DB->count_records('feedback_tracking', $params)) {
239 $url_params = array('id'=>$id, 'courseid'=>$courseid);
240 $analysisurl = new moodle_url('/mod/feedback/analysis.php', $url_params);
241 echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
242 echo get_string('completed_feedbacks', 'feedback').'</a>';
247 //####### mapcourse-start
248 if (has_capability('mod/feedback:mapcourse', $context)) {
249 if ($feedback->course
== SITEID
) {
250 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
251 echo '<div class="mdl-align">';
252 echo '<form action="mapcourse.php" method="get">';
254 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
255 echo '<input type="hidden" name="id" value="'.$id.'" />';
256 echo '<button type="submit">'.get_string('mapcourses', 'feedback').'</button>';
257 echo $OUTPUT->help_icon('mapcourse', 'feedback');
262 echo $OUTPUT->box_end();
265 //####### mapcourse-end
267 //####### completed-start
268 if ($feedback_complete_cap) {
269 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
270 //check, whether the feedback is open (timeopen, timeclose)
272 if (($feedback->timeopen
> $checktime) OR
273 ($feedback->timeclose
< $checktime AND $feedback->timeclose
> 0)) {
275 echo $OUTPUT->notification(get_string('feedback_is_not_open', 'feedback'));
276 echo $OUTPUT->continue_button($CFG->wwwroot
.'/course/view.php?id='.$course->id
);
277 echo $OUTPUT->box_end();
278 echo $OUTPUT->footer();
282 //check multiple Submit
283 $feedback_can_submit = true;
284 if ($feedback->multiple_submit
== 0 ) {
285 if (feedback_is_already_submitted($feedback->id
, $courseid)) {
286 $feedback_can_submit = false;
289 if ($feedback_can_submit) {
290 //if the user is not known so we cannot save the values temporarly
291 if (!isloggedin() or isguestuser()) {
292 $completefile = 'complete_guest.php';
293 $guestid = sesskey();
295 $completefile = 'complete.php';
298 $url_params = array('id'=>$id, 'courseid'=>$courseid, 'gopage'=>0);
299 $completeurl = new moodle_url('/mod/feedback/'.$completefile, $url_params);
301 $feedbackcompletedtmp = feedback_get_current_completed($feedback->id
, true, $courseid, $guestid);
302 if ($feedbackcompletedtmp) {
303 if ($startpage = feedback_get_page_to_continue($feedback->id
, $courseid, $guestid)) {
304 $completeurl->param('gopage', $startpage);
306 echo '<a href="'.$completeurl->out().'">'.get_string('continue_the_form', 'feedback').'</a>';
308 echo '<a href="'.$completeurl->out().'">'.get_string('complete_the_form', 'feedback').'</a>';
311 echo $OUTPUT->notification(get_string('this_feedback_is_already_submitted', 'feedback'));
313 echo $OUTPUT->continue_button($CFG->wwwroot
.'/course/view.php?id='.$courseid);
315 echo $OUTPUT->continue_button($CFG->wwwroot
.'/course/view.php?id='.$course->id
);
318 echo $OUTPUT->box_end();
320 //####### completed-end
323 ///////////////////////////////////////////////////////////////////////////
324 ///////////////////////////////////////////////////////////////////////////
325 ///////////////////////////////////////////////////////////////////////////
327 echo $OUTPUT->footer();