3 // This script uses installed report plugins to print quiz reports
5 require_once("../../config.php");
6 require_once($CFG->libdir.'/tablelib.php');
7 require_once($CFG->dirroot.'/mod/scorm/locallib.php');
8 require_once($CFG->dirroot.'/mod/scorm/reportsettings_form.php');
9 require_once($CFG->libdir.'/formslib.php');
10 define('SCORM_REPORT_DEFAULT_PAGE_SIZE', 20);
11 define('SCORM_REPORT_ATTEMPTS_ALL_STUDENTS', 0);
12 define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH', 1);
13 define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2);
15 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
16 $a = optional_param('a', '', PARAM_INT); // SCORM ID
17 $b = optional_param('b', '', PARAM_INT); // SCO ID
18 $user = optional_param('user', '', PARAM_INT); // User ID
19 $attempt = optional_param('attempt', '1', PARAM_INT); // attempt number
20 $action = optional_param('action', '', PARAM_ALPHA);
21 $attemptids = optional_param('attemptid', array(), PARAM_RAW);
22 $download = optional_param('download', '', PARAM_RAW);
24 $url = new moodle_url('/mod/scorm/report.php');
26 $url->param('user', $user);
28 if ($attempt !== '1') {
29 $url->param('attempt', $attempt);
32 $url->param('action', $action);
36 $url->param('id', $id);
37 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
38 print_error('invalidcoursemodule');
40 if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
41 print_error('coursemisconf');
43 if (! $scorm = $DB->get_record('scorm', array('id'=>$cm->instance))) {
44 print_error('invalidcoursemodule');
49 if (! $sco = $DB->get_record('scorm_scoes', array('id'=>$b))) {
50 print_error('invalidactivity', 'scorm');
56 if (! $scorm = $DB->get_record('scorm', array('id'=>$a))) {
57 print_error('invalidcoursemodule');
59 if (! $course = $DB->get_record('course', array('id'=>$scorm->course))) {
60 print_error('coursemisconf');
62 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
63 print_error('invalidcoursemodule');
69 require_login($course->id, false, $cm);
71 $contextmodule = get_context_instance(CONTEXT_MODULE,$cm->id);
73 require_capability('mod/scorm:viewreport', $contextmodule);
75 add_to_log($course->id, 'scorm', 'report', 'report.php?id='.$cm->id, $scorm->id, $cm->id);
78 $userdata = scorm_get_user_data($user);
82 if (!empty($download)) {
85 /// Print the page header
86 if (empty($noheader)) {
88 $strscorms = get_string('modulenameplural', 'scorm');
89 $strscorm = get_string('modulename', 'scorm');
90 $strreport = get_string('report', 'scorm');
91 $strattempt = get_string('attempt', 'scorm');
92 $strname = get_string('name');
94 $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
95 $PAGE->set_heading($course->fullname);
96 $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id'=>$cm->id)));
100 $PAGE->navbar->add("$strattempt $attempt - ".fullname($userdata));
103 $PAGE->navbar->add("$strattempt $attempt - ".fullname($userdata), new moodle_url('/mod/scorm/report.php', array('a'=>$a, 'user'=>$user, 'attempt'=>$attempt)));
104 $PAGE->navbar->add($sco->title);
106 echo $OUTPUT->header();
107 $currenttab = 'reports';
108 require($CFG->dirroot . '/mod/scorm/tabs.php');
109 echo $OUTPUT->heading(format_string($scorm->name));
112 if ($action == 'delete' && has_capability('mod/scorm:deleteresponses',$contextmodule) && confirm_sesskey()) {
113 if (scorm_delete_responses($attemptids, $scorm)) { //delete responses.
114 add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id);
115 echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
121 // No options, show the global scorm report
122 $pageoptions = array();
123 $pageoptions['id'] = $cm->id;
124 $reporturl = new moodle_url($CFG->wwwroot.'/mod/scorm/report.php', $pageoptions);
126 // find out current groups mode
127 $currentgroup = groups_get_activity_group($cm, true);
130 $mform = new mod_scorm_report_settings( $reporturl, compact('currentgroup') );
131 if ($fromform = $mform->get_data()) {
132 $detailedrep = $fromform->detailedrep;
133 $pagesize = $fromform->pagesize;
134 $attemptsmode = $fromform->attemptsmode;
135 set_user_preference('scorm_report_detailed', $detailedrep);
136 set_user_preference('scorm_report_pagesize', $pagesize);
138 $detailedrep = get_user_preferences('scorm_report_detailed', false);
139 $pagesize = get_user_preferences('scorm_report_pagesize', 0);
140 $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_STUDENTS_WITH, PARAM_INT);
143 $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
147 $displayoptions = array();
148 $displayoptions['id'] = $cm->id;
149 $displayoptions['attemptsmode'] = $attemptsmode;
150 $reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot.'/mod/scorm/report.php', $displayoptions);
152 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
154 groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out());
158 // We only want to show the checkbox to delete attempts
159 // if the user has permissions and if the report mode is showing attempts.
160 $candelete = has_capability('mod/scorm:deleteresponses',$contextmodule)
161 && ($attemptsmode!= SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
162 // select the students
165 if (empty($currentgroup)) {
166 // all users who can attempt scoes
167 if (!$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack','','','','','','',false)){
168 echo $OUTPUT->notification(get_string('nostudentsyet'));
172 $allowedlist = join(',',array_keys($students));
175 // all users who can attempt scoes and who are in the currently selected group
176 if (!$groupstudents = get_users_by_capability($context, 'mod/scorm:savetrack','','','','',$currentgroup,'',false)){
177 echo $OUTPUT->notification(get_string('nostudentsingroup'));
179 $groupstudents = array();
181 $allowedlist = join(',', array_keys($groupstudents));
186 // Now check if asked download of data
188 $filename = clean_filename("$course->shortname ".format_string($scorm->name,true));
191 // Define table columns
194 if (!$download && $candelete) {
195 $columns[]= 'checkbox';
198 if (!$download && $CFG->grade_report_showuserimage) {
199 $columns[]= 'picture';
202 $columns[]= 'fullname';
203 $headers[]= get_string('name');
204 if ($CFG->grade_report_showuseridnumber) {
205 $columns[]= 'idnumber';
206 $headers[]= get_string('idnumber');
208 $columns[]= 'attempt';
209 $headers[]= get_string('attempt', 'scorm');
211 $headers[]= get_string('started','scorm');
212 $columns[]= 'finish';
213 $headers[]= get_string('last','scorm');
215 $headers[]= get_string('score','scorm');
216 if ($detailedrep && $scoes = $DB->get_records('scorm_scoes',array("scorm"=>$scorm->id),'id')) {
217 foreach ($scoes as $sco) {
218 if ($sco->launch!='') {
219 $columns[]= 'scograde'.$sco->id;
220 $headers[]= format_string($sco->title);
221 $table->head[]= format_string($sco->title);
229 $table = new flexible_table('mod-scorm-report');
231 $table->define_columns($columns);
232 $table->define_headers($headers);
233 $table->define_baseurl($reporturlwithdisplayoptions->out());
235 $table->sortable(true);
236 $table->collapsible(true);
238 $table->column_suppress('picture');
239 $table->column_suppress('fullname');
240 $table->column_suppress('idnumber');
242 $table->no_sorting('start');
243 $table->no_sorting('finish');
244 $table->no_sorting('score');
246 foreach ($scoes as $sco) {
247 if ($sco->launch!='') {
248 $table->no_sorting('scograde'.$sco->id);
253 $table->column_class('picture', 'picture');
254 $table->column_class('fullname', 'bold');
255 $table->column_class('score', 'bold');
257 $table->set_attribute('cellspacing', '0');
258 $table->set_attribute('id', 'attempts');
259 $table->set_attribute('class', 'generaltable generalbox');
261 // Start working -- this is necessary as soon as the niceties are over
263 } else if ($download =='ODS') {
264 require_once("$CFG->libdir/odslib.class.php");
267 // Creating a workbook
268 $workbook = new MoodleODSWorkbook("-");
269 // Sending HTTP headers
270 $workbook->send($filename);
271 // Creating the first worksheet
272 $sheettitle = get_string('report','scorm');
273 $myxls =& $workbook->add_worksheet($sheettitle);
275 $format =& $workbook->add_format();
276 $format->set_bold(0);
277 $formatbc =& $workbook->add_format();
278 $formatbc->set_bold(1);
279 $formatbc->set_align('center');
280 $formatb =& $workbook->add_format();
281 $formatb->set_bold(1);
282 $formaty =& $workbook->add_format();
283 $formaty->set_bg_color('yellow');
284 $formatc =& $workbook->add_format();
285 $formatc->set_align('center');
286 $formatr =& $workbook->add_format();
287 $formatr->set_bold(1);
288 $formatr->set_color('red');
289 $formatr->set_align('center');
290 $formatg =& $workbook->add_format();
291 $formatg->set_bold(1);
292 $formatg->set_color('green');
293 $formatg->set_align('center');
294 // Here starts workshhet headers
297 foreach ($headers as $item) {
298 $myxls->write(0,$colnum,$item,$formatbc);
302 } else if ($download =='Excel') {
303 require_once("$CFG->libdir/excellib.class.php");
306 // Creating a workbook
307 $workbook = new MoodleExcelWorkbook("-");
308 // Sending HTTP headers
309 $workbook->send($filename);
310 // Creating the first worksheet
311 $sheettitle = get_string('report','scorm');
312 $myxls =& $workbook->add_worksheet($sheettitle);
314 $format =& $workbook->add_format();
315 $format->set_bold(0);
316 $formatbc =& $workbook->add_format();
317 $formatbc->set_bold(1);
318 $formatbc->set_align('center');
319 $formatb =& $workbook->add_format();
320 $formatb->set_bold(1);
321 $formaty =& $workbook->add_format();
322 $formaty->set_bg_color('yellow');
323 $formatc =& $workbook->add_format();
324 $formatc->set_align('center');
325 $formatr =& $workbook->add_format();
326 $formatr->set_bold(1);
327 $formatr->set_color('red');
328 $formatr->set_align('center');
329 $formatg =& $workbook->add_format();
330 $formatg->set_bold(1);
331 $formatg->set_color('green');
332 $formatg->set_align('center');
335 foreach ($headers as $item) {
336 $myxls->write(0,$colnum,$item,$formatbc);
340 } else if ($download=='CSV') {
342 header("Content-Type: application/download\n");
343 header("Content-Disposition: attachment; filename=\"$filename\"");
344 header("Expires: 0");
345 header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
346 header("Pragma: public");
347 echo implode("\t", $headers)." \n";
351 $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, ';
352 $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' .
353 'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.email ';
355 // This part is the same for all cases - join users and scorm_scoes_track tables
356 $from = 'FROM {user} u ';
357 $from .= 'LEFT JOIN {scorm_scoes_track} st ON st.userid = u.id AND st.scormid = '.$scorm->id;
358 switch ($attemptsmode){
359 case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
360 // Show only students with attempts
361 $where = ' WHERE u.id IN (' .$allowedlist. ') AND st.userid IS NOT NULL';
363 case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
364 // Show only students without attempts
365 $where = ' WHERE u.id IN (' .$allowedlist. ') AND st.userid IS NULL';
367 case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
368 // Show all students with or without attempts
369 $where = ' WHERE u.id IN (' .$allowedlist. ') AND (st.userid IS NOT NULL OR st.userid IS NULL)';
373 $countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').')) AS nbresults, ';
374 $countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'','st.attempt').')) AS nbattempts, ';
375 $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
376 $countsql .= $from.$where;
380 $sort = $table->get_sql_sort();
385 // Fix some wired sorting
387 $sort = ' ORDER BY uniqueid';
389 $sort = ' ORDER BY '.$sort;
393 // Add extra limits due to initials bar
394 list($twhere, $tparams) = $table->get_sql_where();
396 $where .= ' AND '.$twhere; //initial bar
397 $params = array_merge($params, $tparams);
400 if (!empty($countsql)) {
401 $count = $DB->get_record_sql($countsql);
402 $totalinitials = $count->nbresults;
404 $countsql .= ' AND '.$twhere;
406 $count = $DB->get_record_sql($countsql, $params);
407 $total = $count->nbresults;
410 $table->pagesize($pagesize, $total);
412 echo '<div class="quizattemptcounts">';
413 if ( $count->nbresults == $count->nbattempts ) {
414 echo get_string('reportcountattempts','scorm', $count);
415 } else if( $count->nbattempts>0 ) {
416 echo get_string('reportcountallattempts','scorm', $count);
418 echo $count->nbusers.' '.get_string('users');
423 // Fetch the attempts
425 $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params,
426 $table->get_page_start(), $table->get_page_size());
427 echo '<div id="scormtablecontainer">';
430 $strreallydel = addslashes_js(get_string('deleteattemptcheck','scorm'));
431 echo '<form id="attemptsform" method="post" action="' . $reporturlwithdisplayoptions->out(true) .
432 '" onsubmit="return confirm(\''.$strreallydel.'\');">';
433 echo '<input type="hidden" name="action" value="delete"/>';
434 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
435 echo '<div style="display: none;">';
436 echo html_writer::input_hidden_params($reporturlwithdisplayoptions);
440 $table->initialbars($totalinitials>20); // Build table rows
442 $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params);
446 foreach($attempts as $scouser){
448 if (!empty($scouser->attempt)) {
449 $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
451 if (in_array('checkbox', $columns)){
452 if ($candelete && !empty($timetracks->start)) {
453 $row[] = '<input type="checkbox" name="attemptid[]" value="'. $scouser->userid . ':' . $scouser->attempt . '" />';
454 } else if($candelete) {
458 if (in_array('picture', $columns)){
459 $user = (object)array('id'=>$scouser->userid,
460 'picture'=>$scouser->picture,
461 'imagealt'=>$scouser->imagealt,
462 'email'=>$scouser->email,
463 'firstname'=>$scouser->firstname,
464 'lastname'=>$scouser->lastname);
465 $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id));
468 $row[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$scouser->userid.'&course='.$course->id.'">'.fullname($scouser).'</a>';
470 $row[] = fullname($scouser);
472 if (in_array('idnumber', $columns)){
473 $row[] = $scouser->idnumber;
475 if (empty($timetracks->start)) {
481 if (!$download) $row[] = '<a href="report.php?a='.$scorm->id.'&user='.$scouser->userid.'&attempt='.$scouser->attempt.'">'.$scouser->attempt.'</a>';
482 else $row[] = $scouser->attempt;
483 if ($download =='ODS' || $download =='Excel' ) $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
484 else $row[] = userdate($timetracks->start);
485 if ($download =='ODS' || $download =='Excel' ) $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
486 else $row[] = userdate($timetracks->finish);
488 $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
490 // print out all scores of attempt
492 foreach ($scoes as $sco) {
493 if ($sco->launch!='') {
494 if ($trackdata = scorm_get_tracks($sco->id,$scouser->userid,$scouser->attempt)) {
495 if ($trackdata->status == '') {
496 $trackdata->status = 'notattempted';
498 $strstatus = get_string($trackdata->status, 'scorm');
499 // if raw score exists, print it
500 if ($trackdata->score_raw != '') {
501 $score = $trackdata->score_raw;
502 // add max score if it exists
503 if ($scorm->version == 'SCORM_1.3') {
504 $maxkey = 'cmi.score.max';
506 $maxkey = 'cmi.core.score.max';
508 if (isset($trackdata->$maxkey)) {
509 $score .= '/'.$trackdata->$maxkey;
511 // else print out status
516 $row[] = '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" /><br/>
517 <a href="report.php?b='.$sco->id.'&user='.$scouser->userid.'&attempt='.$scouser->attempt.
518 '" title="'.get_string('details','scorm').'">'.$score.'</a>';
523 // if we don't have track data, we haven't attempted yet
524 $strstatus = get_string('notattempted', 'scorm');
526 $row[] = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" /><br/>'.$strstatus;
536 $table->add_data($row);
537 } else if ($download == 'Excel' or $download == 'ODS') {
539 foreach($row as $item){
540 $myxls->write($rownum,$colnum,$item,$format);
544 } else if ($download=='CSV') {
545 $text = implode("\t", $row);
551 echo '<table id="commands">';
553 echo '<a href="javascript:select_all_in(\'DIV\',null,\'scormtablecontainer\');">'.
554 get_string('selectall', 'scorm').'</a> / ';
555 echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'scormtablecontainer\');">'.
556 get_string('selectnone', 'scorm').'</a> ';
558 echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>';
559 echo '</td></tr></table>';
565 if (!empty($attempts)) {
566 echo '<table class="boxaligncenter"><tr>';
568 echo $OUTPUT->single_button(new moodle_url('/mod/scorm/report.php', $pageoptions + $displayoptions + array('download' => 'ODS')), get_string('downloadods'));
571 echo $OUTPUT->single_button(new moodle_url('/mod/scorm/report.php', $pageoptions + $displayoptions + array('download' => 'Excel')), get_string('downloadexcel'));
574 echo $OUTPUT->single_button(new moodle_url('/mod/scorm/report.php', $pageoptions + $displayoptions + array('download' => 'CSV')), get_string('downloadtext'));
578 echo '</tr></table>';
582 $mform->set_data($displayoptions + compact('detailedrep', 'pagesize'));
586 echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
588 if ($download == 'Excel' or $download == 'ODS') {
591 } else if ($download == 'CSV') {
595 echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
600 if ($scoes = $DB->get_records_select('scorm_scoes',"scorm=? ORDER BY id", array($scorm->id))) {
601 if (!empty($userdata)) {
602 echo $OUTPUT->box_start('generalbox boxaligncenter');
603 echo '<div class="mdl-align">'."\n";
604 $userrec = (object)array('id'=>$user);
605 echo $OUTPUT->user_picture($userrec, array('courseid'=>$course->id));
606 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">".
607 "$userdata->firstname $userdata->lastname</a><br />";
608 echo get_string('attempt','scorm').': '.$attempt;
610 echo $OUTPUT->box_end();
612 // Print general score data
613 $table = new html_table();
614 $table->head = array(get_string('title','scorm'),
615 get_string('status','scorm'),
616 get_string('time','scorm'),
617 get_string('score','scorm'),
619 $table->align = array('left', 'center','center','right','left');
620 $table->wrap = array('nowrap', 'nowrap','nowrap','nowrap','nowrap');
621 $table->width = '80%';
622 $table->size = array('*', '*', '*', '*', '*');
623 foreach ($scoes as $sco) {
624 if ($sco->launch!='') {
627 if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) {
628 if ($trackdata->score_raw != '') {
629 $score = $trackdata->score_raw;
631 if ($trackdata->status == '') {
632 $trackdata->status = 'notattempted';
634 $detailslink = '<a href="report.php?b='.$sco->id.'&user='.$user.'&attempt='.$attempt.'" title="'.
635 get_string('details','scorm').'">'.get_string('details','scorm').'</a>';
637 $trackdata->status = 'notattempted';
638 $trackdata->total_time = ' ';
639 $detailslink = ' ';
641 $strstatus = get_string($trackdata->status,'scorm');
642 $row[] = '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.
643 $strstatus.'" /> '.format_string($sco->title);
644 $row[] = get_string($trackdata->status,'scorm');
645 $row[] = scorm_format_duration($trackdata->total_time);
647 $row[] = $detailslink;
649 $row = array(format_string($sco->title), ' ', ' ', ' ', ' ');
651 $table->data[] = $row;
653 echo html_writer::table($table);
657 notice('No users to report');
662 if (!empty($userdata)) {
663 echo $OUTPUT->box_start('generalbox boxaligncenter');
664 //print_heading(format_string($sco->title));
665 echo $OUTPUT->heading('<a href="'.$CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&mode=browse&scoid='.$sco->id.'" target="_new">'.format_string($sco->title).'</a>');
666 echo '<div class="mdl-align">'."\n";
667 $userrec = (object)array('id'=>$user);
668 echo $OUTPUT->user_picture($userrec, array('courseid'=>$course->id));
669 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">".
670 "$userdata->firstname $userdata->lastname</a><br />";
672 if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) {
673 if ($trackdata->score_raw != '') {
674 $scoreview = get_string('score','scorm').': '.$trackdata->score_raw;
676 if ($trackdata->status == '') {
677 $trackdata->status = 'notattempted';
680 $trackdata->status = 'notattempted';
681 $trackdata->total_time = '';
683 $strstatus = get_string($trackdata->status,'scorm');
684 echo '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.
685 $strstatus.'" /> '.scorm_format_duration($trackdata->total_time).'<br />'.$scoreview.'<br />';
687 echo '<hr /><h2>'.get_string('details','scorm').'</h2>';
689 // Print general score data
690 $table = new html_table();
691 $table->head = array(get_string('element','scorm'), get_string('value','scorm'));
692 $table->align = array('left', 'left');
693 $table->wrap = array('nowrap', 'nowrap');
694 $table->width = '100%';
695 $table->size = array('*', '*');
697 $existelements = false;
698 if ($scorm->version == 'SCORM_1.3') {
699 $elements = array('raw' => 'cmi.score.raw',
700 'min' => 'cmi.score.min',
701 'max' => 'cmi.score.max',
702 'status' => 'cmi.completion_status',
703 'time' => 'cmi.total_time');
705 $elements = array('raw' => 'cmi.core.score.raw',
706 'min' => 'cmi.core.score.min',
707 'max' => 'cmi.core.score.max',
708 'status' => 'cmi.core.lesson_status',
709 'time' => 'cmi.core.total_time');
711 $printedelements = array();
712 foreach ($elements as $key => $element) {
713 if (isset($trackdata->$element)) {
714 $existelements = true;
715 $printedelements[]=$element;
717 $row[] = get_string($key,'scorm');
723 $row[] = s(scorm_format_duration($trackdata->$element));
726 s($trackdata->$element);
729 $table->data[] = $row;
732 if ($existelements) {
733 echo '<h3>'.get_string('general','scorm').'</h3>';
734 echo html_writer::table($table);
737 // Print Interactions data
738 $table = new html_table();
739 $table->head = array(get_string('identifier','scorm'),
740 get_string('type','scorm'),
741 get_string('result','scorm'),
742 get_string('student_response','scorm'));
743 $table->align = array('center', 'center', 'center', 'center');
744 $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap');
745 $table->width = '100%';
746 $table->size = array('*', '*', '*', '*', '*');
748 $existinteraction = false;
751 $interactionid = 'cmi.interactions.'.$i.'.id';
753 while (isset($trackdata->$interactionid)) {
754 $existinteraction = true;
755 $printedelements[]=$interactionid;
756 $elements = array($interactionid,
757 'cmi.interactions.'.$i.'.type',
758 'cmi.interactions.'.$i.'.result',
759 'cmi.interactions.'.$i.'.learner_response');
761 foreach ($elements as $element) {
762 if (isset($trackdata->$element)) {
763 $row[] = s($trackdata->$element);
764 $printedelements[]=$element;
769 $table->data[] = $row;
772 $interactionid = 'cmi.interactions.'.$i.'.id';
774 if ($existinteraction) {
775 echo '<h3>'.get_string('interactions','scorm').'</h3>';
776 echo html_writer::table($table);
779 // Print Objectives data
780 $table = new html_table();
781 $table->head = array(get_string('identifier','scorm'),
782 get_string('status','scorm'),
783 get_string('raw','scorm'),
784 get_string('min','scorm'),
785 get_string('max','scorm'));
786 $table->align = array('center', 'center', 'center', 'center', 'center');
787 $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
788 $table->width = '100%';
789 $table->size = array('*', '*', '*', '*', '*');
791 $existobjective = false;
794 $objectiveid = 'cmi.objectives.'.$i.'.id';
796 while (isset($trackdata->$objectiveid)) {
797 $existobjective = true;
798 $printedelements[]=$objectiveid;
799 $elements = array($objectiveid,
800 'cmi.objectives.'.$i.'.status',
801 'cmi.objectives.'.$i.'.score.raw',
802 'cmi.objectives.'.$i.'.score.min',
803 'cmi.objectives.'.$i.'.score.max');
805 foreach ($elements as $element) {
806 if (isset($trackdata->$element)) {
807 $row[] = s($trackdata->$element);
808 $printedelements[]=$element;
813 $table->data[] = $row;
816 $objectiveid = 'cmi.objectives.'.$i.'.id';
818 if ($existobjective) {
819 echo '<h3>'.get_string('objectives','scorm').'</h3>';
820 echo html_writer::table($table);
822 $table = new html_table();
823 $table->head = array(get_string('element','scorm'), get_string('value','scorm'));
824 $table->align = array('left', 'left');
825 $table->wrap = array('nowrap', 'wrap');
826 $table->width = '100%';
827 $table->size = array('*', '*');
829 $existelements = false;
831 foreach($trackdata as $element => $value) {
832 if (substr($element,0,3) == 'cmi') {
833 if (!(in_array ($element, $printedelements))) {
834 $existelements = true;
836 $row[] = get_string($element,'scorm') != '[['.$element.']]' ? get_string($element,'scorm') : $element;
837 if (strpos($element, '_time') === false) {
840 $row[] = s(scorm_format_duration($value));
842 $table->data[] = $row;
846 if ($existelements) {
847 echo '<h3>'.get_string('othertracks','scorm').'</h3>';
848 echo html_writer::table($table);
850 echo $OUTPUT->box_end();
852 print_error('missingparameter');
857 if (empty($noheader)) {
858 echo $OUTPUT->footer();