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
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');
26 if (! $sco = get_record('scorm_scoes', 'id', $b)) {
27 error('Scorm activity is incorrect');
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
);
53 $userdata = scorm_get_user_data($user);
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');
69 $navigation = build_navigation('', $cm);
70 print_header("$course->shortname: ".format_string($scorm->name
), $course->fullname
,$navigation,
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);
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&user=$user&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,
93 print_heading(format_string($scorm->name
));
96 $scormpixdir = $CFG->modpixpath
.'/scorm/pix';
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
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(' ', 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++
) {
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
.'&course='.$course->id
.'">'.
153 fullname($userdata).'</a>';
154 $row[] = '<a href="report.php?a='.$scorm->id
.'&user='.$scouser->userid
.'&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;
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&course=$course->id\">".
175 "$userdata->firstname $userdata->lastname</a><br />";
176 echo get_string('attempt','scorm').': '.$attempt;
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'),
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
!='') {
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
.'&user='.$user.'&attempt='.$attempt.'" title="'.
203 get_string('details','scorm').'">'.get_string('details','scorm').'</a>';
205 $trackdata->status
= 'notattempted';
206 $trackdata->total_time
= ' ';
207 $detailslink = ' ';
209 $strstatus = get_string($trackdata->status
,'scorm');
210 $row[] = '<img src="'.$scormpixdir.'/'.$trackdata->status
.'.gif" alt="'.$strstatus.'" title="'.
211 $strstatus.'" /> '.format_string($sco->title
);
212 $row[] = get_string($trackdata->status
,'scorm');
213 $row[] = $trackdata->total_time
;
215 $row[] = $detailslink;
217 $row = array(format_string($sco->title
), ' ', ' ', ' ', ' ');
219 $table->data
[] = $row;
225 notice('No users to 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
.'&mode=browse&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&course=$course->id\">".
237 "$userdata->firstname $userdata->lastname</a><br />";
239 if ($trackdata = scorm_get_tracks($sco->id
,$user,$attempt)) {
240 if ($trackdata->score_raw
!= '') {
241 $scoreview = get_string('score','scorm').': '.$trackdata->score_raw
;
243 if ($trackdata->status
== '') {
244 $trackdata->status
= 'notattempted';
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.'" /> '.$trackdata->total_time
.'<br />'.$scoreview.'<br />';
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');
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;
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>';
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;
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');
318 foreach ($elements as $element) {
319 if (isset($trackdata->$element)) {
320 $row[] = s($trackdata->$element);
321 $printedelements[]=$element;
326 $table->data
[] = $row;
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>';
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;
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');
363 foreach ($elements as $element) {
364 if (isset($trackdata->$element)) {
365 $row[] = s($trackdata->$element);
366 $printedelements[]=$element;
371 $table->data
[] = $row;
374 $objectiveid = 'cmi.objectives.'.$i.'.id';
376 if ($existobjective) {
377 echo '<h3>'.get_string('objectives','scorm').'</h3>';
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;
394 $row[] = get_string($element,'scorm') != '[['.$element.']]' ?
get_string($element,'scorm') : $element;
396 $table->data
[] = $row;
400 if ($existelements) {
401 echo '<h3>'.get_string('othertracks','scorm').'</h3>';
404 print_simple_box_end();
406 error('Missing script parameter');
411 if (empty($noheader)) {
412 print_footer($course);