MDL-7097 - API debug. Change the control of debugging over to SCORM admin settings.
authorpiers <piers>
Tue, 16 Sep 2008 22:50:16 +0000 (22:50 +0000)
committerpiers <piers>
Tue, 16 Sep 2008 22:50:16 +0000 (22:50 +0000)
lang/en_utf8/scorm.php
mod/scorm/datamodel.php
mod/scorm/datamodels/scorm_12.js.php
mod/scorm/datamodels/scorm_13.js.php
mod/scorm/loadSCO.php
mod/scorm/locallib.php
mod/scorm/settings.php

index cd91df3..cda8290 100644 (file)
@@ -4,6 +4,8 @@
 
 $string['activation'] = 'Activation';
 $string['advanced'] = 'Parameters';
+$string['allowapidebug'] = 'Activate API debug and tracing (set the capture mask with apidebugmask)';
+$string['apidebugmask'] = 'API debug capture mask (simple regex on &lt;username&gt;:&lt;activityname&gt;)';
 $string['allowtypeexternal'] = 'Enable external package type';
 $string['allowtypeimsrepository'] = 'Enable IMS package type';
 $string['allowtypelocalsync'] = 'Enable downloaded package type';
index a10875b..7748509 100755 (executable)
@@ -69,7 +69,7 @@
                 }
 //                // Log every datamodel update requested
 //                if (substr($element,0,15) == 'adl.nav.request' || substr($element,0,3) == 'cmi') {
-//                    if (debugging('',DEBUG_DEVELOPER)) {
+//                    if (scorm_debugging($scorm)) {
 //                        add_to_log($course->id, 'scorm', 'trk: '.trim($scorm->name).' at: '.$attempt, 'view.php?id='.$cm->id, "$element => $value", $cm->id);
 //                    }
 //                }
index c71e6f0..e565ae8 100644 (file)
@@ -159,7 +159,7 @@ function SCORMapi1_2() {
                 Initialized = true;
                 errorCode = "0";
                 <?php 
-                    if (debugging('',DEBUG_DEVELOPER)) {
+                    if (scorm_debugging($scorm)) {
                         //echo 'alert("Initialized SCORM 1.2");';
                         echo 'LogAPICall("LMSInitialize", param, "", errorCode);';
                     }
@@ -172,7 +172,7 @@ function SCORMapi1_2() {
             errorCode = "201";
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("LMSInitialize", param, "", errorCode);';
             }
         ?>
@@ -197,7 +197,7 @@ function SCORMapi1_2() {
                     }
                 }    
                 <?php 
-                    if (debugging('',DEBUG_DEVELOPER)) {
+                    if (scorm_debugging($scorm)) {
                         //echo 'alert("Finished SCORM 1.2");';
                         echo 'LogAPICall("LMSFinish", param, "", 0);';
                     }
@@ -210,7 +210,7 @@ function SCORMapi1_2() {
             errorCode = "201";
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("LMSFinish", param, "", errorCode);';
             }
         ?>
@@ -235,7 +235,7 @@ function SCORMapi1_2() {
                             if (subelement == element) {
                             errorCode = "0";
                             <?php 
-                                if (debugging('',DEBUG_DEVELOPER)) {
+                                if (scorm_debugging($scorm)) {
                                    //echo 'alert(element+": "+eval(element));';
                                     echo 'LogAPICall("LMSGetValue", element, eval(element), 0);';
                                 }
@@ -275,7 +275,7 @@ function SCORMapi1_2() {
             errorCode = "301";
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("LMSGetValue", element, "", errorCode);';
             }
         ?>
@@ -345,7 +345,7 @@ function SCORMapi1_2() {
                                         eval(element+'=value;');
                                         errorCode = "0";
                                         <?php 
-                                            if (debugging('',DEBUG_DEVELOPER)) {
+                                            if (scorm_debugging($scorm)) {
                                                 echo 'LogAPICall("LMSSetValue", element, value, errorCode);';
                                                 //echo 'alert(element+":= "+value);';
                                             }
@@ -362,7 +362,7 @@ function SCORMapi1_2() {
                                     }
                                     errorCode = "0";
                                     <?php 
-                                        if (debugging('',DEBUG_DEVELOPER)) {
+                                        if (scorm_debugging($scorm)) {
                                             echo 'LogAPICall("LMSSetValue", element, value, errorCode);';
                                             //echo 'alert(element+":= "+value);';
                                         }
@@ -386,7 +386,7 @@ function SCORMapi1_2() {
             errorCode = "301";
         }
        <?php 
-        if (debugging('',DEBUG_DEVELOPER)) {
+        if (scorm_debugging($scorm)) {
             echo 'LogAPICall("LMSSetValue", element, value, errorCode);';
         }
         ?>
@@ -399,7 +399,7 @@ function SCORMapi1_2() {
             if (Initialized) {
                 result = StoreData(cmi,false);
                 <?php 
-                    if (debugging('',DEBUG_DEVELOPER)) {
+                    if (scorm_debugging($scorm)) {
                         echo 'LogAPICall("Commit", param, "", 0);';
                         //echo 'alert("Data Commited");';
                     }
@@ -412,7 +412,7 @@ function SCORMapi1_2() {
             errorCode = "201";
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("LMSCommit", param, "", 0);';
             }
         ?>
@@ -421,7 +421,7 @@ function SCORMapi1_2() {
     
     function LMSGetLastError () {
      <?php 
-        if (debugging('',DEBUG_DEVELOPER)) {
+        if (scorm_debugging($scorm)) {
             echo 'LogAPICall("LMSGetLastError", "", "", errorCode);';
         }
     ?>
@@ -443,14 +443,14 @@ function SCORMapi1_2() {
             errorString["404"] = "Element is write only";
             errorString["405"] = "Incorrect data type";
             <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("LMSGetErrorString", param,  errorString[param], 0);';
             }
              ?>
             return errorString[param];
         } else {
            <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("LMSGetErrorString", param,  "No error string found!", 0);';
             }
              ?>
@@ -463,7 +463,7 @@ function SCORMapi1_2() {
             param = errorCode;
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("LMSGetDiagnostic", param, param, 0);';
             }
         ?>
@@ -603,7 +603,7 @@ var API = new SCORMapi1_2();
 
 <?php
 // pull in the debugging utilities
-if (debugging('',DEBUG_DEVELOPER)) {
+if (scorm_debugging($scorm)) {
     include_once($CFG->dirroot.'/mod/scorm/datamodels/debug.js.php');
     echo 'AppendToLog("Moodle SCORM 1.2 API Loaded, Activity: '.$scorm->name.', SCO: '.$sco->identifier.'", 0);';
 }
index bc3aae1..b17ff57 100644 (file)
@@ -230,7 +230,7 @@ function SCORMapi1_3() {
                 Initialized = true;
                 errorCode = "0";
                 <?php 
-                    if (debugging('',DEBUG_DEVELOPER)) {
+                    if (scorm_debugging($scorm)) {
 //                        echo 'alert("Initialized SCORM 1.3");';
                         echo 'LogAPICall("Initialize", param, "", errorCode);';
                     }
@@ -247,7 +247,7 @@ function SCORMapi1_3() {
             errorCode = "201";
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
 //                echo 'alert("Initialize: "+GetErrorString(errorCode));';
                 echo 'LogAPICall("Initialize", param, "", errorCode);';
             }
@@ -260,7 +260,7 @@ function SCORMapi1_3() {
         if (param == "") {
             if ((Initialized) && (!Terminated)) {
                 <?php 
-                    if (debugging('',DEBUG_DEVELOPER)) {
+                    if (scorm_debugging($scorm)) {
 //                        echo 'alert("Terminated SCORM 1.3");';
                         echo 'LogAPICall("Terminate", param, "", 0);';
                     }
@@ -304,7 +304,7 @@ function SCORMapi1_3() {
             errorCode = "201";
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'alert("Terminate: "+GetErrorString(errorCode));';
             }
         ?>
@@ -336,7 +336,7 @@ function SCORMapi1_3() {
                             if ((typeof eval(subelement) != "undefined") && (eval(subelement) != null)) {
                                 errorCode = "0";
                                 <?php 
-                                    if (debugging('',DEBUG_DEVELOPER)) {
+                                    if (scorm_debugging($scorm)) {
 //                                        echo 'alert("GetValue("+element+") -> "+eval(element));';
                                         echo 'LogAPICall("GetValue", element, eval(element), 0);';
                                     }
@@ -402,7 +402,7 @@ function SCORMapi1_3() {
             }
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
 //                echo 'alert("GetValue("+element+") -> "+GetErrorString(errorCode));';
                 echo 'LogAPICall("GetValue", element, "", errorCode);';
             }
@@ -768,7 +768,7 @@ function SCORMapi1_3() {
                                             eval(element+'=value;');
                                             errorCode = "0";
                                             <?php 
-                                                if (debugging('',DEBUG_DEVELOPER)) {
+                                                if (scorm_debugging($scorm)) {
 //                                                    echo 'alert("SetValue("+element+","+value+") -> OK");';
                                                     echo 'LogAPICall("SetValue", element, value, errorCode);';
                                                 }
@@ -784,7 +784,7 @@ function SCORMapi1_3() {
                                     eval(element+'=value;');
                                     errorCode = "0"; 
                                     <?php 
-                                        if (debugging('',DEBUG_DEVELOPER)) {
+                                        if (scorm_debugging($scorm)) {
 //                                           echo 'alert("SetValue("+element+","+value+") -> OK");';
                                             echo 'LogAPICall("SetValue", element, value, errorCode);';
                                         }
@@ -812,7 +812,7 @@ function SCORMapi1_3() {
             }
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("SetValue", element, value, errorCode);';
             }
         ?>
@@ -825,7 +825,7 @@ function SCORMapi1_3() {
             if ((Initialized) && (!Terminated)) {
                 result = StoreData(cmi,false);
                 <?php 
-                    if (debugging('',DEBUG_DEVELOPER)) {
+                    if (scorm_debugging($scorm)) {
                         echo 'LogAPICall("Commit", param, "", 0);';
                         //echo 'alert("Data Commited");';
                     }
@@ -842,7 +842,7 @@ function SCORMapi1_3() {
             errorCode = "201";
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("Commit", param, "", 0);';
 //                echo 'alert("Commit: "+GetErrorString(errorCode));';
             }
@@ -852,7 +852,7 @@ function SCORMapi1_3() {
     
     function GetLastError () {
      <?php 
-        if (debugging('',DEBUG_DEVELOPER)) {
+        if (scorm_debugging($scorm)) {
             echo 'LogAPICall("GetLastError", "", "", errorCode);';
         }
     ?>
@@ -943,14 +943,14 @@ function SCORMapi1_3() {
                 break;
             }
             <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("GetErrorString", param,  errorString, 0);';
             }
              ?>
             return errorString;
         } else {
            <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("GetErrorString", param,  "No error string found!", 0);';
             }
              ?>
@@ -961,14 +961,14 @@ function SCORMapi1_3() {
     function GetDiagnostic (param) {
         if (diagnostic != "") {
             <?php 
-                if (debugging('',DEBUG_DEVELOPER)) {
+                if (scorm_debugging($scorm)) {
                     echo 'LogAPICall("GetDiagnostic", param, diagnostic, 0);';
                 }
             ?>
             return diagnostic;
         }
         <?php 
-            if (debugging('',DEBUG_DEVELOPER)) {
+            if (scorm_debugging($scorm)) {
                 echo 'LogAPICall("GetDiagnostic", param, param, 0);';
             }
         ?>
@@ -1012,7 +1012,7 @@ function SCORMapi1_3() {
 
     function AddTime (first, second) {
         <?php 
-//            if (debugging('',DEBUG_DEVELOPER)) {
+//            if (scorm_debugging($scorm)) {
 //                echo 'alert("AddTime: "+first+" + "+second);';
 //            }
         ?>
@@ -1119,14 +1119,14 @@ function SCORMapi1_3() {
         datastring += '&attempt=<?php echo $attempt ?>';
         datastring += '&scoid=<?php echo $scoid ?>';
         <?php
-//            if (debugging('',DEBUG_DEVELOPER)) {
+//            if (scorm_debugging($scorm)) {
 //                echo 'popupwin(datastring);';
 //            }
         ?>
         var myRequest = NewHttpReq();
         var result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>"+datastring);
         <?php
-//            if (debugging('',DEBUG_DEVELOPER)) {
+//            if (scorm_debugging($scorm)) {
 //                echo 'popupwin(result);';
 //            }
         ?>
@@ -1153,7 +1153,7 @@ var API_1484_11 = new SCORMapi1_3();
 
 <?php
 // pull in the debugging utilities
-if (debugging('',DEBUG_DEVELOPER)) {
+if (scorm_debugging($scorm)) {
     include_once($CFG->dirroot.'/mod/scorm/datamodels/debug.js.php');
     echo 'AppendToLog("Moodle SCORM 1.3 API Loaded, Activity: '.$scorm->name.', SCO: '.$sco->identifier.'", 0);';
 }
index b60e955..597cf8d 100755 (executable)
     </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 (debugging('',DEBUG_DEVELOPER)) {
+        <?php if (scorm_debugging($scorm)) {
                   add_to_log($course->id, 'scorm', 'launch', 'view.php?id='.$cm->id, $result, $cm->id);
               }
         ?>
index 28a6ff0..c4e36ae 100755 (executable)
@@ -896,4 +896,26 @@ function scorm_get_attempt_count($user, $scorm) {
     }
     return $attemptcount;
 }
+
+/**
+* Figure out with this is a debug situation
+*
+* @param object $scorm a moodle scrom object - mdl_scorm
+* @return boolean - debugging true/false
+*/   
+function scorm_debugging($scorm) {
+    global $CFG, $USER;
+    if (!$CFG->scorm_allowapidebug) {
+        return false;
+    }
+    $identifier = $USER->username.':'.$scorm->name;
+    $test = $CFG->scorm_apidebugmask;
+    // check the regex is only a short list of safe characters
+    if (!preg_match('/^[\w\s\*\.\?\+\:\_\\\]+$/', $test)) {
+        return false;
+    }
+    $res = false;
+    eval('$res = preg_match(\'/^'.$test.'/\', $identifier) ? true : false;');
+    return $res;
+}
 ?>
\ No newline at end of file
index 5c75fcf..0563e7b 100644 (file)
@@ -21,5 +21,8 @@ $settings->add(new admin_setting_configcheckbox('scorm_allowtypelocalsync', get_
 $settings->add(new admin_setting_configcheckbox('scorm_allowtypeimsrepository', get_string('allowtypeimsrepository', 'scorm'),
                    '', 0));
 
+$settings->add(new admin_setting_configcheckbox('scorm_allowapidebug', get_string('allowapidebug', 'scorm'),
+                   '', 0));
 
-
+$settings->add(new admin_setting_configtext('scorm_apidebugmask', get_string('apidebugmask', 'scorm'),
+                   '', '.*'));