Fix for reopened bug MDL-6685, "Arrows on course roles screen are displaying as squares"
[moodle.git] / mod / scorm / loadSCO.php
CommitLineData
f4ba7e1a 1<?php // $Id$
b3659259 2 require_once('../../config.php');
03f5a0f8 3 require_once('locallib.php');
4
5 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
6 $a = optional_param('a', '', PARAM_INT); // scorm ID
7 $scoid = required_param('scoid', PARAM_INT); // sco ID
8
9 if (!empty($id)) {
10 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
b3659259 11 error('Course Module ID was incorrect');
03f5a0f8 12 }
b3659259 13 if (! $course = get_record('course', 'id', $cm->course)) {
14 error('Course is misconfigured');
03f5a0f8 15 }
b3659259 16 if (! $scorm = get_record('scorm', 'id', $cm->instance)) {
17 error('Course module is incorrect');
03f5a0f8 18 }
19 } else if (!empty($a)) {
b3659259 20 if (! $scorm = get_record('scorm', 'id', $a)) {
21 error('Course module is incorrect');
03f5a0f8 22 }
b3659259 23 if (! $course = get_record('course', 'id', $scorm->course)) {
24 error('Course is misconfigured');
03f5a0f8 25 }
b3659259 26 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
27 error('Course Module ID was incorrect');
03f5a0f8 28 }
29 } else {
30 error('A required parameter is missing');
31 }
32
33 require_login($course->id, false, $cm);
34 if (!empty($scoid)) {
35 //
36 // Direct SCO request
37 //
b3659259 38 if ($sco = scorm_get_sco($scoid)) {
03f5a0f8 39 if ($sco->launch == '') {
40 // Search for the next launchable sco
b3659259 41 if ($scoes = get_records_select('scorm_scoes','scorm='.$scorm->id." AND launch<>'' AND id>".$sco->id,'id ASC')) {
03f5a0f8 42 $sco = current($scoes);
43 }
44 }
45 }
46 }
47 //
48 // If no sco was found get the first of SCORM package
49 //
50 if (!isset($sco)) {
b3659259 51 $scoes = get_records_select('scorm_scoes','scorm='.$scorm->id." AND launch<>''",'id ASC');
03f5a0f8 52 $sco = current($scoes);
53 }
54
3c6c4eaf 55 if ($sco->scormtype == 'asset') {
56 $attempt = scorm_get_last_attempt($scorm->id,$USER->id);
57 $element = $scorm->version == 'scorm_13'?'cmi.completion_status':'cmi.core.lesson_status';
58 $value = 'completed';
59 $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
60 }
61
03f5a0f8 62 //
63 // Forge SCO URL
64 //
65 $connector = '';
66 $version = substr($scorm->version,0,4);
b3659259 67 if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) {
03f5a0f8 68 if (stripos($sco->launch,'?') !== false) {
69 $connector = '&';
70 } else {
71 $connector = '?';
72 }
b3659259 73 if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) {
03f5a0f8 74 $sco->parameters = substr($sco->parameters,1);
75 }
76 }
77
78 if ($version == 'AICC') {
b3659259 79 if (isset($sco->parameters) && (!empty($sco->parameters))) {
03f5a0f8 80 $sco->parameters = '&'. $sco->parameters;
81 }
3c6c4eaf 82 $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters;
03f5a0f8 83 } else {
b3659259 84 if (isset($sco->parameters) && (!empty($sco->parameters))) {
85 $launcher = $sco->launch.$connector.$sco->parameters;
86 } else {
87 $launcher = $sco->launch;
88 }
03f5a0f8 89 }
90
91 if (scorm_external_link($sco->launch)) {
92 $result = $launcher;
93 } else if ($scorm->reference[0] == '#') {
94 require_once($repositoryconfigfile);
95 $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
96 } else {
97 if (basename($scorm->reference) == 'imsmanifest.xml') {
5297c819 98 $basedir = scorm_dirname($scorm->reference);
03f5a0f8 99 } else {
100 $basedir = 'moddata/scorm/'.$scorm->id;
101 }
102 if ($CFG->slasharguments) {
103 $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
104 } else {
105 $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;
106 }
107 }
108?>
109<html>
110 <head>
111 <title>LoadSCO</title>
f4ba7e1a 112 <script type="text/javascript">
113 //<![CDATA[
03f5a0f8 114 setTimeout('document.location = "<?php echo $result ?>";',2000);
f4ba7e1a 115 //]]>
03f5a0f8 116 </script>
117 <noscript>
118 <meta http-equiv="refresh" content="2;url=<?php echo $result ?>" />
119 </noscript>
120 </head>
121 <body>
122 &nbsp;
123 </body>
124</html>