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