MDL-29190 - XHTML not well formed in show_nonrespondents.php
[moodle.git] / mod / feedback / show_entries_anonym.php
CommitLineData
84973212 1<?php
d4b1d58c 2
84973212 3/**
4 * print the single-values of anonymous completeds
5 *
6 * @author Andreas Grabs
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package feedback
9 */
10
11require_once("../../config.php");
12require_once("lib.php");
8a23b38c 13require_once($CFG->libdir.'/tablelib.php');
84973212 14
15// $SESSION->feedback->current_tab = 'showoneentry';
84973212 16
17$id = required_param('id', PARAM_INT);
8a23b38c
AG
18// $userid = optional_param('userid', false, PARAM_INT);
19$showcompleted = optional_param('showcompleted', false, PARAM_INT);
20$do_show = optional_param('do_show', false, PARAM_ALPHA);
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
23
24$current_tab = $do_show;
84973212 25
a6855934 26$url = new moodle_url('/mod/feedback/show_entries_anonym.php', array('id'=>$id));
8a23b38c
AG
27// if ($userid !== '') {
28 // $url->param('userid', $userid);
29// }
84973212 30$PAGE->set_url($url);
31
b6f26001
AG
32if (! $cm = get_coursemodule_from_id('feedback', $id)) {
33 print_error('invalidcoursemodule');
34}
35
36if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
37 print_error('coursemisconf');
38}
39
40if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
41 print_error('invalidcoursemodule');
84973212 42}
c987dbad
AG
43
44if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
45 print_error('badcontext');
46}
84973212 47
48require_login($course->id, true, $cm);
49
53ba55ec 50require_capability('mod/feedback:viewreports', $context);
84973212 51
84973212 52/// Print the page header
53$strfeedbacks = get_string("modulenameplural", "feedback");
54$strfeedback = get_string("modulename", "feedback");
d4b1d58c 55
9d092aa9 56$PAGE->set_heading(format_string($course->fullname));
84973212 57$PAGE->set_title(format_string($feedback->name));
84973212 58echo $OUTPUT->header();
c70ad9f7 59
84973212 60/// Print the main part of the page
61///////////////////////////////////////////////////////////////////////////
62///////////////////////////////////////////////////////////////////////////
63///////////////////////////////////////////////////////////////////////////
64include('tabs.php');
d4b1d58c 65
84973212 66echo $OUTPUT->heading(format_text($feedback->name));
d4b1d58c 67
84973212 68//print the list with anonymous completeds
8a23b38c
AG
69if(!$showcompleted) {
70
71 //get the completeds
72 // if a new anonymous record has not been assigned a random response number
73 if ($feedbackcompleteds = $DB->get_records('feedback_completed', array('feedback'=>$feedback->id, 'random_response'=>0, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES), 'random_response')){ //arb
74 //then get all of the anonymous records and go through them
75 $feedbackcompleteds = $DB->get_records('feedback_completed', array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES), 'id'); //arb
76 shuffle($feedbackcompleteds);
77 $num = 1;
78 foreach($feedbackcompleteds as $compl){
79 $compl->random_response = $num;
80 $DB->update_record('feedback_completed', $compl);
81 $num++;
82 }
83 }
84
85 $feedbackcompletedscount = $DB->count_records('feedback_completed', array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES));
86
87 // preparing the table for output
88 $baseurl = new moodle_url('/mod/feedback/show_entries_anonym.php');
89 $baseurl->params(array('id'=>$id, 'do_show'=>$do_show, 'showall'=>$showall));
90
91 $tablecolumns = array('response', 'showresponse');
92 $tableheaders = array('', '');
93
94 if(has_capability('mod/feedback:deletesubmissions', $context)) {
95 $tablecolumns[] = 'deleteentry';
96 $tableheaders[] = '';
97 }
98
99 $table = new flexible_table('feedback-showentryanonym-list-'.$course->id);
100
101 $table->define_columns($tablecolumns);
102 $table->define_headers($tableheaders);
103 $table->define_baseurl($baseurl);
104
105 $table->sortable(false);
106 $table->set_attribute('cellspacing', '0');
107 $table->set_attribute('id', 'showentryanonymtable');
108 $table->set_attribute('class', 'generaltable generalbox');
109 $table->set_control_variables(array(
110 TABLE_VAR_SORT => 'ssort',
111 TABLE_VAR_IFIRST => 'sifirst',
112 TABLE_VAR_ILAST => 'silast',
113 TABLE_VAR_PAGE => 'spage'
114 ));
115 $table->setup();
116
117 $matchcount = $feedbackcompletedscount;
118 $table->initialbars(true);
119
120 if($showall) {
121 $startpage = false;
122 $pagecount = false;
123 }else {
124 $table->pagesize($perpage, $matchcount);
125 $startpage = $table->get_page_start();
126 $pagecount = $table->get_page_size();
127 }
128
129
130 $feedbackcompleteds = $DB->get_records('feedback_completed',
131 array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES),
132 'random_response',
133 'id,random_response',
134 $startpage,
135 $pagecount);
136
137 if(is_array($feedbackcompleteds)) {
138 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
028e1e4f 139 echo $OUTPUT->heading(get_string('anonymous_entries', 'feedback'), 3);
8a23b38c
AG
140 foreach($feedbackcompleteds as $compl) {
141 $data = array();
142
143 $data[] = get_string('response_nr', 'feedback').': '. $compl->random_response;
144
145 //link to the entry
146 $showentryurl = new moodle_url($baseurl, array('showcompleted'=>$compl->id));
147 $showentrylink = '<a href="'.$showentryurl->out().'">'.get_string('show_entry', 'feedback').'</a>';
148 $data[] = $showentrylink;
149
150 //link to delete the entry
151 if(has_capability('mod/feedback:deletesubmissions', $context)) {
152 $deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', array('id'=>$cm->id, 'completedid'=>$compl->id, 'do_show'=>'', 'return'=>'entriesanonym'));
153 $deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.get_string('delete_entry', 'feedback').'</a>';
154 $data[] = $deleteentrylink;
155 }
156 $table->add_data($data);
157 }
158 $table->print_html();
159
160 $allurl = new moodle_url($baseurl);
161
162 if ($showall) {
163 $allurl->param('showall', 0);
164 echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)), array(), 'showall');
165 } else if ($matchcount > 0 && $perpage < $matchcount) {
166 $allurl->param('showall', 1);
167 echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
168 }
169 echo $OUTPUT->box_end();
170 }
84973212 171}
172//print the items
8a23b38c
AG
173// if(isset($formdata->showanonym) && $formdata->showanonym == FEEDBACK_ANONYMOUS_YES) {
174if($showcompleted) {
175 $continueurl = new moodle_url('/mod/feedback/show_entries_anonym.php', array('id'=>$id, 'do_show'=>''));
176 echo $OUTPUT->continue_button($continueurl);
177
84973212 178 //get the feedbackitems
179 $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
8a23b38c 180 $feedbackcompleted = $DB->get_record('feedback_completed', array('id'=>$showcompleted));
84973212 181 if(is_array($feedbackitems)){
afdb1920
AG
182 $align = right_to_left() ? 'right' : 'left';
183
84973212 184 if($feedbackcompleted) {
31c0fa53 185 echo $OUTPUT->box_start('feedback_info');
afdb1920 186 echo get_string('chosen_feedback_response', 'feedback');
31c0fa53
AG
187 echo $OUTPUT->box_end();
188 echo $OUTPUT->box_start('feedback_info');
8a23b38c 189 echo get_string('response_nr', 'feedback').': '. $feedbackcompleted->random_response.' ('.get_string('anonymous', 'feedback').')';
31c0fa53 190 echo $OUTPUT->box_end();
84973212 191 } else {
31c0fa53 192 echo $OUTPUT->box_start('feedback_info');
afdb1920 193 echo get_string('not_completed_yet','feedback');
31c0fa53 194 echo $OUTPUT->box_end();
84973212 195 }
afdb1920 196
31c0fa53 197 echo $OUTPUT->box_start('feedback_items');
afdb1920 198 // echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
84973212 199 $itemnr = 0;
200 foreach($feedbackitems as $feedbackitem){
201 //get the values
202 $value = $DB->get_record('feedback_value', array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id));
31c0fa53 203 echo $OUTPUT->box_start('feedback_item_box_'.$align);
84973212 204 if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
205 $itemnr++;
31c0fa53
AG
206 echo $OUTPUT->box_start('feedback_item_number_'.$align);
207 echo $itemnr;
208 echo $OUTPUT->box_end();
c70ad9f7 209 }
84973212 210 if($feedbackitem->typ != 'pagebreak') {
31c0fa53 211 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
84973212 212 $itemvalue = isset($value->value) ? $value->value : false;
9d5fbd65 213 feedback_print_item_show_value($feedbackitem, $itemvalue);
31c0fa53 214 echo $OUTPUT->box_end();
c70ad9f7 215 }
31c0fa53 216 echo $OUTPUT->box_end();
c70ad9f7 217 }
afdb1920 218 // echo $OUTPUT->box_end();
31c0fa53 219 echo $OUTPUT->box_end();
c70ad9f7 220 }
84973212 221}
222/// Finish the page
223///////////////////////////////////////////////////////////////////////////
224///////////////////////////////////////////////////////////////////////////
225///////////////////////////////////////////////////////////////////////////
c70ad9f7 226
84973212 227echo $OUTPUT->footer();
c70ad9f7 228