Added store datamodel and repot
authorbobopinna <bobopinna>
Fri, 29 Apr 2005 14:13:37 +0000 (14:13 +0000)
committerbobopinna <bobopinna>
Fri, 29 Apr 2005 14:13:37 +0000 (14:13 +0000)
13 files changed:
mod/scorm/api.php
mod/scorm/backuplib.php
mod/scorm/config.html
mod/scorm/datamodels/scorm1_2.js.php
mod/scorm/datamodels/scorm1_3.js.php
mod/scorm/db/mysql.php
mod/scorm/db/postgres7.php
mod/scorm/lib.php
mod/scorm/loadSCO.php
mod/scorm/mod.html
mod/scorm/playscorm.php
mod/scorm/version.php
mod/scorm/view.php

index ed09758..8fbd597 100644 (file)
@@ -84,28 +84,6 @@ function underscore(str) {
     return str.replace(/\./g,"__");
 }
 
-function CollectData(apiname,data,parent) {
-    var datastring = '';
-    for (property in data) {
-       if (typeof data[property] == 'object') {
-           datastring += CollectData(apiname,data[property],parent+'.'+property);
-       } else {
-               element = parent+'.'+property;
-               expression = new RegExp(CMIIndex,'g');
-               elementmodel = element.replace(expression,'.n.');
-               if ((typeof eval(apiname+'.datamodel["'+elementmodel+'"]')) != "undefined") {
-                   if (eval(apiname+'.datamodel["'+elementmodel+'"].mod') != 'r') {
-                       if (eval(apiname+'.datamodel["'+elementmodel+'"].defaultvalue') != data[property]) {
-                           datastring += '&'+underscore(element)+'='+escape(data[property]);
-                           //alert(element+'='+data[property]);
-                       }
-                   }
-               }
-       }
-    }
-    return datastring;
-}
-
 function AddTime (first, second) {
     var sFirst = first.split(":");
     var sSecond = second.split(":");
@@ -127,16 +105,13 @@ function AddTime (first, second) {
     return hours + ":" + mins + ":" + secs;
 }
 
-function StoreData(apiname,data,storetotaltime) {
-    datastring = CollectData(apiname,data,'cmi');
-    if (storetotaltime) {
-       datastring += eval(apiname+'.TotalTime();');
+/*
+function SCOFinish() {
+    // Workaround for Safari
+    if (typeof API != 'undefined') {
+       result = API.LMSFinish('');
+    } else {
+       result = API_1484_11.Terminate('');
     }
-    //popupwin(datastring);
-    var myRequest = NewHttpReq();
-    result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>"+datastring);
-    results = result.split('\n');
-    //alert(results);
-    errorCode = results[1];
-    return results[0]; 
 }
+*/
index 35afad6..1fe615b 100755 (executable)
                 fwrite ($bf,full_tag("MODTYPE",4,false,"scorm"));
                 fwrite ($bf,full_tag("NAME",4,false,$scorm->name));
                 fwrite ($bf,full_tag("REFERENCE",4,false,$scorm->reference));
-                fwrite ($bf,full_tag("MAXGRADE",4,false,$scorm->reference));
-                fwrite ($bf,full_tag("GRADEMETHOD",4,false,$scorm->reference));
+                fwrite ($bf,full_tag("VERSION",4,false,$scorm->version));
+                fwrite ($bf,full_tag("MAXGRADE",4,false,$scorm->maxgrade));
+                fwrite ($bf,full_tag("GRADEMETHOD",4,false,$scorm->grademethod));
                 fwrite ($bf,full_tag("LAUNCH",4,false,$scorm->launch));
                 fwrite ($bf,full_tag("SUMMARY",4,false,$scorm->summary));
+                fwrite ($bf,full_tag("BROWSEMODE",4,false,$scorm->browsemode));
                 fwrite ($bf,full_tag("AUTO",4,false,$scorm->auto));
                 fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$scorm->timemodified));
                 $status = backup_scorm_scoes($bf,$preferences,$scorm->id);
@@ -92,6 +94,7 @@
                 fwrite ($bf,full_tag("PARENT",6,false,$sco->parent));
                 fwrite ($bf,full_tag("IDENTIFIER",6,false,$sco->identifier));
                 fwrite ($bf,full_tag("LAUNCH",6,false,$sco->launch));
+                fwrite ($bf,full_tag("PARAMETERS",6,false,$sco->parameters));
                 fwrite ($bf,full_tag("SCORMTYPE",6,false,$sco->scormtype));
                 fwrite ($bf,full_tag("TITLE",6,false,$sco->title));
                 fwrite ($bf,full_tag("PREREQUISITES",6,false,$sco->prerequisites));
index d25d383..853057e 100755 (executable)
@@ -1,8 +1,13 @@
+<?php
+    if (empty($CFG->scorm_frameheight)) {
+       $CFG->scorm_frameheight = 640;
+    }
+?>
 <form method="post" action="module.php" name="form">
 <input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>">
 
 <table cellpadding="9" cellspacing="0" >
-<tr valign="top">
+<!--<tr valign="top">
     <td align="right">scorm_validate:</td>
     <td>
     <?php
     <td>
     <?php print_string("validationtype", "scorm") ?>
     </td>
+</tr> -->
+<tr valign="top">
+    <td align="right">scorm_frameheight:</td>
+    <td>
+       <input type="text" name="scorm_frameheight" value="<?php echo $CFG->scorm_frameheight ?>" size="4" />
+    </td>
+    <td>
+    <?php print_string("frameheight", "scorm") ?>
+    </td>
 </tr>
 <tr>
     <td colspan="3" align="center">
index a5df0b5..87076e0 100644 (file)
@@ -149,7 +149,7 @@ function SCORMapi1_2() {
        if (param == "") {
             if (Initialized) {
                Initialized = false;
-               return StoreData('API',cmi,true);
+               return StoreData(cmi,true);
             } else {
                errorCode = "301";
             }
@@ -203,8 +203,6 @@ function SCORMapi1_2() {
                                    elementIndex = elementIndexes[i];
                                    //alert(elementIndex+' '+elementIndexes[i+1]);
                                    if (elementIndexes[i+1].match(/^\d+$/)) {
-                                       //alert('Matched: '+elementIndexes[i+1]);
-                                       //alert('Check: '+subelement+'.'+elementIndex);
                                        if ((typeof eval(subelement+'.'+elementIndex)) == "undefined") {
                                            eval(subelement+'.'+elementIndex+' = new Object();');
                                            eval(subelement+'.'+elementIndex+'._count = 0;');
@@ -241,7 +239,11 @@ function SCORMapi1_2() {
                                    errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
                                }
                            } else {
-                               eval(element+'="'+value+'";');
+                               if (element == 'cmi.comments') {
+                                   eval(element+'+="'+value+'";');
+                               } else {
+                                   eval(element+'="'+value+'";');
+                               }
                                errorCode = "0";
                                //alert('LMSSetValue: '+element+'\nModel: '+elementmodel+'\nValue: '+value);
                                return "true";
@@ -268,7 +270,7 @@ function SCORMapi1_2() {
     function LMSCommit (param) {
        if (param == "") {
             if (Initialized) {
-               return StoreData('API',cmi,false);
+               return StoreData(cmi,false);
             } else {
                errorCode = "301";
            }
@@ -311,13 +313,64 @@ function SCORMapi1_2() {
 
     function TotalTime() {
         total_time = AddTime(cmi.core.total_time, cmi.core.session_time);
-       //////////////alert (cmi.core.total_time+' '+cmi.core.session_time+' '+total_time);
        return '&'+underscore('cmi.core.total_time')+'='+escape(total_time);
     }
 
-    this.datamodel = datamodel;
-    this.TotalTime = TotalTime;
-    
+    function CollectData(data,parent) {
+       var datastring = '';
+       for (property in data) {
+           if (typeof data[property] == 'object') {
+               datastring += CollectData(data[property],parent+'.'+property);
+           } else {
+               element = parent+'.'+property;
+               expression = new RegExp(CMIIndex,'g');
+               elementmodel = element.replace(expression,'.n.');
+               if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
+                   if (eval('datamodel["'+elementmodel+'"].mod') != 'r') {
+                       if (eval('datamodel["'+elementmodel+'"].defaultvalue') != data[property]) {
+                           datastring += '&'+underscore(element)+'='+escape(data[property]);
+                           //alert(element+'='+data[property]);
+                       }
+                   }
+               }
+           }
+       }
+       return datastring;
+    }
+
+    function StoreData(data,storetotaltime) {
+       if (storetotaltime) {
+           if (cmi.core.lesson_mode == 'normal') {
+               if (cmi.core.credit == 'credit') {
+                   cmi.core.lesson_status = 'completed';
+                   if (cmi.student_data.mastery_score != '') {
+                       if (cmi.core.score.raw >= cmi.student_data.mastery_score) {
+                           cmi.core.lesson_status = 'passed';
+                       } else {
+                           cmi.core.lesson_status = 'failed';
+                       }
+                   }
+               }
+           }
+           if (cmi.core.lesson_mode == 'browse') {
+               if (datamodel['cmi.core.lesson_status'].defaultvalue == '') {
+                   cmi.core.lesson_status = 'browsed';
+               }
+           }
+           datastring = CollectData(data,'cmi');
+           datastring += TotalTime();
+       } else {
+           datastring = CollectData(data,'cmi');
+       }
+       //popupwin(datastring);
+       var myRequest = NewHttpReq();
+       result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>"+datastring);
+       results = result.split('\n');
+       //alert(results);
+       errorCode = results[1];
+       return results[0]; 
+    }
+
     this.LMSInitialize = LMSInitialize;
     this.LMSFinish = LMSFinish;
     this.LMSGetValue = LMSGetValue;
index 870ff55..a9fc68c 100644 (file)
@@ -1,4 +1,8 @@
-    // Standard Data Type Definition
+//
+// SCORM 1.3 API Implementation
+//
+function SCORMapi1_3() {
+   // Standard Data Type Definition
     CMIString255 = '^.{0,255}$';
     CMIString4096 = '^[.|\\n|\\r]{0,4096}$';
     CMITime = '^([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$';
@@ -27,7 +31,7 @@
     audio_range = '-1#100';
     speed_range = '-100#100';
     text_range = '-1#1';
-    // The SCORM 1.2 data model
+    // The SCORM 1.3 data model
     var datamodel =  {
        'cmi._children':{'defaultvalue':cmi_children, 'mod':'r', 'writeerror':'402'},
        'cmi._version':{'defaultvalue':'3.4', 'mod':'r', 'writeerror':'402'},
     this.Commit = Commit;
     this.GetLastError = GetLastError;
     this.GetErrorString = GetErrorString;
-    this.GetDiagnostic = GetDiagnostic;
\ No newline at end of file
+    this.GetDiagnostic = GetDiagnostic;
+}
+
+var API_1484_11 = new SCORMapi1_3();
\ No newline at end of file
index 8f9ea0f..b4fd459 100755 (executable)
@@ -149,6 +149,10 @@ function scorm_upgrade($oldversion) {
        }
     }
 
+    if ($oldversion < 2005042800) {
+       table_column("scorm", "", "browsemode", "TINYINT", "2", "", "1", "NOT NULL", "summary");
+    }
+
     return true;
 }
 ?>
index 393ce64..9ceea0f 100755 (executable)
@@ -133,7 +133,7 @@ function scorm_upgrade($oldversion) {
     }
 
     if ($oldversion < 2005042700) {
-       $trackingdata = get_records_select("scorm_scoes_track","","id ASC");
+       $trackingdata = get_records_select("scorm_scoes_track","1","id ASC");
        if (!empty($trackingdata)) {
            $oldelements = array ('cmi_core_lesson_location','cmi_core_lesson_status','cmi_core_exit','cmi_core_total_time','cmi_core_score_raw','cmi_suspend_data');
            $newelements = array ('cmi.core.lesson_location','cmi.core.lesson_status','cmi.core.exit','cmi.core.total_time','cmi.core.score.raw','cmi.suspend_data');
@@ -146,10 +146,11 @@ function scorm_upgrade($oldversion) {
        }
     }
 
+    if ($oldversion < 2005042800) {
+       table_column("scorm", "", "browsemode", "integer", "", "", "1", "NOT NULL", "summary");
+    }
 
     return true;
 }
-
-
 ?>
 
index a94c14a..10a5b7b 100755 (executable)
@@ -14,8 +14,6 @@ $SCORM_GRADE_METHOD = array (VALUESCOES => get_string('gradescoes', 'scorm'),
 
 if (!isset($CFG->scorm_validate)) {
     $scormvalidate = 'none';
-    //I've commented this out for Moodle 1.4, as I've seen errors in 
-    //SCORM packages even though the actual package worked fine. -- Martin Dougiamas
     if (extension_loaded('domxml') && version_compare(phpversion(),'5.0.0','<')) {
         $scormvalidate = 'domxml';
     }
@@ -25,6 +23,10 @@ if (!isset($CFG->scorm_validate)) {
     set_config('scorm_validate', $scormvalidate);
 }
 
+if (!isset($CFG->scorm_frameheight)) {
+    set_config('scorm_frameheight','640');
+}
+
 function scorm_add_instance($scorm) {
 /// Given an object containing all the necessary data, 
 /// (defined by the form in mod.html) this function 
@@ -903,7 +905,7 @@ function scorm_display_structure($scorm,$liststyle,$currentorg='',$scoid='',$mod
                    }
                    $strstatus = get_string($usertrack->status,'scorm');
                    echo "<img src='pix/".$usertrack->status.".gif' alt='$strstatus' title='$strstatus' />";
-                   if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete')) {
+                   if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
                        $incomplete = true;
                        if ($play && empty($scoid)) {
                            $scoid = $sco->id;
@@ -917,10 +919,10 @@ function scorm_display_structure($scorm,$liststyle,$currentorg='',$scoid='',$mod
                        $scoid = $sco->id;
                    }
                    if ($sco->scormtype == 'sco') {
-                       echo '<img src="pix/notattempted.gif" alt="'.get_string('notattempted','scorm').'" />';
+                       echo '<img src="pix/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
                        $incomplete = true;
                    } else {
-                       echo '<img src="pix/asset.gif" alt="'.get_string('asset','scorm').'" />';
+                       echo '<img src="pix/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
                    }
                }
 
index f1e287f..f01b835 100755 (executable)
 <html>
     <head>
        <title>LoadSCO</title>
+       <meta http-equiv="refresh" content="1;URL=<?php echo $result ?>" />
     </head>
     <body>
-       <script language="javascript">
-           document.location='<?php echo $result ?>';
-       </script>
+       &nbsp;
     </body>
 </html>
index 73a77a8..d35d892 100755 (executable)
@@ -24,6 +24,9 @@
     if (empty($form->grademethod)) {
         $form->grademethod = "0";
     }
+    if (empty($form->browsemode)) {
+        $form->browsemode = "1";
+    }
     $scormid = '';
     if (!empty($form->instance)) {
         $scormid = '&instance='.$form->instance;
                 $options = array();
                 $options[0]=get_string("no");
                 $options[1]=get_string("yes");
-                choose_from_menu ($options, "auto", $form->auto);
+                choose_from_menu ($options, "auto", $form->auto,'');
                 helpbutton("autocontinue", get_string("autocontinue", "scorm"), "scorm", true);
             ?>
            </td>
        </tr>
+       <tr>
+            <td align="right"><b><?php print_string("enablebrowse","scorm") ?>:</b></td>
+            <td>
+            <?php
+                $options = array();
+                $options[0]=get_string("no");
+                $options[1]=get_string("yes");
+                choose_from_menu ($options, "browsemode", $form->browsemode, '');
+                helpbutton("browsemode", get_string("browsemode", "scorm"), "scorm", true);
+            ?>
+           </td>
+       </tr>
     </table>
     <input type="hidden" name="datadir"        value="<?php p($form->datadir) ?>" />
     <input type="hidden" name="pkgtype"        value="<?php p($form->pkgtype) ?>" />
     <input type="hidden" name="launch" value="<?php p($form->launch) ?>" />
-    <input type="hidden" name="maxgrade"       value="<?php p($form->maxgrade) ?>" />
-    <input type="hidden" name="grademethod"    value="<?php p($form->grademethod) ?>" />
+   <!-- <input type="hidden" name="maxgrade"   value="<?php p($form->maxgrade) ?>" />
+    <input type="hidden" name="grademethod"    value="<?php p($form->grademethod) ?>" />-->
     
     <input type="hidden" name="course" value="<?php p($form->course) ?>" />
     <input type="hidden" name="sesskey"        value="<?php p($form->sesskey) ?>" />
index d91bfea..ed0f32c 100755 (executable)
     //
     // Print the page header
     //
-    //$bodyscripts = "onUnload='SCOFinish();'";
+    
+    //$bodyscripts = "onunload='SCOFinish();'";
+    $bodyscripts = '';
     print_header($pagetitle, "$course->fullname",
        "$navigation <a target='{$CFG->framename}' href='view.php?id=$cm->id'>".format_string($scorm->name,true)."</a>",
-       '', '', true, update_module_button($cm->id, $course->id, $strscorm));
+       '', '', true, update_module_button($cm->id, $course->id, $strscorm),'',false,$bodyscripts);
 ?>
     <style type="text/css">
         .scormlist { 
            <tr><td nowrap>  
 <?php
     $sco = scorm_display_structure($scorm,'scormlist',$currentorg,$scoid,$mode,true);
+    if ($mode == 'normal') {
+       if ($trackdata = scorm_get_tracks($USER->id,$sco->id)) {
+           if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
+               $mode = 'review';
+           }
+       }
+    }
     add_to_log($course->id, 'scorm', 'view', "playscorm.php?id=$cm->id&scoid=$sco->id", "$scorm->id");
     $scoidstring = '&scoid='.$sco->id;
+    $modestring = '&mode='.$mode;
 
     $SESSION->scorm_scoid = $sco->id;
 ?>
        </table>
     </td>
     <td class="fullscreen" height="90%">
-       <iframe name="main" class="fullscreen" height="640" src="loadSCO.php?id=<?php echo $cm->id.$scoidstring ?>"></iframe>
+       <iframe name="main" class="fullscreen" height="<?php echo $CFG->scorm_frameheight ?>" src="loadSCO.php?id=<?php echo $cm->id.$scoidstring ?>"></iframe>
     </td></tr>
     </table>
     <script language="JavaScript" type="text/javascript" src="request.js"></script>
-    <script language="JavaScript" type="text/javascript" src="api.php?id=<?php echo $cm->id.$scoidstring ?>"></script>
+    <script language="JavaScript" type="text/javascript" src="api.php?id=<?php echo $cm->id.$scoidstring.$modestring ?>"></script>
 </body>
 </html>
index f229576..8b468c7 100755 (executable)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2005042700;   // The (date) version of this module
+$module->version  = 2005042800;   // The (date) version of this module
 $module->requires = 2005021600;   // The version of Moodle that is required
 $module->cron     = 0;            // How often should cron check this module (seconds)?
 
index 6ef60e3..f39e0d6 100755 (executable)
        print_simple_box_end();
        echo "<form name=\"theform\" method=\"post\" action=\"playscorm.php?id=$cm->id\">\n";
        echo "<table align=\"center\">\n<tr>\n<td align=\"center\">";
-       print_string("mode","scorm");
-        echo ": <input type=\"radio\" id=\"b\" name=\"mode\" value=\"browse\" /><label for=\"b\">".get_string("browse","scorm")."</label>\n";
-        if ($incomplete === true) {
-            echo "<input type=\"radio\" id=\"n\" name=\"mode\" value=\"normal\" checked=\"checked\" /><label for=\"n\">".get_string("normal","scorm")."</label>\n";
-        } else {
-            echo "<input type=\"radio\" id=\"r\" name=\"mode\" value=\"review\" checked=\"checked\" /><label for=\"r\">".get_string("review","scorm")."</label>\n";
-       }
+       if ($scorm->browsemode == 1) {
+           print_string("mode","scorm");
+           echo ": <input type=\"radio\" id=\"b\" name=\"mode\" value=\"browse\" /><label for=\"b\">".get_string("browse","scorm")."</label>\n";
+            if ($incomplete === true) {
+               echo "<input type=\"radio\" id=\"n\" name=\"mode\" value=\"normal\" checked=\"checked\" /><label for=\"n\">".get_string("normal","scorm")."</label>\n";
+            } else {
+               echo "<input type=\"radio\" id=\"r\" name=\"mode\" value=\"review\" checked=\"checked\" /><label for=\"r\">".get_string("review","scorm")."</label>\n";
+           }
+       } else {
+            if ($incomplete === true) {
+               echo '<input type="hidden" name="mode" value="normal" />'."\n";
+           } else {
+               echo '<input type="hidden" name="mode" value="review" />'."\n";
+           }
+       }    
        echo "</td>\n</tr>\n<tr><td align=\"center\">";
        echo '<input type="hidden" name="scoid" />
        <input type="hidden" name="currentorg" value="'.$orgidentifier.'" />