Added _ to version data element
[moodle.git] / mod / scorm / loadSCO.php
CommitLineData
03f5a0f8 1<?php
2 require_once("../../config.php");
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)) {
11 error("Course Module ID was incorrect");
12 }
13 if (! $course = get_record("course", "id", $cm->course)) {
14 error("Course is misconfigured");
15 }
16 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
17 error("Course module is incorrect");
18 }
19 } else if (!empty($a)) {
20 if (! $scorm = get_record("scorm", "id", $a)) {
21 error("Course module is incorrect");
22 }
23 if (! $course = get_record("course", "id", $scorm->course)) {
24 error("Course is misconfigured");
25 }
26 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
27 error("Course Module ID was incorrect");
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 //
38 if ($sco = get_record("scorm_scoes","id",$scoid)) {
39 if ($sco->launch == '') {
40 // Search for the next launchable sco
41 if ($scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' AND id>".$sco->id,"id ASC")) {
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)) {
51 $scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>''","id ASC");
52 $sco = current($scoes);
53 }
54
55 //
56 // Forge SCO URL
57 //
58 $connector = '';
59 $version = substr($scorm->version,0,4);
60 if (!empty($sco->parameters) || ($version == 'AICC')) {
61 if (stripos($sco->launch,'?') !== false) {
62 $connector = '&';
63 } else {
64 $connector = '?';
65 }
66 if (!empty($sco->parameters) && ($sco->parameters[0] == '?')) {
67 $sco->parameters = substr($sco->parameters,1);
68 }
69 }
70
71 if ($version == 'AICC') {
72 if (!empty($sco->parameters)) {
73 $sco->parameters = '&'. $sco->parameters;
74 }
75 $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/type/aicc/aicc.php'.$sco->parameters;
76 } else {
77 $launcher = $sco->launch.$connector.$sco->parameters;
78 }
79
80 if (scorm_external_link($sco->launch)) {
81 $result = $launcher;
82 } else if ($scorm->reference[0] == '#') {
83 require_once($repositoryconfigfile);
84 $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
85 } else {
86 if (basename($scorm->reference) == 'imsmanifest.xml') {
87 $basedir = dirname($scorm->reference);
88 } else {
89 $basedir = 'moddata/scorm/'.$scorm->id;
90 }
91 if ($CFG->slasharguments) {
92 $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
93 } else {
94 $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;
95 }
96 }
97?>
98<html>
99 <head>
100 <title>LoadSCO</title>
101 <script language="javascript" type="text/javascript">
102 <!--
103 setTimeout('document.location = "<?php echo $result ?>";',2000);
104 -->
105 </script>
106 <noscript>
107 <meta http-equiv="refresh" content="2;url=<?php echo $result ?>" />
108 </noscript>
109 </head>
110 <body>
111 &nbsp;
112 </body>
113</html>