MDL-14493 First checkin of Feedback module into HEAD.
[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);
15
16 // $SESSION->feedback->current_tab = 'view';
17 $current_tab = 'view';
18
19 if ($id) {
20 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
21 error("Course Module ID was incorrect");
22 }
23
24 if (! $course = get_record("course", "id", $cm->course)) {
25 error("Course is misconfigured");
26 }
27
28 if (! $feedback = get_record("feedback", "id", $cm->instance)) {
29 error("Course module is incorrect");
30 }
31 }
32
33 $capabilities = feedback_load_capabilities($cm->id);
34
35 if($feedback->anonymous == FEEDBACK_ANONYMOUS_YES AND !$capabilities->edititems) {
36 $capabilities->complete = true;
37 }
38
39 //check whether the feedback is located and! started from the mainsite
40 if($course->id == SITEID AND !$courseid) {
41 $courseid = SITEID;
42 }
43
44 if($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
45 require_login($course->id);
46 } else {
47 require_course_login($course);
48 }
49
50 if($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
51 add_to_log($course->id, "feedback", "view", "view.php?id=$cm->id", "$feedback->name",$cm->id);
52 }
53
54 /// Print the page header
55 $strfeedbacks = get_string("modulenameplural", "feedback");
56 $strfeedback = get_string("modulename", "feedback");
57 $buttontext = update_module_button($cm->id, $course->id, $strfeedback);
58
59 $navlinks = array();
60 $navlinks[] = array('name' => $strfeedbacks, 'link' => "index.php?id=$course->id", 'type' => 'activity');
61 $navlinks[] = array('name' => format_string($feedback->name), 'link' => "", 'type' => 'activityinstance');
62
63 $navigation = build_navigation($navlinks);
64
65 print_header_simple(format_string($feedback->name), "",
66 $navigation, "", "", true, $buttontext, navmenu($course, $cm));
67
68 //ishidden check.
69 if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $course->id != SITEID) {
70 notice(get_string("activityiscurrentlyhidden"));
71 }
72
73 /// Print the main part of the page
74 ///////////////////////////////////////////////////////////////////////////
75 ///////////////////////////////////////////////////////////////////////////
76 ///////////////////////////////////////////////////////////////////////////
77
78 /// print the tabs
79 include('tabs.php');
80
81 print_heading(format_text($feedback->name));
82
83 // print_simple_box_start('center', '80%');
84 print_box_start('generalbox boxaligncenter boxwidthwide');
85 echo format_text($feedback->summary);
86 // print_simple_box_end();
87 print_box_end();
88
89 if($capabilities->edititems) {
90 print_heading(get_string("page_after_submit", "feedback"), '', 4);
91 // print_simple_box_start('center', '80%');
92 print_box_start('generalbox boxaligncenter boxwidthwide');
93 echo format_text($feedback->page_after_submit);
94 // print_simple_box_end();
95 print_box_end();
96 }
97
98 if( (intval($feedback->publish_stats) == 1) AND !( $capabilities->viewreports) ) {
99 if($multiple_count = count_records('feedback_tracking', 'userid', $USER->id, 'feedback', $feedback->id)) {
100 echo '<div align="center"><a href="'.htmlspecialchars('analysis.php?id=' . $id . '&courseid='.$courseid).'">';
101 echo get_string('completed_feedbacks', 'feedback').'</a>';
102 echo '</div>';
103 }
104 }
105 echo '<p>';
106
107 //####### mapcourse-start
108 if($capabilities->mapcourse) {
109 if($feedback->course == SITEID) {
110 // print_simple_box_start('center', '80%');
111 print_box_start('generalbox boxaligncenter boxwidthwide');
112 echo '<div align="center">';
113 echo '<form action="mapcourse.php" method="get">';
114 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
115 echo '<input type="hidden" name="id" value="'.$id.'" />';
116 echo '<button type="submit">'.get_string('mapcourses', 'feedback').'</button>';
117 helpbutton('mapcourse', '', 'feedback', true, true);
118 echo '</form>';
119 echo '<br />';
120 echo '</div>';
121 // print_simple_box_end();
122 print_box_end();
123 }
124 }
125 //####### mapcourse-end
126
127 //####### completed-start
128 if($capabilities->complete AND !$capabilities->edititems) {
129 // print_simple_box_start('center', '80%');
130 print_box_start('generalbox boxaligncenter boxwidthwide');
131 //check, whether the feedback is open (timeopen, timeclose)
132 $checktime = time();
133 if(($feedback->timeopen > $checktime) OR ($feedback->timeclose < $checktime AND $feedback->timeclose > 0)) {
134 // print_simple_box_start('center');
135 print_box_start('generalbox boxaligncenter');
136 echo '<h2><font color="red">'.get_string('feedback_is_not_open', 'feedback').'</font></h2>';
137 print_continue($CFG->wwwroot.'/course/view.php?id='.$course->id);
138 // print_simple_box_end();
139 print_box_end();
140 print_footer($course);
141 exit;
142 }
143
144 //check multiple Submit
145 $feedback_can_submit = true;
146 if($feedback->multiple_submit == 0 ) {
147 if(feedback_is_already_submitted($feedback->id, $courseid)) {
148 $feedback_can_submit = false;
149 }
150 }
151 if($feedback_can_submit) {
152 //if the user is not known so we cannot save the values temporarly
153 if(!isset($USER->username) OR $USER->username == 'guest') {
154 $completefile = 'complete_guest.php';
155 $guestid = $USER->sesskey;
156 }else {
157 $completefile = 'complete.php';
158 $guestid = false;
159 }
160 if($feedbackcompletedtmp = feedback_get_current_completed($feedback->id, true, $courseid, $guestid)) {
161 if($startpage = feedback_get_page_to_continue($feedback->id, $courseid, $guestid)) {
162 echo '<a href="'.htmlspecialchars($completefile.'?id='.$id.'&gopage='.$startpage.'&courseid='.$courseid).'">'.get_string('continue_the_form', 'feedback').'</a>';
163 }else {
164 echo '<a href="'.htmlspecialchars($completefile.'?id='.$id.'&gopage=0&courseid='.$courseid).'">'.get_string('continue_the_form', 'feedback').'</a>';
165 }
166 }else {
167 echo '<a href="'.htmlspecialchars($completefile.'?id='.$id.'&gopage=0&courseid='.$courseid).'">'.get_string('complete_the_form', 'feedback').'</a>';
168 }
169 }else {
170 echo '<h2><font color="red">'.get_string('this_feedback_is_already_submitted', 'feedback').'</font></h2>';
171 if($courseid) {
172 print_continue($CFG->wwwroot.'/course/view.php?id='.$courseid);
173 }else {
174 print_continue($CFG->wwwroot.'/course/view.php?id='.$course->id);
175 }
176 }
177 // print_simple_box_end();
178 print_box_end();
179 }
180 //####### completed-end
181 echo "</p>";
182
183 /// Finish the page
184 ///////////////////////////////////////////////////////////////////////////
185 ///////////////////////////////////////////////////////////////////////////
186 ///////////////////////////////////////////////////////////////////////////
187
188 print_footer($course);
189
190?>