MDL-17436 fixed pg issue with char <> num comparison
[moodle.git] / mod / scorm / loadSCO.php
CommitLineData
f4ba7e1a 1<?php // $Id$
b3659259 2 require_once('../../config.php');
03f5a0f8 3 require_once('locallib.php');
4
9528568b 5 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
6 $a = optional_param('a', '', PARAM_INT); // scorm ID
03f5a0f8 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);
9528568b 36
37 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
38
03f5a0f8 39 if (!empty($scoid)) {
40 //
41 // Direct SCO request
42 //
b3659259 43 if ($sco = scorm_get_sco($scoid)) {
03f5a0f8 44 if ($sco->launch == '') {
45 // Search for the next launchable sco
5b4b959b 46 if ($scoes = $DB->get_records_select('scorm_scoes',"scorm = ? AND launch <> ? AND id > ?",array($scorm->id, $DB->sql_empty(), $sco->id), 'id ASC')) {
03f5a0f8 47 $sco = current($scoes);
48 }
49 }
50 }
51 }
52 //
53 // If no sco was found get the first of SCORM package
54 //
55 if (!isset($sco)) {
5b4b959b 56 $scoes = $DB->get_records_select('scorm_scoes',"scorm = ? AND launch <> ?", array($scorm->id, $DB->sql_empty()),'id ASC');
03f5a0f8 57 $sco = current($scoes);
58 }
59
3c6c4eaf 60 if ($sco->scormtype == 'asset') {
61 $attempt = scorm_get_last_attempt($scorm->id,$USER->id);
62 $element = $scorm->version == 'scorm_13'?'cmi.completion_status':'cmi.core.lesson_status';
63 $value = 'completed';
64 $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
65 }
9528568b 66
03f5a0f8 67 //
68 // Forge SCO URL
69 //
70 $connector = '';
71 $version = substr($scorm->version,0,4);
b3659259 72 if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) {
03f5a0f8 73 if (stripos($sco->launch,'?') !== false) {
74 $connector = '&';
75 } else {
76 $connector = '?';
77 }
b3659259 78 if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) {
03f5a0f8 79 $sco->parameters = substr($sco->parameters,1);
80 }
81 }
9528568b 82
03f5a0f8 83 if ($version == 'AICC') {
b3659259 84 if (isset($sco->parameters) && (!empty($sco->parameters))) {
03f5a0f8 85 $sco->parameters = '&'. $sco->parameters;
86 }
3c6c4eaf 87 $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters;
03f5a0f8 88 } else {
b3659259 89 if (isset($sco->parameters) && (!empty($sco->parameters))) {
90 $launcher = $sco->launch.$connector.$sco->parameters;
91 } else {
92 $launcher = $sco->launch;
93 }
03f5a0f8 94 }
9528568b 95
03f5a0f8 96 if (scorm_external_link($sco->launch)) {
9528568b 97 //TODO: does this happen?
03f5a0f8 98 $result = $launcher;
9528568b 99
100 } else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL) {
101 // Remote learning activity
102 $result = dirname($scorm->reference).'/'.$launcher;
103
104 } else if ($scorm->scormtype === SCORM_TYPE_IMSREPOSITORY) {
8949f8df 105 // Repository
9528568b 106 $result = $CFG->repositorywebroot.substr($scorm->reference, 1).'/'.$sco->launch;
107
108 } else if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) {
109 //note: do not convert this to use get_file_url()!
110 // SCORM does not work without slasharguments anyway and there might be some extra ?xx=yy params
111 // see MDL-16060
112 $result = "$CFG->wwwroot/pluginfile.php/$context->id/scorm_content/$scorm->revision/$launcher";
03f5a0f8 113 }
9528568b 114
e4f781c9 115 $scormpixdir = $CFG->modpixpath.'/scorm/pix';
03f5a0f8 116?>
117<html>
118 <head>
119 <title>LoadSCO</title>
f4ba7e1a 120 <script type="text/javascript">
121 //<![CDATA[
e4f781c9 122 function doredirect() {
123 var e = document.getElementById("countdown");
124 var cSeconds = parseInt(e.innerHTML);
125 var timer = setInterval(function() {
126 if( cSeconds ) {
127 e.innerHTML = --cSeconds;
128 } else {
129 clearInterval(timer);
320f3aab 130 document.body.innerHTML = "<?php echo get_string('activitypleasewait', 'scorm');?>";
e4f781c9 131 location = "<?php echo $result ?>";
132 }
133 }, 1000);
134 }
9528568b 135 //]]>
03f5a0f8 136 </script>
137 <noscript>
86ed86b8 138 <meta http-equiv="refresh" content="0;url=<?php echo $result ?>" />
9528568b 139 </noscript>
03f5a0f8 140 </head>
e4f781c9 141 <body onload="doredirect();">
476c00cb 142 <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>
1881df27 143 <?php if (scorm_debugging($scorm)) {
1eb6604e 144 add_to_log($course->id, 'scorm', 'launch', 'view.php?id='.$cm->id, $result, $cm->id);
145 }
146 ?>
9528568b 147 </body>
03f5a0f8 148</html>