MDL-21695 - Replace built-in HTML help files with proper strings
[moodle.git] / mod / feedback / show_entries.php
CommitLineData
84973212 1<?php
2
c70ad9f7 3/**
84973212 4 * print the single entries
5 *
6 * @author Andreas Grabs
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package feedback
9 */
c70ad9f7 10
84973212 11require_once("../../config.php");
12require_once("lib.php");
d4b1d58c 13
84973212 14////////////////////////////////////////////////////////
15//get the params
16////////////////////////////////////////////////////////
17$id = required_param('id', PARAM_INT);
18$userid = optional_param('userid', false, PARAM_INT);
19$do_show = required_param('do_show', PARAM_ALPHA);
20// $SESSION->feedback->current_tab = $do_show;
21$current_tab = $do_show;
c70ad9f7 22
84973212 23////////////////////////////////////////////////////////
24//get the objects
25////////////////////////////////////////////////////////
d4b1d58c 26
84973212 27if($userid) {
28 $formdata->userid = intval($userid);
29}
c70ad9f7 30
5dee2210
AG
31if (! $cm = get_coursemodule_from_id('feedback', $id)) {
32 print_error('invalidcoursemodule');
33}
d4b1d58c 34
5dee2210
AG
35if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
36 print_error('coursemisconf');
37}
d4b1d58c 38
5dee2210
AG
39if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
40 print_error('invalidcoursemodule');
84973212 41}
d4b1d58c 42
5dee2210
AG
43$url = new moodle_url('/mod/feedback/show_entries.php', array('id'=>$cm->id, 'do_show'=>$do_show));
44
45$PAGE->set_url($url);
ab5bd34d 46
c987dbad
AG
47if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
48 print_error('badcontext');
49}
c70ad9f7 50
84973212 51require_login($course->id, true, $cm);
d4b1d58c 52
84973212 53if(($formdata = data_submitted()) AND !confirm_sesskey()) {
54 print_error('invalidsesskey');
55}
d4b1d58c 56
53ba55ec 57require_capability('mod/feedback:viewreports', $context);
c70ad9f7 58
84973212 59////////////////////////////////////////////////////////
60//get the responses of given user
61////////////////////////////////////////////////////////
62if($do_show == 'showoneentry') {
63 //get the feedbackitems
64 $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
65 $feedbackcompleted = $DB->get_record('feedback_completed', array('feedback'=>$feedback->id, 'userid'=>$formdata->userid, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO)); //arb
66}
d4b1d58c 67
84973212 68/// Print the page header
69$strfeedbacks = get_string("modulenameplural", "feedback");
70$strfeedback = get_string("modulename", "feedback");
d4b1d58c 71
84973212 72$PAGE->navbar->add(get_string('show_entries','feedback'));
73$PAGE->set_title(format_string($feedback->name));
84973212 74echo $OUTPUT->header();
d4b1d58c 75
84973212 76include('tabs.php');
c70ad9f7 77
84973212 78/// Print the main part of the page
79///////////////////////////////////////////////////////////////////////////
80///////////////////////////////////////////////////////////////////////////
81///////////////////////////////////////////////////////////////////////////
c70ad9f7 82
84973212 83////////////////////////////////////////////////////////
84/// Print the links to get responses and analysis
85////////////////////////////////////////////////////////
86if($do_show == 'showentries'){
87 //print the link to analysis
c987dbad 88 if(has_capability('mod/feedback:viewreports', $context)) {
84973212 89 //get the effective groupmode of this course and module
90 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
91 $groupmode = $cm->groupmode;
92 } else {
93 $groupmode = $course->groupmode;
94 }
5dee2210
AG
95
96 // $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/show_entries.php?id=' . $cm->id.'&do_show=showentries', true);
97 $groupselect = groups_print_activity_menu($cm, $url->out(), true);
84973212 98 $mygroupid = groups_get_activity_group($cm);
d4b1d58c 99
84973212 100 //get students in conjunction with groupmode
101 if($groupmode > 0) {
b68bff82 102
84973212 103 if($mygroupid > 0) {
104 $students = feedback_get_complete_users($cm, $mygroupid);
105 } else {
a600ad35 106 $students = feedback_get_complete_users($cm);
c70ad9f7 107 }
84973212 108 }else {
109 $students = feedback_get_complete_users($cm);
110 }
c70ad9f7 111
84973212 112 $completedFeedbackCount = feedback_get_completeds_group_count($feedback, $mygroupid);
113 if($feedback->course == SITEID){
5dee2210
AG
114 $analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id, 'courseid'=>$courseid));
115 echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
84973212 116 echo get_string('course') .' '. get_string('analysis', 'feedback') . ' ('.get_string('completed_feedbacks', 'feedback').': '.intval($completedFeedbackCount).')</a>';
e8790d59 117 echo $OUTPUT->help_icon('viewcompleted', 'feedback');
84973212 118 echo '</div>';
119 }else {
5dee2210
AG
120 $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
121 echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
84973212 122 echo get_string('analysis', 'feedback') . ' ('.get_string('completed_feedbacks', 'feedback').': '.intval($completedFeedbackCount).')</a>';
123 echo '</div>';
c70ad9f7 124 }
84973212 125 }
d4b1d58c 126
84973212 127 //####### viewreports-start
c987dbad 128 if(has_capability('mod/feedback:viewreports', $context)) {
84973212 129 //print the list of students
130 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
131 echo isset($groupselect) ? $groupselect : '';
132 echo '<div class="clearer"></div>';
133 echo '<div class="mdl-align"><table><tr><td width="400">';
134 if (!$students) {
135 if($courseid != SITEID){
136 echo $OUTPUT->notification(get_string('noexistingstudents'));
137 }
138 } else{
139 echo print_string('non_anonymous_entries', 'feedback');
140 echo ' ('.count($students).')<hr />';
c70ad9f7 141
84973212 142 foreach ($students as $student){
143 $completedCount = $DB->count_records('feedback_completed', array('userid'=>$student->id, 'feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO));
144 if($completedCount > 0) {
145 // Are we assuming that there is only one response per user? Should westep through a feedbackcompleteds? I added the addition anonymous check to the select so that only non-anonymous submissions are retrieved.
146 $feedbackcompleted = $DB->get_record('feedback_completed', array('feedback'=>$feedback->id, ' userid'=>$student->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO));
147 ?>
148 <table width="100%">
149 <tr>
150 <td align="left">
812dbaf7 151 <?php echo $OUTPUT->user_picture($student, array('courseid'=>$course->id));?>
84973212 152 </td>
153 <td align="left">
154 <?php echo fullname($student);?>
155 </td>
156 <td align="right">
157 <?php
5dee2210 158 $aurl = new moodle_url($url, array('sesskey'=>sesskey(), 'userid'=>$student->id, 'do_show'=>'showoneentry'));
5c2ed7e2 159 echo $OUTPUT->single_button($aurl, get_string('show_entries', 'feedback'));
84973212 160 ?>
161 </td>
162 <?php
c987dbad 163 if(has_capability('mod/feedback:deletesubmissions', $context)) {
84973212 164 ?>
165 <td align="right">
166 <?php
5dee2210 167 $aurl = new moodle_url($url, array('sesskey'=>sesskey(), 'completedid'=>$feedbackcompleted->id, 'do_show'=>'showoneentry'));
5c2ed7e2 168 echo $OUTPUT->single_button($aurl, get_string('delete_entry', 'feedback'));
84973212 169 ?>
170 </td>
171 <?php
c70ad9f7 172 }
84973212 173 ?>
174 </tr>
175 </table>
176 <?php
c70ad9f7 177 }
178 }
c70ad9f7 179 }
84973212 180?>
181 <hr />
182 <table width="100%">
183 <tr>
184 <td align="left" colspan="2">
185 <?php print_string('anonymous_entries', 'feedback');?>&nbsp;(<?php echo $DB->count_records('feedback_completed', array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES));?>)
186 </td>
187 <td align="right">
188 <?php
5c2ed7e2
PS
189 $aurl = new moodle_url('show_entries_anonym.php', array('sesskey'=>sesskey(), 'userid'=>0, 'do_show'=>'showoneentry', 'id'=>$id));
190 echo $OUTPUT->single_button($aurl, get_string('show_entries', 'feedback'));
84973212 191 ?>
192 </td>
193 </tr>
194 </table>
195<?php
196 echo '</td></tr></table></div>';
197 echo $OUTPUT->box_end();
c70ad9f7 198 }
d4b1d58c 199
84973212 200}
201////////////////////////////////////////////////////////
202/// Print the responses of the given user
203////////////////////////////////////////////////////////
204if($do_show == 'showoneentry') {
205 echo $OUTPUT->heading(format_text($feedback->name));
206
207 //print the items
208 if(is_array($feedbackitems)){
209 $usr = $DB->get_record('user', array('id'=>$formdata->userid));
210 if($feedbackcompleted) {
211 echo '<p align="center">'.UserDate($feedbackcompleted->timemodified).'<br />('.fullname($usr).')</p>';
212 } else {
213 echo '<p align="center">'.get_string('not_completed_yet','feedback').'</p>';
214 }
215 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
216 echo '<form>';
217 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
218 echo '<table width="100%">';
219 $itemnr = 0;
220 foreach($feedbackitems as $feedbackitem){
221 //get the values
222 $value = $DB->get_record('feedback_value', array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id));
223 echo '<tr>';
224 if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
225 $itemnr++;
226 echo '<td valign="top">' . $itemnr . '.&nbsp;</td>';
c70ad9f7 227 } else {
84973212 228 echo '<td>&nbsp;</td>';
c70ad9f7 229 }
d4b1d58c 230
84973212 231 if($feedbackitem->typ != 'pagebreak') {
232 if(isset($value->value)) {
233 feedback_print_item($feedbackitem, $value->value, true);
c70ad9f7 234 }else {
84973212 235 feedback_print_item($feedbackitem, false, true);
c70ad9f7 236 }
84973212 237 }else {
238 echo '<td><hr /></td>';
c70ad9f7 239 }
84973212 240 echo '</tr>';
c70ad9f7 241 }
84973212 242 echo '<tr><td colspan="2" align="center">';
243 echo '</td></tr>';
244 echo '</table>';
245 echo '</form>';
246 echo $OUTPUT->box_end();
c70ad9f7 247 }
5dee2210
AG
248 // echo $OUTPUT->continue_button(htmlspecialchars('show_entries.php?id='.$id.'&do_show=showentries'));
249 echo $OUTPUT->continue_button(new moodle_url($url, array('do_show'=>'showentries')));
84973212 250}
251/// Finish the page
252///////////////////////////////////////////////////////////////////////////
253///////////////////////////////////////////////////////////////////////////
254///////////////////////////////////////////////////////////////////////////
c70ad9f7 255
84973212 256echo $OUTPUT->footer();
c70ad9f7 257
84973212 258?>