ee3cf926a735b9d588f24515ef10fb157858987a
[moodle.git] / mod / feedback / show_entries.php
1 <?php
3 /**
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  */
11 require_once("../../config.php");
12 require_once("lib.php");
14 ////////////////////////////////////////////////////////
15 //get the params
16 ////////////////////////////////////////////////////////
17 $id = required_param('id', PARAM_INT);
18 $userid = optional_param('userid', false, PARAM_INT);
19 $do_show = required_param('do_show', PARAM_ALPHA);
20 // $SESSION->feedback->current_tab = $do_show;
21 $current_tab = $do_show;
23 ////////////////////////////////////////////////////////
24 //get the objects
25 ////////////////////////////////////////////////////////
27 if($userid) {
28     $formdata->userid = intval($userid);
29 }
31 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
32     print_error('invalidcoursemodule');
33 }
35 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
36     print_error('coursemisconf');
37 }
39 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
40     print_error('invalidcoursemodule');
41 }
43 $url = new moodle_url('/mod/feedback/show_entries.php', array('id'=>$cm->id, 'do_show'=>$do_show));
45 $PAGE->set_url($url);
47 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
48         print_error('badcontext');
49 }
51 require_login($course->id, true, $cm);
53 if(($formdata = data_submitted()) AND !confirm_sesskey()) {
54     print_error('invalidsesskey');
55 }
57 require_capability('mod/feedback:viewreports', $context);
59 ////////////////////////////////////////////////////////
60 //get the responses of given user
61 ////////////////////////////////////////////////////////
62 if($do_show == 'showoneentry') {
63     //get the feedbackitems
64     $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
65     $feedbackcompleted = $DB->get_record('feedback_completed', array('feedback'=>$feedback->id, 'userid'=>$formdata->userid, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO)); //arb
66 }
68 /// Print the page header
69 $strfeedbacks = get_string("modulenameplural", "feedback");
70 $strfeedback  = get_string("modulename", "feedback");
72 $PAGE->navbar->add(get_string('show_entries','feedback'));
73 $PAGE->set_title(format_string($feedback->name));
74 echo $OUTPUT->header();
76 include('tabs.php');
78 /// Print the main part of the page
79 ///////////////////////////////////////////////////////////////////////////
80 ///////////////////////////////////////////////////////////////////////////
81 ///////////////////////////////////////////////////////////////////////////
83 ////////////////////////////////////////////////////////
84 /// Print the links to get responses and analysis
85 ////////////////////////////////////////////////////////
86 if($do_show == 'showentries'){
87     //print the link to analysis
88     if(has_capability('mod/feedback:viewreports', $context)) {
89         //get the effective groupmode of this course and module
90         if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
91             $groupmode =  $cm->groupmode;
92         } else {
93             $groupmode = $course->groupmode;
94         }
95         
96         // $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/show_entries.php?id=' . $cm->id.'&do_show=showentries', true);
97         $groupselect = groups_print_activity_menu($cm, $url->out(), true);
98         $mygroupid = groups_get_activity_group($cm);
100         //get students in conjunction with groupmode
101         if($groupmode > 0) {
103             if($mygroupid > 0) {
104                 $students = feedback_get_complete_users($cm, $mygroupid);
105             } else {
106                 $students = feedback_get_complete_users($cm);
107             }
108         }else {
109             $students = feedback_get_complete_users($cm);
110         }
112         $completedFeedbackCount = feedback_get_completeds_group_count($feedback, $mygroupid);
113         if($feedback->course == SITEID){
114             $analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id, 'courseid'=>$courseid));
115             echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
116             echo get_string('course') .' '. get_string('analysis', 'feedback') . ' ('.get_string('completed_feedbacks', 'feedback').': '.intval($completedFeedbackCount).')</a>';
117             echo $OUTPUT->old_help_icon('viewcompleted', '', 'feedback', true);
118             echo '</div>';
119         }else {
120             $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
121             echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
122             echo get_string('analysis', 'feedback') . ' ('.get_string('completed_feedbacks', 'feedback').': '.intval($completedFeedbackCount).')</a>';
123             echo '</div>';
124         }
125     }
127     //####### viewreports-start
128     if(has_capability('mod/feedback:viewreports', $context)) {
129         //print the list of students
130         echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
131         echo isset($groupselect) ? $groupselect : '';
132         echo '<div class="clearer"></div>';
133         echo '<div class="mdl-align"><table><tr><td width="400">';
134         if (!$students) {
135             if($courseid != SITEID){
136                 echo $OUTPUT->notification(get_string('noexistingstudents'));
137             }
138         } else{
139             echo print_string('non_anonymous_entries', 'feedback');
140             echo ' ('.count($students).')<hr />';
142             foreach ($students as $student){
143                 $completedCount = $DB->count_records('feedback_completed', array('userid'=>$student->id, 'feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO));
144                 if($completedCount > 0) {
145                  // Are we assuming that there is only one response per user? Should westep through a feedbackcompleteds? I added the addition anonymous check to the select so that only non-anonymous submissions are retrieved.
146                     $feedbackcompleted = $DB->get_record('feedback_completed', array('feedback'=>$feedback->id, ' userid'=>$student->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO));
147                 ?>
148                     <table width="100%">
149                         <tr>
150                             <td align="left">
151                                 <?php echo $OUTPUT->user_picture($student, array('courseid'=>$course->id));?>
152                             </td>
153                             <td align="left">
154                                 <?php echo fullname($student);?>
155                             </td>
156                             <td align="right">
157                             <?php
158                                 $aurl = new moodle_url($url, array('sesskey'=>sesskey(), 'userid'=>$student->id, 'do_show'=>'showoneentry'));
159                                 echo $OUTPUT->single_button($aurl, get_string('show_entries', 'feedback'));
160                             ?>
161                             </td>
162                 <?php
163                     if(has_capability('mod/feedback:deletesubmissions', $context)) {
164                 ?>
165                             <td align="right">
166                             <?php
167                                 $aurl = new moodle_url($url, array('sesskey'=>sesskey(), 'completedid'=>$feedbackcompleted->id, 'do_show'=>'showoneentry'));
168                                 echo $OUTPUT->single_button($aurl, get_string('delete_entry', 'feedback'));
169                             ?>
170                             </td>
171                 <?php
172                     }
173                 ?>
174                         </tr>
175                     </table>
176                 <?php
177                 }
178             }
179         }
180 ?>
181         <hr />
182         <table width="100%">
183             <tr>
184                 <td align="left" colspan="2">
185                     <?php print_string('anonymous_entries', 'feedback');?>&nbsp;(<?php echo $DB->count_records('feedback_completed', array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES));?>)
186                 </td>
187                 <td align="right">
188                     <?php
189                         $aurl = new moodle_url('show_entries_anonym.php', array('sesskey'=>sesskey(), 'userid'=>0, 'do_show'=>'showoneentry', 'id'=>$id));
190                         echo $OUTPUT->single_button($aurl, get_string('show_entries', 'feedback'));
191                     ?>
192                 </td>
193             </tr>
194         </table>
195 <?php
196         echo '</td></tr></table></div>';
197         echo $OUTPUT->box_end();
198     }
201 ////////////////////////////////////////////////////////
202 /// Print the responses of the given user
203 ////////////////////////////////////////////////////////
204 if($do_show == 'showoneentry') {
205     echo $OUTPUT->heading(format_text($feedback->name));
207     //print the items
208     if(is_array($feedbackitems)){
209         $usr = $DB->get_record('user', array('id'=>$formdata->userid));
210         if($feedbackcompleted) {
211             echo '<p align="center">'.UserDate($feedbackcompleted->timemodified).'<br />('.fullname($usr).')</p>';
212         } else {
213             echo '<p align="center">'.get_string('not_completed_yet','feedback').'</p>';
214         }
215         echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
216         echo '<form>';
217         echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
218         echo '<table width="100%">';
219         $itemnr = 0;
220         foreach($feedbackitems as $feedbackitem){
221             //get the values
222             $value = $DB->get_record('feedback_value', array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id));
223             echo '<tr>';
224             if($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
225                 $itemnr++;
226                 echo '<td valign="top">' . $itemnr . '.&nbsp;</td>';
227             } else {
228                 echo '<td>&nbsp;</td>';
229             }
231             if($feedbackitem->typ != 'pagebreak') {
232                 if(isset($value->value)) {
233                     feedback_print_item($feedbackitem, $value->value, true);
234                 }else {
235                     feedback_print_item($feedbackitem, false, true);
236                 }
237             }else {
238                 echo '<td><hr /></td>';
239             }
240             echo '</tr>';
241         }
242         echo '<tr><td colspan="2" align="center">';
243         echo '</td></tr>';
244         echo '</table>';
245         echo '</form>';
246         echo $OUTPUT->box_end();
247     }
248     // echo $OUTPUT->continue_button(htmlspecialchars('show_entries.php?id='.$id.'&do_show=showentries'));
249     echo $OUTPUT->continue_button(new moodle_url($url, array('do_show'=>'showentries')));
251 /// Finish the page
252 ///////////////////////////////////////////////////////////////////////////
253 ///////////////////////////////////////////////////////////////////////////
254 ///////////////////////////////////////////////////////////////////////////
256 echo $OUTPUT->footer();
258 ?>