MDL-16108 force autocomplete off for unmaskable password fields; merged from MOODLE_1...
[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 require_once($repositoryconfigfile);
99 $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
100 } else {
8949f8df 101 if ((basename($scorm->reference) == 'imsmanifest.xml') && scorm_external_link($scorm->reference)) {
102 // Remote manifest
103 $result = dirname($scorm->reference).'/'.$launcher;
03f5a0f8 104 } else {
8949f8df 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;
110 }
5a254a29 111 require_once($CFG->libdir.'/filelib.php');
112 $result = get_file_url($scorm->course .'/'. $basedir .'/'. $launcher);
03f5a0f8 113 }
114 }
e4f781c9 115
116 $scormpixdir = $CFG->modpixpath.'/scorm/pix';
03f5a0f8 117?>
118<html>
119 <head>
120 <title>LoadSCO</title>
f4ba7e1a 121 <script type="text/javascript">
122 //<![CDATA[
e4f781c9 123 function doredirect() {
124 var e = document.getElementById("countdown");
125 var cSeconds = parseInt(e.innerHTML);
126 var timer = setInterval(function() {
127 if( cSeconds ) {
128 e.innerHTML = --cSeconds;
129 } else {
130 clearInterval(timer);
320f3aab 131 document.body.innerHTML = "<?php echo get_string('activitypleasewait', 'scorm');?>";
e4f781c9 132 location = "<?php echo $result ?>";
133 }
134 }, 1000);
135 }
136 //]]>
03f5a0f8 137 </script>
138 <noscript>
8949f8df 139 <meta http-equiv="refresh" content="<?php echo $delayseconds ?>;url=<?php echo $result ?>" />
03f5a0f8 140 </noscript>
141 </head>
e4f781c9 142 <body onload="doredirect();">
476c00cb 143 <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>
e4f781c9 144 </body>
03f5a0f8 145</html>