-
Notifications
You must be signed in to change notification settings - Fork 466
/
scorm_api.php
executable file
·2364 lines (2156 loc) · 86.9 KB
/
scorm_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* For licensing terms, see /license.txt */
/**
* API event handler functions for Scorm 1.1 and 1.2 and 1.3 (latter not fully supported)
* This script is divided into three sections.
* The first section (below) is the initialisation part.
* The second section is the SCORM object part
* The third section defines the event handlers for Chamilo's internal messaging
* and frames refresh
* @author Denes Nagy <darkden@freemail.hu> (original author - 2003-2004)
* @author Yannick Warnier <ywarnier@beeznest.org> (extended and maintained - 2005-2014)
* @version v 1.2
* @access public
* @package chamilo.learnpath.scorm
*/
// If you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js
// of Maritime Navigation when trying to execute this row
// var result = api.LMSInitialize("");
// get the error response : you are not authorized to call this function
// Flag to allow for anonymous user - needs to be set before global.inc.php.
$use_anonymous = true;
require_once __DIR__.'/../inc/global.inc.php';
$file = (empty($_SESSION['file']) ? '' : $_SESSION['file']);
/** @var learnpath $oLP */
$oLP = unserialize($_SESSION['lpobject']);
/** @var learnpathItem $oItem */
$oItem = isset($oLP->items[$oLP->current]) ? $oLP->items[$oLP->current] : null;
if (!is_object($oItem)) {
error_log('New LP - scorm_api - Could not load oItem item', 0);
exit;
}
$autocomplete_when_80pct = 0;
$user = api_get_user_info();
$userId = api_get_user_id();
header('Content-type: text/javascript');
?>var scorm_logs=<?php echo ((empty($oLP->scorm_debug) or (!api_is_course_admin() && !api_is_platform_admin())) ? '0' : '3'); ?>; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame
var lms_logs = 0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all
// API Object initialization (eases access later on)
function APIobject() {
this.LMSInitialize=LMSInitialize; //for Scorm 1.2
this.Initialize=LMSInitialize; //for Scorm 1.3
this.LMSGetValue=LMSGetValue;
this.GetValue=LMSGetValue;
this.LMSSetValue=LMSSetValue;
this.SetValue=LMSSetValue;
this.LMSCommit=LMSCommit;
this.Commit=LMSCommit;
this.LMSFinish=LMSFinish;
this.Finish=LMSFinish;
this.LMSGetLastError=LMSGetLastError;
this.GetLastError=LMSGetLastError;
this.LMSGetErrorString=LMSGetErrorString;
this.GetErrorString=LMSGetErrorString;
this.LMSGetDiagnostic=LMSGetDiagnostic;
this.GetDiagnostic=LMSGetDiagnostic;
this.Terminate=Terminate; //only in Scorm 1.3
this.save_asset = lms_save_asset;
this.void_save_asset = chamilo_void_save_asset;
}
// it is not sure that the scos use the above declarations. The following
// multiple declarations are to make sure we have an API object for each type of
// SCORM
var API = new APIobject(); //for scorm 1.2
var api = API;
//var API_1484_11 = new APIobject(); //for scorm 1.3
//var api_1484_11 = API_1484_11;
// SCORM-specific Error codes
var G_NoError = 0;
var G_GeneralException = 101;
var G_ServerBusy = 102; // this is not in the Scorm1.2_Runtime document
var G_InvalidArgumentError = 201;
var G_ElementCannotHaveChildren = 202;
var G_ElementIsNotAnArray = 203;
var G_NotInitialized = 301;
var G_NotImplementedError = 401;
var G_InvalidSetValue = 402;
var G_ElementIsReadOnly = 403;
var G_ElementIsWriteOnly = 404;
var G_IncorrectDataType = 405;
// SCORM-specific Error messages
var G_NoErrorMessage = '';
var G_GeneralExceptionMessage = 'General Exception';
var G_ServerBusyMessage = 'Server busy'; // this is not in the Scorm1.2_Runtime document
var G_InvalidArgumentErrorMessage = 'Invalid argument error';
var G_ElementCannotHaveChildrenMessage = 'Element cannot have children';
var G_ElementIsNotAnArrayMessage = 'Element not an array. Cannot have count';
var G_NotInitializedMessage = 'Not initialized';
var G_NotImplementedErrorMessage = 'Not implemented error';
var G_InvalidSetValueMessage = 'Invalid set value, element is a keyword';
var G_ElementIsReadOnlyMessage = 'Element is read only';
var G_ElementIsWriteOnlyMessage = 'Element is write only';
var G_IncorrectDataTypeMessage = 'Incorrect Data Type';
var olms = new Object();
//the last recorded error message was:
olms.G_LastError = G_NoError ;
olms.G_LastErrorMessage = 'No error';
//this is not necessary and is only provided to make bad Articulate contents
// shut up (and not trigger useless JS messages)
olms.G_LastErrorString = 'No error';
//these variables are provided for better control of the current status in the
// SCORM exchange
olms.commit = false;
// informative array helping to select variables to save, later on
olms.scorm_variables = new Array(
'cmi.core.score.raw',
'cmi.core.score.max',
'cmi.core.score.min',
'cmi.core.lesson_location',
'cmi.core.lesson_status',
'cmi.completion_status',
'cmi.core.session_time',
'cmi.score.scaled',
'cmi.success_status',
'cmi.suspend_data',
'cmi.core.exit',
'interactions'
);
// manage variables to save or not
olms.variable_to_send = new Array();
// temporary list of variables (gets set to true when set through LMSSetValue)
olms.updatable_vars_list = new Array();
// marker of whether the LMSFinish() function was called, which is important for SCORM behaviour
olms.finishSignalReceived = 0;
// marker to remember if the SCO has calles a "set" on lesson_status
olms.statusSignalReceived = 0;
// Strictly scorm variables
olms.score=<?php echo $oItem->get_score(); ?>;
olms.max='<?php echo $oItem->get_max(); ?>';
olms.min='<?php echo $oItem->get_min(); ?>';
olms.lesson_status='<?php echo $oItem->get_status(); ?>';
olms.session_time='<?php echo $oItem->get_scorm_time('js'); ?>';
olms.suspend_data = '<?php echo $oItem->get_suspend_data(); ?>';
olms.lesson_location = '<?php echo $oItem->get_lesson_location(); ?>';
olms.total_time = '<?php echo $oItem->get_scorm_time('js'); ?>';
olms.mastery_score = '<?php echo $oItem->get_mastery_score(); ?>';
olms.launch_data = '<?php echo $oItem->get_launch_data(); ?>';
olms.max_time_allowed = '<?php echo $oItem->get_max_time_allowed(); ?>';
olms.interactions = new Array(<?php echo $oItem->get_interactions_js_array(); ?>);
olms.item_objectives = new Array();
olms.info_lms_item = new Array();
// Chamilo internal variables (not SCORM)
// olms.saved_lesson_status = 'not attempted';
olms.lms_lp_id = <?php echo $oLP->get_id(); ?>;
olms.lms_item_id = <?php echo $oItem->get_id(); ?>;
olms.lms_initialized = 0;
// switch_finished indicates if the switch process is finished (if it has gone
// through LMSInitialize() for the new item. Until then, all LMSSetValue()
// commands received are executed on the *previous/current* item
// This flag is updated in LMSInitialize() and in switch_item()
olms.switch_finished = 0;
//olms.lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
//olms.lms_complete_lessons = <?php echo $oLP->get_complete_items_count(); ?>;
//olms.lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode; ?>';
//if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
olms.lms_view_id = '<?php echo $oLP->get_view(); ?>';
if(olms.lms_view_id == ''){ olms.lms_view_id = 1;}
olms.lms_user_id = '<?php echo $userId; ?>';
olms.lms_next_item = '<?php echo $oLP->get_next_item_id(); ?>';
olms.lms_previous_item = '<?php echo $oLP->get_previous_item_id(); ?>';
olms.lms_lp_type = '<?php echo $oLP->get_type(); ?>';
olms.lms_item_type = '<?php echo $oItem->get_type(); ?>';
olms.lms_item_credit = '<?php echo $oItem->get_credit(); ?>';
olms.lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode(); ?>';
olms.lms_item_launch_data = '<?php echo addslashes($oItem->get_launch_data()); ?>';
olms.lms_item_core_exit = '<?php echo $oItem->get_core_exit(); ?>';
olms.lms_course_id = '<?php echo $oLP->get_course_int_id(); ?>';
olms.lms_session_id = '<?php echo api_get_session_id(); ?>';
olms.lms_course_code = '<?php echo $oLP->getCourseCode(); ?>';
olms.lms_course_id = '<?php echo $oLP->get_course_int_id(); ?>';
<?php echo $oLP->get_items_details_as_js('olms.lms_item_types'); ?>
// Following definition of cmi.core.score.raw in SCORM 1.2, "LMS should
// initialize this to an empty string ("") upon initial launch of a SCO. The
// SCO is responsible for setting this value. If an LMSGetValue() is requested
// before the SCO has set this value, then the LMS should return an empty
// string ("")
// As Chamilo initializes this to 0 for non-sco, we need a little hack here.
if (olms.score == 0 && olms.lms_item_type == 'sco' && olms.lesson_status == 'not attempted') {
olms.score = "";
}
olms.asset_timer = 0;
olms.userfname = '<?php echo str_replace("'", "\\'", $user['firstname']); ?>';
olms.userlname = '<?php echo str_replace("'", "\\'", $user['lastname']); ?>';
olms.execute_stats = false;
var courseUrl = '?cidReq='+olms.lms_course_code+'&id_session='+olms.lms_session_id;
/**
* Add the "addListeners" function to the "onload" event of the window and
* start the timer if necessary (asset)
*/
addEvent(window, 'load', addListeners, false);
// Initialize stuff when the page is loaded
$(document).ready(function() {
logit_lms('document.ready event starts');
logit_lms('These logs are generated by the main/lp/scorm_api.php JS '
+ 'library when the admin has clicked on the debug icon in the '
+ 'learning paths list: '
+ 'lines prefixed with "LMS:" refer to actions taken on the LMS side, '
+ 'while lines prefixed with "SCORM:" refer to actions taken to match '
+ 'the SCORM standard at the JS level.', 3);
logit_scorm('LMSSetValue calls are shown in red for better visibility.', 0);
logit_scorm('Other SCORM calls are shown in orange.', 1);
logit_lms('To add new messages to these logs, use logit_lms() or logit_scorm().');
olms.info_lms_item[0] = '<?php echo $oItem->get_id(); ?>';
olms.info_lms_item[1] = '<?php echo $oItem->get_id(); ?>';
$("#content_id").load(function() {
logit_lms('#content_id load event starts');
olms.info_lms_item[0] = olms.info_lms_item[1];
// Only trigger the LMSInitialize automatically if not SCO
if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') {
LMSInitialize();
} else {
logit_lms('Content type is SCO and is responsible to launch LMSInitialize() on its own - Skipping',2);
}
});
});
// This code was moved inside LMSInitialize()
if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset' || olms.lms_item_type == 'document') {
xajax_start_timer();
}
/**
* The following section represents a set of mandatory functions for SCORM
*/
/**
* Function called mandatorily by the SCORM content to start the SCORM comm
* This is the initialize function of all APIobjects
* @return string 'true' or 'false'. Returning a string is mandatory (SCORM).
*/
function LMSInitialize() {
/* load info for this new item by calling the js_api_refresh command in
* the message frame. The message frame will update the JS variables by
* itself, in JS, by doing things like top.lesson_status = 'not attempted'
* and that kind of stuff, so when the content loads in the content frame
* it will have all the correct variables set
*/
logit_scorm('LMSInitialize()');
olms.G_LastError = G_NoError ;
olms.G_LastErrorMessage = 'No error';
olms.lms_initialized = 0;
olms.finishSignalReceived = 0;
olms.statusSignalReceived = 0;
olms.switch_finished = 0;
// if there are more parameters than ""
if (arguments.length > 1) {
olms.G_LastError = G_InvalidArgumentError;
olms.G_LastErrorMessage = G_InvalidArgumentErrorMessage;
logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0);
return('false');
} else {
//reinit the list of modified variables
reinit_updatable_vars_list();
// Get LMS values for this item
var params = {
'lid': olms.lms_lp_id,
'uid': olms.lms_user_id,
'vid': olms.lms_view_id,
'iid': olms.lms_item_id
};
$.ajax({
type: "POST",
url: "lp_ajax_initialize.php" + courseUrl,
data: params,
dataType: 'script',
async: false,
success:function(data) {
jQuery("video:not(.skip), audio:not(.skip)").mediaelementplayer();
}
});
olms.lms_initialized = 1;
olms.switch_finished = 1;
// log a more complete object dump when initializing, so we know what data hasn't been cleaned
var log = '\nitem : '+ olms.lms_item_id
+ '\nitem_type : '+ olms.lms_item_type
+ '\nscore : '+ olms.score
+ '\nmax : '+ olms.max
+ '\nmin : '+ olms.min
+ '\nlesson_status : '+ olms.lesson_status
+ '\nsession_time : '+ olms.session_time
+ '\nlesson_location : '+ olms.lesson_location
+ '\nsuspend_data : '+ olms.suspend_data
+ '\ntotal_time : '+ olms.total_time
+ '\nmastery_score : '+ olms.mastery_score
+ '\nmax_time_allowed: '+ olms.max_time_allowed
+ '\ncredit : '+ olms.lms_item_credit
+ '\nlms_lp_id : '+ olms.lms_lp_id
+ '\nlms_user_id : '+ olms.lms_user_id
+ '\nlms_view_id : '+ olms.lms_view_id
+ '\nfinishSignalReceived : '+ olms.finishSignalReceived
+ '\nstatusSignalReceived : '+ olms.statusSignalReceived
;
logit_scorm('LMSInitialize() with params: '+log);
if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset' || olms.lms_item_type == 'document') {
xajax_start_timer();
}
if (olms.lms_item_type == 'quiz') {
update_toc(olms.lesson_status, olms.lms_item_id);
}
<?php
$glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
$fixLinkSetting = api_get_configuration_value('lp_fix_embed_content');
$showGlossary = in_array($glossaryExtraTools, array('true', 'lp', 'exercise_and_lp'));
if ($showGlossary) {
if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
?>
if (olms.lms_item_type == 'sco') {
attach_glossary_into_scorm('automatic');
} else {
attach_glossary_into_scorm('manual');
}
<?php } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') { ?>
attach_glossary_into_scorm('automatic');
<?php } ?>
<?php } ?>
<?php if ($fixLinkSetting) { ?>
attach_glossary_into_scorm('fix_links');
<?php } ?>
return('true');
}
}
/**
* Twin sister of LMSInitialize(). Only provided for backwards compatibility.
* this is the initialize function of all APIobjects
*/
function Initialize() {
return LMSInitialize();
}
/**
* Gets a value in the current SCORM context and returns it to the calling SCO
* @param string The name of the value we want
* @return string All return values must be string (see SCORM)
*/
function LMSGetValue(param) {
olms.G_LastError = G_NoError ;
olms.G_LastErrorMessage = 'No error';
var result='';
// the LMSInitialize is missing
if (olms.lms_initialized == 0) {
if (param == 'cmi.core.score.raw') {
return '';
}
olms.G_LastError = G_NotInitialized;
olms.G_LastErrorMessage = G_NotInitializedMessage;
logit_scorm('LMSGetValue('+param+') on item id '+olms.lms_item_id+':<br />=> Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0);
return '';
}
//Chamilo does not support these SCO object properties
if (param == 'cmi.student_preference.text' ||
param == 'cmi.student_preference.language' ||
param == 'cmi.student_preference.speed' ||
param == 'cmi.student_preference.audio' ||
param == 'cmi.student_preference._children' ||
param == 'cmi.student_data.time_limit_action' ||
param == 'cmi.comments' ||
param == 'cmi.comments_from_lms' ||
/* The following properties were part of SCORM 1.0 or never implemented at all
but seem to react badly to Captivate content producer when not defined */
param == 'cmi.student_demographics._children' ||
param == 'cmi.student_demographics.city' ||
param == 'cmi.student_demographics.class' ||
param == 'cmi.student_demographics.company' ||
param == 'cmi.student_demographics.country' ||
param == 'cmi.student_demographics.experience' ||
param == 'cmi.student_demographics.familiar_name' ||
param == 'cmi.student_demographics.instructor_name' ||
param == 'cmi.student_demographics.title' ||
param == 'cmi.student_demographics.native_language' ||
param == 'cmi.student_demographics.state' ||
param == 'cmi.student_demographics.street_address' ||
param == 'cmi.student_demographics.telephone' ||
param == 'cmi.student_demographics.years_experience' ) {
// the value is not supported
olms.G_LastError = G_NotImplementedError ;
olms.G_LastErrorString = G_NotImplementedErrorMessage;
logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1);
result = '';
return result;
}
if (param=='cmi.student_demographics.first_name') {
result=olms.userfname;
} else if(param=='cmi.student_demographics.last_name') {
result=olms.userlname;
// ---- cmi.core._children
} else if(param=='cmi.core._children' || param=='cmi.core_children'){
result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
} else if(param == 'cmi.core.entry'){
// ---- cmi.core.entry
if(olms.lms_item_core_exit=='none') {
result='ab-initio';
} else if(olms.lms_item_core_exit=='suspend') {
result='resume';
} else {
result='';
}
} else if(param == 'cmi.core.exit'){
// ---- cmi.core.exit
result='';
olms.G_LastError = G_ElementIsWriteOnly;
} else if(param == 'cmi.core.session_time'){
result='';
olms.G_LastError = G_ElementIsWriteOnly;
} else if(param == 'cmi.core.lesson_status'){
// ---- cmi.core.lesson_status
if(olms.lesson_status != '') {
result=olms.lesson_status;
} else {
//result='not attempted';
}
} else if(param == 'cmi.core.student_id'){
// ---- cmi.core.student_id
result='<?php echo $userId; ?>';
} else if(param == 'cmi.core.student_name'){
// ---- cmi.core.student_name
<?php
$who = addslashes($user['lastname']).', '.addslashes($user['firstname']);
echo "result='$who';";
?>
} else if(param == 'cmi.core.lesson_location'){
// ---- cmi.core.lesson_location
result=olms.lesson_location;
} else if(param == 'cmi.core.total_time'){
// ---- cmi.core.total_time
result=olms.total_time;
} else if(param == 'cmi.core.score._children'){
// ---- cmi.core.score._children
result='raw,min,max';
} else if(param == 'cmi.core.score.raw'){
// ---- cmi.core.score.raw
result=olms.score;
} else if(param == 'cmi.core.score.max'){
// ---- cmi.core.score.max
result=olms.max;
} else if(param == 'cmi.core.score.min'){
// ---- cmi.core.score.min
result=olms.min;
} else if(param == 'cmi.core.score'){
// ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case
result=olms.score;
} else if(param == 'cmi.core.credit'){
// ---- cmi.core.credit
result = olms.lms_item_credit;
} else if(param == 'cmi.core.lesson_mode'){
// ---- cmi.core.lesson_mode
result = olms.lms_item_lesson_mode;
} else if(param == 'cmi.suspend_data'){
// ---- cmi.suspend_data
result = olms.suspend_data;
} else if(param == 'cmi.launch_data'){
// ---- cmi.launch_data
result = olms.lms_item_launch_data;
} else if(param == 'cmi.objectives._children'){
// ---- cmi.objectives._children
result = 'id,score,status';
} else if(param == 'cmi.objectives._count'){
// ---- cmi.objectives._count
//result='<?php echo $oItem->get_view_count(); ?>';
result = olms.item_objectives.length;
} else if(param.substring(0,15)== 'cmi.objectives.'){
var myres = '';
if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/)) {
var obj_id = myres[1];
var req_type = myres[2];
if(olms.item_objectives[obj_id]==null) {
if(req_type == 'id') {
result = '';
} else if(req_type == '_children'){
result = 'id,score,status';
} else if(req_type == 'score'){
if(myres[3]==null) {
result = '';
olms.G_LastError = G_NotImplementedError;
olms.G_LastErrorString = 'Not implemented yet';
}else if (myres[3] == '._children'){
result = 'raw,min,max'; //non-standard, added for NetG
}else if (myres[3] == '.raw'){
result = '';
}else if (myres[3] == '.max'){
result = '';
}else if (myres[3] == '.min'){
result = '';
}else{
result = '';
olms.G_LastError = G_NotImplementedError;
olms.G_LastErrorString = 'Not implemented yet';
}
}else if(req_type == 'status'){
result = 'not attempted';
}
} else {
//the object is not null
if(req_type == 'id') {
result = olms.item_objectives[obj_id][0];
} else if(req_type == '_children'){
result = 'id,score,status';
} else if(req_type == 'score'){
if(myres[3]==null) {
result = '';
olms.G_LastError = G_NotImplementedError;
olms.G_LastErrorString = 'Not implemented yet';
} else if (myres[3] == '._children'){
result = 'raw,min,max'; //non-standard, added for NetG
} else if (myres[3] == '.raw'){
if(olms.item_objectives[obj_id][2] != null)
{
result = olms.item_objectives[obj_id][2];
}else{
result = '';
}
} else if (myres[3] == '.max'){
if(olms.item_objectives[obj_id][3] != null) {
result = olms.item_objectives[obj_id][3];
}else{
result = '';
}
} else if (myres[3] == '.min') {
if(olms.item_objectives[obj_id][4] != null) {
result = olms.item_objectives[obj_id][4];
} else {
result = '';
}
} else{
result = '';
olms.G_LastError = G_NotImplementedError;
olms.G_LastErrorString = 'Not implemented yet';
}
} else if(req_type == 'status'){
if(olms.item_objectives[obj_id][1] != null) {
result = olms.item_objectives[obj_id][1];
} else {
result = 'not attempted';
}
}
}
}
} else if(param == 'cmi.student_data._children'){
// ---- cmi.student_data._children
result = 'mastery_score,max_time_allowed';
} else if(param == 'cmi.student_data.mastery_score'){
// ---- cmi.student_data.mastery_score
result = olms.mastery_score;
} else if(param == 'cmi.student_data.max_time_allowed'){
// ---- cmi.student_data.max_time_allowed
result = olms.max_time_allowed;
} else if(param == 'cmi.interactions._count'){
// ---- cmi.interactions._count
result = olms.interactions.length;
} else if(param == 'cmi.interactions._children'){
// ---- cmi.interactions._children
result = 'id,time,type,correct_responses,weighting,student_response,result,latency';
} else{
// ---- anything else
// Invalid argument error
olms.G_LastError = G_InvalidArgumentError ;
olms.G_LastErrorString = G_InvalidArgumentErrorMessage;
logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1);
result = '';
return result;
}
logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
return result;
}
/**
* Twin sister of LMSGetValue(). Only provided for backwards compatibility.
*/
function GetValue(param) {
return LMSGetValue(param);
}
/**
* Sets a SCORM variable's value through a call from the SCO.
* @param string The SCORM variable's name
* @param string The SCORM variable's new value
* @param string 'true','false' or an error code
*/
function LMSSetValue(param, val) {
logit_scorm("LMSSetValue ('"+param+"','"+val+"')",0);
logit_scorm("Checking olms.lms_item_id " + olms.lms_item_id);
olms.commit = true; //value has changed, need to re-commit
olms.G_LastError = G_NoError ;
olms.G_LastErrorMessage = 'No error';
return_value = 'false';
if ( param == "cmi.core.score.raw" ) {
olms.score= val;
olms.updatable_vars_list['cmi.core.score.raw']=true;
return_value='true';
} else if ( param == "cmi.core.score.max" ) {
olms.max = val;
olms.updatable_vars_list['cmi.core.score.max']=true;
return_value='true';
} else if ( param == "cmi.core.score.min" ) {
olms.min = val;
olms.updatable_vars_list['cmi.core.score.min']=true;
return_value='true';
} else if ( param == "cmi.core.lesson_location" ) {
olms.lesson_location = val;
olms.updatable_vars_list['cmi.core.lesson_location']=true;
return_value='true';
} else if ( param == "cmi.core.lesson_status" ) {
olms.lesson_status = val;
olms.updatable_vars_list['cmi.core.lesson_status'] = true;
olms.statusSignalReceived = 1;
return_value='true';
} else if ( param == "cmi.completion_status" ) {
olms.lesson_status = val;
olms.updatable_vars_list['cmi.completion_status']=true;
return_value='true'; //1.3
} else if ( param == "cmi.core.session_time" ) {
olms.session_time = val;
olms.updatable_vars_list['cmi.core.session_time']=true;
return_value='true';
} else if ( param == "cmi.score.scaled") { //1.3
if (val<=1 && val>=-1) {
olms.score = val ;
olms.updatable_vars_list['cmi.score.scaled']=true;
return_value='true';
} else {
return_value='false';
}
} else if ( param == "cmi.success_status" ) {
success_status = val;
olms.updatable_vars_list['cmi.success_status']=true;
return_value='true'; //1.3
} else if ( param == "cmi.suspend_data" ) {
olms.suspend_data = val;
olms.updatable_vars_list['cmi.suspend_data']=true;
return_value='true';
} else if ( param == "cmi.core.exit" ) {
olms.lms_item_core_exit = val;
olms.updatable_vars_list['cmi.core.exit']=true;
return_value='true';
} else if ( param == "cmi.core.student_id" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.core.student_name" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.core.credit" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.core.entry" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.core.total_time" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.core.lesson_mode" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.comments_from_lms" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.student_data.time_limit_action" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.student_data.mastery_score" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.student_data.max_time_allowed" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.student_preference._children" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else if ( param == "cmi.launch_data" ) {
olms.G_LastError = G_ElementIsReadOnly;
} else {
var myres = new Array();
if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) {
olms.updatable_vars_list['interactions']=true;
elem_id = myres[1];
//interactions setting should start at 0
if(elem_id > olms.interactions.length) {
/*
olms.G_LastError = G_InvalidArgumentError;
olms.G_LastErrorString = 'Invalid argument (interactions)';
return_value = false;
*/
olms.interactions[0] = ['0','','','','','','',''];
}
if(olms.interactions[elem_id] == null) {
olms.interactions[elem_id] = ['','','','','','','',''];
//id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
olms.interactions[elem_id][4] = new Array();
}
elem_attrib = myres[2];
switch (elem_attrib) {
case "id":
olms.interactions[elem_id][0] = val;
logit_scorm("Interaction "+elem_id+"'s id updated",2);
return_value='true';
break;
case "time":
olms.interactions[elem_id][2] = val;
logit_scorm("Interaction "+elem_id+"'s time updated",2);
return_value='true';
break;
case "type":
olms.interactions[elem_id][1] = val;
logit_scorm("Interaction "+elem_id+"'s type updated",2);
return_value='true';
break;
case "correct_responses":
// Add at the end of the array
olms.interactions[elem_id][4][olms.interactions[elem_id][4].length] = val;
logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
return_value='true';
break;
case "weighting":
olms.interactions[elem_id][3] = val;
logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
return_value='true';
break;
case "student_response":
olms.interactions[elem_id][5] = ''+val;
logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
return_value='true';
break;
case "result":
olms.interactions[elem_id][6] = val;
logit_scorm("Interaction "+elem_id+"'s result updated",2);
return_value='true';
break;
case "latency":
olms.interactions[elem_id][7] = val;
logit_scorm("Interaction "+elem_id+"'s latency updated",2);
return_value='true';
break;
default:
olms.G_LastError = G_NotImplementedError;
olms.G_LastErrorString = 'Not implemented yet';
}
} else if(param.substring(0,15)== 'cmi.objectives.') {
var myres = '';
olms.updatable_vars_list['objectives']=true;
if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/)) {
obj_id = myres[1];
//objectives setting should start at 0
if(obj_id > olms.item_objectives.length) {
olms.G_LastError = G_InvalidArgumentError;
olms.G_LastErrorString = 'Invalid argument (objectives)';
return_value = false;
} else {
req_type = myres[2];
if(obj_id == null || obj_id == '') {
;//do nothing
} else {
if(olms.item_objectives[obj_id]==null) {
olms.item_objectives[obj_id] = ['','','','',''];
}
if( req_type == "id" ) {
//olms.item_objectives[obj_id][0] = val.substring(51,57);
olms.item_objectives[obj_id][0] = val;
logit_scorm("Objective "+obj_id+"'s id updated",2);
return_value = 'true';
} else if ( req_type == "score" ) {
if (myres[3] == '._children'){
return_value = '';
olms.G_LastError = G_InvalidSetValue;
olms.G_LastErrorString = 'Invalid set value, element is a keyword';
} else if (myres[3] == '.raw'){
olms.item_objectives[obj_id][2] = val;
logit_scorm("Objective "+obj_id+"'s score raw updated",2);
return_value = 'true';
} else if (myres[3] == '.max'){
olms.item_objectives[obj_id][3] = val;
logit_scorm("Objective "+obj_id+"'s score max updated",2);
return_value = 'true';
} else if (myres[3] == '.min'){
olms.item_objectives[obj_id][4] = val;
logit_scorm("Objective "+obj_id+"'s score min updated",2);
return_value = 'true';
} else{
return_value = '';
olms.G_LastError = G_NotImplementedError;
olms.G_LastErrorString = 'Not implemented yet';
}
} else if ( req_type == "status" ) {
olms.item_objectives[obj_id][1] = val;
logit_scorm("Objective "+obj_id+"'s status updated",2);
return_value = 'true';
} else {
olms.G_LastError = G_NotImplementedError;
olms.G_LastErrorString = 'Not implemented yet';
}
}
}
}
} else {
olms.G_LastError = G_NotImplementedError;
olms.G_LastErrorString = G_NotImplementedErrorMessage;
}
}
<?php
if ($oLP->force_commit == 1) {
echo " var mycommit = LMSCommit('force');";
}
?>
return(return_value);
}
/**
* Twin sister of LMSSetValue(). Only provided for backwards compatibility.
*/
function SetValue(param, val) {
return LMSSetValue(param, val);
}
/**
* Saves the current data from JS memory to the LMS database
*/
function savedata(item_id) {
// Origin can be 'commit', 'finish' or 'terminate' (depending on the calling function)
logit_lms('function savedata(' + item_id + ')', 3);
// Status is NOT modified here see the lp_ajax_save_item.php file
if (olms.lesson_status != '') {
olms.updatable_vars_list['cmi.core.lesson_status'] = true;
}
old_item_id = olms.info_lms_item[0];
var item_to_save = olms.lms_item_id;
logit_lms('item_to_save (original value): ' + item_to_save, 3);
// If saving session_time value, we assume that all the new info is about
// the old item, not the current one
// if (olms.session_time != '' && olms.session_time != '0') {
if (olms.switch_finished == 0) {
logit_lms('item_to_save (changed to): ' + old_item_id, 3);
item_to_save = old_item_id;
}
//Original behaviour
// xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, old_item_id);
// Modified version
xajax_save_item_scorm(
olms.lms_lp_id,
olms.lms_user_id,
olms.lms_view_id,
item_to_save,
olms.lms_session_id,
olms.lms_course_id,
olms.finishSignalReceived,
olms.userNavigatesAway,
olms.statusSignalReceived
);
olms.info_lms_item[1] = olms.lms_item_id;
if (olms.item_objectives.length > 0) {
xajax_save_objectives(
olms.lms_lp_id,
olms.lms_user_id,
olms.lms_view_id,
old_item_id,
olms.item_objectives
);
}
olms.execute_stats = false;
// Clean array
olms.variable_to_send = new Array();
}
/**
* Send the Commit signal to the LMS (save the data for this element without
* closing the current process)
* From SCORM 1.2 RTE: If the API Adapter is caching values received from the
* SCO via an LMSSetValue(), this call requires that any values not yet
* persisted by the LMS be persisted.
* @param string Must be empty string for conformance with SCORM 1.2
*/
function LMSCommit(val) {
logit_scorm('LMSCommit() + val');
olms.G_LastError = G_NoError ;
olms.G_LastErrorMessage = 'No error';
savedata(olms.lms_item_id);
reinit_updatable_vars_list();
//now changes have been commited, no need to update until next SetValue()
//commit = 'false' ;
return('true');
}
/**
* Twin sister of LMSCommit(). Only provided for backwards compatibility.
*/
function Commit(val) {
return LMSCommit(val);
}
/**
* Send the closure signal to the LMS. This saves the data and closes the current SCO.
* From SCORM 1.2 RTE: The SCO must call this when it has determined that it no
* longer needs to communicate with the LMS, if it successfully called
* LMSInitialize at any previous point. This call signifies two things:
* 1.The SCO can be assured that any data set using LMSSetValue() calls has been persisted by the LMS.
* 2.The SCO has finished communicating with the LMS.
* @param string
*/
function LMSFinish(val) {
olms.G_LastError = G_NoError ;
olms.G_LastErrorMessage = 'No error';
olms.finishSignalReceived = 1;
// if olms.commit == false, then the SCORM didn't ask for a commit, so we
// should at least report that
if ( !olms.commit ) {
logit_scorm('LMSFinish() (no LMSCommit())',1);
}
logit_scorm('LMSFinish() called on item ' + olms.lms_item_id, 0);
savedata(olms.lms_item_id);
//reinit the commit detector flag
olms.commit = false;
//reinit the list of modified variables
reinit_updatable_vars_list();
return('true');
}
/**
* Twin sister of LMSFinish(). Only provided for backwards compatibility.
*/
function Finish(val) {
return LMSFinish(val);
}
/**
* Returns the last error code as a string
* @return string Error code
*/
function LMSGetLastError() {
logit_scorm('LMSGetLastError()',1);
return(olms.G_LastError.toString());
}
/**
* Twin sister of LMSGetLastError(). Only provided for backwards compatibility.
*/
function GetLastError() {
return LMSGetLastError();
}
/**
* Returns the last error code literal for a given error code
* @param int Error code
* @return string Last error
*/
function LMSGetErrorString(errCode){
logit_scorm('LMSGetErrorString()',1);
return(olms.G_LastErrorString);
}
/**
* Twin sister of LMSGetErrorString(). Only provided for backwards compatibility.
*/
function GetErrorString(errCode){
return LMSGetErrorString(errCode);