Merge branch 'MDL-31510_group_activities' of git://github.com/andyjdavis/moodle
[moodle.git] / mod / feedback / show_entries_anonym.php
blob1a76475b59ba990cd0d276b187c5e72e168d6b8f
1 <?php
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.
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/>.
17 /**
18 * print the single-values of anonymous completeds
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package feedback
25 require_once("../../config.php");
26 require_once("lib.php");
27 require_once($CFG->libdir.'/tablelib.php');
29 $id = required_param('id', PARAM_INT);
30 $showcompleted = optional_param('showcompleted', false, PARAM_INT);
31 $do_show = optional_param('do_show', false, PARAM_ALPHA);
32 $perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT); // how many per page
33 $showall = optional_param('showall', false, PARAM_INT); // should we show all users
35 $current_tab = $do_show;
37 $url = new moodle_url('/mod/feedback/show_entries_anonym.php', array('id'=>$id));
38 // if ($userid !== '') {
39 // $url->param('userid', $userid);
40 // }
41 $PAGE->set_url($url);
43 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
44 print_error('invalidcoursemodule');
47 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
48 print_error('coursemisconf');
51 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
52 print_error('invalidcoursemodule');
55 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
56 print_error('badcontext');
59 require_login($course, true, $cm);
61 require_capability('mod/feedback:viewreports', $context);
63 /// Print the page header
64 $strfeedbacks = get_string("modulenameplural", "feedback");
65 $strfeedback = get_string("modulename", "feedback");
67 $PAGE->set_heading(format_string($course->fullname));
68 $PAGE->set_title(format_string($feedback->name));
69 echo $OUTPUT->header();
71 /// Print the main part of the page
72 ///////////////////////////////////////////////////////////////////////////
73 ///////////////////////////////////////////////////////////////////////////
74 ///////////////////////////////////////////////////////////////////////////
75 require('tabs.php');
77 echo $OUTPUT->heading(format_text($feedback->name));
79 //print the list with anonymous completeds
80 if (!$showcompleted) {
82 //get the completeds
83 // if a new anonymous record has not been assigned a random response number
84 $params = array('feedback'=>$feedback->id,
85 'random_response'=>0,
86 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
88 if ($feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'random_response')) {
89 //then get all of the anonymous records and go through them
90 $params = array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
91 $feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'id'); //arb
92 shuffle($feedbackcompleteds);
93 $num = 1;
94 foreach ($feedbackcompleteds as $compl) {
95 $compl->random_response = $num;
96 $DB->update_record('feedback_completed', $compl);
97 $num++;
101 $params = array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
102 $feedbackcompletedscount = $DB->count_records('feedback_completed', $params);
104 // preparing the table for output
105 $baseurl = new moodle_url('/mod/feedback/show_entries_anonym.php');
106 $baseurl->params(array('id'=>$id, 'do_show'=>$do_show, 'showall'=>$showall));
108 $tablecolumns = array('response', 'showresponse');
109 $tableheaders = array('', '');
111 if (has_capability('mod/feedback:deletesubmissions', $context)) {
112 $tablecolumns[] = 'deleteentry';
113 $tableheaders[] = '';
116 $table = new flexible_table('feedback-showentryanonym-list-'.$course->id);
118 $table->define_columns($tablecolumns);
119 $table->define_headers($tableheaders);
120 $table->define_baseurl($baseurl);
122 $table->sortable(false);
123 $table->set_attribute('cellspacing', '0');
124 $table->set_attribute('id', 'showentryanonymtable');
125 $table->set_attribute('class', 'generaltable generalbox');
126 $table->set_control_variables(array(
127 TABLE_VAR_SORT => 'ssort',
128 TABLE_VAR_IFIRST => 'sifirst',
129 TABLE_VAR_ILAST => 'silast',
130 TABLE_VAR_PAGE => 'spage'
132 $table->setup();
134 $matchcount = $feedbackcompletedscount;
135 $table->initialbars(true);
137 if ($showall) {
138 $startpage = false;
139 $pagecount = false;
140 } else {
141 $table->pagesize($perpage, $matchcount);
142 $startpage = $table->get_page_start();
143 $pagecount = $table->get_page_size();
147 $feedbackcompleteds = $DB->get_records('feedback_completed',
148 array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES),
149 'random_response',
150 'id,random_response',
151 $startpage,
152 $pagecount);
154 if (is_array($feedbackcompleteds)) {
155 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
156 echo $OUTPUT->heading(get_string('anonymous_entries', 'feedback'), 3);
157 foreach ($feedbackcompleteds as $compl) {
158 $data = array();
160 $data[] = get_string('response_nr', 'feedback').': '. $compl->random_response;
162 //link to the entry
163 $showentryurl = new moodle_url($baseurl, array('showcompleted'=>$compl->id));
164 $showentrylink = '<a href="'.$showentryurl->out().'">'.get_string('show_entry', 'feedback').'</a>';
165 $data[] = $showentrylink;
167 //link to delete the entry
168 if (has_capability('mod/feedback:deletesubmissions', $context)) {
169 $delet_url_params = array('id'=>$cm->id,
170 'completedid'=>$compl->id,
171 'do_show'=>'',
172 'return'=>'entriesanonym');
174 $deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', $delet_url_params);
175 $deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.get_string('delete_entry', 'feedback').'</a>';
176 $data[] = $deleteentrylink;
178 $table->add_data($data);
180 $table->print_html();
182 $allurl = new moodle_url($baseurl);
184 if ($showall) {
185 $allurl->param('showall', 0);
186 $str_showperpage = get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT);
187 echo $OUTPUT->container(html_writer::link($allurl, $str_showperpage), array(), 'showall');
188 } else if ($matchcount > 0 && $perpage < $matchcount) {
189 $allurl->param('showall', 1);
190 echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
192 echo $OUTPUT->box_end();
195 //print the items
196 if ($showcompleted) {
197 $continueurl = new moodle_url('/mod/feedback/show_entries_anonym.php',
198 array('id'=>$id, 'do_show'=>''));
200 echo $OUTPUT->continue_button($continueurl);
202 //get the feedbackitems
203 $params = array('feedback'=>$feedback->id);
204 $feedbackitems = $DB->get_records('feedback_item', $params, 'position');
205 $feedbackcompleted = $DB->get_record('feedback_completed', array('id'=>$showcompleted));
206 if (is_array($feedbackitems)) {
207 $align = right_to_left() ? 'right' : 'left';
209 if ($feedbackcompleted) {
210 echo $OUTPUT->box_start('feedback_info');
211 echo get_string('chosen_feedback_response', 'feedback');
212 echo $OUTPUT->box_end();
213 echo $OUTPUT->box_start('feedback_info');
214 echo get_string('response_nr', 'feedback').': ';
215 echo $feedbackcompleted->random_response.' ('.get_string('anonymous', 'feedback').')';
216 echo $OUTPUT->box_end();
217 } else {
218 echo $OUTPUT->box_start('feedback_info');
219 echo get_string('not_completed_yet', 'feedback');
220 echo $OUTPUT->box_end();
223 echo $OUTPUT->box_start('feedback_items');
224 $itemnr = 0;
225 foreach ($feedbackitems as $feedbackitem) {
226 //get the values
227 $params = array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id);
228 $value = $DB->get_record('feedback_value', $params);
229 echo $OUTPUT->box_start('feedback_item_box_'.$align);
230 if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
231 $itemnr++;
232 echo $OUTPUT->box_start('feedback_item_number_'.$align);
233 echo $itemnr;
234 echo $OUTPUT->box_end();
236 if ($feedbackitem->typ != 'pagebreak') {
237 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
238 $itemvalue = isset($value->value) ? $value->value : false;
239 feedback_print_item_show_value($feedbackitem, $itemvalue);
240 echo $OUTPUT->box_end();
242 echo $OUTPUT->box_end();
244 echo $OUTPUT->box_end();
247 /// Finish the page
248 ///////////////////////////////////////////////////////////////////////////
249 ///////////////////////////////////////////////////////////////////////////
250 ///////////////////////////////////////////////////////////////////////////
252 echo $OUTPUT->footer();