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
);
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');
68 $navlinks[] = array('name' => $strscorms, 'link' => "index.php?id=$course->id", 'type' => 'activity');
69 $navlinks[] = array('name' => format_string($scorm->name
,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
73 $navigation = build_navigation($navlinks);
74 print_header("$course->shortname: ".format_string($scorm->name
), $course->fullname
,$navigation,
78 $navlinks[] = array('name' => $strreport, 'link' => "report.php?id=$cm->id", 'type' => 'title');
79 $navlinks[] = array('name' => "$strattempt $attempt - ".fullname($userdata), 'link' => '', 'type' => 'title');
80 $navigation = build_navigation($navlinks);
82 print_header("$course->shortname: ".format_string($scorm->name
), $course->fullname
,
83 $navigation, '', '', true);
87 $navlinks[] = array('name' => $strreport, 'link' => "report.php?id=$cm->id", 'type' => 'title');
88 $navlinks[] = array('name' => "$strattempt $attempt - ".fullname($userdata), 'link' => "report.php?a=$a&user=$user&attempt=$attempt", 'type' => 'title');
89 $navlinks[] = array('name' => $sco->title
, 'link' => '', 'type' => 'title');
90 $navigation = build_navigation($navlinks);
92 print_header("$course->shortname: ".format_string($scorm->name
), $course->fullname
, $navigation,
95 print_heading(format_string($scorm->name
));
98 $scormpixdir = $CFG->modpixpath
.'/scorm/pix';
102 // No options, show the global scorm report
103 if ($scousers=get_records_select('scorm_scoes_track', "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) {
104 $table = new stdClass();
105 $table->head
= array(' ', get_string('name'));
106 $table->align
= array('center', 'left');
107 $table->wrap
= array('nowrap', 'nowrap');
108 $table->width
= '100%';
109 $table->size
= array(10, '*');
111 $table->head
[]= get_string('attempt','scorm');
112 $table->align
[] = 'center';
113 $table->wrap
[] = 'nowrap';
114 $table->size
[] = '*';
116 $table->head
[]= get_string('started','scorm');
117 $table->align
[] = 'center';
118 $table->wrap
[] = 'nowrap';
119 $table->size
[] = '*';
121 $table->head
[]= get_string('last','scorm');
122 $table->align
[] = 'center';
123 $table->wrap
[] = 'nowrap';
124 $table->size
[] = '*';
126 $table->head
[]= get_string('score','scorm');
127 $table->align
[] = 'center';
128 $table->wrap
[] = 'nowrap';
129 $table->size
[] = '*';
131 foreach($scousers as $scouser){
132 $userdata = scorm_get_user_data($scouser->userid
);
133 $attempt = scorm_get_last_attempt($scorm->id
,$scouser->userid
);
134 for ($a = 1; $a<=$attempt; $a++
) {
136 $row[] = print_user_picture($scouser->userid
, $course->id
, $userdata->picture
, false, true);
137 $row[] = '<a href="'.$CFG->wwwroot
.'/user/view.php?id='.$scouser->userid
.'&course='.$course->id
.'">'.
138 fullname($userdata).'</a>';
139 $row[] = '<a href="report.php?a='.$scorm->id
.'&user='.$scouser->userid
.'&attempt='.$a.'">'.$a.'</a>';
140 $select = 'scormid = '.$scorm->id
.' and userid = '.$scouser->userid
.' and attempt = '.$a;
141 $timetracks = get_record_select('scorm_scoes_track', $select,'min(timemodified) as started, max(timemodified) as last');
142 $row[] = userdate($timetracks->started
, get_string('strftimedaydatetime'));
143 $row[] = userdate($timetracks->last
, get_string('strftimedaydatetime'));
145 $row[] = scorm_grade_user_attempt($scorm, $scouser->userid
, $a);
146 $table->data
[] = $row;
154 if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' ORDER BY id")) {
155 if (!empty($userdata)) {
156 print_simple_box_start('center');
157 echo '<div align="center">'."\n";
158 print_user_picture($user, $course->id
, $userdata->picture
, false, false);
159 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">".
160 "$userdata->firstname $userdata->lastname</a><br />";
161 echo get_string('attempt','scorm').': '.$attempt;
163 print_simple_box_end();
165 // Print general score data
166 $table = new stdClass();
167 $table->head
= array(get_string('title','scorm'),
168 get_string('status','scorm'),
169 get_string('time','scorm'),
170 get_string('score','scorm'),
172 $table->align
= array('left', 'center','center','right','left');
173 $table->wrap
= array('nowrap', 'nowrap','nowrap','nowrap','nowrap');
174 $table->width
= '80%';
175 $table->size
= array('*', '*', '*', '*', '*');
176 foreach ($scoes as $sco) {
177 if ($sco->launch
!='') {
180 if ($trackdata = scorm_get_tracks($sco->id
,$user,$attempt)) {
181 if ($trackdata->score_raw
!= '') {
182 $score = $trackdata->score_raw
;
184 if ($trackdata->status
== '') {
185 $trackdata->status
= 'notattempted';
187 $detailslink = '<a href="report.php?b='.$sco->id
.'&user='.$user.'&attempt='.$attempt.'" title="'.
188 get_string('details','scorm').'">'.get_string('details','scorm').'</a>';
190 $trackdata->status
= 'notattempted';
191 $trackdata->total_time
= ' ';
192 $detailslink = ' ';
194 $strstatus = get_string($trackdata->status
,'scorm');
195 $row[] = '<img src="'.$scormpixdir.'/'.$trackdata->status
.'.gif" alt="'.$strstatus.'" title="'.
196 $strstatus.'"> '.format_string($sco->title
);
197 $row[] = get_string($trackdata->status
,'scorm');
198 $row[] = $trackdata->total_time
;
200 $row[] = $detailslink;
202 $row = array(format_string($sco->title
), ' ', ' ', ' ', ' ');
204 $table->data
[] = $row;
210 notice('No users to report');
215 if (!empty($userdata)) {
216 print_simple_box_start('center');
217 //print_heading(format_string($sco->title));
218 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>');
219 echo '<div align="center">'."\n";
220 print_user_picture($user, $course->id
, $userdata->picture
, false, false);
221 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">".
222 "$userdata->firstname $userdata->lastname</a><br />";
224 if ($trackdata = scorm_get_tracks($sco->id
,$user,$attempt)) {
225 if ($trackdata->score_raw
!= '') {
226 $scoreview = get_string('score','scorm').': '.$trackdata->score_raw
;
228 if ($trackdata->status
== '') {
229 $trackdata->status
= 'notattempted';
232 $trackdata->status
= 'notattempted';
233 $trackdata->total_time
= '';
235 $strstatus = get_string($trackdata->status
,'scorm');
236 echo '<img src="'.$scormpixdir.'/'.$trackdata->status
.'.gif" alt="'.$strstatus.'" title="'.
237 $strstatus.'"> '.$trackdata->total_time
.'<br />'.$scoreview.'<br />';
239 echo '<hr /><h2>'.get_string('details','scorm').'</h2>';
241 // Print general score data
242 $table = new stdClass();
243 $table->head
= array(get_string('element','scorm'), get_string('value','scorm'));
244 $table->align
= array('left', 'left');
245 $table->wrap
= array('nowrap', 'nowrap');
246 $table->width
= '100%';
247 $table->size
= array('*', '*');
249 $existelements = false;
250 if ($scorm->version
== 'SCORM_1.3') {
251 $elements = array('raw' => 'cmi.score.raw',
252 'min' => 'cmi.score.min',
253 'max' => 'cmi.score.max',
254 'status' => 'cmi.completition_status',
255 'time' => 'cmi.total_time');
257 $elements = array('raw' => 'cmi.core.score.raw',
258 'min' => 'cmi.core.score.min',
259 'max' => 'cmi.core.score.max',
260 'status' => 'cmi.core.lesson_status',
261 'time' => 'cmi.core.total_time');
263 $printedelements = array();
264 foreach ($elements as $key => $element) {
265 if (isset($trackdata->$element)) {
266 $existelements = true;
267 $printedelements[]=$element;
269 $row[] = get_string($key,'scorm');
270 $row[] = s($trackdata->$element);
271 $table->data
[] = $row;
274 if ($existelements) {
275 echo '<h3>'.get_string('general','scorm').'</h3>';
279 // Print Interactions data
280 $table = new stdClass();
281 $table->head
= array(get_string('identifier','scorm'),
282 get_string('type','scorm'),
283 get_string('result','scorm'),
284 get_string('student_response','scorm'));
285 $table->align
= array('center', 'center', 'center', 'center');
286 $table->wrap
= array('nowrap', 'nowrap', 'nowrap', 'nowrap');
287 $table->width
= '100%';
288 $table->size
= array('*', '*', '*', '*', '*');
290 $existinteraction = false;
293 $interactionid = 'cmi.interactions.'.$i.'.id';
295 while (isset($trackdata->$interactionid)) {
296 $existinteraction = true;
297 $printedelements[]=$interactionid;
298 $elements = array($interactionid,
299 'cmi.interactions.'.$i.'.type',
300 'cmi.interactions.'.$i.'.result',
301 'cmi.interactions.'.$i.'.student_response');
303 foreach ($elements as $element) {
304 if (isset($trackdata->$element)) {
305 $row[] = s($trackdata->$element);
306 $printedelements[]=$element;
311 $table->data
[] = $row;
314 $interactionid = 'cmi.interactions.'.$i.'.id';
316 if ($existinteraction) {
317 echo '<h3>'.get_string('interactions','scorm').'</h3>';
318 echo '<h3>'.get_string('interactions','scorm').'</h3>';
322 // Print Objectives data
323 $table = new stdClass();
324 $table->head
= array(get_string('identifier','scorm'),
325 get_string('status','scorm'),
326 get_string('raw','scorm'),
327 get_string('min','scorm'),
328 get_string('max','scorm'));
329 $table->align
= array('center', 'center', 'center', 'center', 'center');
330 $table->wrap
= array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
331 $table->width
= '100%';
332 $table->size
= array('*', '*', '*', '*', '*');
334 $existobjective = false;
337 $objectiveid = 'cmi.objectives.'.$i.'.id';
339 while (isset($trackdata->$objectiveid)) {
340 $existobjective = true;
341 $printedelements[]=$objectiveid;
342 $elements = array($objectiveid,
343 'cmi.objectives.'.$i.'.status',
344 'cmi.objectives.'.$i.'.score.raw',
345 'cmi.objectives.'.$i.'.score.min',
346 'cmi.objectives.'.$i.'.score.max');
348 foreach ($elements as $element) {
349 if (isset($trackdata->$element)) {
350 $row[] = s($trackdata->$element);
351 $printedelements[]=$element;
356 $table->data
[] = $row;
359 $objectiveid = 'cmi.objectives.'.$i.'.id';
361 if ($existobjective) {
362 echo '<h3>'.get_string('objectives','scorm').'</h3>';
365 $table = new stdClass();
366 $table->head
= array(get_string('element','scorm'), get_string('value','scorm'));
367 $table->align
= array('left', 'left');
368 $table->wrap
= array('nowrap', 'wrap');
369 $table->width
= '100%';
370 $table->size
= array('*', '*');
372 $existelements = false;
374 foreach($trackdata as $element => $value) {
375 if (substr($element,0,3) == 'cmi') {
376 if (!(in_array ($element, $printedelements))) {
377 $existelements = true;
379 $row[] = get_string($element,'scorm') != '[['.$element.']]' ?
get_string($element,'scorm') : $element;
381 $table->data
[] = $row;
385 if ($existelements) {
386 echo '<h3>'.get_string('othertracks','scorm').'</h3>';
389 print_simple_box_end();
391 error('Missing script parameter');
396 if (empty($noheader)) {
397 print_footer($course);