MDL-16163 disable mnet scripts properly if mnet not enabled
[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
8949f8df 9 $delayseconds = 2; // Delay time before sco launch, used to give time to browser to define API
10
03f5a0f8 11 if (!empty($id)) {
12 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
08b56f93 13 print_error('invalidcoursemodule');
03f5a0f8 14 }
bf347041 15 if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
08b56f93 16 print_error('coursemisconf');
03f5a0f8 17 }
bf347041 18 if (! $scorm = $DB->get_record('scorm', array('id'=>$cm->instance))) {
08b56f93 19 print_error('invalidcoursemodule');
03f5a0f8 20 }
21 } else if (!empty($a)) {
bf347041 22 if (! $scorm = $DB->get_record('scorm', array('id'=>$a))) {
08b56f93 23 print_error('coursemisconf');
03f5a0f8 24 }
bf347041 25 if (! $course = $DB->get_record('course', array('id'=>$scorm->course))) {
08b56f93 26 print_error('coursemisconf');
03f5a0f8 27 }
b3659259 28 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
08b56f93 29 print_error('invalidcoursemodule');
03f5a0f8 30 }
31 } else {
08b56f93 32 print_error('missingparameter');
03f5a0f8 33 }
34
35 require_login($course->id, false, $cm);
36 if (!empty($scoid)) {
37 //
38 // Direct SCO request
39 //
b3659259 40 if ($sco = scorm_get_sco($scoid)) {
03f5a0f8 41 if ($sco->launch == '') {
42 // Search for the next launchable sco
6280b17a 43 if ($scoes = $DB->get_records_select('scorm_scoes',"scorm = ? AND launch <> ? AND id > ?",array($scorm->id, '', $sco->id), 'id ASC')) {
03f5a0f8 44 $sco = current($scoes);
45 }
46 }
47 }
48 }
49 //
50 // If no sco was found get the first of SCORM package
51 //
52 if (!isset($sco)) {
6280b17a 53 $scoes = $DB->get_records_select('scorm_scoes',"scorm = ? AND launch <> ?", array($scorm->id, ''),'id ASC');
03f5a0f8 54 $sco = current($scoes);
55 }
56
3c6c4eaf 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);
62 }
63
03f5a0f8 64 //
65 // Forge SCO URL
66 //
67 $connector = '';
68 $version = substr($scorm->version,0,4);
b3659259 69 if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) {
03f5a0f8 70 if (stripos($sco->launch,'?') !== false) {
71 $connector = '&';
72 } else {
73 $connector = '?';
74 }
b3659259 75 if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) {
03f5a0f8 76 $sco->parameters = substr($sco->parameters,1);
77 }
78 }
79
80 if ($version == 'AICC') {
b3659259 81 if (isset($sco->parameters) && (!empty($sco->parameters))) {
03f5a0f8 82 $sco->parameters = '&'. $sco->parameters;
83 }
3c6c4eaf 84 $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters;
03f5a0f8 85 } else {
b3659259 86 if (isset($sco->parameters) && (!empty($sco->parameters))) {
87 $launcher = $sco->launch.$connector.$sco->parameters;
88 } else {
89 $launcher = $sco->launch;
90 }
03f5a0f8 91 }
92
93 if (scorm_external_link($sco->launch)) {
8949f8df 94 // Remote learning activity
03f5a0f8 95 $result = $launcher;
96 } else if ($scorm->reference[0] == '#') {
8949f8df 97 // Repository
03f5a0f8 98 $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
99 } else {
8949f8df 100 if ((basename($scorm->reference) == 'imsmanifest.xml') && scorm_external_link($scorm->reference)) {
101 // Remote manifest
102 $result = dirname($scorm->reference).'/'.$launcher;
03f5a0f8 103 } else {
8949f8df 104 // Moodle internal package/manifest or remote (auto-imported) package
105 if (basename($scorm->reference) == 'imsmanifest.xml') {
106 $basedir = dirname($scorm->reference);
107 } else {
108 $basedir = $CFG->moddata.'/scorm/'.$scorm->id;
109 }
b8dddc9e 110 //note: do not convert this to use get_file_url()!
111 // SCORM does not work without slasharguments anyway and there might be some extra ?xx=yy params
112 // see MDL-16060
113 $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
03f5a0f8 114 }
115 }
e4f781c9 116
117 $scormpixdir = $CFG->modpixpath.'/scorm/pix';
03f5a0f8 118?>
119<html>
120 <head>
121 <title>LoadSCO</title>
f4ba7e1a 122 <script type="text/javascript">
123 //<![CDATA[
e4f781c9 124 function doredirect() {
125 var e = document.getElementById("countdown");
126 var cSeconds = parseInt(e.innerHTML);
127 var timer = setInterval(function() {
128 if( cSeconds ) {
129 e.innerHTML = --cSeconds;
130 } else {
131 clearInterval(timer);
320f3aab 132 document.body.innerHTML = "<?php echo get_string('activitypleasewait', 'scorm');?>";
e4f781c9 133 location = "<?php echo $result ?>";
134 }
135 }, 1000);
136 }
137 //]]>
03f5a0f8 138 </script>
139 <noscript>
8949f8df 140 <meta http-equiv="refresh" content="<?php echo $delayseconds ?>;url=<?php echo $result ?>" />
03f5a0f8 141 </noscript>
142 </head>
e4f781c9 143 <body onload="doredirect();">
476c00cb 144 <p><?php echo get_string('activityloading', 'scorm');?> <span id="countdown"><?php echo $delayseconds ?></span> <?php echo get_string('numseconds');?>. &nbsp; <img src='<?php echo $scormpixdir;?>/wait.gif'><p>
1eb6604e 145 <?php if (debugging('',DEBUG_DEVELOPER)) {
146 add_to_log($course->id, 'scorm', 'launch', 'view.php?id='.$cm->id, $result, $cm->id);
147 }
148 ?>
e4f781c9 149 </body>
03f5a0f8 150</html>