Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / scorm / datamodels / debug.js.php
blobe8a64730ad6b15124a19e69c7424c647c7b42df8
1 // hopefully fool ie IE proof way of getting DOM element
2 function safeGetElement(doc, el) {
3 return doc.ids ? doc.ids[el] : doc.getElementById ? doc.getElementById(el) : doc.all[el];
6 // Add in a JS controlled link for toggling the Debug logging
7 var logButton = document.createElement('a');
8 logButton.id = 'mod-scorm-log-toggle';
9 logButton.name = 'logToggle';
10 logButton.href = 'javascript:toggleLog();';
11 if (getLoggingActive() == "A") {
12 logButton.innerHTML = '<?php print_string('scormloggingon','scorm') ?>';
13 } else {
14 logButton.innerHTML = '<?php print_string('scormloggingoff','scorm') ?>';
16 var content = safeGetElement(document, 'content');
17 content.appendChild(logButton);
19 // retrieve cookie data
20 function getCookie (cookie_name){
21 var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
22 if ( results ) {
23 return (unescape(results[2]));
24 } else {
25 return null;
29 // retrieve the logging flag from a Cookie
30 function getLoggingActive () {
31 var loggingActive = getCookie('SCORMLoggingActive');
32 if (!loggingActive) {
33 loggingActive = 'A';
35 return loggingActive;
38 // set the logging flag in a cookie
39 function setLoggingActive (flag) {
40 new cookie("SCORMLoggingActive", flag, 365, "/").set();
43 // toggle the logging
44 function toggleLog () {
45 if (getLoggingActive() == "A") {
46 AppendToLog("Moodle Logging Deactivated", 0);
47 setLoggingActive('N');
48 logButton.innerHTML = '<?php print_string('scormloggingoff','scorm') ?>';
49 } else {
50 setLoggingActive('A');
51 AppendToLog("Moodle Logging Activated", 0);
52 logButton.innerHTML = '<?php print_string('scormloggingon','scorm') ?>';
53 logPopUpWindow.focus();
57 // globals for the log accumulation
58 var logString = "";
59 var logRow = 0;
60 var logPopUpWindow = "N";
62 // add each entry to the log, or setup the log pane first time round
63 function UpdateLog(s) {
64 var s1 = '<html><head><style>\n'
65 + 'body {font-family: Arial, Helvetica, Sans-Serif;font-size: xx-small;'
66 + 'margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; '
67 + 'background-color: ffffff;}\n'
68 + '.even {background-color: ffffff; width: 100%;}\n'
69 + '.odd {background-color: e8f2fe; width: 100%;}\n'
70 + '.error {background-color: ffffff; color: red; width: 100%;}\n'
71 + '<\/style><\/head><body STYLE="background-color: ffffff; color: black"'
72 + 'marginwidth="0" leftmargin="0" hspace="0">'
73 + '<input type="hidden" id="mod-scorm-logstate" name="mod-scorm-logstate" value="A" \/>'
74 + '<h3 id="mod-scorm-marker">SCORM API Activity Log<\/h3>';
76 // Is logging active?
77 if (getLoggingActive() != "A") {
78 return;
81 var popupdoc = '';
82 logString += s;
83 if (logPopUpWindow != 'N' && !logPopUpWindow.closed) {
84 popupdoc = logPopUpWindow.document;
85 popupdoc.body.innerHTML += s;
86 } else {
87 logPopUpWindow = open( '', 'logpopupwindow', '' );
88 popupdoc = logPopUpWindow.document;
89 // Is logging active?
90 var marker = safeGetElement(popupdoc, 'mod-scorm-marker');
91 if (marker) {
92 popupdoc.body.innerHTML += s;
93 } else {
94 popupdoc.open();
95 popupdoc.write(s1);
96 popupdoc.write(logString);
97 popupdoc.write('<\/body><\/html>')
98 popupdoc.close();
99 popupdoc.title = 'SCORM API Activity Log';
100 logPopUpWindow.focus();
103 if (popupdoc.body.childNodes.length > 0) {
104 popupdoc.body.lastChild.scrollIntoView();
108 //add an individual log entry
109 function AppendToLog(s, rc) {
110 var sStyle;
111 if (rc != 0) {
112 sStyle = 'class="error';
113 } else if (logRow % 2 != 0) {
114 sStyle = 'class="even';
115 } else {
116 sStyle = 'class="odd';
118 sStyle += '"';
119 var now = new Date();
120 now.setTime( now.getTime() );
121 s = '<div ' + sStyle + '>' + now.toGMTString() + ': ' + s + '<\/div>';
122 UpdateLog(s);
123 // switch colours for a new section of work
124 if (s.match(/Commit|Loaded|Initialize|Terminate|Finish|Moodle SCORM|Moodle Logging/)) {
125 logRow++;
129 // format a log entry
130 function LogAPICall(func, nam, val, rc) {
131 // drop call to GetLastError for the time being - it produces too much chatter
132 if (func.match(/GetLastError/)) {
133 return;
135 var s = func + '("' + nam + '"';
136 if (val != null && ! (func.match(/GetValue|GetLastError/))) {
137 s += ', "' + val + '"';
139 s += ')';
140 if (func.match(/GetValue/)) {
141 s += ' - ' + val;
143 s += ' => ' + String(rc);
144 AppendToLog(s, rc);