From: piers Date: Tue, 16 Sep 2008 22:50:16 +0000 (+0000) Subject: MDL-7097 - API debug. Change the control of debugging over to SCORM admin settings. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1881df27331f2cc2212d656aa479beef3d28b721;p=moodle.git MDL-7097 - API debug. Change the control of debugging over to SCORM admin settings. --- diff --git a/lang/en_utf8/scorm.php b/lang/en_utf8/scorm.php index cd91df31b9..cda8290314 100644 --- a/lang/en_utf8/scorm.php +++ b/lang/en_utf8/scorm.php @@ -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 <username>:<activityname>)'; $string['allowtypeexternal'] = 'Enable external package type'; $string['allowtypeimsrepository'] = 'Enable IMS package type'; $string['allowtypelocalsync'] = 'Enable downloaded package type'; diff --git a/mod/scorm/datamodel.php b/mod/scorm/datamodel.php index a10875b745..774850921b 100755 --- a/mod/scorm/datamodel.php +++ b/mod/scorm/datamodel.php @@ -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); // } // } diff --git a/mod/scorm/datamodels/scorm_12.js.php b/mod/scorm/datamodels/scorm_12.js.php index c71e6f0b80..e565ae8285 100644 --- a/mod/scorm/datamodels/scorm_12.js.php +++ b/mod/scorm/datamodels/scorm_12.js.php @@ -159,7 +159,7 @@ function SCORMapi1_2() { Initialized = true; errorCode = "0"; @@ -197,7 +197,7 @@ function SCORMapi1_2() { } } @@ -235,7 +235,7 @@ function SCORMapi1_2() { if (subelement == element) { errorCode = "0"; @@ -345,7 +345,7 @@ function SCORMapi1_2() { eval(element+'=value;'); errorCode = "0"; @@ -399,7 +399,7 @@ function SCORMapi1_2() { if (Initialized) { result = StoreData(cmi,false); @@ -421,7 +421,7 @@ function SCORMapi1_2() { function LMSGetLastError () { @@ -443,14 +443,14 @@ function SCORMapi1_2() { errorString["404"] = "Element is write only"; errorString["405"] = "Incorrect data type"; return errorString[param]; } else { @@ -463,7 +463,7 @@ function SCORMapi1_2() { param = errorCode; } @@ -603,7 +603,7 @@ var API = new SCORMapi1_2(); dirroot.'/mod/scorm/datamodels/debug.js.php'); echo 'AppendToLog("Moodle SCORM 1.2 API Loaded, Activity: '.$scorm->name.', SCO: '.$sco->identifier.'", 0);'; } diff --git a/mod/scorm/datamodels/scorm_13.js.php b/mod/scorm/datamodels/scorm_13.js.php index bc3aae1b2c..b17ff57494 100644 --- a/mod/scorm/datamodels/scorm_13.js.php +++ b/mod/scorm/datamodels/scorm_13.js.php @@ -230,7 +230,7 @@ function SCORMapi1_3() { Initialized = true; errorCode = "0"; @@ -336,7 +336,7 @@ function SCORMapi1_3() { if ((typeof eval(subelement) != "undefined") && (eval(subelement) != null)) { errorCode = "0"; "+eval(element));'; echo 'LogAPICall("GetValue", element, eval(element), 0);'; } @@ -402,7 +402,7 @@ function SCORMapi1_3() { } } "+GetErrorString(errorCode));'; echo 'LogAPICall("GetValue", element, "", errorCode);'; } @@ -768,7 +768,7 @@ function SCORMapi1_3() { eval(element+'=value;'); errorCode = "0"; OK");'; echo 'LogAPICall("SetValue", element, value, errorCode);'; } @@ -784,7 +784,7 @@ function SCORMapi1_3() { eval(element+'=value;'); errorCode = "0"; OK");'; echo 'LogAPICall("SetValue", element, value, errorCode);'; } @@ -812,7 +812,7 @@ function SCORMapi1_3() { } } @@ -825,7 +825,7 @@ function SCORMapi1_3() { if ((Initialized) && (!Terminated)) { result = StoreData(cmi,false); @@ -943,14 +943,14 @@ function SCORMapi1_3() { break; } return errorString; } else { @@ -961,14 +961,14 @@ function SCORMapi1_3() { function GetDiagnostic (param) { if (diagnostic != "") { return diagnostic; } @@ -1012,7 +1012,7 @@ function SCORMapi1_3() { function AddTime (first, second) { @@ -1119,14 +1119,14 @@ function SCORMapi1_3() { datastring += '&attempt='; datastring += '&scoid='; var myRequest = NewHttpReq(); var result = DoRequest(myRequest,"wwwroot) ?>/mod/scorm/datamodel.php","id=&sesskey=sesskey) ?>"+datastring); @@ -1153,7 +1153,7 @@ var API_1484_11 = new SCORMapi1_3(); dirroot.'/mod/scorm/datamodels/debug.js.php'); echo 'AppendToLog("Moodle SCORM 1.3 API Loaded, Activity: '.$scorm->name.', SCO: '.$sco->identifier.'", 0);'; } diff --git a/mod/scorm/loadSCO.php b/mod/scorm/loadSCO.php index b60e9554dd..597cf8d12c 100755 --- a/mod/scorm/loadSCO.php +++ b/mod/scorm/loadSCO.php @@ -140,7 +140,7 @@

.  

- id, 'scorm', 'launch', 'view.php?id='.$cm->id, $result, $cm->id); } ?> diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 28a6ff0355..c4e36ae478 100755 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -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 diff --git a/mod/scorm/settings.php b/mod/scorm/settings.php index 5c75fcf2c7..0563e7bd37 100644 --- a/mod/scorm/settings.php +++ b/mod/scorm/settings.php @@ -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'), + '', '.*'));