MDL-10910 Corrected two errors committed while fixing MDL-10870
[moodle-pu.git] / mod / scorm / loadSCO.php
blobfb3804656ff55813a148dc45f156434eccbabe18
1 <?php // $Id$
2 require_once('../../config.php');
3 require_once('locallib.php');
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
9 $delayseconds = 2; // Delay time before sco launch, used to give time to browser to define API
11 if (!empty($id)) {
12 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
13 error('Course Module ID was incorrect');
15 if (! $course = get_record('course', 'id', $cm->course)) {
16 error('Course is misconfigured');
18 if (! $scorm = get_record('scorm', 'id', $cm->instance)) {
19 error('Course module is incorrect');
21 } else if (!empty($a)) {
22 if (! $scorm = get_record('scorm', 'id', $a)) {
23 error('Course module is incorrect');
25 if (! $course = get_record('course', 'id', $scorm->course)) {
26 error('Course is misconfigured');
28 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
29 error('Course Module ID was incorrect');
31 } else {
32 error('A required parameter is missing');
35 require_login($course->id, false, $cm);
36 if (!empty($scoid)) {
38 // Direct SCO request
40 if ($sco = scorm_get_sco($scoid)) {
41 if ($sco->launch == '') {
42 // Search for the next launchable sco
43 if ($scoes = get_records_select('scorm_scoes','scorm='.$scorm->id." AND launch<>'' AND id>".$sco->id,'id ASC')) {
44 $sco = current($scoes);
50 // If no sco was found get the first of SCORM package
52 if (!isset($sco)) {
53 $scoes = get_records_select('scorm_scoes','scorm='.$scorm->id." AND launch<>''",'id ASC');
54 $sco = current($scoes);
57 if ($sco->scormtype == 'asset') {
58 $attempt = scorm_get_last_attempt($scorm->id,$USER->id);
59 $element = $scorm->version == 'scorm_13'?'cmi.completion_status':'cmi.core.lesson_status';
60 $value = 'completed';
61 $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
65 // Forge SCO URL
67 $connector = '';
68 $version = substr($scorm->version,0,4);
69 if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) {
70 if (stripos($sco->launch,'?') !== false) {
71 $connector = '&';
72 } else {
73 $connector = '?';
75 if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) {
76 $sco->parameters = substr($sco->parameters,1);
80 if ($version == 'AICC') {
81 if (isset($sco->parameters) && (!empty($sco->parameters))) {
82 $sco->parameters = '&'. $sco->parameters;
84 $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters;
85 } else {
86 if (isset($sco->parameters) && (!empty($sco->parameters))) {
87 $launcher = $sco->launch.$connector.$sco->parameters;
88 } else {
89 $launcher = $sco->launch;
93 if (scorm_external_link($sco->launch)) {
94 // Remote learning activity
95 $result = $launcher;
96 } else if ($scorm->reference[0] == '#') {
97 // Repository
98 require_once($repositoryconfigfile);
99 $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
100 } else {
101 if ((basename($scorm->reference) == 'imsmanifest.xml') && scorm_external_link($scorm->reference)) {
102 // Remote manifest
103 $result = dirname($scorm->reference).'/'.$launcher;
104 } else {
105 // Moodle internal package/manifest or remote (auto-imported) package
106 if (basename($scorm->reference) == 'imsmanifest.xml') {
107 $basedir = dirname($scorm->reference);
108 } else {
109 $basedir = $CFG->moddata.'/scorm/'.$scorm->id;
111 if ($CFG->slasharguments) {
112 $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
113 } else {
114 $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;
119 <html>
120 <head>
121 <title>LoadSCO</title>
122 <script type="text/javascript">
123 //<![CDATA[
124 setTimeout('document.location = "<?php echo $result ?>";',<?php echo $delayseconds ?>000);
125 //]]>
126 </script>
127 <noscript>
128 <meta http-equiv="refresh" content="<?php echo $delayseconds ?>;url=<?php echo $result ?>" />
129 </noscript>
130 </head>
131 <body>
132 &nbsp;
133 </body>
134 </html>