Updated backup to popup windows. Modified auto-continue feature. Added nav.event...
authorbobopinna <bobopinna>
Thu, 1 Jul 2004 09:54:08 +0000 (09:54 +0000)
committerbobopinna <bobopinna>
Thu, 1 Jul 2004 09:54:08 +0000 (09:54 +0000)
mod/scorm/api1_2.php
mod/scorm/backuplib.php
mod/scorm/cmi.php
mod/scorm/playscorm.php
mod/scorm/restorelib.php
mod/scorm/scormAPI.php

index 1598d7f..e7d1c72 100644 (file)
@@ -46,6 +46,15 @@ function SCORMapi() {
            //
            // end CMI Initialization
            //
+           
+           nav = new Object();
+           <?php 
+               if ($scorm->auto) {
+                   echo 'nav.event = "continue";'."\n";
+               } else {
+                   echo 'nav.event = "";'."\n";
+               }
+           ?>
 
            return "true";
        } else {
@@ -93,14 +102,28 @@ function SCORMapi() {
     function LMSSetValue (param,value) {
        if (Initialized) {
            //top.status="SET "+param+" = "+value;
-           //top.alert("SET "+param+" = "+value);
+           top.alert("SET "+param+" = "+value);
            switch (param) {
                case "cmi.core.session_time":
-                   cmi.core.total_time = AddTime(cmi.core.total_time, value);
-                   //top.status="SET cmi.core.total_time = "+cmi.core.total_time;
-                   eval(param+'="'+value+'";');
-                   errorCode = 0;
-                   return "true";
+                   //top.alert(typeof(value));
+                   if (typeof(value) == "string") {
+                       var parsedtime = value.match(/[0-9]+/g);
+                       if (((parsedtime.length == 3) || (parsedtime.length == 4)) && (parsedtime[0]>=0) && (parsedtime[0]<=9999) && (parsedtime[1]>=0) && (parsedtime[1]<=59) && (parsedtime[2]>=0) && (parsedtime[2]<=59)) {
+                           if ((parsedtime.length == 4) && (parsedtime[3]<=0) && (parsedtime[3]>=99)) {
+                               errorCode = 405;
+                               return "false";
+                           }
+                           eval(param+'="'+value+'";');
+                           errorCode = 0;
+                           return "true";
+                       } else {
+                           errorCode = 405;
+                           return "false";
+                       }
+                   } else {
+                       errorCode = 405;
+                       return "false";
+                   }
                break;
                case "cmi.core.lesson_status":
                    if ((value!="passed")&&(value!="completed")&&(value!="failed")&&(value!="incomplete")&&(value!="browsed")) {
@@ -159,6 +182,17 @@ function SCORMapi() {
                    errorCode = 403;
                    return "false";
                break;
+               case "nav.event":
+                   if ((value == "previous") || (value == "continue")) {
+                       eval(param+'="'+value+'";');
+                       //changeSco(value);
+                       errorCode = 0;
+                       return "true";
+                   } else {
+                       erroCode = 405;
+                       return "false";
+                   }
+               break;  
                default:
                    //errorCode = 401;  This is more correct but may have problem with some SCOes
                    errorCode = 0; // With this disable any possible SCO errors alert
@@ -183,8 +217,6 @@ function SCORMapi() {
                cmiform.cmi_core_lesson_location.value = cmi.core.lesson_location;
                cmiform.cmi_core_lesson_status.value = cmi.core.lesson_status;
                cmiform.cmi_core_exit.value = cmi.core.exit;
-               cmiform.cmi_core_session_time.value = cmi.core.session_time;
-               cmiform.cmi_core_total_time.value = cmi.core.total_time;
                cmiform.cmi_core_score_raw.value = cmi.core.score.raw;
                cmiform.cmi_suspend_data.value = cmi.suspend_data;
                cmiform.submit();
@@ -208,16 +240,23 @@ function SCORMapi() {
        } else {
            Initialized = false;
            errorCode = 0;
+           cmi.core.total_time = AddTime(cmi.core.total_time, cmi.core.session_time);
+           if (<?php echo $navObj ?>cmi.document.theform) {
+               cmiform = <?php echo $navObj ?>cmi.document.forms[0];
+               cmiform.scoid.value = "<?php echo $sco->id; ?>";
+               cmiform.cmi_core_total_time.value = cmi.core.total_time;
+               cmiform.submit();
+           }
+            if (nav.event != "") {
             <?php
-                if ($scorm->auto) {
-                    if ($sco != $last) {
-                        echo "setTimeout('".$navObj."document.navform.next.click();',500);\n";
-                    } else {
-                        echo "exitloc = '".$CFG->wwwroot."/mod/scorm/view.php?id=".$cm->id."';\n";
-                        echo "setTimeout('top.location = exitloc;',500);\n";
-                    }
+               if ($sco != $last) {
+                   echo "setTimeout('top.changeSco(nav.event);',500);\n";
+               } else {
+                   echo "exitloc = '".$CFG->wwwroot."/mod/scorm/view.php?id=".$cm->id."';\n";
+                   echo "setTimeout('top.location = exitloc;',500);\n";
                } 
            ?>
+           }
            return "true";
        }    
     }
index 817372f..9b6959a 100755 (executable)
@@ -47,6 +47,7 @@
                 fwrite ($bf,full_tag("LAUNCH",4,false,$scorm->launch));
                 fwrite ($bf,full_tag("SUMMARY",4,false,$scorm->summary));
                 fwrite ($bf,full_tag("AUTO",4,false,$scorm->auto));
+                fwrite ($bf,full_tag("POPUP",4,false,$scorm->popup));
                 fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$scorm->timemodified));
                 $status = backup_scorm_scoes($bf,$preferences,$scorm->id);
  
index 2ce1476..ef780bf 100755 (executable)
     require_login($course->id);
     
     if ($_POST["scoid"]) {
-       set_field("scorm_sco_users","cmi_core_lesson_location",$_POST["cmi_core_lesson_location"],"scoid",$_POST["scoid"],"userid",$USER->id);
-        set_field("scorm_sco_users","cmi_core_lesson_status",$_POST["cmi_core_lesson_status"],"scoid",$_POST["scoid"],"userid",$USER->id);
-        set_field("scorm_sco_users","cmi_core_exit",$_POST["cmi_core_exit"],"scoid",$_POST["scoid"],"userid",$USER->id);
-        set_field("scorm_sco_users","cmi_core_session_time",$_POST["cmi_core_session_time"],"scoid",$_POST["scoid"],"userid",$USER->id);
-        set_field("scorm_sco_users","cmi_core_total_time",$_POST["cmi_core_total_time"],"scoid",$_POST["scoid"],"userid",$USER->id);
-        set_field("scorm_sco_users","cmi_core_score_raw",$_POST["cmi_core_score_raw"],"scoid",$_POST["scoid"],"userid",$USER->id);
-        set_field("scorm_sco_users","cmi_suspend_data",$_POST["cmi_suspend_data"],"scoid",$_POST["scoid"],"userid",$USER->id);
-    /*    if ($scorm->auto)
-            $result="<script language=\"Javascript\">\n\ttop.nav.document.navform.next.click();\n    </script>\n"; */
+        if ($_POST["cmi_core_lesson_location"]) {
+           set_field("scorm_sco_users","cmi_core_lesson_location",$_POST["cmi_core_lesson_location"],"scoid",$_POST["scoid"],"userid",$USER->id);
+       }
+       if ($_POST["cmi_core_lesson_status"]) {
+            set_field("scorm_sco_users","cmi_core_lesson_status",$_POST["cmi_core_lesson_status"],"scoid",$_POST["scoid"],"userid",$USER->id);
+        }
+       if ($_POST["cmi_core_exit"]) {
+            set_field("scorm_sco_users","cmi_core_exit",$_POST["cmi_core_exit"],"scoid",$_POST["scoid"],"userid",$USER->id);
+        }
+       if ($_POST["cmi_core_total_time"]) {
+            set_field("scorm_sco_users","cmi_core_total_time",$_POST["cmi_core_total_time"],"scoid",$_POST["scoid"],"userid",$USER->id);
+        }
+       if ($_POST["cmi_core_score_raw"]) {
+            set_field("scorm_sco_users","cmi_core_score_raw",$_POST["cmi_core_score_raw"],"scoid",$_POST["scoid"],"userid",$USER->id);
+        }
+       if ($_POST["cmi_suspend_data"]) {
+            set_field("scorm_sco_users","cmi_suspend_data",$_POST["cmi_suspend_data"],"scoid",$_POST["scoid"],"userid",$USER->id);
+        }
     }
 ?>
 <html>
index 5eabc85..7daa10a 100755 (executable)
                     <form name=\"navform\" method=\"POST\" action=\"playscorm.php?id=$cm->id\" target=\"_top\">
                        <input name=\"scoid\" type=\"hidden\" />
                        <input name=\"mode\" type=\"hidden\" value=\"".$mode."\" />
-                       <input name=\"prev\" type=\"button\" value=\"".get_string("prev","scorm")."\" onClick=\"top.changeSco('prev');\" />&nbsp;\n";
+                       <input name=\"prev\" type=\"button\" value=\"".get_string("prev","scorm")."\" onClick=\"top.changeSco('previous');\" />&nbsp;\n";
                        
        if ($scorm->popup == "") {
            if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){
            }
            choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();");
        }
-       echo "          &nbsp;<input name=\"next\" type=\"button\" value=\"".get_string("next","scorm")."\" onClick=\"top.changeSco('next')\" />\n";
+       echo "          &nbsp;<input name=\"next\" type=\"button\" value=\"".get_string("next","scorm")."\" onClick=\"top.changeSco('continue')\" />\n";
        echo "       </form>
                </td>\n";
        
             echo "<head><title>$course->shortname: $scorm->name</title></head>\n";
             echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&mode=".$mode.$scoid."\"></script>\n";
            echo "<frameset rows=\"$CFG->scorm_framesize,*\" onLoad=\"SCOInitialize();\">\n";
-            echo "\t    <frame name=\"nav\" src=\"playscorm.php?id=$cm->id&mode=".$mode."&frameset=top\">\n";
+            echo "\t    <frame name=\"navigation\" src=\"playscorm.php?id=$cm->id&mode=".$mode."&frameset=top\">\n";
             echo "\t    <frame name=\"main\" src=\"\">\n";
             echo "</frameset>\n";
             echo "</html>\n";
index 9ad58f7..bb8f41d 100755 (executable)
@@ -51,6 +51,7 @@
             $scorm->launch = backup_todb($info['MOD']['#']['LAUNCH']['0']['#']);
             $scorm->summary = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
             $scorm->auto = backup_todb($info['MOD']['#']['AUTO']['0']['#']);
+            $scorm->popup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
             $scorm->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
 
             //The structure is equal to the db, so insert the scorm
index ff4a4de..f5d6403 100755 (executable)
         //
        if (!empty($scoid)) {   
            // Direct sco request
-           $sco = get_record("scorm_scoes","id",$scoid);
+           //$sco = get_record("scorm_scoes","id",$scoid);
+           if ($sco = get_record("scorm_scoes","id",$scoid)) {
+               if ($sco->launch == '') {
+                   // Search for th first launchable sco 
+                   if ($scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC")) {
+                       $sco = current($scoes);
+                       while ($sco->id < $scoid) {
+                           $sco = next($scoes);
+                       }
+                       while ($sco->launch == '') {
+                           $sco = next($scoes);
+                       }
+                   }
+               }
+           }
        } else {
            // Search for first incomplete sco
            foreach ( $scoes_user as $sco_user ) {
     }
     $navObj = "top.";
     if ($scorm->popup == "")
-        $navObj = "top.nav.";
+        $navObj = "top.navigation.";
         
     include("api1_2.php");
 
@@ -169,7 +183,7 @@ function SCOInitialize() {
 } 
 
 function changeSco(direction) {
-       if (direction == "prev")
+       if (direction == "previous")
            <?php echo $navObj ?>document.navform.scoid.value="<?php echo $prevsco; ?>";
        else
            <?php echo $navObj ?>document.navform.scoid.value="<?php echo $nextsco; ?>";