Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / scorm / datamodels / aicc.js.php
blobe061f812d1055d08cb0362613d4ae3f63e146e94
1 <?php
2 if (isset($userdata->status)) {
3 if ($userdata->status == '') {
4 $userdata->entry = 'ab-initio';
5 } else {
6 if (isset($userdata->{'cmi.core.exit'}) && ($userdata->{'cmi.core.exit'} == 'suspend')) {
7 $userdata->entry = 'resume';
8 } else {
9 $userdata->entry = '';
15 // SCORM 1.2 API Implementation
17 function AICCapi() {
18 // Standard Data Type Definition
19 CMIString256 = '^[\\u0000-\\uffff]{0,255}$';
20 CMIString4096 = '^[\\u0000-\\uffff]{0,4096}$';
21 CMITime = '^([0-2]{1}[0-9]{1}):([0-5]{1}[0-9]{1}):([0-5]{1}[0-9]{1})(\.[0-9]{1,2})?$';
22 CMITimespan = '^([0-9]{2,4}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$';
23 CMIInteger = '^\\d+$';
24 CMISInteger = '^-?([0-9]+)$';
25 CMIDecimal = '^-?([0-9]{0,3})(\.[0-9]{1,2})?$';
26 CMIIdentifier = '^\\w{1,255}$';
27 CMIFeedback = CMIString256; // This must be redefined
28 CMIIndex = '[._](\\d+).';
29 // Vocabulary Data Type Definition
30 CMIStatus = '^passed$|^completed$|^failed$|^incomplete$|^browsed$';
31 CMIStatus2 = '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$';
32 CMIExit = '^time-out$|^suspend$|^logout$|^$';
33 CMIType = '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$';
34 CMIResult = '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]{1,2})?$';
35 NAVEvent = '^previous$|^continue$';
36 // Children lists
37 cmi_children = 'core, suspend_data, launch_data, comments, objectives, student_data, student_preference, interactions';
38 core_children = 'student_id, student_name, lesson_location, credit, lesson_status, entry, score, total_time, lesson_mode, exit, session_time';
39 score_children = 'raw, min, max';
40 comments_children = 'content, location, time';
41 objectives_children = 'id, score, status';
42 student_data_children = 'attempt_number, tries, mastery_score, max_time_allowed, time_limit_action';
43 student_preference_children = 'audio, language, speed, text';
44 interactions_children = 'id, objectives, time, type, correct_responses, weighting, student_response, result, latency';
45 // Data ranges
46 score_range = '0#100';
47 audio_range = '-1#100';
48 speed_range = '-100#100';
49 weighting_range = '-100#100';
50 text_range = '-1#1';
51 // The AICC data model
52 var datamodel = {
53 'cmi._children':{'defaultvalue':cmi_children, 'mod':'r', 'writeerror':'402'},
54 'cmi._version':{'defaultvalue':'3.4', 'mod':'r', 'writeerror':'402'},
55 'cmi.core._children':{'defaultvalue':core_children, 'mod':'r', 'writeerror':'402'},
56 'cmi.core.student_id':{'defaultvalue':'<?php echo $userdata->student_id ?>', 'mod':'r', 'writeerror':'403'},
57 'cmi.core.student_name':{'defaultvalue':'<?php echo $userdata->student_name ?>', 'mod':'r', 'writeerror':'403'},
58 'cmi.core.lesson_location':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.lesson_location'})?$userdata->{'cmi.core.lesson_location'}:'' ?>', 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},
59 'cmi.core.credit':{'defaultvalue':'<?php echo $userdata->credit ?>', 'mod':'r', 'writeerror':'403'},
60 'cmi.core.lesson_status':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.lesson_status'})?$userdata->{'cmi.core.lesson_status'}:'' ?>', 'format':CMIStatus, 'mod':'rw', 'writeerror':'405'},
61 'cmi.core.exit':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.exit'})?$userdata->{'cmi.core.exit'}:'' ?>', 'format':CMIExit, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
62 'cmi.core.entry':{'defaultvalue':'<?php echo $userdata->entry ?>', 'mod':'r', 'writeerror':'403'},
63 'cmi.core.score._children':{'defaultvalue':score_children, 'mod':'r', 'writeerror':'402'},
64 'cmi.core.score.raw':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.score.raw'})?$userdata->{'cmi.core.score.raw'}:'' ?>', 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
65 'cmi.core.score.max':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.score.max'})?$userdata->{'cmi.core.score.max'}:'' ?>', 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
66 'cmi.core.score.min':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.score.min'})?$userdata->{'cmi.core.score.min'}:'' ?>', 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
67 'cmi.core.session_time':{'format':CMITimespan, 'mod':'w', 'defaultvalue':'00:00:00', 'readerror':'404', 'writeerror':'405'},
68 'cmi.core.total_time':{'defaultvalue':'<?php echo isset($userdata->{'cmi.core.total_time'})?$userdata->{'cmi.core.total_time'}:'00:00:00' ?>', 'mod':'r', 'writeerror':'403'},
69 'cmi.core.lesson_mode':{'defaultvalue':'<?php echo $userdata->mode ?>', 'mod':'r', 'writeerror':'403'},
70 'cmi.suspend_data':{'defaultvalue':'<?php echo isset($userdata->{'cmi.suspend_data'})?$userdata->{'cmi.suspend_data'}:'' ?>', 'format':CMIString4096, 'mod':'rw', 'writeerror':'405'},
71 'cmi.launch_data':{'defaultvalue':'<?php echo isset($userdata->datafromlms)?$userdata->datafromlms:'' ?>', 'mod':'r', 'writeerror':'403'},
72 'cmi.comments':{'defaultvalue':'<?php echo isset($userdata->{'cmi.comments'})?$userdata->{'cmi.comments'}:'' ?>', 'format':CMIString4096, 'mod':'rw', 'writeerror':'405'},
73 'cmi.evaluation.comments._count':{'defaultvalue':'0', 'mod':'r', 'writeerror':'402'},
74 'cmi.evaluation.comments._children':{'defaultvalue':comments_children, 'mod':'r', 'writeerror':'402'},
75 'cmi.evaluation.comments.n.content':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},
76 'cmi.evaluation.comments.n.location':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},
77 'cmi.evaluation.comments.n.time':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMITime, 'mod':'rw', 'writeerror':'405'},
78 'cmi.comments_from_lms':{'mod':'r', 'writeerror':'403'},
79 'cmi.objectives._children':{'defaultvalue':objectives_children, 'mod':'r', 'writeerror':'402'},
80 'cmi.objectives._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
81 'cmi.objectives.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'rw', 'writeerror':'405'},
82 'cmi.objectives.n.score._children':{'pattern':CMIIndex, 'mod':'r', 'writeerror':'402'},
83 'cmi.objectives.n.score.raw':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
84 'cmi.objectives.n.score.min':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
85 'cmi.objectives.n.score.max':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
86 'cmi.objectives.n.status':{'pattern':CMIIndex, 'format':CMIStatus2, 'mod':'rw', 'writeerror':'405'},
87 'cmi.student_data._children':{'defaultvalue':student_data_children, 'mod':'r', 'writeerror':'402'},
88 'cmi.student_data.attempt_number':{'defaultvalue':'<?php echo isset($userdata->{'cmi.student_data.attempt_number'})?$userdata->{'cmi.student_data.attempt_number'}:'' ?>', 'mod':'r', 'writeerror':'402'},
89 'cmi.student_data.tries.n.score.raw':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
90 'cmi.student_data.tries.n.score.min':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
91 'cmi.student_data.tries.n.score.max':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
92 'cmi.student_data.tries.n.status':{'pattern':CMIIndex, 'format':CMIStatus2, 'mod':'rw', 'writeerror':'405'},
93 'cmi.student_data.tries.n.time':{'pattern':CMIIndex, 'format':CMITime, 'mod':'rw', 'writeerror':'405'},
94 'cmi.student_data.mastery_score':{'defaultvalue':'<?php echo isset($userdata->masteryscore)?$userdata->masteryscore:'' ?>', 'mod':'r', 'writeerror':'403'},
95 'cmi.student_data.max_time_allowed':{'defaultvalue':'<?php echo isset($userdata->maxtimeallowed)?$userdata->maxtimeallowed:'' ?>', 'mod':'r', 'writeerror':'403'},
96 'cmi.student_data.time_limit_action':{'defaultvalue':'<?php echo isset($userdata->timelimitaction)?$userdata->timelimitaction:'' ?>', 'mod':'r', 'writeerror':'403'},
97 'cmi.student_data.tries_during_lesson':{'defaultvalue':'<?php echo isset($userdata->{'cmi.student_data.tries_during_lesson'})?$userdata->{'cmi.student_data.tries_during_lesson'}:'' ?>', 'mod':'r', 'writeerror':'402'},
98 'cmi.student_preference._children':{'defaultvalue':student_preference_children, 'mod':'r', 'writeerror':'402'},
99 'cmi.student_preference.audio':{'defaultvalue':'0', 'format':CMISInteger, 'range':audio_range, 'mod':'rw', 'writeerror':'405'},
100 'cmi.student_preference.language':{'defaultvalue':'', 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},
101 'cmi.student_preference.speed':{'defaultvalue':'0', 'format':CMISInteger, 'range':speed_range, 'mod':'rw', 'writeerror':'405'},
102 'cmi.student_preference.text':{'defaultvalue':'0', 'format':CMISInteger, 'range':text_range, 'mod':'rw', 'writeerror':'405'},
103 'cmi.interactions._children':{'defaultvalue':interactions_children, 'mod':'r', 'writeerror':'402'},
104 'cmi.interactions._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
105 'cmi.interactions.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
106 'cmi.interactions.n.objectives._count':{'pattern':CMIIndex, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
107 'cmi.interactions.n.objectives.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
108 'cmi.interactions.n.time':{'pattern':CMIIndex, 'format':CMITime, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
109 'cmi.interactions.n.type':{'pattern':CMIIndex, 'format':CMIType, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
110 'cmi.interactions.n.correct_responses._count':{'pattern':CMIIndex, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
111 'cmi.interactions.n.correct_responses.n.pattern':{'pattern':CMIIndex, 'format':CMIFeedback, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
112 'cmi.interactions.n.weighting':{'pattern':CMIIndex, 'format':CMIDecimal, 'range':weighting_range, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
113 'cmi.interactions.n.student_response':{'pattern':CMIIndex, 'format':CMIFeedback, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
114 'cmi.interactions.n.result':{'pattern':CMIIndex, 'format':CMIResult, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
115 'cmi.interactions.n.latency':{'pattern':CMIIndex, 'format':CMITimespan, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
116 'nav.event':{'defaultvalue':'', 'format':NAVEvent, 'mod':'w', 'readerror':'404', 'writeerror':'405'}
119 // Datamodel inizialization
121 var cmi = new Object();
122 cmi.core = new Object();
123 cmi.core.score = new Object();
124 cmi.objectives = new Object();
125 cmi.student_data = new Object();
126 cmi.student_preference = new Object();
127 cmi.interactions = new Object();
128 cmi.evaluation = new Object();
129 cmi.evaluation.comments = new Object();
131 // Navigation Object
132 var nav = new Object();
134 for (element in datamodel) {
135 if (element.match(/\.n\./) == null) {
136 if ((typeof eval('datamodel["'+element+'"].defaultvalue')) != 'undefined') {
137 eval(element+' = datamodel["'+element+'"].defaultvalue;');
138 } else {
139 eval(element+' = "";');
144 <?php
145 $current_objective = '';
146 $count = 0;
147 $objectives = '';
148 foreach($userdata as $element => $value){
149 if (substr($element,0,14) == 'cmi.objectives') {
150 $element = preg_replace('/\.(\d+)\./', "_\$1.", $element);
151 preg_match('/\_(\d+)\./', $element, $matches);
152 if (count($matches) > 0 && $current_objective != $matches[1]) {
153 $current_objective = $matches[1];
154 $end = strpos($element,$matches[1])+strlen($matches[1]);
155 $subelement = substr($element,0,$end);
156 echo ' '.$subelement." = new Object();\n";
157 echo ' '.$subelement.".score = new Object();\n";
158 echo ' '.$subelement.".score._children = score_children;\n";
159 echo ' '.$subelement.".score.raw = '';\n";
160 echo ' '.$subelement.".score.min = '';\n";
161 echo ' '.$subelement.".score.max = '';\n";
163 echo ' '.$element.' = \''.$value."';\n";
166 if ($count > 0) {
167 echo ' cmi.objectives._count = '.$count.";\n";
171 if (cmi.core.lesson_status == '') {
172 cmi.core.lesson_status = 'not attempted';
176 // API Methods definition
178 var Initialized = false;
180 function LMSInitialize (param) {
181 errorCode = "0";
182 if (param == "") {
183 if (!Initialized) {
184 Initialized = true;
185 errorCode = "0";
186 return "true";
187 } else {
188 errorCode = "101";
190 } else {
191 errorCode = "201";
193 return "false";
196 function LMSFinish (param) {
197 errorCode = "0";
198 if (param == "") {
199 if (Initialized) {
200 Initialized = false;
201 result = StoreData(cmi,true);
202 if (nav.event != '') {
203 if (nav.event == 'continue') {
204 setTimeout('top.nextSCO();',500);
205 } else {
206 setTimeout('top.prevSCO();',500);
208 } else {
209 if (<?php echo $scorm->auto ?> == 1) {
210 setTimeout('top.nextSCO();',500);
213 return "true";
214 } else {
215 errorCode = "301";
217 } else {
218 errorCode = "201";
220 return "false";
223 function LMSGetValue (element) {
224 errorCode = "0";
225 if (Initialized) {
226 if (element !="") {
227 expression = new RegExp(CMIIndex,'g');
228 elementmodel = String(element).replace(expression,'.n.');
229 if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
230 if (eval('datamodel["'+elementmodel+'"].mod') != 'w') {
231 element = String(element).replace(expression, "_$1.");
232 elementIndexes = element.split('.');
233 subelement = 'cmi';
234 i = 1;
235 while ((i < elementIndexes.length) && (typeof eval(subelement) != "undefined")) {
236 subelement += '.'+elementIndexes[i++];
238 if (subelement == element) {
239 errorCode = "0";
240 return eval(element);
241 } else {
242 errorCode = "0"; // Need to check if it is the right errorCode
244 } else {
245 errorCode = eval('datamodel["'+elementmodel+'"].readerror');
247 } else {
248 childrenstr = '._children';
249 countstr = '._count';
250 if (elementmodel.substr(elementmodel.length-childrenstr.length,elementmodel.length) == childrenstr) {
251 parentmodel = elementmodel.substr(0,elementmodel.length-childrenstr.length);
252 if ((typeof eval('datamodel["'+parentmodel+'"]')) != "undefined") {
253 errorCode = "202";
254 } else {
255 errorCode = "201";
257 } else if (elementmodel.substr(elementmodel.length-countstr.length,elementmodel.length) == countstr) {
258 parentmodel = elementmodel.substr(0,elementmodel.length-countstr.length);
259 if ((typeof eval('datamodel["'+parentmodel+'"]')) != "undefined") {
260 errorCode = "203";
261 } else {
262 errorCode = "201";
264 } else {
265 errorCode = "201";
268 } else {
269 errorCode = "201";
271 } else {
272 errorCode = "301";
274 return "";
277 function LMSSetValue (element,value) {
278 errorCode = "0";
279 if (Initialized) {
280 if (element != "") {
281 expression = new RegExp(CMIIndex,'g');
282 elementmodel = String(element).replace(expression,'.n.');
283 if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
284 if (eval('datamodel["'+elementmodel+'"].mod') != 'r') {
285 expression = new RegExp(eval('datamodel["'+elementmodel+'"].format'));
286 value = value+'';
287 matches = value.match(expression);
288 if (matches != null) {
289 //Create dynamic data model element
290 if (element != elementmodel) {
291 elementIndexes = element.split('.');
292 subelement = 'cmi';
293 for (i=1;i < elementIndexes.length-1;i++) {
294 elementIndex = elementIndexes[i];
295 if (elementIndexes[i+1].match(/^\d+$/)) {
296 if ((typeof eval(subelement+'.'+elementIndex)) == "undefined") {
297 eval(subelement+'.'+elementIndex+' = new Object();');
298 eval(subelement+'.'+elementIndex+'._count = 0;');
300 if (elementIndexes[i+1] == eval(subelement+'.'+elementIndex+'._count')) {
301 eval(subelement+'.'+elementIndex+'._count++;');
303 if (elementIndexes[i+1] > eval(subelement+'.'+elementIndex+'._count')) {
304 errorCode = "201";
306 subelement = subelement.concat('.'+elementIndex+'_'+elementIndexes[i+1]);
307 i++;
308 } else {
309 subelement = subelement.concat('.'+elementIndex);
311 if ((typeof eval(subelement)) == "undefined") {
312 eval(subelement+' = new Object();');
313 if (subelement.substr(0,14) == 'cmi.objectives') {
314 eval(subelement+'.score = new Object();');
315 eval(subelement+'.score._children = score_children;');
316 eval(subelement+'.score.raw = "";');
317 eval(subelement+'.score.min = "";');
318 eval(subelement+'.score.max = "";');
320 if (subelement.substr(0,16) == 'cmi.interactions') {
321 eval(subelement+'.objectives = new Object();');
322 eval(subelement+'.objectives._count = 0;');
323 eval(subelement+'.correct_responses = new Object();');
324 eval(subelement+'.correct_responses._count = 0;');
328 element = subelement.concat('.'+elementIndexes[elementIndexes.length-1]);
330 //Store data
331 if (errorCode == "0") {
332 if ((typeof eval('datamodel["'+elementmodel+'"].range')) != "undefined") {
333 range = eval('datamodel["'+elementmodel+'"].range');
334 ranges = range.split('#');
335 value = value*1.0;
336 if ((value >= ranges[0]) && (value <= ranges[1])) {
337 eval(element+'="'+value+'";');
338 errorCode = "0";
339 return "true";
340 } else {
341 errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
343 } else {
344 if (element == 'cmi.comments') {
345 eval(element+'+="'+value+'";');
346 } else {
347 eval(element+'="'+value+'";');
349 errorCode = "0";
350 return "true";
353 } else {
354 errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
356 } else {
357 errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
359 } else {
360 errorCode = "201"
362 } else {
363 errorCode = "201";
365 } else {
366 errorCode = "301";
368 return "false";
371 function LMSCommit (param) {
372 errorCode = "0";
373 if (param == "") {
374 if (Initialized) {
375 result = StoreData(cmi,false);
376 return "true";
377 } else {
378 errorCode = "301";
380 } else {
381 errorCode = "201";
383 return "false";
386 function LMSGetLastError () {
387 return errorCode;
390 function LMSGetErrorString (param) {
391 if (param != "") {
392 var errorString = new Array();
393 errorString["0"] = "No error";
394 errorString["101"] = "General exception";
395 errorString["201"] = "Invalid argument error";
396 errorString["202"] = "Element cannot have children";
397 errorString["203"] = "Element not an array - cannot have count";
398 errorString["301"] = "Not initialized";
399 errorString["401"] = "Not implemented error";
400 errorString["402"] = "Invalid set value, element is a keyword";
401 errorString["403"] = "Element is read only";
402 errorString["404"] = "Element is write only";
403 errorString["405"] = "Incorrect data type";
404 return errorString[param];
405 } else {
406 return "";
410 function LMSGetDiagnostic (param) {
411 if (param == "") {
412 param = errorCode;
414 return param;
417 function AddTime (first, second) {
418 var sFirst = first.split(":");
419 var sSecond = second.split(":");
420 var cFirst = sFirst[2].split(".");
421 var cSecond = sSecond[2].split(".");
422 var change = 0;
424 FirstCents = 0; //Cents
425 if (cFirst.length > 1) {
426 FirstCents = parseInt(cFirst[1],10);
428 SecondCents = 0;
429 if (cSecond.length > 1) {
430 SecondCents = parseInt(cSecond[1],10);
432 var cents = FirstCents + SecondCents;
433 change = Math.floor(cents / 100);
434 cents = cents - (change * 100);
435 if (Math.floor(cents) < 10) {
436 cents = "0" + cents.toString();
439 var secs = parseInt(cFirst[0],10)+parseInt(cSecond[0],10)+change; //Seconds
440 change = Math.floor(secs / 60);
441 secs = secs - (change * 60);
442 if (Math.floor(secs) < 10) {
443 secs = "0" + secs.toString();
446 mins = parseInt(sFirst[1],10)+parseInt(sSecond[1],10)+change; //Minutes
447 change = Math.floor(mins / 60);
448 mins = mins - (change * 60);
449 if (mins < 10) {
450 mins = "0" + mins.toString();
453 hours = parseInt(sFirst[0],10)+parseInt(sSecond[0],10)+change; //Hours
454 if (hours < 10) {
455 hours = "0" + hours.toString();
458 if (cents != '0') {
459 return hours + ":" + mins + ":" + secs + '.' + cents;
460 } else {
461 return hours + ":" + mins + ":" + secs;
465 function TotalTime() {
466 total_time = AddTime(cmi.core.total_time, cmi.core.session_time);
467 return '&'+underscore('cmi.core.total_time')+'='+escape(total_time);
470 function CollectData(data,parent) {
471 var datastring = '';
472 for (property in data) {
473 if (typeof data[property] == 'object') {
474 datastring += CollectData(data[property],parent+'.'+property);
475 } else {
476 element = parent+'.'+property;
477 expression = new RegExp(CMIIndex,'g');
478 elementmodel = String(element).replace(expression,'.n.');
479 if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
480 if (eval('datamodel["'+elementmodel+'"].mod') != 'r') {
481 elementstring = '&'+underscore(element)+'='+escape(data[property]);
482 if ((typeof eval('datamodel["'+elementmodel+'"].defaultvalue')) != "undefined") {
483 if (eval('datamodel["'+elementmodel+'"].defaultvalue') != data[property]) {
484 datastring += elementstring;
486 } else {
487 datastring += elementstring;
493 return datastring;
496 function StoreData(data,storetotaltime) {
497 if (storetotaltime) {
498 if (cmi.core.lesson_mode == 'normal') {
499 if (cmi.core.credit == 'credit') {
500 cmi.core.lesson_status = 'completed';
501 if (cmi.student_data.mastery_score != '') {
502 if (cmi.core.score.raw >= cmi.student_data.mastery_score) {
503 cmi.core.lesson_status = 'passed';
504 } else {
505 cmi.core.lesson_status = 'failed';
510 if (cmi.core.lesson_mode == 'browse') {
511 if (datamodel['cmi.core.lesson_status'].defaultvalue == '') {
512 cmi.core.lesson_status = 'browsed';
515 datastring = CollectData(data,'cmi');
516 datastring += TotalTime();
517 } else {
518 datastring = CollectData(data,'cmi');
520 //popupwin(datastring);
521 var myRequest = NewHttpReq();
522 result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>"+datastring);
523 results = result.split('\n');
524 errorCode = results[1];
525 return results[0];
528 this.LMSInitialize = LMSInitialize;
529 this.LMSFinish = LMSFinish;
530 this.LMSGetValue = LMSGetValue;
531 this.LMSSetValue = LMSSetValue;
532 this.LMSCommit = LMSCommit;
533 this.LMSGetLastError = LMSGetLastError;
534 this.LMSGetErrorString = LMSGetErrorString;
535 this.LMSGetDiagnostic = LMSGetDiagnostic;
538 var API = new AICCapi();