MDL-22151 backup - added label module backup
[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
a6855934 93$PAGE->set_url('/mod/feedback/view.php', array('id'=>$cm->id, 'do_show'=>'view'));
84973212 94$PAGE->set_title(format_string($feedback->name));
84973212 95echo $OUTPUT->header();
96
97//ishidden check.
98//feedback in courses
c987dbad 99if ((empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) AND $course->id != SITEID) {
84973212 100 notice(get_string("activityiscurrentlyhidden"));
101}
102
103//ishidden check.
104//feedback on mainsite
c987dbad 105if ((empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) AND $courseid == SITEID) {
84973212 106 notice(get_string("activityiscurrentlyhidden"));
107}
108
109/// Print the main part of the page
110///////////////////////////////////////////////////////////////////////////
111///////////////////////////////////////////////////////////////////////////
112///////////////////////////////////////////////////////////////////////////
113
114/// print the tabs
115include('tabs.php');
116
117echo $OUTPUT->heading(format_text($feedback->name));
118
119echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
120$options = (object)array('noclean'=>true);
121echo format_module_intro('feedback', $feedback, $cm->id);
122echo $OUTPUT->box_end();
123
c987dbad 124if(has_capability('mod/feedback:edititems', $context)) {
84973212 125 echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
126 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
127 echo format_text($feedback->page_after_submit);
128 echo $OUTPUT->box_end();
129}
c70ad9f7 130
c987dbad
AG
131if( (intval($feedback->publish_stats) == 1) AND
132 ( has_capability('mod/feedback:viewanalysepage', $context)) AND
133 !( has_capability('mod/feedback:viewreports', $context)) ) {
84973212 134 if($multiple_count = $DB->count_records('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
5dee2210
AG
135 $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
136 echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
84973212 137 echo get_string('completed_feedbacks', 'feedback').'</a>';
138 echo '</div>';
c70ad9f7 139 }
84973212 140}
cf6c33cb 141// echo '<p>';
c70ad9f7 142
84973212 143//####### mapcourse-start
6a471fe0 144if(has_capability('mod/feedback:mapcourse', $context)) {
84973212 145 if($feedback->course == SITEID) {
146 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
147 echo '<div class="mdl-align">';
148 echo '<form action="mapcourse.php" method="get">';
149 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
150 echo '<input type="hidden" name="id" value="'.$id.'" />';
151 echo '<button type="submit">'.get_string('mapcourses', 'feedback').'</button>';
e8790d59 152 echo $OUTPUT->help_icon('mapcourse', 'feedback');
84973212 153 echo '</form>';
154 echo '<br />';
155 echo '</div>';
156 echo $OUTPUT->box_end();
da329996 157 }
84973212 158}
159//####### mapcourse-end
da329996 160
84973212 161//####### completed-start
c987dbad 162if($feedback_complete_cap) {
d4b1d58c 163 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
84973212 164 //check, whether the feedback is open (timeopen, timeclose)
165 $checktime = time();
166 if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
84973212 167 echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
168 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
d4b1d58c 169 echo $OUTPUT->box_end();
84973212 170 echo $OUTPUT->footer();
171 exit;
c70ad9f7 172 }
d4b1d58c 173
84973212 174 //check multiple Submit
175 $feedback_can_submit = true;
176 if($feedback->multiple_submit == 0 ) {
177 if(feedback_is_already_submitted($feedback->id, $courseid)) {
178 $feedback_can_submit = false;
c70ad9f7 179 }
180 }
84973212 181 if($feedback_can_submit) {
182 //if the user is not known so we cannot save the values temporarly
183 if(!isset($USER->username) OR $USER->username == 'guest') {
184 $completefile = 'complete_guest.php';
185 $guestid = sesskey();
186 }else {
187 $completefile = 'complete.php';
188 $guestid = false;
c70ad9f7 189 }
5dee2210
AG
190 $completeurl = new moodle_url('/mod/feedback/'.$completefile, array('id'=>$id, 'courseid'=>$courseid, 'gopage'=>0));
191
84973212 192 if($feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, $guestid)) {
193 if($startpage = feedback_get_page_to_continue($feedback->id, $courseid, $guestid)) {
5dee2210 194 $completeurl->param('gopage', $startpage);
c70ad9f7 195 }
5dee2210 196 echo '<a href="'.$completeurl->out().'">'.get_string('continue_the_form', 'feedback').'</a>';
c70ad9f7 197 }else {
5dee2210 198 echo '<a href="'.$completeurl->out().'">'.get_string('complete_the_form', 'feedback').'</a>';
84973212 199 }
200 }else {
201 echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>';
202 if($courseid) {
203 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
204 }else {
205 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
c70ad9f7 206 }
c70ad9f7 207 }
84973212 208 echo $OUTPUT->box_end();
209}
210//####### completed-end
cf6c33cb 211// echo "</p>";
c70ad9f7 212
84973212 213/// Finish the page
214///////////////////////////////////////////////////////////////////////////
215///////////////////////////////////////////////////////////////////////////
216///////////////////////////////////////////////////////////////////////////
c70ad9f7 217
84973212 218echo $OUTPUT->footer();
c70ad9f7 219