Revert "MDL-38678 SCORM: Runtime Environment (RTE) checks not required in case of...
[moodle.git] / mod / scorm / datamodels / debug.js.php
CommitLineData
f7b5c6aa
DM
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17?>
18
33f54da3 19<!--// hopefully fool ie IE proof way of getting DOM element
7bbb7f49 20function safeGetElement(doc, el) {
21 return doc.ids ? doc.ids[el] : doc.getElementById ? doc.getElementById(el) : doc.all[el];
22}
485f4ce6
PH
23// Find elements by class name
24var aryClassElements = new Array();
25function getNextElementByClassName( strClassName, obj ) {
26 if ( obj.className == strClassName ) {
27 aryClassElements[aryClassElements.length] = obj;
28 }
29 for ( var i = 0; i < obj.childNodes.length; i++ )
30 getNextElementByClassName( strClassName, obj.childNodes[i] );
31}
32
33function getElementsByClassName( strClassName, obj ) {
34 aryClassElements = new Array();
35 getNextElementByClassName( strClassName, obj );
36 if (aryClassElements.length > 0) {
37 return aryClassElements[0];
38 }
39 else {
40 return null;
41 }
42}
7bbb7f49 43
7bbb7f49 44// retrieve cookie data
45function getCookie (cookie_name){
46 var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
47 if ( results ) {
48 return (unescape(results[2]));
49 } else {
50 return null;
51 }
52}
53
54// retrieve the logging flag from a Cookie
55function getLoggingActive () {
56 var loggingActive = getCookie('SCORMLoggingActive');
57 if (!loggingActive) {
58 loggingActive = 'A';
59 }
60 return loggingActive;
61}
62
63// set the logging flag in a cookie
64function setLoggingActive (flag) {
65 new cookie("SCORMLoggingActive", flag, 365, "/").set();
66}
67
309ee089 68// toggle the logging
7bbb7f49 69function toggleLog () {
70 if (getLoggingActive() == "A") {
71 AppendToLog("Moodle Logging Deactivated", 0);
72 setLoggingActive('N');
9e93f995 73 logButton.innerHTML = '--><?php echo addslashes_js(get_string('scormloggingoff', 'scorm')); ?>';
7bbb7f49 74 } else {
75 setLoggingActive('A');
76 AppendToLog("Moodle Logging Activated", 0);
9e93f995 77 logButton.innerHTML = '<?php echo addslashes_js(get_string('scormloggingon', 'scorm')); ?>';
7bbb7f49 78 logPopUpWindow.focus();
79 }
80}
81
82// globals for the log accumulation
83var logString = "";
84var logRow = 0;
85var logPopUpWindow = "N";
1cd167cc 86var debugSCORMVersion = '<?php echo $scorm->version; ?>';
309ee089 87<?php
e6402b54
DM
88 $LMS_prefix = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'LMS' : '';
89 $LMS_api = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'API' : 'API_1484_11';
309ee089 90
1cd167cc 91 $LMS_elements = array();
e6402b54 92 if (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) {
1cd167cc 93 $LMS_elements = array( 'cmi.core._children',
94 'cmi.core.student_id',
95 'cmi.core.student_name',
96 'cmi.core.lesson_location',
97 'cmi.core.credit',
98 'cmi.core.lesson_status',
99 'cmi.core.entry',
100 'cmi.core._children',
101 'cmi.core.score.raw',
102 'cmi.core.score.max',
103 'cmi.core.score.min',
104 'cmi.core.total_time',
105 'cmi.core.lesson_mode',
106 'cmi.core.exit',
107 'cmi.core.session_time',
108 'cmi.suspend_data',
109 'cmi.launch_data',
110 'cmi.comments',
111 'cmi.comments_from_lms',
112 'cmi.objectives._count',
113 'cmi.objectives._children',
114 'cmi.objectives.n.id',
115 'cmi.objectives.n.score._children',
116 'cmi.objectives.n.score.raw',
117 'cmi.objectives.n.score.min',
118 'cmi.objectives.n.score.max',
119 'cmi.objectives.n.status',
120 'cmi.student_data._children',
121 'cmi.student_data.mastery_score',
122 'cmi.student_data.max_time_allowed',
123 'cmi.student_data.time_limit_action',
124 'cmi.student_preference._children',
125 'cmi.student_preference.audio',
126 'cmi.student_preference.language',
127 'cmi.student_preference.speed',
128 'cmi.student_preference.text',
129 'cmi.interactions._children',
130 'cmi.interactions._count',
131 'cmi.interactions.n.id',
132 'cmi.interactions.n.objectives._count',
133 'cmi.interactions.n.objectives.m.id',
134 'cmi.interactions.n.time',
135 'cmi.interactions.n.type',
136 'cmi.interactions.n.correct_responses._count',
137 'cmi.interactions.n.correct_responses.m.pattern',
138 'cmi.interactions.n.weighting',
139 'cmi.interactions.n.student_response',
140 'cmi.interactions.n.result',
141 'cmi.interactions.n.latency');
142 } else {
143 $LMS_elements = array( 'cmi._children',
144 'cmi._version',
145 'cmi.learner_id',
146 'cmi.learner_name',
147 'cmi.location',
148 'cmi.completion_status',
149 'cmi.completion_threshold',
150 'cmi.scaled_passing_score',
151 'cmi.progressive_measure',
152 'cmi.score._children',
153 'cmi.score.raw',
154 'cmi.score.max',
155 'cmi.score.min',
156 'cmi.score.scaled',
157 'cmi.total_time',
158 'cmi.time_limit_action',
159 'cmi.max_time_allowed',
160 'cmi.session_time',
161 'cmi.success_status',
162 'cmi.lesson_mode',
163 'cmi.entry',
164 'cmi.exit',
165 'cmi.credit',
166 'cmi.mode',
167 'cmi.suspend_data',
168 'cmi.launch_data',
169 'cmi.comments',
170 'cmi.comments_from_lms._children',
171 'cmi.comments_from_lms._count',
172 'cmi.comments_from_lms.n.comment',
173 'cmi.comments_from_lms.n.location',
174 'cmi.comments_from_lms.n.timestamp',
175 'cmi.comments_from_learner._children',
176 'cmi.comments_from_learner._count',
177 'cmi.comments_from_learner.n.comment',
178 'cmi.comments_from_learner.n.location',
179 'cmi.comments_from_learner.n.timestamp',
180 'cmi.objectives._count',
181 'cmi.objectives._children',
182 'cmi.objectives.n.id',
183 'cmi.objectives.n.score._children',
184 'cmi.objectives.n.score.raw',
185 'cmi.objectives.n.score.min',
186 'cmi.objectives.n.score.max',
187 'cmi.objectives.n.score.scaled',
188 'cmi.objectives.n.success_status',
189 'cmi.objectives.n.completion_status',
190 'cmi.objectives.n.progress_measure',
191 'cmi.objectives.n.description',
192 'cmi.student_data._children',
193 'cmi.student_data.mastery_score',
194 'cmi.student_data.max_time_allowed',
195 'cmi.student_data.time_limit_action',
196 'cmi.student_preference._children',
197 'cmi.student_preference.audio',
198 'cmi.student_preference.language',
199 'cmi.student_preference.speed',
200 'cmi.student_preference.text',
201 'cmi.interactions._children',
202 'cmi.interactions._count',
203 'cmi.interactions.n.id',
204 'cmi.interactions.n.objectives._count',
205 'cmi.interactions.n.objectives.m.id',
206 'cmi.interactions.n.time',
207 'cmi.interactions.n.type',
208 'cmi.interactions.n.correct_responses._count',
209 'cmi.interactions.n.correct_responses.m.pattern',
210 'cmi.interactions.n.weighting',
211 'cmi.interactions.n.learner_response',
212 'cmi.interactions.n.result',
213 'cmi.interactions.n.latency',
214 'cmi.interactions.n.description',
215 'adl.nav.request');
216 }
217?>
7bbb7f49 218
219// add each entry to the log, or setup the log pane first time round
1cd167cc 220// The code written into the header is based on the ADL test suite API interaction code
221// and various examples of test wrappers out in the community
7bbb7f49 222function UpdateLog(s) {
223 var s1 = '<html><head><style>\n'
224 + 'body {font-family: Arial, Helvetica, Sans-Serif;font-size: xx-small;'
225 + 'margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; '
226 + 'background-color: ffffff;}\n'
227 + '.even {background-color: ffffff; width: 100%;}\n'
228 + '.odd {background-color: e8f2fe; width: 100%;}\n'
229 + '.error {background-color: ffffff; color: red; width: 100%;}\n'
1cd167cc 230 + '<\/style>'
231 + '<script>\n'
232 + 'var LMSVersion = \'<?php echo $scorm->version; ?>\';\n'
233 + ' \n'
234 + 'function checkLMSVersion() { \n'
235 + ' if (this.document.body.childNodes.length > 0) { \n'
236 + ' if (this.document.body.lastChild.id == LMSVersion) { \n'
237 + ' return true; \n'
238 + ' } \n'
239 + ' }; \n'
240 + ' alert(\'LMS Version: \' + this.document.body.lastChild.id + \n'
241 + ' \' does not equal: \' + LMSVersion + \n'
242 + ' \' so API calls will fail - did navigate to another SCORM package?\'); \n'
243 + ' return false; \n'
244 + '} \n'
245 + ' \n'
246 + 'var saveElement = ""; \n'
247 + 'function setAPIValue() { \n'
248 + ' document.elemForm.API_ELEMENT.value = document.elemForm.ELEMENT_LIST.value; \n'
249 + ' saveElement = document.elemForm.API_ELEMENT.value; \n'
250 + '} \n'
251 + ' \n'
252 + 'var _Debug = false; // set this to false to turn debugging off \n'
253 + ' \n'
254 + '// Define exception/error codes \n'
255 + 'var _NoError = 0; \n'
256 + 'var _GeneralException = 101; \n'
257 + 'var _ServerBusy = 102; \n'
258 + 'var _InvalidArgumentError = 201; \n'
259 + 'var _ElementCannotHaveChildren = 202; \n'
260 + 'var _ElementIsNotAnArray = 203; \n'
261 + 'var _NotInitialized = 301; \n'
262 + 'var _NotImplementedError = 401; \n'
263 + 'var _InvalidSetValue = 402; \n'
264 + 'var _ElementIsReadOnly = 403; \n'
265 + 'var _ElementIsWriteOnly = 404; \n'
266 + 'var _IncorrectDataType = 405; \n'
267 + ' \n'
268 + '// local variable definitions \n'
269 + 'var apiHandle = null; \n'
270 + 'var API = null; \n'
271 + 'var findAPITries = 0; \n'
272 + ' \n'
273 + ' \n'
274 + 'function doLMSInitialize() { \n'
275 + ' checkLMSVersion(); \n'
276 + ' var api = getAPIHandle(); \n'
277 + ' if (api == null) { \n'
278 + ' alert("Unable to locate the LMS\'s API Implementation.\\nLMSInitialize was not successful."); \n'
279 + ' return "false"; \n'
280 + ' } \n'
c78b79d0 281 + ' var result = api.<?php echo $LMS_prefix; ?>Initialize(""); \n'
1cd167cc 282 + ' if (result.toString() != "true") { \n'
283 + ' var err = ErrorHandler(); \n'
284 + ' } \n'
285 + ' return result.toString(); \n'
286 + '} \n'
287 + ' \n'
288 + 'function doLMSFinish() { \n'
289 + ' checkLMSVersion(); \n'
290 + ' var api = getAPIHandle(); \n'
291 + ' if (api == null) { \n'
292 + ' alert("Unable to locate the LMS\'s API Implementation.\\nLMSFinish was not successful."); \n'
293 + ' return "false"; \n'
294 + ' } else { \n'
295 + ' // call the LMSFinish function that should be implemented by the API \n'
c78b79d0 296 + ' var result = api.<?php echo $LMS_prefix; ?>Finish(""); \n'
1cd167cc 297 + ' if (result.toString() != "true") { \n'
298 + ' var err = ErrorHandler(); \n'
299 + ' } \n'
300 + ' } \n'
301 + ' return result.toString(); \n'
302 + '} \n'
303 + ' \n'
304 + 'function doLMSTerminate() { \n'
305 + ' checkLMSVersion(); \n'
306 + ' var api = getAPIHandle(); \n'
307 + ' if (api == null) { \n'
308 + ' alert("Unable to locate the LMS\'s API Implementation.\\nTerminate was not successful."); \n'
309 + ' return "false"; \n'
310 + ' } else { \n'
311 + ' // call the Terminate function that should be implemented by the API \n'
312 + ' var result = api.Terminate(""); \n'
313 + ' if (result.toString() != "true") { \n'
314 + ' var err = ErrorHandler(); \n'
315 + ' } \n'
316 + ' } \n'
317 + ' return result.toString(); \n'
318 + '} \n'
319 + ' \n'
320 + 'function doLMSGetValue(name) { \n'
321 + ' checkLMSVersion(); \n'
322 + ' var api = getAPIHandle(); \n'
323 + ' if (api == null) { \n'
324 + ' alert("Unable to locate the LMS\'s API Implementation.\\nLMSGetValue was not successful."); \n'
325 + ' return ""; \n'
326 + ' } else { \n'
c78b79d0 327 + ' var value = api.<?php echo $LMS_prefix; ?>GetValue(name); \n'
328 + ' var errCode = api.<?php echo $LMS_prefix; ?>GetLastError().toString(); \n'
1cd167cc 329 + ' if (errCode != _NoError) { \n'
330 + ' // an error was encountered so display the error description \n'
c78b79d0 331 + ' var errDescription = api.<?php echo $LMS_prefix; ?>GetErrorString(errCode); \n'
332 + ' alert("<?php echo $LMS_prefix; ?>GetValue("+name+") failed. \\n"+ errDescription); \n'
1cd167cc 333 + ' return ""; \n'
334 + ' } else { \n'
335 + ' return value.toString(); \n'
336 + ' } \n'
337 + ' } \n'
338 + '} \n'
339 + ' \n'
340 + 'function doLMSSetValue(name, value) { \n'
341 + ' checkLMSVersion(); \n'
342 + ' var api = getAPIHandle(); \n'
343 + ' if (api == null) { \n'
344 + ' alert("Unable to locate the LMS\'s API Implementation.\\nLMSSetValue was not successful."); \n'
345 + ' return; \n'
346 + ' } else { \n'
c78b79d0 347 + ' var result = api.<?php echo $LMS_prefix; ?>SetValue(name, value); \n'
1cd167cc 348 + ' if (result.toString() != "true") { \n'
349 + ' var err = ErrorHandler(); \n'
350 + ' } \n'
351 + ' } \n'
352 + ' return; \n'
353 + '} \n'
354 + ' \n'
355 + 'function doLMSCommit() { \n'
356 + ' checkLMSVersion(); \n'
357 + ' var api = getAPIHandle(); \n'
358 + ' if (api == null) { \n'
359 + ' alert("Unable to locate the LMS\'s API Implementation.\\nLMSCommit was not successful."); \n'
360 + ' return "false"; \n'
361 + ' } else { \n'
c78b79d0 362 + ' var result = api.<?php echo $LMS_prefix; ?>Commit(""); \n'
1cd167cc 363 + ' if (result != "true") { \n'
364 + ' var err = ErrorHandler(); \n'
365 + ' } \n'
366 + ' } \n'
367 + ' return result.toString(); \n'
368 + '} \n'
369 + ' \n'
370 + 'function doLMSGetLastError() { \n'
371 + ' var api = getAPIHandle(); \n'
372 + ' if (api == null) { \n'
373 + ' alert("Unable to locate the LMS\'s API Implementation.\\nLMSGetLastError was not successful."); \n'
374 + ' //since we can\'t get the error code from the LMS, return a general error \n'
375 + ' return _GeneralError; \n'
376 + ' } \n'
c78b79d0 377 + ' return api.<?php echo $LMS_prefix; ?>GetLastError().toString(); \n'
1cd167cc 378 + '} \n'
379 + ' \n'
380 + 'function doLMSGetErrorString(errorCode) { \n'
381 + ' var api = getAPIHandle(); \n'
382 + ' if (api == null) { \n'
383 + ' alert("Unable to locate the LMS\'s API Implementation.\\nLMSGetErrorString was not successful."); \n'
384 + ' } \n'
c78b79d0 385 + ' return api.<?php echo $LMS_prefix; ?>GetErrorString(errorCode).toString(); \n'
1cd167cc 386 + '} \n'
387 + ' \n'
388 + 'function doLMSGetDiagnostic(errorCode) { \n'
389 + ' var api = getAPIHandle(); \n'
390 + ' if (api == null) { \n'
391 + ' alert("Unable to locate the LMS\'s API Implementation.\\nLMSGetDiagnostic was not successful."); \n'
392 + ' } \n'
c78b79d0 393 + ' return api.<?php echo $LMS_prefix; ?>GetDiagnostic(errorCode).toString(); \n'
1cd167cc 394 + '} \n'
395 + ' \n'
396 + 'function LMSIsInitialized() { \n'
397 + ' // there is no direct method for determining if the LMS API is initialized \n'
398 + ' // for example an LMSIsInitialized function defined on the API so we\'ll try \n'
399 + ' // a simple LMSGetValue and trap for the LMS Not Initialized Error \n'
400 + ' var api = getAPIHandle(); \n'
401 + ' if (api == null) { \n'
402 + ' alert("Unable to locate the LMS\'s API Implementation.\\nLMSIsInitialized() failed."); \n'
403 + ' return false; \n'
404 + ' } else { \n'
c78b79d0 405 + ' var value = api.<?php echo $LMS_prefix; ?>GetValue("cmi.core.student_name"); \n'
406 + ' var errCode = api.<?php echo $LMS_prefix; ?>GetLastError().toString(); \n'
1cd167cc 407 + ' if (errCode == _NotInitialized) { \n'
408 + ' return false; \n'
409 + ' } else { \n'
410 + ' return true; \n'
411 + ' } \n'
412 + ' } \n'
413 + '} \n'
414 + ' \n'
415 + 'function ErrorHandler() { \n'
416 + ' var api = getAPIHandle(); \n'
417 + ' if (api == null) { \n'
418 + ' alert("Unable to locate the LMS\'s API Implementation.\\nCannot determine LMS error code."); \n'
419 + ' return; \n'
420 + ' } \n'
421 + ' // check for errors caused by or from the LMS \n'
c78b79d0 422 + ' var errCode = api.<?php echo $LMS_prefix; ?>GetLastError().toString(); \n'
1cd167cc 423 + ' if (errCode != _NoError) { \n'
424 + ' // an error was encountered so display the error description \n'
c78b79d0 425 + ' var errDescription = api.<?php echo $LMS_prefix; ?>GetErrorString(errCode); \n'
1cd167cc 426 + ' if (_Debug == true) { \n'
427 + ' errDescription += "\\n"; \n'
c78b79d0 428 + ' errDescription += api.<?php echo $LMS_prefix; ?>GetDiagnostic(null); \n'
1cd167cc 429 + ' // by passing null to LMSGetDiagnostic, we get any available diagnostics \n'
430 + ' // on the previous error. \n'
431 + ' } \n'
432 + ' alert(errDescription); \n'
433 + ' } \n'
434 + ' return errCode; \n'
435 + '} \n'
436 + ' \n'
437 + 'function getAPIHandle() { \n'
438 + ' if (apiHandle == null) { \n'
439 + ' apiHandle = getAPI(); \n'
440 + ' } \n'
441 + ' return apiHandle; \n'
442 + '} \n'
443 + ' \n'
444 + 'function findAPI(win) { \n'
c78b79d0 445 + ' while ((win.<?php echo $LMS_api; ?> == null) && (win.parent != null) && (win.parent != win)) { \n'
1cd167cc 446 + ' findAPITries++; \n'
447 + ' // Note: 7 is an arbitrary number, but should be more than sufficient \n'
448 + ' if (findAPITries > 7) { \n'
449 + ' alert("Error finding API -- too deeply nested."); \n'
450 + ' return null; \n'
451 + ' } \n'
452 + ' win = win.parent; \n'
453 + ' } \n'
c78b79d0 454 + ' return win.<?php echo $LMS_api; ?>; \n'
1cd167cc 455 + '} \n'
456 + ' \n'
457 + 'function getAPI() { \n'
458 + ' var theAPI = findAPI(window); \n'
459 + ' if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) { \n'
460 + ' theAPI = findAPI(window.opener); \n'
461 + ' } \n'
462 + ' if (theAPI == null) { \n'
463 + ' alert("Unable to find an API adapter"); \n'
464 + ' } \n'
465 + ' return theAPI \n'
466 + '} \n'
467 + ' \n'
468 + ' function tryLMSInitialize() { \n'
469 + ' var result = doLMSInitialize(); \n'
470 + ' var msg; \n'
471 + ' if(result == "true") { \n'
c78b79d0 472 + ' msg = "<?php echo $LMS_prefix; ?>Initialize Successful!"; \n'
1cd167cc 473 + ' } else { \n'
474 + ' var err = doLMSGetLastError(); \n'
475 + ' var errString = doLMSGetErrorString(err); \n'
c78b79d0 476 + ' msg = "<?php echo $LMS_prefix; ?>Initialize Failed! Error Code: "+err; \n'
1cd167cc 477 + ' msg += " Error Description: " + errString; \n'
478 + ' } \n'
479 + ' document.initForm.msgtxt.value= msg; \n'
480 + ' } \n'
481 + ' \n'
482 + ' function tryLMSCommit() { \n'
483 + ' var result = doLMSCommit(); \n'
484 + ' var msg; \n'
485 + ' if(result == "true") { \n'
c78b79d0 486 + ' msg = "<?php echo $LMS_prefix; ?>Commit was Successful!"; \n'
1cd167cc 487 + ' } else { \n'
488 + ' var err = doLMSGetLastError(); \n'
489 + ' var errString = doLMSGetErrorString(err); \n'
c78b79d0 490 + ' var msg = "<?php echo $LMS_prefix; ?>Commit Failed! Error Code: "+err; \n'
1cd167cc 491 + ' msg += " Error Description: " + errString; \n'
492 + ' } \n'
493 + ' document.otherForm.msgtxt.value = msg; \n'
494 + ' document.elemForm.API_ELEMENT.value = saveElement; \n'
495 + ' } \n'
496 + ' \n'
497 + ' function tryLMSFinish() { \n'
498 + ' // set now, in case the SCO is unloaded on LMSFinish \n'
499 + ' doLMSSetValue("cmi.core.lesson_status", "completed"); \n'
500 + ' doLMSSetValue("cmi.core.exit", ""); \n'
501 + ' doLMSSetValue("cmi.core.session_time", "00:00:30"); \n'
502 + ' var result = doLMSFinish(); \n'
503 + ' var msg; \n'
504 + ' if(result == "true") { \n'
505 + ' msg = "LMSFinish Successful!"; \n'
506 + ' document.otherForm.msgtxt.value = msg; \n'
507 + ' } else { \n'
508 + ' var err = doLMSGetLastError(); \n'
509 + ' var errString = doLMSGetErrorString(err); \n'
510 + ' var msg = "LMSFinish Failed! Error Code: "+err; \n'
511 + ' msg += " Error Description: " + errString; \n'
512 + ' document.otherForm.msgtxt.value = msg; \n'
513 + ' } \n'
514 + ' } \n'
515 + ' \n'
516 + ' function tryLMSTerminate() { \n'
517 + ' var result = doLMSTerminate(); \n'
518 + ' var msg; \n'
519 + ' if(result == "true") { \n'
520 + ' msg = "Terminate Successful!"; \n'
521 + ' document.otherForm.msgtxt.value = msg; \n'
522 + ' } else { \n'
523 + ' var err = doLMSGetLastError(); \n'
524 + ' var errString = doLMSGetErrorString(err); \n'
525 + ' var msg = "Terminate Failed! Error Code: "+err; \n'
526 + ' msg += " Error Description: " + errString; \n'
527 + ' document.otherForm.msgtxt.value = msg; \n'
528 + ' } \n'
529 + ' } \n'
530 + ' \n'
531 + ' function tryLMSGetValue() { \n'
532 + ' var value = document.elemForm.API_ELEMENT.value; \n'
533 + ' var msg; \n'
534 + ' var result = doLMSGetValue(value); \n'
535 + ' var err = doLMSGetLastError(); \n'
536 + ' var errString = doLMSGetErrorString(err); \n'
c78b79d0 537 + ' msg = "<?php echo $LMS_prefix; ?>GetValue Returned: " + result; \n'
1cd167cc 538 + ' msg += "\\nError Code: " + err; \n'
539 + ' msg += "\\nError Description: " + errString; \n'
540 + ' document.elemForm.msgtxt.value = msg; \n'
541 + ' document.elemForm.API_ELEMENT.value = saveElement; \n'
542 + ' } \n'
543 + ' \n'
544 + ' function tryLMSSetValue() { \n'
545 + ' // Get the element that is to be set \n'
546 + ' var setValue = document.elemForm.SET_VAL.value; \n'
547 + ' var item = document.elemForm.API_ELEMENT.value; \n'
548 + ' var msg; \n'
549 + ' var api = getAPIHandle(); \n'
550 + ' if (api == null) { \n'
551 + ' alert("Unable to locate the LMS\'s API Implementation.\\n"+ \n'
c78b79d0 552 + ' "<?php echo $LMS_prefix; ?>SetValue was not successful."); \n'
1cd167cc 553 + ' return false; \n'
554 + ' } \n'
555 + ' // Try to set the element \n'
c78b79d0 556 + ' var result = api.<?php echo $LMS_prefix; ?>SetValue( item, setValue ); \n'
1cd167cc 557 + ' var err = doLMSGetLastError(); \n'
558 + ' var errString = doLMSGetErrorString(err); \n'
c78b79d0 559 + ' msg = "<?php echo $LMS_prefix; ?>SetValue returned: " + result; \n'
1cd167cc 560 + ' msg += "\\nError Code: " + err; \n'
561 + ' msg += "\\nError Description: " + errString; \n'
562 + ' document.elemForm.msgtxt.value = msg; \n'
563 + ' document.elemForm.API_ELEMENT.value = saveElement; \n'
564 + ' } \n'
565 + ' \n'
566 + ' function tryLMSGetLastError() { \n'
567 + ' var err = doLMSGetLastError(); \n'
c78b79d0 568 + ' document.otherForm.msgtxt.value = "<?php echo $LMS_prefix; ?>GetLastError returned Error Code: " + err; \n'
1cd167cc 569 + ' } \n'
570 + ' \n'
571 + ' function tryLMSGetErrorString() { \n'
572 + ' var err = doLMSGetLastError(); \n'
573 + ' var errString = doLMSGetErrorString(err); \n'
c78b79d0 574 + ' document.otherForm.msgtxt.value = "<?php echo $LMS_prefix; ?>GetErrorString returned: " + errString; \n'
1cd167cc 575 + ' } \n'
576 + ' \n'
577 + ' function tryLMSGetDiagnostic() { \n'
578 + ' var err = doLMSGetLastError(); \n'
579 + ' var diagnostic = doLMSGetDiagnostic(err); \n'
c78b79d0 580 + ' document.otherForm.msgtxt.value = "<?php echo $LMS_prefix; ?>GetDiagnostic returned: " + diagnostic; \n'
1cd167cc 581 + ' } \n'
582 + ' \n'
583 + '</script>\n'
584 + '<\/head><body STYLE="background-color: ffffff; color: black"'
7bbb7f49 585 + 'marginwidth="0" leftmargin="0" hspace="0">'
1cd167cc 586 + '<h1>SCORM Debugging interface</h1>'
587 + '<h2>SCORM Version Detected: <?php echo $scorm->version; ?></h2>'
7bbb7f49 588 + '<input type="hidden" id="mod-scorm-logstate" name="mod-scorm-logstate" value="A" \/>'
1cd167cc 589 + '<form name="initForm" onsubmit="return false;">'
590 + ' <table width="100%" border="0">'
591 + ' <tr>'
592 + ' <td>'
c78b79d0 593 + ' <input type = "button" value = "Call <?php echo $LMS_prefix; ?>Initialize()" onclick = "tryLMSInitialize();" id="Initialize" name="Initialize" />'
1cd167cc 594 + ' </td>'
595 + ' <td>'
596 + ' <label>Result: </label><input type="text" name="msgtxt" id="msgtxt" size="80" readonly value="NotCalled" />'
597 + ' </td>'
598 + ' </tr>'
599 + ' </table>'
600 + '</form>'
601 + '<hr />'
602 + '<form name="elemForm" id="elemForm" onsubmit="return false;">'
603 + ' <table width="100%" border="0">'
604 + ' <tr>'
605 + ' <td><b>Select Data Model Element to Get or Set</b> &nbsp;&nbsp;&nbsp;&nbsp;'
606 + ' <select name = "ELEMENT_LIST" id="ELEMENT_LIST" onchange="setAPIValue()">'
607 + ' <option value="NONE">--None Selected--</option> <option value="">******************************************</option>'
608<?php
609 foreach ($LMS_elements as $element) {
610 echo ' + \' <option value="'.$element.'">'.$element.'</option>\\n\'';
611 }
612?>
613 + ' </select>'
614 + ' <input type="text" name="API_ELEMENT" id="API_ELEMENT" size="40"><br />'
615 + ' <br />'
c78b79d0 616 + ' <label><b>Select API Function to Call</b></label> &nbsp;&nbsp;&nbsp;&nbsp; <input type = "button" value = "<?php echo $LMS_prefix; ?>GetValue()"'
1cd167cc 617 + ' onclick = "tryLMSGetValue();" id="lmsGetButton"'
618 + ' name="lmsGetButton">&nbsp;&nbsp;-- OR --&nbsp;&nbsp;'
c78b79d0 619 + ' <input type="button" value="<?php echo $LMS_prefix; ?>SetValue()"'
1cd167cc 620 + ' onclick="tryLMSSetValue();" id="lmsSetButton"'
621 + ' name="lmsSetButton">'
622 + ' <label><b>&nbsp; value to Set: </b></label>&nbsp; <input type="text" name="SET_VAL" id="SET_VAL" size="25">'
623 + ' <br />'
624 + ' <label>Result: </label><br />'
625 + ' <textarea name="msgtxt" id="msgtxt" rows="2" cols="150" wrap="VIRTUAL" readonly>None</textarea>'
626 + ' </td>'
627 + ' </tr>'
628 + ' </table>'
629 + '</form>'
630 + '<hr />'
631 + '<form name="otherForm" onsubmit="return false;">'
632 + ' <h3>Additional API Functions</h3>'
633 + ' <table width="100%" border="0">'
634 + ' <tr>'
635 + ' <td><input type="button"'
636 + ' value="<?php echo $LMS_prefix; ?>GetLastError() "'
637 + ' onclick="tryLMSGetLastError();"'
638 + ' id="lastErrorButton"'
639 + ' name="lastErrorButton">'
640 + ' <input type="button"'
641 + ' value="<?php echo $LMS_prefix; ?>GetErrorString() "'
642 + ' onclick="tryLMSGetErrorString();"'
643 + ' id="getErrorStringButton"'
644 + ' name="getErrorStringButton">'
645 + ' <input type="button"'
646 + ' value="<?php echo $LMS_prefix; ?>GetDiagnostic() "'
647 + ' onclick="tryLMSGetDiagnostic();"'
648 + ' id="getDiagnosticButton"'
649 + ' name="getDiagnosticButton">'
650 + ' <input type="button"'
651 + ' value="<?php echo $LMS_prefix; ?>Commit() "'
652 + ' onclick="tryLMSCommit();"'
653 + ' id="commitButton"'
654 + ' name="commitButton">'
655 + ' <input type="button"'
e6402b54
DM
656 + ' value="<?php echo scorm_version_check($scorm->version, SCORM_12) ? 'LMSFinish' : 'Terminate'; ?>() "'
657 + ' onclick="try<?php echo scorm_version_check($scorm->version, SCORM_12) ? 'LMSFinish' : 'LMSTerminate'; ?>();"'
1cd167cc 658 + ' id="finishButton"'
659 + ' name="finishButton">'
660 + ' </td>'
661 + ' </tr>'
662 + ' <tr>'
663 + ' <td>'
664 + ' <label>Result: </label><br />'
665 + ' <textarea name="msgtxt" id="msgtxt" rows="2" cols="150" wrap="VIRTUAL" readonly>None</textarea>'
666 + ' </td>'
667 + ' </tr>'
668 + ' </table>'
669 + '</form>'
7bbb7f49 670 + '<h3 id="mod-scorm-marker">SCORM API Activity Log<\/h3>';
671
672 // Is logging active?
673 if (getLoggingActive() != "A") {
674 return;
675 }
676
677 var popupdoc = '';
678 logString += s;
679 if (logPopUpWindow != 'N' && !logPopUpWindow.closed) {
680 popupdoc = logPopUpWindow.document;
681 popupdoc.body.innerHTML += s;
682 } else {
1cd167cc 683 logPopUpWindow = open( '', 'scormlogpopupwindow', '' );
7bbb7f49 684 popupdoc = logPopUpWindow.document;
685 // Is logging active?
686 var marker = safeGetElement(popupdoc, 'mod-scorm-marker');
687 if (marker) {
688 popupdoc.body.innerHTML += s;
689 } else {
690 popupdoc.open();
691 popupdoc.write(s1);
692 popupdoc.write(logString);
693 popupdoc.write('<\/body><\/html>')
694 popupdoc.close();
695 popupdoc.title = 'SCORM API Activity Log';
696 logPopUpWindow.focus();
697 }
698 }
1cd167cc 699 if (popupdoc.body && popupdoc.body.childNodes.length > 0) {
7bbb7f49 700 popupdoc.body.lastChild.scrollIntoView();
701 };
702}
703
704//add an individual log entry
705function AppendToLog(s, rc) {
cc351eda 706 var sStyle = '';
7bbb7f49 707 if (rc != 0) {
cc351eda 708 sStyle = 'class="error"';
7bbb7f49 709 } else if (logRow % 2 != 0) {
1cd167cc 710 sStyle = 'class="even"';
7bbb7f49 711 } else {
1cd167cc 712 sStyle = 'class="odd"';
7bbb7f49 713 }
7bbb7f49 714 var now = new Date();
715 now.setTime( now.getTime() );
cc351eda 716 s = '<div ' + sStyle + ' id="<?php echo $scorm->version; ?>">' + now.toGMTString() + ': ' + s + '<\/div>';
7bbb7f49 717 UpdateLog(s);
718 // switch colours for a new section of work
719 if (s.match(/Commit|Loaded|Initialize|Terminate|Finish|Moodle SCORM|Moodle Logging/)) {
720 logRow++;
721 }
722}
723
724// format a log entry
725function LogAPICall(func, nam, val, rc) {
726 // drop call to GetLastError for the time being - it produces too much chatter
727 if (func.match(/GetLastError/)) {
728 return;
729 }
730 var s = func + '("' + nam + '"';
731 if (val != null && ! (func.match(/GetValue|GetLastError/))) {
732 s += ', "' + val + '"';
733 }
734 s += ')';
735 if (func.match(/GetValue/)) {
736 s += ' - ' + val;
737 }
738 s += ' => ' + String(rc);
739 AppendToLog(s, rc);
740}
22a79674
PH
741
742
743// Add in a JS controlled link for toggling the Debug logging
fd106868
MS
744if (!document.getElementById('mod-scorm-log-toggle')) {
745 var logButton = document.createElement('a');
746 logButton.id = 'mod-scorm-log-toggle';
747 logButton.name = 'logToggle';
748 logButton.href = 'javascript:toggleLog();';
749 if (getLoggingActive() == "A") {
750 logButton.innerHTML = '<?php echo addslashes_js(get_string('scormloggingon', 'scorm')); ?>';
751 } else {
752 logButton.innerHTML = '<?php echo addslashes_js(get_string('scormloggingoff', 'scorm')); ?>';
753 }
754 var content = safeGetElement(document, 'scormpage');
755 content.insertBefore(logButton, content.firstChild);
22a79674 756}