]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17115 - SCORM onload API checking. Hunt for the API.
authorpiers <piers>
Fri, 5 Dec 2008 03:19:56 +0000 (03:19 +0000)
committerpiers <piers>
Fri, 5 Dec 2008 03:19:56 +0000 (03:19 +0000)
mod/scorm/loadSCO.php

index c954105b4aff372d955c9c6773ab48b1ba1bf807..bf518ca9922d3e3fb0807c375652f1b2edf9832b 100755 (executable)
@@ -33,7 +33,7 @@
     }
 
     require_login($course->id, false, $cm);
-    
+
     //check if scorm closed
     $timenow = time();
     if ($scorm->timeclose !=0) {
@@ -43,7 +43,7 @@
             error(get_string("expired", "scorm", userdate($scorm->timeclose)));
         }
     }
-   
+
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
     if (!empty($scoid)) {
@@ -69,7 +69,7 @@
 
     if ($sco->scormtype == 'asset') {
        $attempt = scorm_get_last_attempt($scorm->id,$USER->id);
-       $element = $scorm->version == 'scorm_13'?'cmi.completion_status':'cmi.core.lesson_status';
+       $element = ($scorm->version == 'scorm_13' || $scorm->version == 'SCORM_1.3') ? 'cmi.completion_status':'cmi.core.lesson_status';
        $value = 'completed';
        $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
     }
     }
 
     $scormpixdir = $CFG->modpixpath.'/scorm/pix';
+
+    // which API are we looking for
+    $LMS_api = ($scorm->version == 'scorm_12' || $scorm->version == 'SCORM_1.2' || empty($scorm->version)) ? 'API' : 'API_1484_11';
 ?>
 <html>
     <head>
         <title>LoadSCO</title>
         <script type="text/javascript">
         //<![CDATA[
-        function doredirect() {
-            var e = document.getElementById("countdown");
-            var cSeconds = parseInt(e.innerHTML);
-            var timer = setInterval(function() {
-                                            if( cSeconds ) {
-                                                e.innerHTML = --cSeconds;
-                                            } else {
-                                                clearInterval(timer);
-                                                document.body.innerHTML = "<?php echo get_string('activitypleasewait', 'scorm');?>";
-                                                location = "<?php echo $result ?>";
-                                            }
-                                        }, 1000);
+        var apiHandle = null;
+        var findAPITries = 0;
+
+        function getAPIHandle() {
+           if (apiHandle == null) {
+              apiHandle = getAPI();
+           }
+           return apiHandle;
+        }
+
+        function findAPI(win) {
+           while ((win.<?echo $LMS_api; ?> == null) && (win.parent != null) && (win.parent != win)) {
+              findAPITries++;
+              // Note: 7 is an arbitrary number, but should be more than sufficient
+              if (findAPITries > 7) {
+                 return null;
+              }
+              win = win.parent;
+           }
+           return win.<?echo $LMS_api; ?>;
+        }
+
+        // hun for the API - needs to be loaded before we can launch the package
+        function getAPI() {
+           var theAPI = findAPI(window);
+           if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) {
+              theAPI = findAPI(window.opener);
+           }
+           if (theAPI == null) {
+              return null;
+           }
+           return theAPI;
+        }
+
+       function doredirect() {
+            if (getAPI() != null) {
+                location = "<?php echo $result ?>";
+            }
+            else {
+                document.body.innerHTML = "<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>";
+                var e = document.getElementById("countdown");
+                var cSeconds = parseInt(e.innerHTML);
+                var timer = setInterval(function() {
+                                                if( cSeconds && getAPI() == null ) {
+                                                    e.innerHTML = --cSeconds;
+                                                } else {
+                                                    clearInterval(timer);
+                                                    document.body.innerHTML = "<p><?php echo get_string('activitypleasewait', 'scorm');?></p>";
+                                                    location = "<?php echo $result ?>";
+                                                }
+                                            }, 1000);
+            }
         }
         //]]>
         </script>
         </noscript>
     </head>
     <body onload="doredirect();">
-        <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>
-        <?php if (scorm_debugging($scorm)) {
+        <p><?php echo get_string('activitypleasewait', 'scorm');?></p>
+        <?php if (debugging('',DEBUG_DEVELOPER)) {
                   add_to_log($course->id, 'scorm', 'launch', 'view.php?id='.$cm->id, $result, $cm->id);
               }
         ?>
     </body>
-</html>
+</html>
\ No newline at end of file