$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';
}
// // 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);
// }
// }
Initialized = true;
errorCode = "0";
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
//echo 'alert("Initialized SCORM 1.2");';
echo 'LogAPICall("LMSInitialize", param, "", errorCode);';
}
errorCode = "201";
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("LMSInitialize", param, "", errorCode);';
}
?>
}
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
//echo 'alert("Finished SCORM 1.2");';
echo 'LogAPICall("LMSFinish", param, "", 0);';
}
errorCode = "201";
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("LMSFinish", param, "", errorCode);';
}
?>
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);';
}
errorCode = "301";
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("LMSGetValue", element, "", errorCode);';
}
?>
eval(element+'=value;');
errorCode = "0";
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("LMSSetValue", element, value, errorCode);';
//echo 'alert(element+":= "+value);';
}
}
errorCode = "0";
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("LMSSetValue", element, value, errorCode);';
//echo 'alert(element+":= "+value);';
}
errorCode = "301";
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("LMSSetValue", element, value, errorCode);';
}
?>
if (Initialized) {
result = StoreData(cmi,false);
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("Commit", param, "", 0);';
//echo 'alert("Data Commited");';
}
errorCode = "201";
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("LMSCommit", param, "", 0);';
}
?>
function LMSGetLastError () {
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("LMSGetLastError", "", "", errorCode);';
}
?>
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);';
}
?>
param = errorCode;
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("LMSGetDiagnostic", param, param, 0);';
}
?>
<?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);';
}
Initialized = true;
errorCode = "0";
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
// echo 'alert("Initialized SCORM 1.3");';
echo 'LogAPICall("Initialize", param, "", errorCode);';
}
errorCode = "201";
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
// echo 'alert("Initialize: "+GetErrorString(errorCode));';
echo 'LogAPICall("Initialize", param, "", errorCode);';
}
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);';
}
errorCode = "201";
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'alert("Terminate: "+GetErrorString(errorCode));';
}
?>
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);';
}
}
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
// echo 'alert("GetValue("+element+") -> "+GetErrorString(errorCode));';
echo 'LogAPICall("GetValue", element, "", errorCode);';
}
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);';
}
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);';
}
}
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("SetValue", element, value, errorCode);';
}
?>
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");';
}
errorCode = "201";
}
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("Commit", param, "", 0);';
// echo 'alert("Commit: "+GetErrorString(errorCode));';
}
function GetLastError () {
<?php
- if (debugging('',DEBUG_DEVELOPER)) {
+ if (scorm_debugging($scorm)) {
echo 'LogAPICall("GetLastError", "", "", errorCode);';
}
?>
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);';
}
?>
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);';
}
?>
function AddTime (first, second) {
<?php
-// if (debugging('',DEBUG_DEVELOPER)) {
+// if (scorm_debugging($scorm)) {
// echo 'alert("AddTime: "+first+" + "+second);';
// }
?>
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);';
// }
?>
<?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);';
}
</head>
<body onload="doredirect();">
<p><?php echo get_string('activityloading', 'scorm');?> <span id="countdown"><?php echo $delayseconds ?></span> <?php echo get_string('numseconds');?>. <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);
}
?>
}
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
$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'),
+ '', '.*'));