5c508e3f |
1 | <?php |
b3659259 |
2 | require_once('../../config.php'); |
86996ffe |
3 | require_once($CFG->dirroot.'/mod/scorm/locallib.php'); |
03f5a0f8 |
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 | |
a6855934 |
35 | $PAGE->set_url('/mod/scorm/loadSCO.php', array('scoid'=>$scoid, 'id'=>$cm->id)); |
5c508e3f |
36 | |
03f5a0f8 |
37 | require_login($course->id, false, $cm); |
f2c86f94 |
38 | |
d54e2145 |
39 | //check if scorm closed |
40 | $timenow = time(); |
41 | if ($scorm->timeclose !=0) { |
42 | if ($scorm->timeopen > $timenow) { |
60e40dda |
43 | print_error('notopenyet', 'scorm', null, userdate($scorm->timeopen)); |
d54e2145 |
44 | } else if ($timenow > $scorm->timeclose) { |
60e40dda |
45 | print_error('expired', 'scorm', null, userdate($scorm->timeclose)); |
d54e2145 |
46 | } |
47 | } |
f2c86f94 |
48 | |
9528568b |
49 | $context = get_context_instance(CONTEXT_MODULE, $cm->id); |
50 | |
03f5a0f8 |
51 | if (!empty($scoid)) { |
52 | // |
53 | // Direct SCO request |
54 | // |
b3659259 |
55 | if ($sco = scorm_get_sco($scoid)) { |
03f5a0f8 |
56 | if ($sco->launch == '') { |
57 | // Search for the next launchable sco |
5b4b959b |
58 | if ($scoes = $DB->get_records_select('scorm_scoes',"scorm = ? AND launch <> ? AND id > ?",array($scorm->id, $DB->sql_empty(), $sco->id), 'id ASC')) { |
03f5a0f8 |
59 | $sco = current($scoes); |
60 | } |
61 | } |
62 | } |
63 | } |
64 | // |
65 | // If no sco was found get the first of SCORM package |
66 | // |
67 | if (!isset($sco)) { |
5b4b959b |
68 | $scoes = $DB->get_records_select('scorm_scoes',"scorm = ? AND launch <> ?", array($scorm->id, $DB->sql_empty()),'id ASC'); |
03f5a0f8 |
69 | $sco = current($scoes); |
70 | } |
71 | |
3c6c4eaf |
72 | if ($sco->scormtype == 'asset') { |
73 | $attempt = scorm_get_last_attempt($scorm->id,$USER->id); |
f2c86f94 |
74 | $element = ($scorm->version == 'scorm_13' || $scorm->version == 'SCORM_1.3') ? 'cmi.completion_status':'cmi.core.lesson_status'; |
3c6c4eaf |
75 | $value = 'completed'; |
76 | $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); |
77 | } |
9528568b |
78 | |
03f5a0f8 |
79 | // |
80 | // Forge SCO URL |
81 | // |
82 | $connector = ''; |
83 | $version = substr($scorm->version,0,4); |
b3659259 |
84 | if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) { |
03f5a0f8 |
85 | if (stripos($sco->launch,'?') !== false) { |
86 | $connector = '&'; |
87 | } else { |
88 | $connector = '?'; |
89 | } |
b3659259 |
90 | if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) { |
03f5a0f8 |
91 | $sco->parameters = substr($sco->parameters,1); |
92 | } |
93 | } |
9528568b |
94 | |
03f5a0f8 |
95 | if ($version == 'AICC') { |
5eaf56b8 |
96 | $sco_params = ''; |
b3659259 |
97 | if (isset($sco->parameters) && (!empty($sco->parameters))) { |
5eaf56b8 |
98 | $sco_params = '&'. $sco->parameters; |
03f5a0f8 |
99 | } |
5eaf56b8 |
100 | $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco_params; |
03f5a0f8 |
101 | } else { |
b3659259 |
102 | if (isset($sco->parameters) && (!empty($sco->parameters))) { |
103 | $launcher = $sco->launch.$connector.$sco->parameters; |
104 | } else { |
105 | $launcher = $sco->launch; |
106 | } |
03f5a0f8 |
107 | } |
9528568b |
108 | |
03f5a0f8 |
109 | if (scorm_external_link($sco->launch)) { |
9528568b |
110 | //TODO: does this happen? |
03f5a0f8 |
111 | $result = $launcher; |
9528568b |
112 | |
113 | } else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL) { |
114 | // Remote learning activity |
115 | $result = dirname($scorm->reference).'/'.$launcher; |
116 | |
117 | } else if ($scorm->scormtype === SCORM_TYPE_IMSREPOSITORY) { |
8949f8df |
118 | // Repository |
9528568b |
119 | $result = $CFG->repositorywebroot.substr($scorm->reference, 1).'/'.$sco->launch; |
120 | |
121 | } else if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) { |
122 | //note: do not convert this to use get_file_url()! |
123 | // SCORM does not work without slasharguments anyway and there might be some extra ?xx=yy params |
124 | // see MDL-16060 |
125 | $result = "$CFG->wwwroot/pluginfile.php/$context->id/scorm_content/$scorm->revision/$launcher"; |
03f5a0f8 |
126 | } |
9528568b |
127 | |
f2c86f94 |
128 | // which API are we looking for |
129 | $LMS_api = ($scorm->version == 'scorm_12' || $scorm->version == 'SCORM_1.2' || empty($scorm->version)) ? 'API' : 'API_1484_11'; |
03f5a0f8 |
130 | ?> |
131 | <html> |
132 | <head> |
133 | <title>LoadSCO</title> |
f4ba7e1a |
134 | <script type="text/javascript"> |
135 | //<![CDATA[ |
f2c86f94 |
136 | var apiHandle = null; |
137 | var findAPITries = 0; |
138 | |
139 | function getAPIHandle() { |
140 | if (apiHandle == null) { |
141 | apiHandle = getAPI(); |
142 | } |
143 | return apiHandle; |
144 | } |
145 | |
146 | function findAPI(win) { |
46e58e80 |
147 | while ((win.<?php echo $LMS_api; ?> == null) && (win.parent != null) && (win.parent != win)) { |
f2c86f94 |
148 | findAPITries++; |
149 | // Note: 7 is an arbitrary number, but should be more than sufficient |
150 | if (findAPITries > 7) { |
151 | return null; |
152 | } |
153 | win = win.parent; |
154 | } |
46e58e80 |
155 | return win.<?php echo $LMS_api; ?>; |
f2c86f94 |
156 | } |
157 | |
158 | // hun for the API - needs to be loaded before we can launch the package |
159 | function getAPI() { |
160 | var theAPI = findAPI(window); |
161 | if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) { |
162 | theAPI = findAPI(window.opener); |
163 | } |
164 | if (theAPI == null) { |
165 | return null; |
166 | } |
167 | return theAPI; |
168 | } |
169 | |
170 | function doredirect() { |
171 | if (getAPI() != null) { |
172 | location = "<?php echo $result ?>"; |
173 | } |
174 | else { |
b5d0cafc |
175 | document.body.innerHTML = "<p><?php echo get_string('activityloading', 'scorm');?> <span id='countdown'><?php echo $delayseconds ?></span> <?php echo get_string('numseconds');?>. <img src='<?php echo $OUTPUT->pix_url('pix/wait', 'scorm') ?>'><p>"; |
f2c86f94 |
176 | var e = document.getElementById("countdown"); |
177 | var cSeconds = parseInt(e.innerHTML); |
178 | var timer = setInterval(function() { |
179 | if( cSeconds && getAPI() == null ) { |
180 | e.innerHTML = --cSeconds; |
181 | } else { |
182 | clearInterval(timer); |
183 | document.body.innerHTML = "<p><?php echo get_string('activitypleasewait', 'scorm');?></p>"; |
184 | location = "<?php echo $result ?>"; |
185 | } |
186 | }, 1000); |
187 | } |
e4f781c9 |
188 | } |
9528568b |
189 | //]]> |
03f5a0f8 |
190 | </script> |
191 | <noscript> |
86ed86b8 |
192 | <meta http-equiv="refresh" content="0;url=<?php echo $result ?>" /> |
9528568b |
193 | </noscript> |
03f5a0f8 |
194 | </head> |
e4f781c9 |
195 | <body onload="doredirect();"> |
f2c86f94 |
196 | <p><?php echo get_string('activitypleasewait', 'scorm');?></p> |
197 | <?php if (debugging('',DEBUG_DEVELOPER)) { |
1eb6604e |
198 | add_to_log($course->id, 'scorm', 'launch', 'view.php?id='.$cm->id, $result, $cm->id); |
199 | } |
200 | ?> |
9528568b |
201 | </body> |
60e40dda |
202 | </html> |