MDL-29190 - XHTML not well formed in show_nonrespondents.php
[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");
248bafd6 13require_once($CFG->libdir.'/tablelib.php');
d4b1d58c 14
84973212 15////////////////////////////////////////////////////////
16//get the params
17////////////////////////////////////////////////////////
18$id = required_param('id', PARAM_INT);
19$userid = optional_param('userid', false, PARAM_INT);
20$do_show = required_param('do_show', PARAM_ALPHA);
248bafd6
AG
21$perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT); // how many per page
22$showall = optional_param('showall', false, PARAM_INT); // should we show all users
84973212 23// $SESSION->feedback->current_tab = $do_show;
24$current_tab = $do_show;
c70ad9f7 25
84973212 26////////////////////////////////////////////////////////
27//get the objects
28////////////////////////////////////////////////////////
d4b1d58c 29
84973212 30if($userid) {
31 $formdata->userid = intval($userid);
32}
c70ad9f7 33
5dee2210
AG
34if (! $cm = get_coursemodule_from_id('feedback', $id)) {
35 print_error('invalidcoursemodule');
36}
d4b1d58c 37
5dee2210
AG
38if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
39 print_error('coursemisconf');
40}
d4b1d58c 41
5dee2210
AG
42if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
43 print_error('invalidcoursemodule');
84973212 44}
d4b1d58c 45
5dee2210
AG
46$url = new moodle_url('/mod/feedback/show_entries.php', array('id'=>$cm->id, 'do_show'=>$do_show));
47
48$PAGE->set_url($url);
ab5bd34d 49
c987dbad
AG
50if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
51 print_error('badcontext');
52}
c70ad9f7 53
84973212 54require_login($course->id, true, $cm);
d4b1d58c 55
84973212 56if(($formdata = data_submitted()) AND !confirm_sesskey()) {
57 print_error('invalidsesskey');
58}
d4b1d58c 59
53ba55ec 60require_capability('mod/feedback:viewreports', $context);
c70ad9f7 61
84973212 62////////////////////////////////////////////////////////
63//get the responses of given user
64////////////////////////////////////////////////////////
65if($do_show == 'showoneentry') {
66 //get the feedbackitems
67 $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
74be01e5 68 $feedbackcompleted = $DB->get_record('feedback_completed', array('feedback'=>$feedback->id, 'userid'=>$userid, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO)); //arb
84973212 69}
d4b1d58c 70
84973212 71/// Print the page header
72$strfeedbacks = get_string("modulenameplural", "feedback");
73$strfeedback = get_string("modulename", "feedback");
d4b1d58c 74
9d092aa9 75$PAGE->set_heading(format_string($course->fullname));
84973212 76$PAGE->set_title(format_string($feedback->name));
84973212 77echo $OUTPUT->header();
d4b1d58c 78
84973212 79include('tabs.php');
c70ad9f7 80
84973212 81/// Print the main part of the page
82///////////////////////////////////////////////////////////////////////////
83///////////////////////////////////////////////////////////////////////////
84///////////////////////////////////////////////////////////////////////////
c70ad9f7 85
84973212 86////////////////////////////////////////////////////////
87/// Print the links to get responses and analysis
88////////////////////////////////////////////////////////
89if($do_show == 'showentries'){
90 //print the link to analysis
c987dbad 91 if(has_capability('mod/feedback:viewreports', $context)) {
84973212 92 //get the effective groupmode of this course and module
93 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
94 $groupmode = $cm->groupmode;
95 } else {
96 $groupmode = $course->groupmode;
97 }
df997f84 98
5dee2210
AG
99 // $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/show_entries.php?id=' . $cm->id.'&do_show=showentries', true);
100 $groupselect = groups_print_activity_menu($cm, $url->out(), true);
84973212 101 $mygroupid = groups_get_activity_group($cm);
d4b1d58c 102
248bafd6
AG
103 // preparing the table for output
104 $baseurl = new moodle_url('/mod/feedback/show_entries.php');
105 $baseurl->params(array('id'=>$id, 'do_show'=>$do_show, 'showall'=>$showall));
df997f84 106
7cc5cec6 107 $tablecolumns = array('userpic', 'fullname', 'c.timemodified');
8a23b38c 108 $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('date'));
df997f84 109
248bafd6
AG
110 if(has_capability('mod/feedback:deletesubmissions', $context)) {
111 $tablecolumns[] = 'deleteentry';
112 $tableheaders[] = '';
113 }
df997f84 114
248bafd6
AG
115 $table = new flexible_table('feedback-showentry-list-'.$course->id);
116
117 $table->define_columns($tablecolumns);
118 $table->define_headers($tableheaders);
119 $table->define_baseurl($baseurl);
120
121 $table->sortable(true, 'lastname', SORT_DESC);
122 $table->set_attribute('cellspacing', '0');
123 $table->set_attribute('id', 'showentrytable');
124 $table->set_attribute('class', 'generaltable generalbox');
125 $table->set_control_variables(array(
126 TABLE_VAR_SORT => 'ssort',
127 TABLE_VAR_IFIRST => 'sifirst',
128 TABLE_VAR_ILAST => 'silast',
129 TABLE_VAR_PAGE => 'spage'
130 ));
131 $table->setup();
132
133 if($table->get_sql_sort()) {
134 $sort = $table->get_sql_sort();
135 }else {
136 $sort = '';
137 }
138
0f21a964
PS
139 list($where, $params) = $table->get_sql_where();
140 if ($where) {
248bafd6 141 $where .= ' AND';
248bafd6
AG
142 }
143
84973212 144 //get students in conjunction with groupmode
145 if($groupmode > 0) {
84973212 146 if($mygroupid > 0) {
248bafd6 147 $usedgroupid = $mygroupid;
84973212 148 } else {
248bafd6 149 $usedgroupid = false;
c70ad9f7 150 }
84973212 151 }else {
248bafd6
AG
152 $usedgroupid = false;
153 }
df997f84 154
248bafd6
AG
155 $matchcount = feedback_count_complete_users($cm, $usedgroupid);
156 $table->initialbars(true);
df997f84 157
248bafd6
AG
158 if($showall) {
159 $startpage = false;
160 $pagecount = false;
161 }else {
162 $table->pagesize($perpage, $matchcount);
163 $startpage = $table->get_page_start();
164 $pagecount = $table->get_page_size();
84973212 165 }
df997f84 166
0f21a964 167 $students = feedback_get_complete_users($cm, $usedgroupid, $where, $params, $sort, $startpage, $pagecount);
c70ad9f7 168
84973212 169 $completedFeedbackCount = feedback_get_completeds_group_count($feedback, $mygroupid);
170 if($feedback->course == SITEID){
5dee2210 171 $analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id, 'courseid'=>$courseid));
31c0fa53
AG
172 echo $OUTPUT->box_start('mdl-align');
173 echo '<a href="'.$analysisurl->out().'">'.get_string('course').' '.get_string('analysis', 'feedback').' ('.get_string('completed_feedbacks', 'feedback').': '.intval($completedFeedbackCount).')</a>';
e8790d59 174 echo $OUTPUT->help_icon('viewcompleted', 'feedback');
31c0fa53 175 echo $OUTPUT->box_end();
84973212 176 }else {
5dee2210 177 $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
31c0fa53
AG
178 echo $OUTPUT->box_start('mdl-align');
179 echo '<a href="'.$analysisurl->out().'">'.get_string('analysis', 'feedback').' ('.get_string('completed_feedbacks', 'feedback').': '.intval($completedFeedbackCount).')</a>';
180 echo $OUTPUT->box_end();
c70ad9f7 181 }
84973212 182 }
d4b1d58c 183
84973212 184 //####### viewreports-start
c987dbad 185 if(has_capability('mod/feedback:viewreports', $context)) {
84973212 186 //print the list of students
187 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
188 echo isset($groupselect) ? $groupselect : '';
189 echo '<div class="clearer"></div>';
31c0fa53 190 echo $OUTPUT->box_start('mdl-align');
248bafd6 191 // echo '<table><tr><td width="400">';
84973212 192 if (!$students) {
193 if($courseid != SITEID){
df997f84 194 echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
84973212 195 }
196 } else{
197 echo print_string('non_anonymous_entries', 'feedback');
198 echo ' ('.count($students).')<hr />';
c70ad9f7 199
84973212 200 foreach ($students as $student){
201 $completedCount = $DB->count_records('feedback_completed', array('userid'=>$student->id, 'feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO));
202 if($completedCount > 0) {
df997f84 203
248bafd6
AG
204 //userpicture and link to the profilepage
205 $profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id.'">'.fullname($student).'</a></strong>';
206 $data = array ($OUTPUT->user_picture($student, array('courseid'=>$course->id)), $profilelink);
df997f84 207
248bafd6 208 //link to the entry of the user
794cc28d 209 $feedbackcompleted = $DB->get_record('feedback_completed', array('feedback'=>$feedback->id, 'userid'=>$student->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO));
248bafd6
AG
210 $showentryurl = new moodle_url($url, array('userid'=>$student->id, 'do_show'=>'showoneentry'));
211 $showentrylink = '<a href="'.$showentryurl->out().'">'.UserDate($feedbackcompleted->timemodified).'</a>';
212 $data[] = $showentrylink;
df997f84 213
248bafd6 214 //link to delete the entry
c987dbad 215 if(has_capability('mod/feedback:deletesubmissions', $context)) {
248bafd6
AG
216 $deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', array('id'=>$cm->id, 'completedid'=>$feedbackcompleted->id, 'do_show'=>'showoneentry'));
217 $deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.get_string('delete_entry', 'feedback').'</a>';
218 $data[] = $deleteentrylink;
c70ad9f7 219 }
248bafd6 220 $table->add_data($data);
c70ad9f7 221 }
222 }
248bafd6 223 $table->print_html();
df997f84 224
248bafd6 225 $allurl = new moodle_url($baseurl);
df997f84 226
248bafd6
AG
227 if ($showall) {
228 $allurl->param('showall', 0);
229 echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)), array(), 'showall');
230 } else if ($matchcount > 0 && $perpage < $matchcount) {
231 $allurl->param('showall', 1);
232 echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
233 }
c70ad9f7 234 }
84973212 235?>
236 <hr />
237 <table width="100%">
238 <tr>
239 <td align="left" colspan="2">
240 <?php print_string('anonymous_entries', 'feedback');?>&nbsp;(<?php echo $DB->count_records('feedback_completed', array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES));?>)
241 </td>
242 <td align="right">
243 <?php
5c2ed7e2
PS
244 $aurl = new moodle_url('show_entries_anonym.php', array('sesskey'=>sesskey(), 'userid'=>0, 'do_show'=>'showoneentry', 'id'=>$id));
245 echo $OUTPUT->single_button($aurl, get_string('show_entries', 'feedback'));
84973212 246 ?>
247 </td>
248 </tr>
249 </table>
250<?php
31c0fa53 251 echo $OUTPUT->box_end();
84973212 252 echo $OUTPUT->box_end();
c70ad9f7 253 }
d4b1d58c 254
84973212 255}
256////////////////////////////////////////////////////////
257/// Print the responses of the given user
258////////////////////////////////////////////////////////
259if($do_show == 'showoneentry') {
260 echo $OUTPUT->heading(format_text($feedback->name));
261
262 //print the items
263 if(is_array($feedbackitems)){
31c0fa53 264 $align = right_to_left() ? 'right' : 'left';
74be01e5 265 $usr = $DB->get_record('user', array('id'=>$userid));
df997f84 266
84973212 267 if($feedbackcompleted) {
028e1e4f 268 echo $OUTPUT->heading(UserDate($feedbackcompleted->timemodified).' ('.fullname($usr).')', 3);
84973212 269 } else {
028e1e4f 270 echo $OUTPUT->heading(get_string('not_completed_yet','feedback'), 3);
84973212 271 }
df997f84 272
31c0fa53 273 echo $OUTPUT->box_start('feedback_items');
84973212 274 $itemnr = 0;
275 foreach($feedbackitems as $feedbackitem){
276 //get the values
277 $value = $DB->get_record('feedback_value', array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id));
31c0fa53 278 echo $OUTPUT->box_start('feedback_item_box_'.$align);
84973212 279 if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
280 $itemnr++;
31c0fa53
AG
281 echo $OUTPUT->box_start('feedback_item_number_'.$align);
282 echo $itemnr;
283 echo $OUTPUT->box_end();
c70ad9f7 284 }
d4b1d58c 285
84973212 286 if($feedbackitem->typ != 'pagebreak') {
31c0fa53 287 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
84973212 288 if(isset($value->value)) {
9d5fbd65 289 feedback_print_item_show_value($feedbackitem, $value->value);
c70ad9f7 290 }else {
9d5fbd65 291 feedback_print_item_show_value($feedbackitem, false);
c70ad9f7 292 }
31c0fa53 293 echo $OUTPUT->box_end();
c70ad9f7 294 }
31c0fa53 295 echo $OUTPUT->box_end();
c70ad9f7 296 }
84973212 297 echo $OUTPUT->box_end();
c70ad9f7 298 }
5dee2210 299 echo $OUTPUT->continue_button(new moodle_url($url, array('do_show'=>'showentries')));
84973212 300}
301/// Finish the page
302///////////////////////////////////////////////////////////////////////////
303///////////////////////////////////////////////////////////////////////////
304///////////////////////////////////////////////////////////////////////////
c70ad9f7 305
84973212 306echo $OUTPUT->footer();
c70ad9f7 307