Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / scorm / report.php
blob2372d8288a25c48165ed6d185c621372b883aa83
1 <?php // $Id$
3 // This script uses installed report plugins to print quiz reports
5 require_once("../../config.php");
6 require_once('locallib.php');
8 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
9 $a = optional_param('a', '', PARAM_INT); // SCORM ID
10 $b = optional_param('b', '', PARAM_INT); // SCO ID
11 $user = optional_param('user', '', PARAM_INT); // User ID
12 $attempt = optional_param('attempt', '1', PARAM_INT); // attempt number
14 if (!empty($id)) {
15 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
16 error('Course Module ID was incorrect');
18 if (! $course = get_record('course', 'id', $cm->course)) {
19 error('Course is misconfigured');
21 if (! $scorm = get_record('scorm', 'id', $cm->instance)) {
22 error('Course module is incorrect');
24 } else {
25 if (!empty($b)) {
26 if (! $sco = get_record('scorm_scoes', 'id', $b)) {
27 error('Scorm activity is incorrect');
29 $a = $sco->scorm;
31 if (!empty($a)) {
32 if (! $scorm = get_record('scorm', 'id', $a)) {
33 error('Course module is incorrect');
35 if (! $course = get_record('course', 'id', $scorm->course)) {
36 error('Course is misconfigured');
38 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
39 error('Course Module ID was incorrect');
44 require_login($course->id, false, $cm);
46 if (!has_capability('mod/scorm:viewreport', get_context_instance(CONTEXT_MODULE,$cm->id))) {
47 error('You are not allowed to use this script');
50 add_to_log($course->id, 'scorm', 'report', 'report.php?id='.$cm->id, $scorm->id, $cm->id);
52 if (!empty($user)) {
53 $userdata = scorm_get_user_data($user);
54 } else {
55 $userdata = null;
58 /// Print the page header
59 if (empty($noheader)) {
61 $strscorms = get_string('modulenameplural', 'scorm');
62 $strscorm = get_string('modulename', 'scorm');
63 $strreport = get_string('report', 'scorm');
64 $strattempt = get_string('attempt', 'scorm');
65 $strname = get_string('name');
67 if (empty($b)) {
68 if (empty($a)) {
69 $navigation = build_navigation('', $cm);
70 print_header("$course->shortname: ".format_string($scorm->name), $course->fullname,$navigation,
71 '', '', true);
72 } else {
74 $navlinks = array();
75 $navlinks[] = array('name' => $strreport, 'link' => "report.php?id=$cm->id", 'type' => 'title');
76 $navlinks[] = array('name' => "$strattempt $attempt - ".fullname($userdata), 'link' => '', 'type' => 'title');
77 $navigation = build_navigation($navlinks, $cm);
79 print_header("$course->shortname: ".format_string($scorm->name), $course->fullname,
80 $navigation, '', '', true);
82 } else {
84 $navlinks = array();
85 $navlinks[] = array('name' => $strreport, 'link' => "report.php?id=$cm->id", 'type' => 'title');
86 $navlinks[] = array('name' => "$strattempt $attempt - ".fullname($userdata), 'link' => "report.php?a=$a&amp;user=$user&amp;attempt=$attempt", 'type' => 'title');
87 $navlinks[] = array('name' => $sco->title, 'link' => '', 'type' => 'title');
88 $navigation = build_navigation($navlinks, $cm);
90 print_header("$course->shortname: ".format_string($scorm->name), $course->fullname, $navigation,
91 '', '', true);
93 print_heading(format_string($scorm->name));
96 $scormpixdir = $CFG->modpixpath.'/scorm/pix';
98 if (empty($b)) {
99 if (empty($a)) {
100 // No options, show the global scorm report
102 if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
103 $sql = "SELECT st.userid, st.scormid
104 FROM {$CFG->prefix}scorm_scoes_track st
105 INNER JOIN {$CFG->prefix}groups_members gm ON st.userid = gm.userid
106 INNER JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = gg.groupid
107 WHERE st.scormid = {$scorm->id} AND gg.groupingid = {$cm->groupingid}
108 GROUP BY st.userid,st.scormid
110 } else {
111 $sql = "SELECT st.userid, st.scormid
112 FROM {$CFG->prefix}scorm_scoes_track st
113 WHERE st.scormid = {$scorm->id}
114 GROUP BY st.userid,st.scormid
118 if ($scousers=get_records_sql($sql)) {
119 $table = new stdClass();
120 $table->head = array('&nbsp;', get_string('name'));
121 $table->align = array('center', 'left');
122 $table->wrap = array('nowrap', 'nowrap');
123 $table->width = '100%';
124 $table->size = array(10, '*');
126 $table->head[]= get_string('attempt','scorm');
127 $table->align[] = 'center';
128 $table->wrap[] = 'nowrap';
129 $table->size[] = '*';
131 $table->head[]= get_string('started','scorm');
132 $table->align[] = 'center';
133 $table->wrap[] = 'nowrap';
134 $table->size[] = '*';
136 $table->head[]= get_string('last','scorm');
137 $table->align[] = 'center';
138 $table->wrap[] = 'nowrap';
139 $table->size[] = '*';
141 $table->head[]= get_string('score','scorm');
142 $table->align[] = 'center';
143 $table->wrap[] = 'nowrap';
144 $table->size[] = '*';
146 foreach($scousers as $scouser){
147 $userdata = scorm_get_user_data($scouser->userid);
148 $attempt = scorm_get_last_attempt($scorm->id,$scouser->userid);
149 for ($a = 1; $a<=$attempt; $a++) {
150 $row = array();
151 $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true);
152 $row[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$scouser->userid.'&amp;course='.$course->id.'">'.
153 fullname($userdata).'</a>';
154 $row[] = '<a href="report.php?a='.$scorm->id.'&amp;user='.$scouser->userid.'&amp;attempt='.$a.'">'.$a.'</a>';
155 $select = 'scormid = '.$scorm->id.' and userid = '.$scouser->userid.' and attempt = '.$a;
156 $timetracks = get_record_select('scorm_scoes_track', $select,'min(timemodified) as started, max(timemodified) as last');
157 $row[] = userdate($timetracks->started, get_string('strftimedaydatetime'));
158 $row[] = userdate($timetracks->last, get_string('strftimedaydatetime'));
160 $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $a);
161 $table->data[] = $row;
165 print_table($table);
166 } else {
167 if (!empty($user)) {
168 // User SCORM report
169 if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' ORDER BY id")) {
170 if (!empty($userdata)) {
171 print_simple_box_start('center');
172 echo '<div align="center">'."\n";
173 print_user_picture($user, $course->id, $userdata->picture, false, false);
174 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&amp;course=$course->id\">".
175 "$userdata->firstname $userdata->lastname</a><br />";
176 echo get_string('attempt','scorm').': '.$attempt;
177 echo '</div>'."\n";
178 print_simple_box_end();
180 // Print general score data
181 $table = new stdClass();
182 $table->head = array(get_string('title','scorm'),
183 get_string('status','scorm'),
184 get_string('time','scorm'),
185 get_string('score','scorm'),
186 '');
187 $table->align = array('left', 'center','center','right','left');
188 $table->wrap = array('nowrap', 'nowrap','nowrap','nowrap','nowrap');
189 $table->width = '80%';
190 $table->size = array('*', '*', '*', '*', '*');
191 foreach ($scoes as $sco) {
192 if ($sco->launch!='') {
193 $row = array();
194 $score = '&nbsp;';
195 if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) {
196 if ($trackdata->score_raw != '') {
197 $score = $trackdata->score_raw;
199 if ($trackdata->status == '') {
200 $trackdata->status = 'notattempted';
202 $detailslink = '<a href="report.php?b='.$sco->id.'&amp;user='.$user.'&amp;attempt='.$attempt.'" title="'.
203 get_string('details','scorm').'">'.get_string('details','scorm').'</a>';
204 } else {
205 $trackdata->status = 'notattempted';
206 $trackdata->total_time = '&nbsp;';
207 $detailslink = '&nbsp;';
209 $strstatus = get_string($trackdata->status,'scorm');
210 $row[] = '<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
211 $strstatus.'" />&nbsp;'.format_string($sco->title);
212 $row[] = get_string($trackdata->status,'scorm');
213 $row[] = $trackdata->total_time;
214 $row[] = $score;
215 $row[] = $detailslink;
216 } else {
217 $row = array(format_string($sco->title), '&nbsp;', '&nbsp;', '&nbsp;', '&nbsp;');
219 $table->data[] = $row;
221 print_table($table);
224 } else {
225 notice('No users to report');
228 } else {
229 // User SCO report
230 if (!empty($userdata)) {
231 print_simple_box_start('center');
232 //print_heading(format_string($sco->title));
233 print_heading('<a href="'.$CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;mode=browse&amp;scoid='.$sco->id.'" target="_new">'.format_string($sco->title).'</a>');
234 echo '<div align="center">'."\n";
235 print_user_picture($user, $course->id, $userdata->picture, false, false);
236 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&amp;course=$course->id\">".
237 "$userdata->firstname $userdata->lastname</a><br />";
238 $scoreview = '';
239 if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) {
240 if ($trackdata->score_raw != '') {
241 $scoreview = get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;
243 if ($trackdata->status == '') {
244 $trackdata->status = 'notattempted';
246 } else {
247 $trackdata->status = 'notattempted';
248 $trackdata->total_time = '';
250 $strstatus = get_string($trackdata->status,'scorm');
251 echo '<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
252 $strstatus.'" />&nbsp;'.$trackdata->total_time.'<br />'.$scoreview.'<br />';
253 echo '</div>'."\n";
254 echo '<hr /><h2>'.get_string('details','scorm').'</h2>';
256 // Print general score data
257 $table = new stdClass();
258 $table->head = array(get_string('element','scorm'), get_string('value','scorm'));
259 $table->align = array('left', 'left');
260 $table->wrap = array('nowrap', 'nowrap');
261 $table->width = '100%';
262 $table->size = array('*', '*');
264 $existelements = false;
265 if ($scorm->version == 'SCORM_1.3') {
266 $elements = array('raw' => 'cmi.score.raw',
267 'min' => 'cmi.score.min',
268 'max' => 'cmi.score.max',
269 'status' => 'cmi.completion_status',
270 'time' => 'cmi.total_time');
271 } else {
272 $elements = array('raw' => 'cmi.core.score.raw',
273 'min' => 'cmi.core.score.min',
274 'max' => 'cmi.core.score.max',
275 'status' => 'cmi.core.lesson_status',
276 'time' => 'cmi.core.total_time');
278 $printedelements = array();
279 foreach ($elements as $key => $element) {
280 if (isset($trackdata->$element)) {
281 $existelements = true;
282 $printedelements[]=$element;
283 $row = array();
284 $row[] = get_string($key,'scorm');
285 $row[] = s($trackdata->$element);
286 $table->data[] = $row;
289 if ($existelements) {
290 echo '<h3>'.get_string('general','scorm').'</h3>';
291 print_table($table);
294 // Print Interactions data
295 $table = new stdClass();
296 $table->head = array(get_string('identifier','scorm'),
297 get_string('type','scorm'),
298 get_string('result','scorm'),
299 get_string('student_response','scorm'));
300 $table->align = array('center', 'center', 'center', 'center');
301 $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap');
302 $table->width = '100%';
303 $table->size = array('*', '*', '*', '*', '*');
305 $existinteraction = false;
307 $i = 0;
308 $interactionid = 'cmi.interactions.'.$i.'.id';
310 while (isset($trackdata->$interactionid)) {
311 $existinteraction = true;
312 $printedelements[]=$interactionid;
313 $elements = array($interactionid,
314 'cmi.interactions.'.$i.'.type',
315 'cmi.interactions.'.$i.'.result',
316 'cmi.interactions.'.$i.'.learner_response');
317 $row = array();
318 foreach ($elements as $element) {
319 if (isset($trackdata->$element)) {
320 $row[] = s($trackdata->$element);
321 $printedelements[]=$element;
322 } else {
323 $row[] = '&nbsp;';
326 $table->data[] = $row;
328 $i++;
329 $interactionid = 'cmi.interactions.'.$i.'.id';
331 if ($existinteraction) {
332 echo '<h3>'.get_string('interactions','scorm').'</h3>';
333 echo '<h3>'.get_string('interactions','scorm').'</h3>';
334 print_table($table);
337 // Print Objectives data
338 $table = new stdClass();
339 $table->head = array(get_string('identifier','scorm'),
340 get_string('status','scorm'),
341 get_string('raw','scorm'),
342 get_string('min','scorm'),
343 get_string('max','scorm'));
344 $table->align = array('center', 'center', 'center', 'center', 'center');
345 $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
346 $table->width = '100%';
347 $table->size = array('*', '*', '*', '*', '*');
349 $existobjective = false;
351 $i = 0;
352 $objectiveid = 'cmi.objectives.'.$i.'.id';
354 while (isset($trackdata->$objectiveid)) {
355 $existobjective = true;
356 $printedelements[]=$objectiveid;
357 $elements = array($objectiveid,
358 'cmi.objectives.'.$i.'.status',
359 'cmi.objectives.'.$i.'.score.raw',
360 'cmi.objectives.'.$i.'.score.min',
361 'cmi.objectives.'.$i.'.score.max');
362 $row = array();
363 foreach ($elements as $element) {
364 if (isset($trackdata->$element)) {
365 $row[] = s($trackdata->$element);
366 $printedelements[]=$element;
367 } else {
368 $row[] = '&nbsp;';
371 $table->data[] = $row;
373 $i++;
374 $objectiveid = 'cmi.objectives.'.$i.'.id';
376 if ($existobjective) {
377 echo '<h3>'.get_string('objectives','scorm').'</h3>';
378 print_table($table);
380 $table = new stdClass();
381 $table->head = array(get_string('element','scorm'), get_string('value','scorm'));
382 $table->align = array('left', 'left');
383 $table->wrap = array('nowrap', 'wrap');
384 $table->width = '100%';
385 $table->size = array('*', '*');
387 $existelements = false;
389 foreach($trackdata as $element => $value) {
390 if (substr($element,0,3) == 'cmi') {
391 if (!(in_array ($element, $printedelements))) {
392 $existelements = true;
393 $row = array();
394 $row[] = get_string($element,'scorm') != '[['.$element.']]' ? get_string($element,'scorm') : $element;
395 $row[] = s($value);
396 $table->data[] = $row;
400 if ($existelements) {
401 echo '<h3>'.get_string('othertracks','scorm').'</h3>';
402 print_table($table);
404 print_simple_box_end();
405 } else {
406 error('Missing script parameter');
411 if (empty($noheader)) {
412 print_footer($course);