|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00017 require_once('../../config.php'); 00018 require_once($CFG->dirroot.'/mod/scorm/locallib.php'); 00019 00020 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or 00021 $a = optional_param('a', '', PARAM_INT); // scorm ID 00022 $scoid = required_param('scoid', PARAM_INT); // sco ID 00023 00024 $delayseconds = 2; // Delay time before sco launch, used to give time to browser to define API 00025 00026 if (!empty($id)) { 00027 if (! $cm = get_coursemodule_from_id('scorm', $id)) { 00028 print_error('invalidcoursemodule'); 00029 } 00030 if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { 00031 print_error('coursemisconf'); 00032 } 00033 if (! $scorm = $DB->get_record('scorm', array('id'=>$cm->instance))) { 00034 print_error('invalidcoursemodule'); 00035 } 00036 } else if (!empty($a)) { 00037 if (! $scorm = $DB->get_record('scorm', array('id'=>$a))) { 00038 print_error('coursemisconf'); 00039 } 00040 if (! $course = $DB->get_record('course', array('id'=>$scorm->course))) { 00041 print_error('coursemisconf'); 00042 } 00043 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) { 00044 print_error('invalidcoursemodule'); 00045 } 00046 } else { 00047 print_error('missingparameter'); 00048 } 00049 00050 $PAGE->set_url('/mod/scorm/loadSCO.php', array('scoid'=>$scoid, 'id'=>$cm->id)); 00051 00052 require_login($course->id, false, $cm); 00053 00054 //check if scorm closed 00055 $timenow = time(); 00056 if ($scorm->timeclose !=0) { 00057 if ($scorm->timeopen > $timenow) { 00058 print_error('notopenyet', 'scorm', null, userdate($scorm->timeopen)); 00059 } else if ($timenow > $scorm->timeclose) { 00060 print_error('expired', 'scorm', null, userdate($scorm->timeclose)); 00061 } 00062 } 00063 00064 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00065 00066 if (!empty($scoid)) { 00067 // 00068 // Direct SCO request 00069 // 00070 if ($sco = scorm_get_sco($scoid)) { 00071 if ($sco->launch == '') { 00072 // Search for the next launchable sco 00073 if ($scoes = $DB->get_records_select('scorm_scoes', "scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true).' AND id > ?", array($scorm->id, $sco->id), 'id ASC')) { 00074 $sco = current($scoes); 00075 } 00076 } 00077 } 00078 } 00079 // 00080 // If no sco was found get the first of SCORM package 00081 // 00082 if (!isset($sco)) { 00083 $scoes = $DB->get_records_select('scorm_scoes', "scorm = ? AND ".$DB->sql_isnotempty('scorm_scoes', 'launch', false, true), array($scorm->id), 'id ASC'); 00084 $sco = current($scoes); 00085 } 00086 00087 if ($sco->scormtype == 'asset') { 00088 $attempt = scorm_get_last_attempt($scorm->id, $USER->id); 00089 $element = (scorm_version_check($scorm->version, SCORM_13)) ? 'cmi.completion_status':'cmi.core.lesson_status'; 00090 $value = 'completed'; 00091 $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); 00092 } 00093 00094 // 00095 // Forge SCO URL 00096 // 00097 $connector = ''; 00098 $version = substr($scorm->version, 0, 4); 00099 if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) { 00100 if (stripos($sco->launch, '?') !== false) { 00101 $connector = '&'; 00102 } else { 00103 $connector = '?'; 00104 } 00105 if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) { 00106 $sco->parameters = substr($sco->parameters, 1); 00107 } 00108 } 00109 00110 if ($version == 'AICC') { 00111 require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php"); 00112 $aicc_sid = scorm_aicc_get_hacp_session($scorm->id); 00113 if (empty($aicc_sid)) { 00114 $aicc_sid = sesskey(); 00115 } 00116 $sco_params = ''; 00117 if (isset($sco->parameters) && (!empty($sco->parameters))) { 00118 $sco_params = '&'. $sco->parameters; 00119 } 00120 $launcher = $sco->launch.$connector.'aicc_sid='.$aicc_sid.'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco_params; 00121 } else { 00122 if (isset($sco->parameters) && (!empty($sco->parameters))) { 00123 $launcher = $sco->launch.$connector.$sco->parameters; 00124 } else { 00125 $launcher = $sco->launch; 00126 } 00127 } 00128 00129 if (scorm_external_link($sco->launch)) { 00130 //TODO: does this happen? 00131 $result = $launcher; 00132 } else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL) { 00133 // Remote learning activity 00134 $result = dirname($scorm->reference).'/'.$launcher; 00135 } else if ($scorm->scormtype === SCORM_TYPE_IMSREPOSITORY) { 00136 // Repository 00137 $result = $CFG->repositorywebroot.substr($scorm->reference, 1).'/'.$sco->launch; 00138 } else if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) { 00139 //note: do not convert this to use get_file_url() or moodle_url() 00140 //SCORM does not work without slasharguments and moodle_url() encodes querystring vars 00141 $result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/content/$scorm->revision/$launcher"; 00142 } 00143 00144 add_to_log($course->id, 'scorm', 'launch', 'view.php?id='.$cm->id, $result, $cm->id); 00145 00146 // which API are we looking for 00147 $LMS_api = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'API' : 'API_1484_11'; 00148 ?> 00149 <html> 00150 <head> 00151 <title>LoadSCO</title> 00152 <script type="text/javascript"> 00153 //<![CDATA[ 00154 var myApiHandle = null; 00155 var myFindAPITries = 0; 00156 00157 function myGetAPIHandle() { 00158 myFindAPITries = 0; 00159 if (myApiHandle == null) { 00160 myApiHandle = myGetAPI(); 00161 } 00162 return myApiHandle; 00163 } 00164 00165 function myFindAPI(win) { 00166 while ((win.<?php echo $LMS_api; ?> == null) && (win.parent != null) && (win.parent != win)) { 00167 myFindAPITries++; 00168 // Note: 7 is an arbitrary number, but should be more than sufficient 00169 if (myFindAPITries > 7) { 00170 return null; 00171 } 00172 win = win.parent; 00173 } 00174 return win.<?php echo $LMS_api; ?>; 00175 } 00176 00177 // hun for the API - needs to be loaded before we can launch the package 00178 function myGetAPI() { 00179 var theAPI = myFindAPI(window); 00180 if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) { 00181 theAPI = myFindAPI(window.opener); 00182 } 00183 if (theAPI == null) { 00184 return null; 00185 } 00186 return theAPI; 00187 } 00188 00189 function doredirect() { 00190 if (myGetAPIHandle() != null) { 00191 location = "<?php echo $result ?>"; 00192 } 00193 else { 00194 document.body.innerHTML = "<p><?php echo get_string('activityloading', 'scorm');?> <span id='countdown'><?php echo $delayseconds ?></span> <?php echo get_string('numseconds', 'moodle', '');?>. <img src='<?php echo $OUTPUT->pix_url('wait', 'scorm') ?>'><p>"; 00195 var e = document.getElementById("countdown"); 00196 var cSeconds = parseInt(e.innerHTML); 00197 var timer = setInterval(function() { 00198 if( cSeconds && myGetAPIHandle() == null ) { 00199 e.innerHTML = --cSeconds; 00200 } else { 00201 clearInterval(timer); 00202 document.body.innerHTML = "<p><?php echo get_string('activitypleasewait', 'scorm');?></p>"; 00203 location = "<?php echo $result ?>"; 00204 } 00205 }, 1000); 00206 } 00207 } 00208 //]]> 00209 </script> 00210 <noscript> 00211 <meta http-equiv="refresh" content="0;url=<?php echo $result ?>" /> 00212 </noscript> 00213 </head> 00214 <body onload="doredirect();"> 00215 <p><?php echo get_string('activitypleasewait', 'scorm');?></p> 00216 </body> 00217 </html>