more fixes for lockoptions behaviour; changes to forum/mod_form.php; removed forum...
[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
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);
67 if (!empty($sco->parameters) || ($version == 'AICC')) {
68 if (stripos($sco->launch,'?') !== false) {
69 $connector = '&';
70 } else {
71 $connector = '?';
72 }
73 if (!empty($sco->parameters) && ($sco->parameters[0] == '?')) {
74 $sco->parameters = substr($sco->parameters,1);
75 }
76 }
77
78 if ($version == 'AICC') {
79 if (!empty($sco->parameters)) {
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 {
84 $launcher = $sco->launch.$connector.$sco->parameters;
85 }
86
87 if (scorm_external_link($sco->launch)) {
88 $result = $launcher;
89 } else if ($scorm->reference[0] == '#') {
90 require_once($repositoryconfigfile);
91 $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
92 } else {
93 if (basename($scorm->reference) == 'imsmanifest.xml') {
94 $basedir = dirname($scorm->reference);
95 } else {
96 $basedir = 'moddata/scorm/'.$scorm->id;
97 }
98 if ($CFG->slasharguments) {
99 $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
100 } else {
101 $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;
102 }
103 }
104?>
105<html>
106 <head>
107 <title>LoadSCO</title>
108 <script language="javascript" type="text/javascript">
109 <!--
110 setTimeout('document.location = "<?php echo $result ?>";',2000);
111 -->
112 </script>
113 <noscript>
114 <meta http-equiv="refresh" content="2;url=<?php echo $result ?>" />
115 </noscript>
116 </head>
117 <body>
118 &nbsp;
119 </body>
120</html>