[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 require_once('../../config.php'); 18 require_once($CFG->dirroot.'/mod/scorm/locallib.php'); 19 20 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or 21 $a = optional_param('a', '', PARAM_INT); // scorm ID 22 $scoid = required_param('scoid', PARAM_INT); // sco ID. 23 24 $delayseconds = 2; // Delay time before sco launch, used to give time to browser to define API. 25 26 if (!empty($id)) { 27 if (! $cm = get_coursemodule_from_id('scorm', $id)) { 28 print_error('invalidcoursemodule'); 29 } 30 if (! $course = $DB->get_record('course', array('id' => $cm->course))) { 31 print_error('coursemisconf'); 32 } 33 if (! $scorm = $DB->get_record('scorm', array('id' => $cm->instance))) { 34 print_error('invalidcoursemodule'); 35 } 36 } else if (!empty($a)) { 37 if (! $scorm = $DB->get_record('scorm', array('id' => $a))) { 38 print_error('coursemisconf'); 39 } 40 if (! $course = $DB->get_record('course', array('id' => $scorm->course))) { 41 print_error('coursemisconf'); 42 } 43 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) { 44 print_error('invalidcoursemodule'); 45 } 46 } else { 47 print_error('missingparameter'); 48 } 49 50 $PAGE->set_url('/mod/scorm/loadSCO.php', array('scoid' => $scoid, 'id' => $cm->id)); 51 52 if (!isloggedin()) { // Prevent login page from being shown in iframe. 53 // Using simple html instead of exceptions here as shown inside iframe/object. 54 echo html_writer::start_tag('html'); 55 echo html_writer::tag('head', ''); 56 echo html_writer::tag('body', get_string('loggedinnot')); 57 echo html_writer::end_tag('html'); 58 exit; 59 } 60 61 require_login($course, false, $cm, false); // Call require_login anyway to set up globals correctly. 62 63 // Check if scorm closed. 64 $timenow = time(); 65 if ($scorm->timeclose != 0) { 66 if ($scorm->timeopen > $timenow) { 67 print_error('notopenyet', 'scorm', null, userdate($scorm->timeopen)); 68 } else if ($timenow > $scorm->timeclose) { 69 print_error('expired', 'scorm', null, userdate($scorm->timeclose)); 70 } 71 } 72 73 $context = context_module::instance($cm->id); 74 75 if (!empty($scoid)) { 76 // Direct SCO request. 77 if ($sco = scorm_get_sco($scoid)) { 78 if ($sco->launch == '') { 79 // Search for the next launchable sco. 80 if ($scoes = $DB->get_records_select( 81 'scorm_scoes', 82 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true).' AND id > ?', 83 array($scorm->id, $sco->id), 84 'sortorder, id')) { 85 $sco = current($scoes); 86 } 87 } 88 } 89 } 90 91 // If no sco was found get the first of SCORM package. 92 if (!isset($sco)) { 93 $scoes = $DB->get_records_select( 94 'scorm_scoes', 95 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true), 96 array($scorm->id), 97 'sortorder, id' 98 ); 99 $sco = current($scoes); 100 } 101 102 if ($sco->scormtype == 'asset') { 103 $attempt = scorm_get_last_attempt($scorm->id, $USER->id); 104 $element = (scorm_version_check($scorm->version, SCORM_13)) ? 'cmi.completion_status' : 'cmi.core.lesson_status'; 105 $value = 'completed'; 106 $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); 107 } 108 109 // Forge SCO URL. 110 $connector = ''; 111 $version = substr($scorm->version, 0, 4); 112 if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) { 113 if (stripos($sco->launch, '?') !== false) { 114 $connector = '&'; 115 } else { 116 $connector = '?'; 117 } 118 if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) { 119 $sco->parameters = substr($sco->parameters, 1); 120 } 121 } 122 123 if ($version == 'AICC') { 124 require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php"); 125 $aiccsid = scorm_aicc_get_hacp_session($scorm->id); 126 if (empty($aiccsid)) { 127 $aiccsid = sesskey(); 128 } 129 $scoparams = ''; 130 if (isset($sco->parameters) && (!empty($sco->parameters))) { 131 $scoparams = '&'. $sco->parameters; 132 } 133 $launcher = $sco->launch.$connector.'aicc_sid='.$aiccsid.'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$scoparams; 134 } else { 135 if (isset($sco->parameters) && (!empty($sco->parameters))) { 136 $launcher = $sco->launch.$connector.$sco->parameters; 137 } else { 138 $launcher = $sco->launch; 139 } 140 } 141 142 if (scorm_external_link($sco->launch)) { 143 // TODO: does this happen? 144 $result = $launcher; 145 } else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL) { 146 // Remote learning activity. 147 $result = dirname($scorm->reference).'/'.$launcher; 148 } else if ($scorm->scormtype === SCORM_TYPE_LOCAL && strtolower($scorm->reference) == 'imsmanifest.xml') { 149 // This SCORM content sits in a repository that allows relative links. 150 $result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/imsmanifest/$scorm->revision/$launcher"; 151 } else if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) { 152 // Note: do not convert this to use get_file_url() or moodle_url() 153 // SCORM does not work without slasharguments and moodle_url() encodes querystring vars. 154 $result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/content/$scorm->revision/$launcher"; 155 } 156 157 // Trigger a Sco launched event. 158 $event = \mod_scorm\event\sco_launched::create(array( 159 'objectid' => $sco->id, 160 'context' => $context, 161 'other' => array('instanceid' => $scorm->id, 'loadedcontent' => $result) 162 )); 163 $event->add_record_snapshot('course_modules', $cm); 164 $event->add_record_snapshot('scorm', $scorm); 165 $event->add_record_snapshot('scorm_scoes', $sco); 166 $event->trigger(); 167 168 header('Content-Type: text/html; charset=UTF-8'); 169 170 if ($sco->scormtype == 'asset') { 171 // HTTP 302 Found => Moved Temporarily. 172 header('Location: ' . $result); 173 // Provide a short feedback in case of slow network connection. 174 echo html_writer::start_tag('html'); 175 echo html_writer::tag('body', html_writer::tag('p', get_string('activitypleasewait', 'scorm'))); 176 echo html_writer::end_tag('html'); 177 exit; 178 } 179 180 // We expect a SCO: select which API are we looking for. 181 $lmsapi = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'API' : 'API_1484_11'; 182 183 echo html_writer::start_tag('html'); 184 echo html_writer::start_tag('head'); 185 echo html_writer::tag('title', 'LoadSCO'); 186 ?> 187 <script type="text/javascript"> 188 //<![CDATA[ 189 var myApiHandle = null; 190 var myFindAPITries = 0; 191 192 function myGetAPIHandle() { 193 myFindAPITries = 0; 194 if (myApiHandle == null) { 195 myApiHandle = myGetAPI(); 196 } 197 return myApiHandle; 198 } 199 200 function myFindAPI(win) { 201 while ((win.<?php echo $lmsapi; ?> == null) && (win.parent != null) && (win.parent != win)) { 202 myFindAPITries++; 203 // Note: 7 is an arbitrary number, but should be more than sufficient 204 if (myFindAPITries > 7) { 205 return null; 206 } 207 win = win.parent; 208 } 209 return win.<?php echo $lmsapi; ?>; 210 } 211 212 // hun for the API - needs to be loaded before we can launch the package 213 function myGetAPI() { 214 var theAPI = myFindAPI(window); 215 if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) { 216 theAPI = myFindAPI(window.opener); 217 } 218 if (theAPI == null) { 219 return null; 220 } 221 return theAPI; 222 } 223 224 function doredirect() { 225 if (myGetAPIHandle() != null) { 226 location = "<?php echo $result ?>"; 227 } 228 else { 229 document.body.innerHTML = "<p><?php echo get_string('activityloading', 'scorm');?>" + 230 "<span id='countdown'><?php echo $delayseconds ?></span> " + 231 "<?php echo get_string('numseconds', 'moodle', '');?>. " + 232 "<img src='<?php echo $OUTPUT->pix_url('wait', 'scorm') ?>'></p>"; 233 var e = document.getElementById("countdown"); 234 var cSeconds = parseInt(e.innerHTML); 235 var timer = setInterval(function() { 236 if( cSeconds && myGetAPIHandle() == null ) { 237 e.innerHTML = --cSeconds; 238 } else { 239 clearInterval(timer); 240 document.body.innerHTML = "<p><?php echo get_string('activitypleasewait', 'scorm');?></p>"; 241 location = "<?php echo $result ?>"; 242 } 243 }, 1000); 244 } 245 } 246 //]]> 247 </script> 248 <noscript> 249 <meta http-equiv="refresh" content="0;url=<?php echo $result ?>" /> 250 </noscript> 251 <?php 252 echo html_writer::end_tag('head'); 253 echo html_writer::tag('body', html_writer::tag('p', get_string('activitypleasewait', 'scorm')), array('onload' => "doredirect();")); 254 echo html_writer::end_tag('html');
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |