mod-data MDL-19806 Added set_url calls, replaced deprecated functions, and added...
[moodle.git] / mod / feedback / view.php
CommitLineData
c70ad9f7 1<?php // $Id$
2/**
3* the first page to view the feedback
4*
5* @version $Id$
6* @author Andreas Grabs
7* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8* @package feedback
9*/
10 require_once("../../config.php");
11 require_once("lib.php");
12
13 $id = required_param('id', PARAM_INT);
14 $courseid = optional_param('courseid', false, PARAM_INT);
d4b1d58c 15
c70ad9f7 16 // $SESSION->feedback->current_tab = 'view';
17 $current_tab = 'view';
18
50aa3fcc 19 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
20 print_error('invalidcoursemodule');
21 }
d4b1d58c 22
50aa3fcc 23 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
24 print_error('coursemisconf');
25 }
d4b1d58c 26
50aa3fcc 27 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
28 print_error('invalidcoursemodule');
c70ad9f7 29 }
30
31 $capabilities = feedback_load_capabilities($cm->id);
32
dd5cb0b5 33 if($feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
c70ad9f7 34 $capabilities->complete = true;
35 }
d4b1d58c 36
58627682 37 //check whether the feedback is located and! started from the mainsite
38 if($course->id == SITEID AND !$courseid) {
39 $courseid = SITEID;
40 }
d4b1d58c 41
da329996 42 //check whether the feedback is mapped to the given courseid
43 if($course->id == SITEID AND !$capabilities->edititems) {
44 if($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
45 if(!$DB->get_record('feedback_sitecourse_map', array('feedbackid'=>$feedback->id, 'courseid'=>$courseid))){
5d2edd1c 46 print_error('invalidcoursemodule');
da329996 47 }
48 }
49 }
d4b1d58c 50
c70ad9f7 51 if($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
aeb7e1ae 52 if($course->id == SITEID) {
53 require_login($course->id, true);
54 }else {
55 require_login($course->id, true, $cm);
56 }
c70ad9f7 57 } else {
da329996 58 if($course->id == SITEID) {
59 require_course_login($course, true);
60 }else {
61 require_course_login($course, true, $cm);
62 }
63 }
d4b1d58c 64
da329996 65 //check whether the given courseid exists
66 if($courseid AND $courseid != SITEID) {
67 if($course2 = $DB->get_record('course', array('id'=>$courseid))){
68 require_course_login($course2); //this overwrites the object $course :-(
69 $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
70 }else {
5d2edd1c 71 print_error('invalidcourseid');
da329996 72 }
c70ad9f7 73 }
74
75 if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
a78b88e7 76 add_to_log($course->id, 'feedback', 'view', 'view.php?id='.$cm->id, $feedback->id,$cm->id);
c70ad9f7 77 }
78
79 /// Print the page header
80 $strfeedbacks = get_string("modulenameplural", "feedback");
81 $strfeedback = get_string("modulename", "feedback");
82 $buttontext = update_module_button($cm->id, $course->id, $strfeedback);
d4b1d58c 83
ab5bd34d 84 $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/feedback/view.php', array('id'=>$cm->id, 'do_show'=>'view')));
84f797db 85 $PAGE->set_title(format_string($feedback->name));
86 $PAGE->set_button($buttontext);
87 echo $OUTPUT->header();
c70ad9f7 88
89 //ishidden check.
da329996 90 //feedback in courses
c70ad9f7 91 if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $course->id != SITEID) {
92 notice(get_string("activityiscurrentlyhidden"));
93 }
94
da329996 95 //ishidden check.
96 //feedback on mainsite
97 if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $courseid == SITEID) {
98 notice(get_string("activityiscurrentlyhidden"));
99 }
100
c70ad9f7 101 /// Print the main part of the page
102 ///////////////////////////////////////////////////////////////////////////
103 ///////////////////////////////////////////////////////////////////////////
104 ///////////////////////////////////////////////////////////////////////////
105
106 /// print the tabs
107 include('tabs.php');
108
53b1f5da 109 echo $OUTPUT->heading(format_text($feedback->name));
c70ad9f7 110
d4b1d58c 111 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
63b02567 112 $options = (object)array('noclean'=>true);
50aa3fcc 113 echo format_module_intro('feedback', $feedback, $cm->id);
d4b1d58c 114 echo $OUTPUT->box_end();
115
c70ad9f7 116 if($capabilities->edititems) {
53b1f5da 117 echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
d4b1d58c 118 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
c70ad9f7 119 echo format_text($feedback->page_after_submit);
d4b1d58c 120 echo $OUTPUT->box_end();
c70ad9f7 121 }
d4b1d58c 122
488b13ba 123 if( (intval($feedback->publish_stats) == 1) AND ( $capabilities->viewanalysepage) AND !( $capabilities->viewreports) ) {
0085fff8 124 if($multiple_count = $DB->count_records('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
ff9b4ea4 125 echo '<div class="mdl-align"><a href="'.htmlspecialchars('analysis.php?id=' . $id . '&courseid='.$courseid).'">';
c70ad9f7 126 echo get_string('completed_feedbacks', 'feedback').'</a>';
127 echo '</div>';
128 }
129 }
130 echo '<p>';
131
132 //####### mapcourse-start
133 if($capabilities->mapcourse) {
134 if($feedback->course == SITEID) {
d4b1d58c 135 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
ff9b4ea4 136 echo '<div class="mdl-align">';
c70ad9f7 137 echo '<form action="mapcourse.php" method="get">';
d4a1fcaf 138 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
c70ad9f7 139 echo '<input type="hidden" name="id" value="'.$id.'" />';
140 echo '<button type="submit">'.get_string('mapcourses', 'feedback').'</button>';
9fad7b20 141 echo $OUTPUT->help_icon(moodle_help_icon::make('mapcourse', '', 'feedback', true));
c70ad9f7 142 echo '</form>';
143 echo '<br />';
144 echo '</div>';
d4b1d58c 145 echo $OUTPUT->box_end();
c70ad9f7 146 }
147 }
148 //####### mapcourse-end
149
150 //####### completed-start
dd5cb0b5 151 if($capabilities->complete) {
d4b1d58c 152 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
c70ad9f7 153 //check, whether the feedback is open (timeopen, timeclose)
154 $checktime = time();
155 if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
d4b1d58c 156 echo $OUTPUT->box_start('generalbox boxaligncenter');
c70ad9f7 157 echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
9fad7b20 158 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
d4b1d58c 159 echo $OUTPUT->box_end();
c6ea0876 160 echo $OUTPUT->footer();
c70ad9f7 161 exit;
162 }
d4b1d58c 163
c70ad9f7 164 //check multiple Submit
165 $feedback_can_submit = true;
166 if($feedback->multiple_submit == 0 ) {
167 if(feedback_is_already_submitted($feedback->id, $courseid)) {
168 $feedback_can_submit = false;
169 }
170 }
171 if($feedback_can_submit) {
172 //if the user is not known so we cannot save the values temporarly
173 if(!isset($USER->username) OR $USER->username == 'guest') {
174 $completefile = 'complete_guest.php';
973d2660 175 $guestid = sesskey();
c70ad9f7 176 }else {
177 $completefile = 'complete.php';
178 $guestid = false;
179 }
180 if($feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, $guestid)) {
181 if($startpage = feedback_get_page_to_continue($feedback->id, $courseid, $guestid)) {
182 echo '<a href="'.htmlspecialchars($completefile.'?id='.$id.'&gopage='.$startpage.'&courseid='.$courseid).'">'.get_string('continue_the_form', 'feedback').'</a>';
183 }else {
184 echo '<a href="'.htmlspecialchars($completefile.'?id='.$id.'&gopage=0&courseid='.$courseid).'">'.get_string('continue_the_form', 'feedback').'</a>';
185 }
186 }else {
187 echo '<a href="'.htmlspecialchars($completefile.'?id='.$id.'&gopage=0&courseid='.$courseid).'">'.get_string('complete_the_form', 'feedback').'</a>';
188 }
189 }else {
190 echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>';
191 if($courseid) {
9fad7b20 192 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$courseid);
c70ad9f7 193 }else {
9fad7b20 194 echo $OUTPUT->continue_button($CFG->wwwroot.'/course/view.php?id='.$course->id);
c70ad9f7 195 }
196 }
d4b1d58c 197 echo $OUTPUT->box_end();
c70ad9f7 198 }
199 //####### completed-end
200 echo "</p>";
201
202 /// Finish the page
203 ///////////////////////////////////////////////////////////////////////////
204 ///////////////////////////////////////////////////////////////////////////
205 ///////////////////////////////////////////////////////////////////////////
206
c6ea0876 207 echo $OUTPUT->footer();
c70ad9f7 208
209?>