MDL-21845 user profile: Fixed missing multilang support
[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
31$capabilities = feedback_load_capabilities($cm->id);
32
8001d6e7
AG
33if(isset($CFG->feedback_allowfullanonymous)
34 AND $CFG->feedback_allowfullanonymous
35 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
84973212 36 $capabilities->complete = true;
37}
38
39//check whether the feedback is located and! started from the mainsite
40if($course->id == SITEID AND !$courseid) {
41 $courseid = SITEID;
42}
43
44//check whether the feedback is mapped to the given courseid
45if($course->id == SITEID AND !$capabilities->edititems) {
46 if($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
47 if(!$DB->get_record('feedback_sitecourse_map', array('feedbackid'=>$feedback->id, 'courseid'=>$courseid))){
48 print_error('invalidcoursemodule');
da329996 49 }
50 }
84973212 51}
d4b1d58c 52
84973212 53if($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
54 if($course->id == SITEID) {
55 require_login($course->id, true);
56 }else {
57 require_login($course->id, true, $cm);
da329996 58 }
84973212 59} else {
60 if($course->id == SITEID) {
61 require_course_login($course, true);
62 }else {
63 require_course_login($course, true, $cm);
c70ad9f7 64 }
84973212 65}
66
67//check whether the given courseid exists
68if($courseid AND $courseid != SITEID) {
69 if($course2 = $DB->get_record('course', array('id'=>$courseid))){
70 require_course_login($course2); //this overwrites the object $course :-(
71 $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
72 }else {
73 print_error('invalidcourseid');
c70ad9f7 74 }
84973212 75}
76
77if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
78 add_to_log($course->id, 'feedback', 'view', 'view.php?id='.$cm->id, $feedback->id,$cm->id);
79}
80
81/// Print the page header
82$strfeedbacks = get_string("modulenameplural", "feedback");
83$strfeedback = get_string("modulename", "feedback");
84
a6855934 85$PAGE->set_url('/mod/feedback/view.php', array('id'=>$cm->id, 'do_show'=>'view'));
84973212 86$PAGE->set_title(format_string($feedback->name));
84973212 87echo $OUTPUT->header();
88
89//ishidden check.
90//feedback in courses
91if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $course->id != SITEID) {
92 notice(get_string("activityiscurrentlyhidden"));
93}
94
95//ishidden check.
96//feedback on mainsite
97if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $courseid == SITEID) {
98 notice(get_string("activityiscurrentlyhidden"));
99}
100
101/// Print the main part of the page
102///////////////////////////////////////////////////////////////////////////
103///////////////////////////////////////////////////////////////////////////
104///////////////////////////////////////////////////////////////////////////
105
106/// print the tabs
107include('tabs.php');
108
109echo $OUTPUT->heading(format_text($feedback->name));
110
111echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
112$options = (object)array('noclean'=>true);
113echo format_module_intro('feedback', $feedback, $cm->id);
114echo $OUTPUT->box_end();
115
116if($capabilities->edititems) {
117 echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
118 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
119 echo format_text($feedback->page_after_submit);
120 echo $OUTPUT->box_end();
121}
c70ad9f7 122
84973212 123if( (intval($feedback->publish_stats) == 1) AND ( $capabilities->viewanalysepage) AND !( $capabilities->viewreports) ) {
124 if($multiple_count = $DB->count_records('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
5dee2210
AG
125 $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
126 echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
84973212 127 echo get_string('completed_feedbacks', 'feedback').'</a>';
128 echo '</div>';
c70ad9f7 129 }
84973212 130}
131echo '<p>';
c70ad9f7 132
84973212 133//####### mapcourse-start
134if($capabilities->mapcourse) {
135 if($feedback->course == SITEID) {
136 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
137 echo '<div class="mdl-align">';
138 echo '<form action="mapcourse.php" method="get">';
139 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
140 echo '<input type="hidden" name="id" value="'.$id.'" />';
141 echo '<button type="submit">'.get_string('mapcourses', 'feedback').'</button>';
4bcc5118 142 echo $OUTPUT->help_icon('mapcourse', '', 'feedback', true);
84973212 143 echo '</form>';
144 echo '<br />';
145 echo '</div>';
146 echo $OUTPUT->box_end();
da329996 147 }
84973212 148}
149//####### mapcourse-end
da329996 150
84973212 151//####### completed-start
152if($capabilities->complete) {
d4b1d58c 153 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
84973212 154 //check, whether the feedback is open (timeopen, timeclose)
155 $checktime = time();
156 if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
157 echo $OUTPUT->box_start('generalbox boxaligncenter');
158 echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
159 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
d4b1d58c 160 echo $OUTPUT->box_end();
84973212 161 echo $OUTPUT->footer();
162 exit;
c70ad9f7 163 }
d4b1d58c 164
84973212 165 //check multiple Submit
166 $feedback_can_submit = true;
167 if($feedback->multiple_submit == 0 ) {
168 if(feedback_is_already_submitted($feedback->id, $courseid)) {
169 $feedback_can_submit = false;
c70ad9f7 170 }
171 }
84973212 172 if($feedback_can_submit) {
173 //if the user is not known so we cannot save the values temporarly
174 if(!isset($USER->username) OR $USER->username == 'guest') {
175 $completefile = 'complete_guest.php';
176 $guestid = sesskey();
177 }else {
178 $completefile = 'complete.php';
179 $guestid = false;
c70ad9f7 180 }
5dee2210
AG
181 $completeurl = new moodle_url('/mod/feedback/'.$completefile, array('id'=>$id, 'courseid'=>$courseid, 'gopage'=>0));
182
84973212 183 if($feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, $guestid)) {
184 if($startpage = feedback_get_page_to_continue($feedback->id, $courseid, $guestid)) {
5dee2210 185 $completeurl->param('gopage', $startpage);
c70ad9f7 186 }
5dee2210 187 echo '<a href="'.$completeurl->out().'">'.get_string('continue_the_form', 'feedback').'</a>';
c70ad9f7 188 }else {
5dee2210 189 echo '<a href="'.$completeurl->out().'">'.get_string('complete_the_form', 'feedback').'</a>';
84973212 190 }
191 }else {
192 echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>';
193 if($courseid) {
194 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
195 }else {
196 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
c70ad9f7 197 }
c70ad9f7 198 }
84973212 199 echo $OUTPUT->box_end();
200}
201//####### completed-end
202echo "</p>";
c70ad9f7 203
84973212 204/// Finish the page
205///////////////////////////////////////////////////////////////////////////
206///////////////////////////////////////////////////////////////////////////
207///////////////////////////////////////////////////////////////////////////
c70ad9f7 208
84973212 209echo $OUTPUT->footer();
c70ad9f7 210