Merge branch 'w18_MDL-32676_m23_yuibootstrap' of git://github.com/skodak/moodle
[moodle.git] / mod / feedback / show_entries.php
CommitLineData
84973212 1<?php
9c5bc7a5
AG
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
84973212 16
c70ad9f7 17/**
84973212 18 * print the single entries
19 *
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package feedback
23 */
c70ad9f7 24
84973212 25require_once("../../config.php");
26require_once("lib.php");
248bafd6 27require_once($CFG->libdir.'/tablelib.php');
d4b1d58c 28
84973212 29////////////////////////////////////////////////////////
30//get the params
31////////////////////////////////////////////////////////
32$id = required_param('id', PARAM_INT);
33$userid = optional_param('userid', false, PARAM_INT);
34$do_show = required_param('do_show', PARAM_ALPHA);
248bafd6
AG
35$perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT); // how many per page
36$showall = optional_param('showall', false, PARAM_INT); // should we show all users
84973212 37// $SESSION->feedback->current_tab = $do_show;
38$current_tab = $do_show;
c70ad9f7 39
84973212 40////////////////////////////////////////////////////////
41//get the objects
42////////////////////////////////////////////////////////
d4b1d58c 43
9c5bc7a5 44if ($userid) {
84973212 45 $formdata->userid = intval($userid);
46}
c70ad9f7 47
5dee2210
AG
48if (! $cm = get_coursemodule_from_id('feedback', $id)) {
49 print_error('invalidcoursemodule');
50}
d4b1d58c 51
5dee2210
AG
52if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
53 print_error('coursemisconf');
54}
d4b1d58c 55
5dee2210
AG
56if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
57 print_error('invalidcoursemodule');
84973212 58}
d4b1d58c 59
5dee2210
AG
60$url = new moodle_url('/mod/feedback/show_entries.php', array('id'=>$cm->id, 'do_show'=>$do_show));
61
62$PAGE->set_url($url);
ab5bd34d 63
c987dbad
AG
64if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
65 print_error('badcontext');
66}
c70ad9f7 67
cdbea7ee 68require_login($course, true, $cm);
d4b1d58c 69
9c5bc7a5 70if (($formdata = data_submitted()) AND !confirm_sesskey()) {
84973212 71 print_error('invalidsesskey');
72}
d4b1d58c 73
53ba55ec 74require_capability('mod/feedback:viewreports', $context);
c70ad9f7 75
84973212 76////////////////////////////////////////////////////////
77//get the responses of given user
78////////////////////////////////////////////////////////
9c5bc7a5 79if ($do_show == 'showoneentry') {
84973212 80 //get the feedbackitems
81 $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
9c5bc7a5
AG
82
83 $params = array('feedback'=>$feedback->id,
84 'userid'=>$userid,
85 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO);
86
87 $feedbackcompleted = $DB->get_record('feedback_completed', $params); //arb
84973212 88}
d4b1d58c 89
84973212 90/// Print the page header
91$strfeedbacks = get_string("modulenameplural", "feedback");
92$strfeedback = get_string("modulename", "feedback");
d4b1d58c 93
9d092aa9 94$PAGE->set_heading(format_string($course->fullname));
84973212 95$PAGE->set_title(format_string($feedback->name));
84973212 96echo $OUTPUT->header();
d4b1d58c 97
9c5bc7a5 98require('tabs.php');
c70ad9f7 99
84973212 100/// Print the main part of the page
101///////////////////////////////////////////////////////////////////////////
102///////////////////////////////////////////////////////////////////////////
103///////////////////////////////////////////////////////////////////////////
c70ad9f7 104
84973212 105////////////////////////////////////////////////////////
106/// Print the links to get responses and analysis
107////////////////////////////////////////////////////////
9c5bc7a5 108if ($do_show == 'showentries') {
84973212 109 //print the link to analysis
9c5bc7a5 110 if (has_capability('mod/feedback:viewreports', $context)) {
84973212 111 //get the effective groupmode of this course and module
112 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
113 $groupmode = $cm->groupmode;
114 } else {
115 $groupmode = $course->groupmode;
116 }
df997f84 117
5dee2210 118 $groupselect = groups_print_activity_menu($cm, $url->out(), true);
84973212 119 $mygroupid = groups_get_activity_group($cm);
d4b1d58c 120
248bafd6
AG
121 // preparing the table for output
122 $baseurl = new moodle_url('/mod/feedback/show_entries.php');
123 $baseurl->params(array('id'=>$id, 'do_show'=>$do_show, 'showall'=>$showall));
df997f84 124
a5448b3f 125 $tablecolumns = array('userpic', 'fullname', 'completed_timemodified');
8a23b38c 126 $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('date'));
df997f84 127
9c5bc7a5 128 if (has_capability('mod/feedback:deletesubmissions', $context)) {
248bafd6
AG
129 $tablecolumns[] = 'deleteentry';
130 $tableheaders[] = '';
131 }
df997f84 132
248bafd6
AG
133 $table = new flexible_table('feedback-showentry-list-'.$course->id);
134
135 $table->define_columns($tablecolumns);
136 $table->define_headers($tableheaders);
137 $table->define_baseurl($baseurl);
138
139 $table->sortable(true, 'lastname', SORT_DESC);
140 $table->set_attribute('cellspacing', '0');
141 $table->set_attribute('id', 'showentrytable');
142 $table->set_attribute('class', 'generaltable generalbox');
143 $table->set_control_variables(array(
144 TABLE_VAR_SORT => 'ssort',
145 TABLE_VAR_IFIRST => 'sifirst',
146 TABLE_VAR_ILAST => 'silast',
147 TABLE_VAR_PAGE => 'spage'
148 ));
149 $table->setup();
150
9c5bc7a5 151 if ($table->get_sql_sort()) {
248bafd6 152 $sort = $table->get_sql_sort();
9c5bc7a5 153 } else {
248bafd6
AG
154 $sort = '';
155 }
156
0f21a964
PS
157 list($where, $params) = $table->get_sql_where();
158 if ($where) {
248bafd6 159 $where .= ' AND';
248bafd6
AG
160 }
161
84973212 162 //get students in conjunction with groupmode
9c5bc7a5
AG
163 if ($groupmode > 0) {
164 if ($mygroupid > 0) {
248bafd6 165 $usedgroupid = $mygroupid;
84973212 166 } else {
248bafd6 167 $usedgroupid = false;
c70ad9f7 168 }
9c5bc7a5 169 } else {
248bafd6
AG
170 $usedgroupid = false;
171 }
df997f84 172
248bafd6
AG
173 $matchcount = feedback_count_complete_users($cm, $usedgroupid);
174 $table->initialbars(true);
df997f84 175
9c5bc7a5 176 if ($showall) {
248bafd6
AG
177 $startpage = false;
178 $pagecount = false;
9c5bc7a5 179 } else {
248bafd6
AG
180 $table->pagesize($perpage, $matchcount);
181 $startpage = $table->get_page_start();
182 $pagecount = $table->get_page_size();
84973212 183 }
df997f84 184
0f21a964 185 $students = feedback_get_complete_users($cm, $usedgroupid, $where, $params, $sort, $startpage, $pagecount);
9c5bc7a5
AG
186 $str_analyse = get_string('analysis', 'feedback');
187 $str_complete = get_string('completed_feedbacks', 'feedback');
188 $str_course = get_string('course');
c70ad9f7 189
9c5bc7a5
AG
190 $completed_fb_count = feedback_get_completeds_group_count($feedback, $mygroupid);
191 if ($feedback->course == SITEID) {
5dee2210 192 $analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id, 'courseid'=>$courseid));
31c0fa53 193 echo $OUTPUT->box_start('mdl-align');
9c5bc7a5
AG
194 echo '<a href="'.$analysisurl->out().'">';
195 echo $str_course.' '.$str_analyse.' ('.$str_complete.': '.intval($completed_fb_count).')';
196 echo '</a>';
e8790d59 197 echo $OUTPUT->help_icon('viewcompleted', 'feedback');
31c0fa53 198 echo $OUTPUT->box_end();
9c5bc7a5 199 } else {
5dee2210 200 $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
31c0fa53 201 echo $OUTPUT->box_start('mdl-align');
9c5bc7a5
AG
202 echo '<a href="'.$analysisurl->out().'">';
203 echo $str_analyse.' ('.$str_complete.': '.intval($completed_fb_count).')';
204 echo '</a>';
31c0fa53 205 echo $OUTPUT->box_end();
c70ad9f7 206 }
84973212 207 }
d4b1d58c 208
84973212 209 //####### viewreports-start
9c5bc7a5 210 if (has_capability('mod/feedback:viewreports', $context)) {
84973212 211 //print the list of students
212 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
213 echo isset($groupselect) ? $groupselect : '';
214 echo '<div class="clearer"></div>';
31c0fa53 215 echo $OUTPUT->box_start('mdl-align');
84973212 216 if (!$students) {
7e5dc9f3 217 $table->print_html();
9c5bc7a5 218 } else {
84973212 219 echo print_string('non_anonymous_entries', 'feedback');
220 echo ' ('.count($students).')<hr />';
c70ad9f7 221
9c5bc7a5
AG
222 foreach ($students as $student) {
223 $params = array('userid'=>$student->id,
224 'feedback'=>$feedback->id,
225 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO);
226
227 $completed_count = $DB->count_records('feedback_completed', $params);
228 if ($completed_count > 0) {
df997f84 229
248bafd6 230 //userpicture and link to the profilepage
9c5bc7a5
AG
231 $fullname_url = $CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id;
232 $profilelink = '<strong><a href="'.$fullname_url.'">'.fullname($student).'</a></strong>';
248bafd6 233 $data = array ($OUTPUT->user_picture($student, array('courseid'=>$course->id)), $profilelink);
df997f84 234
248bafd6 235 //link to the entry of the user
9c5bc7a5
AG
236 $params = array('feedback'=>$feedback->id,
237 'userid'=>$student->id,
238 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO);
239
240 $feedbackcompleted = $DB->get_record('feedback_completed', $params);
241 $showentryurl_params = array('userid'=>$student->id, 'do_show'=>'showoneentry');
242 $showentryurl = new moodle_url($url, $showentryurl_params);
243 $showentrylink = '<a href="'.$showentryurl->out().'">'.userdate($feedbackcompleted->timemodified).'</a>';
248bafd6 244 $data[] = $showentrylink;
df997f84 245
248bafd6 246 //link to delete the entry
9c5bc7a5
AG
247 if (has_capability('mod/feedback:deletesubmissions', $context)) {
248 $delete_url_params = array('id' => $cm->id,
249 'completedid' => $feedbackcompleted->id,
250 'do_show' => 'showoneentry');
251
252 $deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', $delete_url_params);
253 $deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.
254 get_string('delete_entry', 'feedback').
255 '</a>';
248bafd6 256 $data[] = $deleteentrylink;
c70ad9f7 257 }
248bafd6 258 $table->add_data($data);
c70ad9f7 259 }
260 }
248bafd6 261 $table->print_html();
df997f84 262
248bafd6 263 $allurl = new moodle_url($baseurl);
df997f84 264
248bafd6
AG
265 if ($showall) {
266 $allurl->param('showall', 0);
9c5bc7a5
AG
267 echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
268 array(),
269 'showall');
270
248bafd6
AG
271 } else if ($matchcount > 0 && $perpage < $matchcount) {
272 $allurl->param('showall', 1);
9c5bc7a5
AG
273 echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)),
274 array(),
275 'showall');
248bafd6 276 }
c70ad9f7 277 }
9c5bc7a5 278 ?>
84973212 279 <hr />
280 <table width="100%">
281 <tr>
282 <td align="left" colspan="2">
9c5bc7a5
AG
283 <?php
284 $params = array('feedback' => $feedback->id,
285 'anonymous_response' => FEEDBACK_ANONYMOUS_YES);
286
287 $feedback_completeds_count = $DB->count_records('feedback_completed', $params);
288 print_string('anonymous_entries', 'feedback');
289 echo '&nbsp;('.$feedback_completeds_count.')';
290 ?>
84973212 291 </td>
292 <td align="right">
293 <?php
9c5bc7a5
AG
294 $url_params = array('sesskey'=>sesskey(),
295 'userid'=>0,
296 'do_show'=>'showoneentry',
297 'id'=>$id);
298 $aurl = new moodle_url('show_entries_anonym.php', $url_params);
5c2ed7e2 299 echo $OUTPUT->single_button($aurl, get_string('show_entries', 'feedback'));
84973212 300 ?>
301 </td>
302 </tr>
303 </table>
9c5bc7a5 304 <?php
31c0fa53 305 echo $OUTPUT->box_end();
84973212 306 echo $OUTPUT->box_end();
c70ad9f7 307 }
d4b1d58c 308
84973212 309}
310////////////////////////////////////////////////////////
311/// Print the responses of the given user
312////////////////////////////////////////////////////////
9c5bc7a5 313if ($do_show == 'showoneentry') {
84973212 314 echo $OUTPUT->heading(format_text($feedback->name));
315
316 //print the items
9c5bc7a5 317 if (is_array($feedbackitems)) {
31c0fa53 318 $align = right_to_left() ? 'right' : 'left';
74be01e5 319 $usr = $DB->get_record('user', array('id'=>$userid));
df997f84 320
9c5bc7a5
AG
321 if ($feedbackcompleted) {
322 echo $OUTPUT->heading(userdate($feedbackcompleted->timemodified).' ('.fullname($usr).')', 3);
84973212 323 } else {
9c5bc7a5 324 echo $OUTPUT->heading(get_string('not_completed_yet', 'feedback'), 3);
84973212 325 }
df997f84 326
31c0fa53 327 echo $OUTPUT->box_start('feedback_items');
84973212 328 $itemnr = 0;
9c5bc7a5 329 foreach ($feedbackitems as $feedbackitem) {
84973212 330 //get the values
9c5bc7a5
AG
331 $params = array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id);
332 $value = $DB->get_record('feedback_value', $params);
31c0fa53 333 echo $OUTPUT->box_start('feedback_item_box_'.$align);
9c5bc7a5 334 if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
84973212 335 $itemnr++;
31c0fa53
AG
336 echo $OUTPUT->box_start('feedback_item_number_'.$align);
337 echo $itemnr;
338 echo $OUTPUT->box_end();
c70ad9f7 339 }
d4b1d58c 340
9c5bc7a5 341 if ($feedbackitem->typ != 'pagebreak') {
31c0fa53 342 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
9c5bc7a5 343 if (isset($value->value)) {
9d5fbd65 344 feedback_print_item_show_value($feedbackitem, $value->value);
9c5bc7a5 345 } else {
9d5fbd65 346 feedback_print_item_show_value($feedbackitem, false);
c70ad9f7 347 }
31c0fa53 348 echo $OUTPUT->box_end();
c70ad9f7 349 }
31c0fa53 350 echo $OUTPUT->box_end();
c70ad9f7 351 }
84973212 352 echo $OUTPUT->box_end();
c70ad9f7 353 }
5dee2210 354 echo $OUTPUT->continue_button(new moodle_url($url, array('do_show'=>'showentries')));
84973212 355}
356/// Finish the page
357///////////////////////////////////////////////////////////////////////////
358///////////////////////////////////////////////////////////////////////////
359///////////////////////////////////////////////////////////////////////////
c70ad9f7 360
84973212 361echo $OUTPUT->footer();
c70ad9f7 362