Merge branch 'MDL-46239-28-2' of git://github.com/xow/moodle into MOODLE_28_STABLE
[moodle.git] / mod / feedback / show_entries_anonym.php
blobe9bcc04adc7c20447a6450673a712bc52605e47e
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 mod_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 $context = context_module::instance($cm->id);
57 require_login($course, true, $cm);
59 require_capability('mod/feedback:viewreports', $context);
61 /// Print the page header
62 $strfeedbacks = get_string("modulenameplural", "feedback");
63 $strfeedback = get_string("modulename", "feedback");
65 $PAGE->set_heading($course->fullname);
66 $PAGE->set_title($feedback->name);
67 echo $OUTPUT->header();
68 echo $OUTPUT->heading(format_string($feedback->name));
70 /// Print the main part of the page
71 ///////////////////////////////////////////////////////////////////////////
72 ///////////////////////////////////////////////////////////////////////////
73 ///////////////////////////////////////////////////////////////////////////
74 require('tabs.php');
76 //print the list with anonymous completeds
77 if (!$showcompleted) {
79 //get the completeds
80 // if a new anonymous record has not been assigned a random response number
81 $params = array('feedback'=>$feedback->id,
82 'random_response'=>0,
83 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
85 if ($feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'random_response')) {
86 //then get all of the anonymous records and go through them
87 $params = array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
88 $feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'id'); //arb
89 shuffle($feedbackcompleteds);
90 $num = 1;
91 foreach ($feedbackcompleteds as $compl) {
92 $compl->random_response = $num;
93 $DB->update_record('feedback_completed', $compl);
94 $num++;
98 $params = array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
99 $feedbackcompletedscount = $DB->count_records('feedback_completed', $params);
101 // preparing the table for output
102 $baseurl = new moodle_url('/mod/feedback/show_entries_anonym.php');
103 $baseurl->params(array('id'=>$id, 'do_show'=>$do_show, 'showall'=>$showall));
105 $tablecolumns = array('response', 'showresponse');
106 $tableheaders = array('', '');
108 if (has_capability('mod/feedback:deletesubmissions', $context)) {
109 $tablecolumns[] = 'deleteentry';
110 $tableheaders[] = '';
113 $table = new flexible_table('feedback-showentryanonym-list-'.$course->id);
115 $table->define_columns($tablecolumns);
116 $table->define_headers($tableheaders);
117 $table->define_baseurl($baseurl);
119 $table->sortable(false);
120 $table->set_attribute('cellspacing', '0');
121 $table->set_attribute('id', 'showentryanonymtable');
122 $table->set_attribute('class', 'generaltable generalbox');
123 $table->set_control_variables(array(
124 TABLE_VAR_SORT => 'ssort',
125 TABLE_VAR_IFIRST => 'sifirst',
126 TABLE_VAR_ILAST => 'silast',
127 TABLE_VAR_PAGE => 'spage'
129 $table->setup();
131 $matchcount = $feedbackcompletedscount;
132 $table->initialbars(true);
134 if ($showall) {
135 $startpage = false;
136 $pagecount = false;
137 } else {
138 $table->pagesize($perpage, $matchcount);
139 $startpage = $table->get_page_start();
140 $pagecount = $table->get_page_size();
144 $feedbackcompleteds = $DB->get_records('feedback_completed',
145 array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES),
146 'random_response',
147 'id,random_response',
148 $startpage,
149 $pagecount);
151 if (is_array($feedbackcompleteds)) {
152 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
153 echo $OUTPUT->heading(get_string('anonymous_entries', 'feedback'), 3);
154 foreach ($feedbackcompleteds as $compl) {
155 $data = array();
157 $data[] = get_string('response_nr', 'feedback').': '. $compl->random_response;
159 //link to the entry
160 $showentryurl = new moodle_url($baseurl, array('showcompleted'=>$compl->id));
161 $showentrylink = '<a href="'.$showentryurl->out().'">'.get_string('show_entry', 'feedback').'</a>';
162 $data[] = $showentrylink;
164 //link to delete the entry
165 if (has_capability('mod/feedback:deletesubmissions', $context)) {
166 $delet_url_params = array('id'=>$cm->id,
167 'completedid'=>$compl->id,
168 'do_show'=>'',
169 'return'=>'entriesanonym');
171 $deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', $delet_url_params);
172 $deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.get_string('delete_entry', 'feedback').'</a>';
173 $data[] = $deleteentrylink;
175 $table->add_data($data);
177 $table->print_html();
179 $allurl = new moodle_url($baseurl);
181 if ($showall) {
182 $allurl->param('showall', 0);
183 $str_showperpage = get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT);
184 echo $OUTPUT->container(html_writer::link($allurl, $str_showperpage), array(), 'showall');
185 } else if ($matchcount > 0 && $perpage < $matchcount) {
186 $allurl->param('showall', 1);
187 echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
189 echo $OUTPUT->box_end();
192 //print the items
193 if ($showcompleted) {
194 $continueurl = new moodle_url('/mod/feedback/show_entries_anonym.php',
195 array('id'=>$id, 'do_show'=>''));
197 echo $OUTPUT->continue_button($continueurl);
199 //get the feedbackitems
200 $params = array('feedback'=>$feedback->id);
201 $feedbackitems = $DB->get_records('feedback_item', $params, 'position');
202 $feedbackcompleted = $DB->get_record('feedback_completed', array('id'=>$showcompleted));
203 if (is_array($feedbackitems)) {
204 $align = right_to_left() ? 'right' : 'left';
206 if ($feedbackcompleted) {
207 echo $OUTPUT->box_start('feedback_info');
208 echo get_string('chosen_feedback_response', 'feedback');
209 echo $OUTPUT->box_end();
210 echo $OUTPUT->box_start('feedback_info');
211 echo get_string('response_nr', 'feedback').': ';
212 echo $feedbackcompleted->random_response.' ('.get_string('anonymous', 'feedback').')';
213 echo $OUTPUT->box_end();
214 } else {
215 echo $OUTPUT->box_start('feedback_info');
216 echo get_string('not_completed_yet', 'feedback');
217 echo $OUTPUT->box_end();
220 echo $OUTPUT->box_start('feedback_items');
221 $itemnr = 0;
222 foreach ($feedbackitems as $feedbackitem) {
223 //get the values
224 $params = array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id);
225 $value = $DB->get_record('feedback_value', $params);
226 echo $OUTPUT->box_start('feedback_item_box_'.$align);
227 if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
228 $itemnr++;
229 echo $OUTPUT->box_start('feedback_item_number_'.$align);
230 echo $itemnr;
231 echo $OUTPUT->box_end();
233 if ($feedbackitem->typ != 'pagebreak') {
234 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
235 $itemvalue = isset($value->value) ? $value->value : false;
236 feedback_print_item_show_value($feedbackitem, $itemvalue);
237 echo $OUTPUT->box_end();
239 echo $OUTPUT->box_end();
241 echo $OUTPUT->box_end();
244 /// Finish the page
245 ///////////////////////////////////////////////////////////////////////////
246 ///////////////////////////////////////////////////////////////////////////
247 ///////////////////////////////////////////////////////////////////////////
249 echo $OUTPUT->footer();