MDL-29190 - XHTML not well formed in show_nonrespondents.php
[moodle.git] / mod / feedback / show_entries_anonym.php
1 <?php
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  */
11 require_once("../../config.php");
12 require_once("lib.php");
13 require_once($CFG->libdir.'/tablelib.php');
15 // $SESSION->feedback->current_tab = 'showoneentry';
17 $id = required_param('id', PARAM_INT);
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
24 $current_tab = $do_show;
26 $url = new moodle_url('/mod/feedback/show_entries_anonym.php', array('id'=>$id));
27 // if ($userid !== '') {
28     // $url->param('userid', $userid);
29 // }
30 $PAGE->set_url($url);
32 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
33     print_error('invalidcoursemodule');
34 }
36 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
37     print_error('coursemisconf');
38 }
40 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
41     print_error('invalidcoursemodule');
42 }
44 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
45         print_error('badcontext');
46 }
48 require_login($course->id, true, $cm);
50 require_capability('mod/feedback:viewreports', $context);
52 /// Print the page header
53 $strfeedbacks = get_string("modulenameplural", "feedback");
54 $strfeedback  = get_string("modulename", "feedback");
56 $PAGE->set_heading(format_string($course->fullname));
57 $PAGE->set_title(format_string($feedback->name));
58 echo $OUTPUT->header();
60 /// Print the main part of the page
61 ///////////////////////////////////////////////////////////////////////////
62 ///////////////////////////////////////////////////////////////////////////
63 ///////////////////////////////////////////////////////////////////////////
64 include('tabs.php');
66 echo $OUTPUT->heading(format_text($feedback->name));
68 //print the list with anonymous completeds
69 if(!$showcompleted) {
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));
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));
91     $tablecolumns = array('response', 'showresponse');
92     $tableheaders = array('', '');
93     
94     if(has_capability('mod/feedback:deletesubmissions', $context)) {
95         $tablecolumns[] = 'deleteentry';
96         $tableheaders[] = '';
97     }
99     $table = new flexible_table('feedback-showentryanonym-list-'.$course->id);
101     $table->define_columns($tablecolumns);
102     $table->define_headers($tableheaders);
103     $table->define_baseurl($baseurl);
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();
117     $matchcount = $feedbackcompletedscount;
118     $table->initialbars(true);
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     }
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);
137     if(is_array($feedbackcompleteds)) {
138         echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
139         echo $OUTPUT->heading(get_string('anonymous_entries', 'feedback'), 3);
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     }
172 //print the items
173 // if(isset($formdata->showanonym) && $formdata->showanonym == FEEDBACK_ANONYMOUS_YES) {
174 if($showcompleted) {
175     $continueurl = new moodle_url('/mod/feedback/show_entries_anonym.php', array('id'=>$id, 'do_show'=>''));
176     echo $OUTPUT->continue_button($continueurl);
177     
178     //get the feedbackitems
179     $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
180     $feedbackcompleted = $DB->get_record('feedback_completed', array('id'=>$showcompleted));
181     if(is_array($feedbackitems)){
182         $align = right_to_left() ? 'right' : 'left';
183         
184         if($feedbackcompleted) {
185             echo $OUTPUT->box_start('feedback_info');
186             echo get_string('chosen_feedback_response', 'feedback');
187             echo $OUTPUT->box_end();
188             echo $OUTPUT->box_start('feedback_info');
189             echo get_string('response_nr', 'feedback').': '. $feedbackcompleted->random_response.' ('.get_string('anonymous', 'feedback').')';
190             echo $OUTPUT->box_end();
191         } else {
192             echo $OUTPUT->box_start('feedback_info');
193             echo get_string('not_completed_yet','feedback');
194             echo $OUTPUT->box_end();
195         }
196             
197         echo $OUTPUT->box_start('feedback_items');
198         // echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
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));
203             echo $OUTPUT->box_start('feedback_item_box_'.$align);
204             if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
205                 $itemnr++;
206                 echo $OUTPUT->box_start('feedback_item_number_'.$align);
207                 echo $itemnr;
208                 echo $OUTPUT->box_end();
209             }
210             if($feedbackitem->typ != 'pagebreak') {
211                 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
212                 $itemvalue = isset($value->value) ? $value->value : false;
213                 feedback_print_item_show_value($feedbackitem, $itemvalue);
214                 echo $OUTPUT->box_end();
215             }
216             echo $OUTPUT->box_end();
217         }
218         // echo $OUTPUT->box_end();
219         echo $OUTPUT->box_end();
220     }
222 /// Finish the page
223 ///////////////////////////////////////////////////////////////////////////
224 ///////////////////////////////////////////////////////////////////////////
225 ///////////////////////////////////////////////////////////////////////////
227 echo $OUTPUT->footer();