Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/scorm/datamodels/debug.js.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 ?>
00018 
00019 <!--// hopefully fool ie IE proof way of getting DOM element
00020 function safeGetElement(doc, el) {
00021     return doc.ids ? doc.ids[el] : doc.getElementById ? doc.getElementById(el) : doc.all[el];
00022 }
00023 // Find elements by class name
00024 var aryClassElements = new Array();
00025 function getNextElementByClassName( strClassName, obj ) {
00026     if ( obj.className == strClassName ) {
00027         aryClassElements[aryClassElements.length] = obj;
00028     }
00029     for ( var i = 0; i < obj.childNodes.length; i++ )
00030         getNextElementByClassName( strClassName, obj.childNodes[i] );
00031 }
00032 
00033 function getElementsByClassName( strClassName, obj ) {
00034     aryClassElements = new Array();
00035     getNextElementByClassName( strClassName, obj );
00036     if (aryClassElements.length > 0) {
00037         return aryClassElements[0];
00038     }
00039     else {
00040         return null;
00041     }
00042 }
00043 
00044 // retrieve cookie data
00045 function getCookie (cookie_name){
00046     var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
00047     if ( results ) {
00048         return (unescape(results[2]));
00049     } else {
00050         return null;
00051     }
00052 }
00053 
00054 // retrieve the logging flag from a Cookie
00055 function getLoggingActive () {
00056     var loggingActive = getCookie('SCORMLoggingActive');
00057     if (!loggingActive) {
00058         loggingActive = 'A';
00059     }
00060     return loggingActive;
00061 }
00062 
00063 // set the logging flag in a cookie
00064 function setLoggingActive (flag) {
00065     new cookie("SCORMLoggingActive", flag, 365, "/").set();
00066 }
00067 
00068 // toggle the logging
00069 function toggleLog () {
00070     if (getLoggingActive() == "A") {
00071         AppendToLog("Moodle Logging Deactivated", 0);
00072         setLoggingActive('N');
00073         logButton.innerHTML = '--><?php echo addslashes_js(get_string('scormloggingoff', 'scorm')); ?>';
00074     } else {
00075         setLoggingActive('A');
00076         AppendToLog("Moodle Logging Activated", 0);
00077         logButton.innerHTML = '<?php echo addslashes_js(get_string('scormloggingon', 'scorm')); ?>';
00078         logPopUpWindow.focus();
00079     }
00080 }
00081 
00082 // globals for the log accumulation
00083 var logString = "";
00084 var logRow = 0;
00085 var logPopUpWindow = "N";
00086 var debugSCORMVersion = '<?php echo $scorm->version; ?>';
00087 <?php
00088    $LMS_prefix = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'LMS' : '';
00089    $LMS_api = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'API' : 'API_1484_11';
00090 
00091    $LMS_elements = array();
00092    if (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) {
00093        $LMS_elements = array(   'cmi.core._children',
00094                                 'cmi.core.student_id',
00095                                 'cmi.core.student_name',
00096                                 'cmi.core.lesson_location',
00097                                 'cmi.core.credit',
00098                                 'cmi.core.lesson_status',
00099                                 'cmi.core.entry',
00100                                 'cmi.core._children',
00101                                 'cmi.core.score.raw',
00102                                 'cmi.core.score.max',
00103                                 'cmi.core.score.min',
00104                                 'cmi.core.total_time',
00105                                 'cmi.core.lesson_mode',
00106                                 'cmi.core.exit',
00107                                 'cmi.core.session_time',
00108                                 'cmi.suspend_data',
00109                                 'cmi.launch_data',
00110                                 'cmi.comments',
00111                                 'cmi.comments_from_lms',
00112                                 'cmi.objectives._count',
00113                                 'cmi.objectives._children',
00114                                 'cmi.objectives.n.id',
00115                                 'cmi.objectives.n.score._children',
00116                                 'cmi.objectives.n.score.raw',
00117                                 'cmi.objectives.n.score.min',
00118                                 'cmi.objectives.n.score.max',
00119                                 'cmi.objectives.n.status',
00120                                 'cmi.student_data._children',
00121                                 'cmi.student_data.mastery_score',
00122                                 'cmi.student_data.max_time_allowed',
00123                                 'cmi.student_data.time_limit_action',
00124                                 'cmi.student_preference._children',
00125                                 'cmi.student_preference.audio',
00126                                 'cmi.student_preference.language',
00127                                 'cmi.student_preference.speed',
00128                                 'cmi.student_preference.text',
00129                                 'cmi.interactions._children',
00130                                 'cmi.interactions._count',
00131                                 'cmi.interactions.n.id',
00132                                 'cmi.interactions.n.objectives._count',
00133                                 'cmi.interactions.n.objectives.m.id',
00134                                 'cmi.interactions.n.time',
00135                                 'cmi.interactions.n.type',
00136                                 'cmi.interactions.n.correct_responses._count',
00137                                 'cmi.interactions.n.correct_responses.m.pattern',
00138                                 'cmi.interactions.n.weighting',
00139                                 'cmi.interactions.n.student_response',
00140                                 'cmi.interactions.n.result',
00141                                 'cmi.interactions.n.latency');
00142    } else {
00143        $LMS_elements = array(   'cmi._children',
00144                                 'cmi._version',
00145                                 'cmi.learner_id',
00146                                 'cmi.learner_name',
00147                                 'cmi.location',
00148                                 'cmi.completion_status',
00149                                 'cmi.completion_threshold',
00150                                 'cmi.scaled_passing_score',
00151                                 'cmi.progressive_measure',
00152                                 'cmi.score._children',
00153                                 'cmi.score.raw',
00154                                 'cmi.score.max',
00155                                 'cmi.score.min',
00156                                 'cmi.score.scaled',
00157                                 'cmi.total_time',
00158                                 'cmi.time_limit_action',
00159                                 'cmi.max_time_allowed',
00160                                 'cmi.session_time',
00161                                 'cmi.success_status',
00162                                 'cmi.lesson_mode',
00163                                 'cmi.entry',
00164                                 'cmi.exit',
00165                                 'cmi.credit',
00166                                 'cmi.mode',
00167                                 'cmi.suspend_data',
00168                                 'cmi.launch_data',
00169                                 'cmi.comments',
00170                                 'cmi.comments_from_lms._children',
00171                                 'cmi.comments_from_lms._count',
00172                                 'cmi.comments_from_lms.n.comment',
00173                                 'cmi.comments_from_lms.n.location',
00174                                 'cmi.comments_from_lms.n.timestamp',
00175                                 'cmi.comments_from_learner._children',
00176                                 'cmi.comments_from_learner._count',
00177                                 'cmi.comments_from_learner.n.comment',
00178                                 'cmi.comments_from_learner.n.location',
00179                                 'cmi.comments_from_learner.n.timestamp',
00180                                 'cmi.objectives._count',
00181                                 'cmi.objectives._children',
00182                                 'cmi.objectives.n.id',
00183                                 'cmi.objectives.n.score._children',
00184                                 'cmi.objectives.n.score.raw',
00185                                 'cmi.objectives.n.score.min',
00186                                 'cmi.objectives.n.score.max',
00187                                 'cmi.objectives.n.score.scaled',
00188                                 'cmi.objectives.n.success_status',
00189                                 'cmi.objectives.n.completion_status',
00190                                 'cmi.objectives.n.progress_measure',
00191                                 'cmi.objectives.n.description',
00192                                 'cmi.student_data._children',
00193                                 'cmi.student_data.mastery_score',
00194                                 'cmi.student_data.max_time_allowed',
00195                                 'cmi.student_data.time_limit_action',
00196                                 'cmi.student_preference._children',
00197                                 'cmi.student_preference.audio',
00198                                 'cmi.student_preference.language',
00199                                 'cmi.student_preference.speed',
00200                                 'cmi.student_preference.text',
00201                                 'cmi.interactions._children',
00202                                 'cmi.interactions._count',
00203                                 'cmi.interactions.n.id',
00204                                 'cmi.interactions.n.objectives._count',
00205                                 'cmi.interactions.n.objectives.m.id',
00206                                 'cmi.interactions.n.time',
00207                                 'cmi.interactions.n.type',
00208                                 'cmi.interactions.n.correct_responses._count',
00209                                 'cmi.interactions.n.correct_responses.m.pattern',
00210                                 'cmi.interactions.n.weighting',
00211                                 'cmi.interactions.n.learner_response',
00212                                 'cmi.interactions.n.result',
00213                                 'cmi.interactions.n.latency',
00214                                 'cmi.interactions.n.description',
00215                                 'adl.nav.request');
00216    }
00217 ?>
00218 
00219 // add each entry to the log, or setup the log pane first time round
00220 // The code written into the header is based on the ADL test suite API interaction code
00221 // and various examples of test wrappers out in the community
00222 function UpdateLog(s) {
00223     var s1 = '<html><head><style>\n'
00224         + 'body {font-family: Arial, Helvetica, Sans-Serif;font-size: xx-small;'
00225         + 'margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; '
00226         + 'background-color: ffffff;}\n'
00227         + '.even {background-color: ffffff; width: 100%;}\n'
00228         + '.odd {background-color: e8f2fe; width: 100%;}\n'
00229         + '.error {background-color: ffffff; color: red; width: 100%;}\n'
00230         + '<\/style>'
00231         + '<script>\n'
00232         + 'var LMSVersion = \'<?php echo $scorm->version; ?>\';\n'
00233         + ' \n'
00234         + 'function checkLMSVersion() {  \n'
00235         + '    if (this.document.body.childNodes.length > 0) { \n'
00236         + '        if (this.document.body.lastChild.id == LMSVersion) { \n'
00237         + '            return true; \n'
00238         + '        } \n'
00239         + '    }; \n'
00240         + '    alert(\'LMS Version: \' + this.document.body.lastChild.id + \n'
00241         + '          \' does not equal: \' + LMSVersion +  \n'
00242         + '          \' so API calls will fail - did navigate to another SCORM package?\'); \n'
00243         + '    return false; \n'
00244         + '} \n'
00245         + ' \n'
00246         + 'var saveElement = ""; \n'
00247         + 'function setAPIValue() {  \n'
00248         + '  document.elemForm.API_ELEMENT.value = document.elemForm.ELEMENT_LIST.value; \n'
00249         + '  saveElement = document.elemForm.API_ELEMENT.value; \n'
00250         + '} \n'
00251         + '  \n'
00252         + 'var _Debug = false;  // set this to false to turn debugging off  \n'
00253         + '  \n'
00254         + '// Define exception/error codes  \n'
00255         + 'var _NoError = 0;  \n'
00256         + 'var _GeneralException = 101;  \n'
00257         + 'var _ServerBusy = 102;  \n'
00258         + 'var _InvalidArgumentError = 201;  \n'
00259         + 'var _ElementCannotHaveChildren = 202;  \n'
00260         + 'var _ElementIsNotAnArray = 203;  \n'
00261         + 'var _NotInitialized = 301;  \n'
00262         + 'var _NotImplementedError = 401;  \n'
00263         + 'var _InvalidSetValue = 402;  \n'
00264         + 'var _ElementIsReadOnly = 403;  \n'
00265         + 'var _ElementIsWriteOnly = 404;  \n'
00266         + 'var _IncorrectDataType = 405;  \n'
00267         + '  \n'
00268         + '// local variable definitions  \n'
00269         + 'var apiHandle = null;  \n'
00270         + 'var API = null;  \n'
00271         + 'var findAPITries = 0;  \n'
00272         + '  \n'
00273         + '  \n'
00274         + 'function doLMSInitialize() { \n'
00275         + '   checkLMSVersion(); \n'
00276         + '   var api = getAPIHandle();  \n'
00277         + '   if (api == null) {  \n'
00278         + '      alert("Unable to locate the LMS\'s API Implementation.\\nLMSInitialize was not successful.");  \n'
00279         + '      return "false";  \n'
00280         + '   }  \n'
00281         + '   var result = api.<?php echo $LMS_prefix; ?>Initialize("");  \n'
00282         + '   if (result.toString() != "true") {  \n'
00283         + '      var err = ErrorHandler();  \n'
00284         + '   }  \n'
00285         + '   return result.toString();  \n'
00286         + '}  \n'
00287         + '  \n'
00288         + 'function doLMSFinish() {  \n'
00289         + '   checkLMSVersion(); \n'
00290         + '   var api = getAPIHandle();  \n'
00291         + '   if (api == null) {  \n'
00292         + '      alert("Unable to locate the LMS\'s API Implementation.\\nLMSFinish was not successful.");  \n'
00293         + '      return "false";  \n'
00294         + '   } else {  \n'
00295         + '      // call the LMSFinish function that should be implemented by the API  \n'
00296         + '      var result = api.<?php echo $LMS_prefix; ?>Finish("");  \n'
00297         + '      if (result.toString() != "true") {  \n'
00298         + '         var err = ErrorHandler();  \n'
00299         + '      }  \n'
00300         + '   }  \n'
00301         + '   return result.toString();  \n'
00302         + '}  \n'
00303         + '  \n'
00304         + 'function doLMSTerminate() {  \n'
00305         + '   checkLMSVersion(); \n'
00306         + '   var api = getAPIHandle();  \n'
00307         + '   if (api == null) {  \n'
00308         + '      alert("Unable to locate the LMS\'s API Implementation.\\nTerminate was not successful.");  \n'
00309         + '      return "false";  \n'
00310         + '   } else {  \n'
00311         + '      // call the Terminate function that should be implemented by the API  \n'
00312         + '      var result = api.Terminate("");  \n'
00313         + '      if (result.toString() != "true") {  \n'
00314         + '         var err = ErrorHandler();  \n'
00315         + '      }  \n'
00316         + '   }  \n'
00317         + '   return result.toString();  \n'
00318         + '}  \n'
00319         + '  \n'
00320         + 'function doLMSGetValue(name) {  \n'
00321         + '   checkLMSVersion(); \n'
00322         + '   var api = getAPIHandle();  \n'
00323         + '   if (api == null) {  \n'
00324         + '      alert("Unable to locate the LMS\'s API Implementation.\\nLMSGetValue was not successful.");  \n'
00325         + '      return "";  \n'
00326         + '   } else {  \n'
00327         + '      var value = api.<?php echo $LMS_prefix; ?>GetValue(name);  \n'
00328         + '      var errCode = api.<?php echo $LMS_prefix; ?>GetLastError().toString();  \n'
00329         + '      if (errCode != _NoError) {  \n'
00330         + '         // an error was encountered so display the error description  \n'
00331         + '         var errDescription = api.<?php echo $LMS_prefix; ?>GetErrorString(errCode);  \n'
00332         + '         alert("<?php echo $LMS_prefix; ?>GetValue("+name+") failed. \\n"+ errDescription);  \n'
00333         + '         return "";  \n'
00334         + '      } else {  \n'
00335         + '         return value.toString();  \n'
00336         + '      }  \n'
00337         + '   }  \n'
00338         + '}  \n'
00339         + '  \n'
00340         + 'function doLMSSetValue(name, value) {  \n'
00341         + '   checkLMSVersion(); \n'
00342         + '   var api = getAPIHandle();  \n'
00343         + '   if (api == null) {  \n'
00344         + '      alert("Unable to locate the LMS\'s API Implementation.\\nLMSSetValue was not successful.");  \n'
00345         + '      return;  \n'
00346         + '   } else {  \n'
00347         + '      var result = api.<?php echo $LMS_prefix; ?>SetValue(name, value);  \n'
00348         + '      if (result.toString() != "true") {  \n'
00349         + '         var err = ErrorHandler();  \n'
00350         + '      }  \n'
00351         + '   }  \n'
00352         + '   return;  \n'
00353         + '}  \n'
00354         + '  \n'
00355         + 'function doLMSCommit() {  \n'
00356         + '   checkLMSVersion(); \n'
00357         + '   var api = getAPIHandle();  \n'
00358         + '   if (api == null) {  \n'
00359         + '      alert("Unable to locate the LMS\'s API Implementation.\\nLMSCommit was not successful.");  \n'
00360         + '      return "false";  \n'
00361         + '   } else {  \n'
00362         + '      var result = api.<?php echo $LMS_prefix; ?>Commit("");  \n'
00363         + '      if (result != "true") {  \n'
00364         + '         var err = ErrorHandler();  \n'
00365         + '      }  \n'
00366         + '   }  \n'
00367         + '   return result.toString();  \n'
00368         + '}  \n'
00369         + '  \n'
00370         + 'function doLMSGetLastError() {  \n'
00371         + '   var api = getAPIHandle();  \n'
00372         + '   if (api == null) {  \n'
00373         + '      alert("Unable to locate the LMS\'s API Implementation.\\nLMSGetLastError was not successful.");  \n'
00374         + '      //since we can\'t get the error code from the LMS, return a general error  \n'
00375         + '      return _GeneralError;  \n'
00376         + '   }  \n'
00377         + '   return api.<?php echo $LMS_prefix; ?>GetLastError().toString();  \n'
00378         + '}  \n'
00379         + '  \n'
00380         + 'function doLMSGetErrorString(errorCode) {  \n'
00381         + '   var api = getAPIHandle();  \n'
00382         + '   if (api == null) {  \n'
00383         + '      alert("Unable to locate the LMS\'s API Implementation.\\nLMSGetErrorString was not successful.");  \n'
00384         + '   }  \n'
00385         + '   return api.<?php echo $LMS_prefix; ?>GetErrorString(errorCode).toString();  \n'
00386         + '}  \n'
00387         + '  \n'
00388         + 'function doLMSGetDiagnostic(errorCode) {  \n'
00389         + '   var api = getAPIHandle();  \n'
00390         + '   if (api == null) {  \n'
00391         + '      alert("Unable to locate the LMS\'s API Implementation.\\nLMSGetDiagnostic was not successful.");  \n'
00392         + '   }  \n'
00393         + '   return api.<?php echo $LMS_prefix; ?>GetDiagnostic(errorCode).toString();  \n'
00394         + '}  \n'
00395         + '  \n'
00396         + 'function LMSIsInitialized() {  \n'
00397         + '   // there is no direct method for determining if the LMS API is initialized  \n'
00398         + '   // for example an LMSIsInitialized function defined on the API so we\'ll try  \n'
00399         + '   // a simple LMSGetValue and trap for the LMS Not Initialized Error  \n'
00400         + '   var api = getAPIHandle();  \n'
00401         + '   if (api == null) {  \n'
00402         + '      alert("Unable to locate the LMS\'s API Implementation.\\nLMSIsInitialized() failed.");  \n'
00403         + '      return false;  \n'
00404         + '   } else {  \n'
00405         + '      var value = api.<?php echo $LMS_prefix; ?>GetValue("cmi.core.student_name");  \n'
00406         + '      var errCode = api.<?php echo $LMS_prefix; ?>GetLastError().toString();  \n'
00407         + '      if (errCode == _NotInitialized) {  \n'
00408         + '         return false;  \n'
00409         + '      } else {  \n'
00410         + '         return true;  \n'
00411         + '      }  \n'
00412         + '   }  \n'
00413         + '}  \n'
00414         + '  \n'
00415         + 'function ErrorHandler() {  \n'
00416         + '   var api = getAPIHandle();  \n'
00417         + '   if (api == null) {  \n'
00418         + '      alert("Unable to locate the LMS\'s API Implementation.\\nCannot determine LMS error code.");  \n'
00419         + '      return;  \n'
00420         + '   }  \n'
00421         + '   // check for errors caused by or from the LMS  \n'
00422         + '   var errCode = api.<?php echo $LMS_prefix; ?>GetLastError().toString();  \n'
00423         + '   if (errCode != _NoError) {  \n'
00424         + '      // an error was encountered so display the error description  \n'
00425         + '      var errDescription = api.<?php echo $LMS_prefix; ?>GetErrorString(errCode);  \n'
00426         + '      if (_Debug == true) {  \n'
00427         + '         errDescription += "\\n";  \n'
00428         + '         errDescription += api.<?php echo $LMS_prefix; ?>GetDiagnostic(null);  \n'
00429         + '         // by passing null to LMSGetDiagnostic, we get any available diagnostics  \n'
00430         + '         // on the previous error.  \n'
00431         + '      }  \n'
00432         + '      alert(errDescription);  \n'
00433         + '   }  \n'
00434         + '   return errCode;  \n'
00435         + '}  \n'
00436         + '  \n'
00437         + 'function getAPIHandle() {  \n'
00438         + '   if (apiHandle == null) {  \n'
00439         + '      apiHandle = getAPI();  \n'
00440         + '   }  \n'
00441         + '   return apiHandle;  \n'
00442         + '}  \n'
00443         + '  \n'
00444         + 'function findAPI(win) {  \n'
00445         + '   while ((win.<?php echo $LMS_api; ?> == null) && (win.parent != null) && (win.parent != win)) {  \n'
00446         + '      findAPITries++;  \n'
00447         + '      // Note: 7 is an arbitrary number, but should be more than sufficient  \n'
00448         + '      if (findAPITries > 7) {  \n'
00449         + '         alert("Error finding API -- too deeply nested.");  \n'
00450         + '         return null;  \n'
00451         + '      }  \n'
00452         + '      win = win.parent;  \n'
00453         + '   }  \n'
00454         + '   return win.<?php echo $LMS_api; ?>;  \n'
00455         + '}  \n'
00456         + '  \n'
00457         + 'function getAPI() {  \n'
00458         + '   var theAPI = findAPI(window);  \n'
00459         + '   if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) {  \n'
00460         + '      theAPI = findAPI(window.opener);  \n'
00461         + '   }  \n'
00462         + '   if (theAPI == null) {  \n'
00463         + '      alert("Unable to find an API adapter");  \n'
00464         + '   }  \n'
00465         + '   return theAPI  \n'
00466         + '}  \n'
00467         + '  \n'
00468         + '   function tryLMSInitialize() {  \n'
00469         + '      var result = doLMSInitialize();  \n'
00470         + '      var msg;  \n'
00471         + '      if(result == "true") {  \n'
00472         + '         msg = "<?php echo $LMS_prefix; ?>Initialize Successful!";  \n'
00473         + '      } else {  \n'
00474         + '         var err = doLMSGetLastError();  \n'
00475         + '         var errString = doLMSGetErrorString(err);  \n'
00476         + '         msg = "<?php echo $LMS_prefix; ?>Initialize Failed! Error Code: "+err;  \n'
00477         + '         msg += " Error Description: " + errString;  \n'
00478         + '      }  \n'
00479         + '      document.initForm.msgtxt.value= msg;  \n'
00480         + '   }  \n'
00481         + '  \n'
00482         + '   function tryLMSCommit() {  \n'
00483         + '      var result = doLMSCommit();  \n'
00484         + '      var msg;  \n'
00485         + '      if(result == "true") {  \n'
00486         + '         msg = "<?php echo $LMS_prefix; ?>Commit was Successful!";  \n'
00487         + '      } else {  \n'
00488         + '         var err = doLMSGetLastError();  \n'
00489         + '         var errString = doLMSGetErrorString(err);  \n'
00490         + '         var msg = "<?php echo $LMS_prefix; ?>Commit Failed! Error Code: "+err;  \n'
00491         + '         msg += " Error Description: " + errString;  \n'
00492         + '      }  \n'
00493         + '      document.otherForm.msgtxt.value = msg; \n'
00494         + '      document.elemForm.API_ELEMENT.value = saveElement; \n'
00495         + '   }  \n'
00496         + '  \n'
00497         + '   function tryLMSFinish() {  \n'
00498         + '      // set now, in case the SCO is unloaded on LMSFinish  \n'
00499         + '      doLMSSetValue("cmi.core.lesson_status", "completed");  \n'
00500         + '      doLMSSetValue("cmi.core.exit", "");  \n'
00501         + '      doLMSSetValue("cmi.core.session_time", "00:00:30");  \n'
00502         + '      var result = doLMSFinish();  \n'
00503         + '      var msg;  \n'
00504         + '      if(result == "true") {  \n'
00505         + '         msg = "LMSFinish Successful!";  \n'
00506         + '         document.otherForm.msgtxt.value = msg;  \n'
00507         + '      } else {  \n'
00508         + '         var err = doLMSGetLastError();  \n'
00509         + '         var errString = doLMSGetErrorString(err);  \n'
00510         + '         var msg = "LMSFinish Failed! Error Code: "+err;  \n'
00511         + '         msg += " Error Description: " + errString;  \n'
00512         + '         document.otherForm.msgtxt.value = msg;  \n'
00513         + '      }  \n'
00514         + '   }  \n'
00515         + '  \n'
00516         + '   function tryLMSTerminate() {  \n'
00517         + '      var result = doLMSTerminate();  \n'
00518         + '      var msg;  \n'
00519         + '      if(result == "true") {  \n'
00520         + '         msg = "Terminate Successful!";  \n'
00521         + '         document.otherForm.msgtxt.value = msg;  \n'
00522         + '      } else {  \n'
00523         + '         var err = doLMSGetLastError();  \n'
00524         + '         var errString = doLMSGetErrorString(err);  \n'
00525         + '         var msg = "Terminate Failed! Error Code: "+err;  \n'
00526         + '         msg += " Error Description: " + errString;  \n'
00527         + '         document.otherForm.msgtxt.value = msg;  \n'
00528         + '      }  \n'
00529         + '   }  \n'
00530         + '  \n'
00531         + '   function tryLMSGetValue() {  \n'
00532         + '     var value = document.elemForm.API_ELEMENT.value;  \n'
00533         + '     var msg;  \n'
00534         + '     var result = doLMSGetValue(value);  \n'
00535         + '     var err = doLMSGetLastError();  \n'
00536         + '     var errString = doLMSGetErrorString(err);  \n'
00537         + '     msg = "<?php echo $LMS_prefix; ?>GetValue Returned: " + result;  \n'
00538         + '     msg += "\\nError Code: " + err;  \n'
00539         + '     msg += "\\nError Description: " + errString;  \n'
00540         + '     document.elemForm.msgtxt.value = msg;  \n'
00541         + '     document.elemForm.API_ELEMENT.value = saveElement; \n'
00542         + '   }  \n'
00543         + '  \n'
00544         + '   function tryLMSSetValue() {  \n'
00545         + '     // Get the element that is to be set  \n'
00546         + '     var setValue = document.elemForm.SET_VAL.value;  \n'
00547         + '     var item = document.elemForm.API_ELEMENT.value;  \n'
00548         + '     var msg;  \n'
00549         + '     var api = getAPIHandle();  \n'
00550         + '     if (api == null) {  \n'
00551         + '        alert("Unable to locate the LMS\'s API Implementation.\\n"+  \n'
00552         + '              "<?php echo $LMS_prefix; ?>SetValue was not successful.");  \n'
00553         + '        return false;  \n'
00554         + '     }  \n'
00555         + '     // Try to set the element  \n'
00556         + '     var result = api.<?php echo $LMS_prefix; ?>SetValue( item, setValue );  \n'
00557         + '     var err = doLMSGetLastError();  \n'
00558         + '     var errString = doLMSGetErrorString(err);  \n'
00559         + '     msg = "<?php echo $LMS_prefix; ?>SetValue returned: " + result;  \n'
00560         + '     msg += "\\nError Code: " + err;  \n'
00561         + '     msg += "\\nError Description: " + errString;  \n'
00562         + '     document.elemForm.msgtxt.value = msg;  \n'
00563         + '     document.elemForm.API_ELEMENT.value = saveElement; \n'
00564         + '   }  \n'
00565         + '  \n'
00566         + '   function tryLMSGetLastError() {  \n'
00567         + '      var err = doLMSGetLastError();  \n'
00568         + '      document.otherForm.msgtxt.value = "<?php echo $LMS_prefix; ?>GetLastError returned Error Code:  " + err;  \n'
00569         + '   }  \n'
00570         + '  \n'
00571         + '   function tryLMSGetErrorString() {  \n'
00572         + '      var err = doLMSGetLastError();  \n'
00573         + '      var errString = doLMSGetErrorString(err);  \n'
00574         + '      document.otherForm.msgtxt.value = "<?php echo $LMS_prefix; ?>GetErrorString returned:  " + errString;  \n'
00575         + '   }  \n'
00576         + '  \n'
00577         + '   function tryLMSGetDiagnostic() {  \n'
00578         + '      var err = doLMSGetLastError();  \n'
00579         + '      var diagnostic = doLMSGetDiagnostic(err);  \n'
00580         + '      document.otherForm.msgtxt.value = "<?php echo $LMS_prefix; ?>GetDiagnostic returned:  " + diagnostic;  \n'
00581         + '   } \n'
00582         + ' \n'
00583         + '</script>\n'
00584         + '<\/head><body STYLE="background-color: ffffff; color: black"'
00585         + 'marginwidth="0" leftmargin="0" hspace="0">'
00586         + '<h1>SCORM Debugging interface</h1>'
00587         + '<h2>SCORM Version Detected: <?php echo $scorm->version; ?></h2>'
00588         + '<input type="hidden" id="mod-scorm-logstate" name="mod-scorm-logstate" value="A" \/>'
00589         + '<form name="initForm" onsubmit="return false;">'
00590         + '   <table width="100%" border="0">'
00591         + '      <tr>'
00592         + '         <td>'
00593         + '            <input type = "button" value = "Call <?php echo $LMS_prefix; ?>Initialize()" onclick = "tryLMSInitialize();" id="Initialize" name="Initialize" />'
00594         + '         </td>'
00595         + '         <td>'
00596         + '            <label>Result: </label><input type="text" name="msgtxt" id="msgtxt" size="80" readonly value="NotCalled" />'
00597         + '         </td>'
00598         + '      </tr>'
00599         + '   </table>'
00600         + '</form>'
00601         + '<hr />'
00602         + '<form name="elemForm" id="elemForm" onsubmit="return false;">'
00603         + '   <table width="100%" border="0">'
00604         + '      <tr>'
00605         + '         <td><b>Select Data Model Element to Get or Set</b> &nbsp;&nbsp;&nbsp;&nbsp;'
00606         + '            <select name = "ELEMENT_LIST" id="ELEMENT_LIST" onchange="setAPIValue()">'
00607         + '               <option value="NONE">--None Selected--</option> <option value="">******************************************</option>'
00608 <?php
00609                           foreach ($LMS_elements as $element) {
00610                               echo ' + \'               <option value="'.$element.'">'.$element.'</option>\\n\'';
00611                           }
00612 ?>
00613         + '            </select>'
00614         + '            <input type="text" name="API_ELEMENT" id="API_ELEMENT" size="40"><br />'
00615         + '            <br />'
00616         + '            <label><b>Select API Function to Call</b></label> &nbsp;&nbsp;&nbsp;&nbsp; <input type = "button" value = "<?php echo $LMS_prefix; ?>GetValue()"'
00617         + '                         onclick = "tryLMSGetValue();" id="lmsGetButton"'
00618         + '                         name="lmsGetButton">&nbsp;&nbsp;-- OR --&nbsp;&nbsp;'
00619         + '            <input type="button" value="<?php echo $LMS_prefix; ?>SetValue()"'
00620         + '                          onclick="tryLMSSetValue();" id="lmsSetButton"'
00621         + '                          name="lmsSetButton">'
00622         + '            <label><b>&nbsp; value to Set: </b></label>&nbsp; <input type="text" name="SET_VAL" id="SET_VAL" size="25">'
00623         + '            <br />'
00624         + '            <label>Result: </label><br />'
00625         + '            <textarea name="msgtxt" id="msgtxt" rows="2" cols="150" wrap="VIRTUAL" readonly>None</textarea>'
00626         + '         </td>'
00627         + '      </tr>'
00628         + '   </table>'
00629         + '</form>'
00630         + '<hr />'
00631         + '<form name="otherForm" onsubmit="return false;">'
00632         + '   <h3>Additional API Functions</h3>'
00633         + '   <table width="100%" border="0">'
00634         + '      <tr>'
00635         + '         <td><input type="button"'
00636         + '             value="<?php echo $LMS_prefix; ?>GetLastError()  "'
00637         + '             onclick="tryLMSGetLastError();"'
00638         + '             id="lastErrorButton"'
00639         + '             name="lastErrorButton">'
00640         + '            <input type="button"'
00641         + '             value="<?php echo $LMS_prefix; ?>GetErrorString()  "'
00642         + '             onclick="tryLMSGetErrorString();"'
00643         + '             id="getErrorStringButton"'
00644         + '             name="getErrorStringButton">'
00645         + '            <input type="button"'
00646         + '             value="<?php echo $LMS_prefix; ?>GetDiagnostic()  "'
00647         + '             onclick="tryLMSGetDiagnostic();"'
00648         + '             id="getDiagnosticButton"'
00649         + '             name="getDiagnosticButton">'
00650         + '            <input type="button"'
00651         + '             value="<?php echo $LMS_prefix; ?>Commit()  "'
00652         + '             onclick="tryLMSCommit();"'
00653         + '             id="commitButton"'
00654         + '             name="commitButton">'
00655         + '            <input type="button"'
00656         + '             value="<?php echo scorm_version_check($scorm->version, SCORM_12) ? 'LMSFinish' : 'Terminate'; ?>()  "'
00657         + '             onclick="try<?php echo scorm_version_check($scorm->version, SCORM_12) ? 'LMSFinish' : 'LMSTerminate'; ?>();"'
00658         + '             id="finishButton"'
00659         + '             name="finishButton">'
00660         + '         </td>'
00661         + '    </tr>'
00662         + '    <tr>'
00663         + '         <td>'
00664         + '         <label>Result: </label><br />'
00665         + '            <textarea name="msgtxt" id="msgtxt" rows="2" cols="150" wrap="VIRTUAL" readonly>None</textarea>'
00666         + '     </td>'
00667         + '      </tr>'
00668         + '   </table>'
00669         + '</form>'
00670         + '<h3 id="mod-scorm-marker">SCORM API Activity Log<\/h3>';
00671 
00672     // Is logging active?
00673     if (getLoggingActive() != "A") {
00674         return;
00675     }
00676 
00677     var popupdoc = '';
00678     logString += s;
00679     if (logPopUpWindow != 'N' && !logPopUpWindow.closed) {
00680         popupdoc = logPopUpWindow.document;
00681         popupdoc.body.innerHTML += s;
00682     } else {
00683         logPopUpWindow = open( '', 'scormlogpopupwindow', '' );
00684         popupdoc = logPopUpWindow.document;
00685         // Is logging active?
00686         var marker = safeGetElement(popupdoc, 'mod-scorm-marker');
00687         if (marker) {
00688             popupdoc.body.innerHTML += s;
00689         } else {
00690             popupdoc.open();
00691             popupdoc.write(s1);
00692             popupdoc.write(logString);
00693             popupdoc.write('<\/body><\/html>')
00694             popupdoc.close();
00695             popupdoc.title = 'SCORM API Activity Log';
00696             logPopUpWindow.focus();
00697         }
00698     }
00699     if (popupdoc.body && popupdoc.body.childNodes.length > 0) {
00700         popupdoc.body.lastChild.scrollIntoView();
00701     };
00702 }
00703 
00704 //add an individual log entry
00705 function AppendToLog(s, rc) {
00706     var sStyle;
00707     if (rc != 0) {
00708         sStyle = 'class="error';
00709     } else if (logRow % 2 != 0) {
00710         sStyle = 'class="even"';
00711     } else {
00712         sStyle = 'class="odd"';
00713     }
00714     sStyle += '"';
00715     var now = new Date();
00716     now.setTime( now.getTime() );
00717     s = '<div ' + sStyle + ' id="<?php echo $scorm->version;?>">' + now.toGMTString() + ': ' + s + '<\/div>';
00718     UpdateLog(s);
00719     // switch colours for a new section of work
00720     if (s.match(/Commit|Loaded|Initialize|Terminate|Finish|Moodle SCORM|Moodle Logging/)) {
00721         logRow++;
00722     }
00723 }
00724 
00725 // format a log entry
00726 function LogAPICall(func, nam, val, rc) {
00727     // drop call to GetLastError for the time being - it produces too much chatter
00728     if (func.match(/GetLastError/)) {
00729         return;
00730     }
00731     var s = func + '("' + nam + '"';
00732     if (val != null && ! (func.match(/GetValue|GetLastError/))) {
00733         s += ', "' + val + '"';
00734     }
00735     s += ')';
00736     if (func.match(/GetValue/)) {
00737         s += ' - ' + val;
00738     }
00739     s += ' => ' + String(rc);
00740     AppendToLog(s, rc);
00741 }
00742 
00743 
00744 // Add in a JS controlled link for toggling the Debug logging
00745 var logButton = document.createElement('a');
00746 logButton.id = 'mod-scorm-log-toggle';
00747 logButton.name = 'logToggle';
00748 logButton.href = 'javascript:toggleLog();';
00749 if (getLoggingActive() == "A") {
00750     logButton.innerHTML = '<?php echo addslashes_js(get_string('scormloggingon', 'scorm')); ?>';
00751 } else {
00752     logButton.innerHTML = '<?php echo addslashes_js(get_string('scormloggingoff', 'scorm')); ?>';
00753 }
00754 var content = safeGetElement(document, 'scormpage');
00755 content.insertBefore(logButton, content.firstChild);
00756 
 All Data Structures Namespaces Files Functions Variables Enumerations