First step to SCORM2004, new communication subsystem
authorbobopinna <bobopinna>
Thu, 17 Feb 2005 16:04:42 +0000 (16:04 +0000)
committerbobopinna <bobopinna>
Thu, 17 Feb 2005 16:04:42 +0000 (16:04 +0000)
mod/scorm/api.php
mod/scorm/datamodel.php
mod/scorm/index.php
mod/scorm/lib.php
mod/scorm/mod.html
mod/scorm/playscorm.php
mod/scorm/validate.php

index 4d2d54b..ef7a3f0 100644 (file)
@@ -54,13 +54,13 @@ function closeMain() {
 var errorCode = "0";
 
 function SCORM_Call (call,param,value) {
-    if (arguments.caller.length < 2) {
+    if (arguments.length < 2) {
        alert ("Invalid SCORM_Call function call: too few arguments.\nYou need pass at least 2 parameters");
-    } else if (arguments.caller.length == 3) {
+    } else if (arguments.length == 3) {
        param = param.concat("&value=",value);
     }
     var myRequest = NewHttpReq();
-    result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php?id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>&param="+param);
+    result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php?id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>&call="+call+"&param="+param);
     results = result.split('\n');
     
     errorCode = results[1];
@@ -180,7 +180,7 @@ function SCORMapi2004() {
        errorString["401"] = "Undefinited Data Model";
        errorString["402"] = "Unimplemented Data Model Element";
        errorString["403"] = "Data Model Element Value Not Initialized";
-       errorString["404"] = "Data Model Element Is Read Only;
+       errorString["404"] = "Data Model Element Is Read Only";
        errorString["405"] = "Data Model Element Is Write Only";
        errorString["406"] = "Data Model Element Type Mismatch";
        errorString["407"] = "Data Model Element Value Out Of Range";
index 1cfed79..0580508 100755 (executable)
     }
 
     require_login($course->id, false, $cm);
-    if (!empty($_POST['scoid'])) {
-        //echo 'scoid: '.$_POST['scoid']."\n";
-        if (!empty($_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);
-           //echo 'cmi_core_lesson_location: '.$_POST['cmi_core_lesson_location']."\n";
-       }
-       if (!empty($_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);
-            //echo 'cmi_core_lesson_status: '.$_POST['cmi_core_lesson_status']."\n";
-        }
-       if (!empty($_POST['cmi_core_exit'])) {
-            set_field('scorm_sco_users','cmi_core_exit',$_POST['cmi_core_exit'],'scoid',$_POST['scoid'],'userid',$USER->id);
-            //echo 'cmi_core_exit: '.$_POST['cmi_core_exit']."\n";
-        }
-       if (!empty($_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);
-            //echo 'cmi_core_score_raw: '.$_POST['cmi_core_score_raw']."\n";
-        }
-       if (!empty($_POST['cmi_suspend_data'])) {
-            set_field('scorm_sco_users','cmi_suspend_data',$_POST['cmi_suspend_data'],'scoid',$_POST['scoid'],'userid',$USER->id);
-            //echo 'cmi_suspend_data: '.$_POST['cmi_suspend_data']."\n";
-        }
-        if (!empty($_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);
-            //echo 'cmi_core_total_time: '.$_POST['cmi_core_total_time']."\n";
-        }
+    
+    if (isset($_POST['call']) && confirm_sesskey()) {
+       
     }
 ?>
-<html>
-<head>
-   <title>cmi</title>
-</head>
-<body>
-   <form name="theform" method="POST" action="<?php echo $ME ?>?id=<?php echo $cm->id ?>"> 
-       <input type="hidden" name="scoid" />
-       <input type="hidden" name="cmi_core_lesson_location" />
-       <input type="hidden" name="cmi_core_lesson_status" />
-       <input type="hidden" name="cmi_core_exit" />
-       <input type="hidden" name="cmi_core_total_time"  />
-       <input type="hidden" name="cmi_core_score_raw" />
-       <input type="hidden" name="cmi_suspend_data" />
-   </form>
-</body>
-</html>
+
index 13607c1..7bd56e4 100755 (executable)
@@ -8,7 +8,7 @@
         error("Course ID is incorrect");
     }
 
-    require_course_login($course->id, false, $cm);
+    require_course_login($course->id);
 
     add_to_log($course->id, "scorm", "view all", "index.php?id=$course->id", "");
 
@@ -20,7 +20,7 @@
     $strsummary = get_string("summary");
     $strlastmodified = get_string("lastmodified");
 
-    print_header_simple("$strscorms", "", "$navigation $strscorms",
+    print_header_simple("$strscorms", "", "$strscorms",
                  "", "", true, "", navmenu($course));
 
     if ($course->format == "weeks" or $course->format == "topics") {
index a6888ea..81d98e8 100755 (executable)
@@ -115,19 +115,16 @@ function scorm_update_instance($scorm) {
        $scorm->auto = '0';
     }
     
-    $id = update_record('scorm', $scorm);
-    
     //
     // Check if scorm manifest needs to be reparsed
     //
     if ($scorm->launch == 0) {
        $basedir = $CFG->dataroot."/".$scorm->course;
                $scormdir = "/moddata/scorm";
-       $scorm->launch = scorm_parse($basedir,$scormdir.$scorm->datadir."/imsmanifest.xml",$id);
-       set_field("scorm","launch",$scorm->launch,"id",$id);
+       $scorm->launch = scorm_parse($basedir,$scormdir.$scorm->datadir."/imsmanifest.xml",$scorm->id);
     }
     
-    return $id;
+    return update_record('scorm', $scorm);
 }
 
 
index 30c34c7..5a5946f 100755 (executable)
     function validate_scorm(theform,filename) {
        //alert(filename);
         var myRequest = NewHttpReq();
-       result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php?id=<?php p($form->course) ?>&reference="+filename+"<?php p($scormid.$datadir) ?>");
+       result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php?id=<?php p($form->course) ?>&reference="+filename+"<?php echo $scormid.$datadir ?>");
        //alert(result);
        results = result.split('\n');
        if ((results[0] == "found") || (results[0] == "regular")) {
-           theform.launch.value = results[1];
            theform.datadir.value = results[2];
+           if (results[1] == 0) {
+               theform.launch.value = results[1];
+               if ('<?php echo $scormid ?>' != '') {
+                   return confirm('<?php print_string('trackingloose','scorm') ?>');
+               }
+           }
            return true;
        } else {
            result = '<?php print_string('validation','scorm') ?>: '+ results[0] + '\n';
             <td align="right"><b><?php print_string("grademethod", "scorm") ?>:</b></td>
             <td>
             <?php
-                $options = array();
-                $options[0] = get_string("gradescoes", "scorm");
-                $options[1] = get_string("gradehighest", "scorm");
-                $options[2] = get_string("gradeaverage", "scorm");
                 choose_from_menu($SCORM_GRADE_METHOD, "grademethod", "$form->grademethod", "");
                 helpbutton("grademethod", get_string("grademethod","scorm"), "scorm");
             ?>
index d96f98a..4e498f3 100755 (executable)
        if ($scorm->popup != "") {
            $bodyscripts = "onUnload='SCOFinish(); closeMain();' ";
        }
-       //print_header($pagetitle, "$course->fullname",
-       //      "$navigation <a target=\"{$CFG->framename}\" href=\"view.php?id=$cm->id\">$scorm->name</a>",
-       //      "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top'),"",$bodyscripts);
-       print_header($pagetitle, "$course->fullname",
+               print_header($pagetitle, "$course->fullname",
                "$navigation <a target=\"{$CFG->framename}\" href=\"view.php?id=$cm->id\">$scorm->name</a>",
                "", "", true, update_module_button($cm->id, $course->id, $strscorm), "", "", $bodyscripts);
        echo "<table width=\"100%\">\n    <tr><td align=\"center\">".text_to_html($scorm->summary, true, false)."</td>\n";
                    $options[$sco->id] = $indenting."&gt; ".$sco->title;
                }
            }
-           choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();");
+           choose_from_menu($options, "courseStructure", "", $scoid, "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('continue')\" />\n";
        echo "       </form>
             echo "<head><title>$course->shortname: $scorm->name</title></head>\n";
             echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"request.js\"></script>\n";
             echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"api.php?id=$cm->id\"></script>\n";
-           echo "<frameset rows=\"$CFG->scorm_framesize,*\" onLoad=\"SCOInitialize();\" onUnload=\"SCOFinish();\">\n";
-            echo "\t    <frame name=\"navigation\" src=\"playscorm.php?id=$cm->id".$modestring.$currentorgstring."&frameset=top\">\n";
+           echo "<frameset rows=\"$CFG->scorm_framesize,*\" onUnload=\"SCOFinish();\">\n";
+            echo "\t    <frame name=\"navigation\" src=\"playscorm.php?id=$cm->id".$modestring.$currentorgstring.$scoidstring."&frameset=top\">\n";
             echo "\t    <frame name=\"main\" src=\"loadSCO.php?id=$cm->id$scoidstring\">\n";
             echo "</frameset>\n";
             echo "</html>\n";
index 510f11c..84daf04 100755 (executable)
@@ -5,57 +5,70 @@
 
     require_login();
     
-    //
-    // Create a temporary directory to unzip package and validate imsmanifest
-    //
-
+    
     $reference = clean_param($_GET["reference"], PARAM_PATH);
     $courseid = $_GET["id"];
     $datadir = '';
-    $launch = 0;
     if (isset($_GET["datadir"])) {
         $datadir = $_GET["datadir"];
     }
+    
+    $scormid = 0;
+    $launch = 0;
     $result = '';
-    if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
-        if ($tempdir = scorm_datadir($scormdir, $datadir)) {
-            copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference));
-            unzip_file($tempdir."/".basename($reference), $tempdir, false);
-            $result = scorm_validate($tempdir."/imsmanifest.xml");
-        } else {
-            $result = "packagedir";
-        }
-    } else {
-        $result = "datadir";
-    }
     $errorlogs = '';
-    if (($result != "regular") && ($result != "found")) {
-       $result = get_string($result,'scorm');
-        if ($CFG->scorm_validate == 'domxml') {
-            foreach ($errors as $error) {
-                $errorlogs .= get_string($error->type,"scorm",$error->data) . ".\n";
+    if (isset($_GET["instance"])) {
+       $scormid = $_GET["instance"];
+       $launch = 1;
+       $fp = fopen($CFG->dataroot.'/'.$courseid.'/'.$reference,"r");
+       $fstat = fstat($fp);
+       fclose($fp);
+       if ($scorm = get_record("scorm","id",$scormid)) {
+           if ((($scorm->timemodified < $fstat["mtime"]) && ($scorm->reference == $reference)) || ($scorm->reference != $reference)) {
+               // This is a new package
+               $launch = 0;
+           } else {
+               // Old package already validated
+               $result = 'found';
+           }
+       }
+    }
+    if ($launch == 0) {
+       //
+       // Package must be validated
+       //
+       
+        // Create a temporary directory to unzip package and validate imsmanifest
+        $tempdir = '';
+        $scormdir = '';
+       if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
+           if ($tempdir = scorm_datadir($scormdir, $datadir)) {
+               copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference));
+               unzip_file($tempdir."/".basename($reference), $tempdir, false);
+               $result = scorm_validate($tempdir."/imsmanifest.xml");
+           } else {
+               $result = "packagedir";
+           }
+       } else {
+           $result = "datadir";
+       }
+       if (($result != "regular") && ($result != "found")) {
+           // Generate error log string
+           $result = get_string($result,'scorm');
+           if ($CFG->scorm_validate == 'domxml') {
+               foreach ($errors as $error) {
+                   $errorlogs .= get_string($error->type,"scorm",$error->data) . ".\n";
+               }
+           }
+            if (is_dir($tempdir)) {
+                // Delete files and temporary directory
+                scorm_delete_files($tempdir);
+            } else {
+                // Delete package file
+                unlink ($tempdir."/".basename($reference));
             }
-        }
-        //
-        // Delete files and temporary directory
-        //
-        if (is_dir($tempdir))
-            scorm_delete_files($tempdir);
         } else {
-        //
-        // Delete package file
-        //
-        unlink ($tempdir."/".basename($reference));
-        if (isset($_GET["instance"])) {
-            $fp = fopen($CFG->dataroot.'/'.$reference,"r");
-            $fstat = fstat($fp);
-            fclose($fp);
-            if ($scorm = get_record("scorm","id",$_GET["instance"])) {
-               $launch = $scorm->launch;
-               if ($scorm->timemodified < $fstat["mtime"]) {
-                    $launch = 0;
-                }
-            }
+            $datadir = substr($tempdir,strlen($scormdir));
         }
     }
     //
@@ -63,7 +76,6 @@
     //
     echo $result . "\n";
     echo $launch . "\n";
-    $datadir = substr($tempdir,strlen($scormdir));
     echo $datadir . "\n";
     if ($errorlogs != '') {
        echo $errorlogs;