2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 require_once($CFG->dirroot
.'/mod/scorm/locallib.php');
19 if (isset($userdata->status
)) {
20 if (!isset($userdata->{'cmi.exit'}) ||
(($userdata->{'cmi.exit'} == 'time-out') ||
($userdata->{'cmi.exit'} == 'normal'))) {
21 $userdata->entry
= 'ab-initio';
23 if (isset($userdata->{'cmi.exit'}) && (($userdata->{'cmi.exit'} == 'suspend') ||
($userdata->{'cmi.exit'} == 'logout'))) {
24 $userdata->entry
= 'resume';
26 $userdata->entry
= '';
30 if (!isset($currentorg)) {
35 // Used need to debug cmi content (if you uncomment this, you must comment the definition inside SCORMapi1_3)
36 //var cmi = new Object();
39 // SCORM 1.3 API Implementation
41 function SCORMapi1_3() {
42 // Standard Data Type Definition
44 // language key has to be checked for language dependent strings
45 var validLanguages
= {'aa':'aa', 'ab':'ab', 'ae':'ae', 'af':'af', 'ak':'ak', 'am':'am', 'an':'an', 'ar':'ar', 'as':'as', 'av':'av', 'ay':'ay', 'az':'az',
46 'ba':'ba', 'be':'be', 'bg':'bg', 'bh':'bh', 'bi':'bi', 'bm':'bm', 'bn':'bn', 'bo':'bo', 'br':'br', 'bs':'bs',
47 'ca':'ca', 'ce':'ce', 'ch':'ch', 'co':'co', 'cr':'cr', 'cs':'cs', 'cu':'cu', 'cv':'cv', 'cy':'cy',
48 'da':'da', 'de':'de', 'dv':'dv', 'dz':'dz', 'ee':'ee', 'el':'el', 'en':'en', 'eo':'eo', 'es':'es', 'et':'et', 'eu':'eu',
49 'fa':'fa', 'ff':'ff', 'fi':'fi', 'fj':'fj', 'fo':'fo', 'fr':'fr', 'fy':'fy', 'ga':'ga', 'gd':'gd', 'gl':'gl', 'gn':'gn', 'gu':'gu', 'gv':'gv',
50 'ha':'ha', 'he':'he', 'hi':'hi', 'ho':'ho', 'hr':'hr', 'ht':'ht', 'hu':'hu', 'hy':'hy', 'hz':'hz',
51 'ia':'ia', 'id':'id', 'ie':'ie', 'ig':'ig', 'ii':'ii', 'ik':'ik', 'io':'io', 'is':'is', 'it':'it', 'iu':'iu',
52 'ja':'ja', 'jv':'jv', 'ka':'ka', 'kg':'kg', 'ki':'ki', 'kj':'kj', 'kk':'kk', 'kl':'kl', 'km':'km', 'kn':'kn', 'ko':'ko', 'kr':'kr', 'ks':'ks', 'ku':'ku', 'kv':'kv', 'kw':'kw', 'ky':'ky',
53 'la':'la', 'lb':'lb', 'lg':'lg', 'li':'li', 'ln':'ln', 'lo':'lo', 'lt':'lt', 'lu':'lu', 'lv':'lv',
54 'mg':'mg', 'mh':'mh', 'mi':'mi', 'mk':'mk', 'ml':'ml', 'mn':'mn', 'mo':'mo', 'mr':'mr', 'ms':'ms', 'mt':'mt', 'my':'my',
55 'na':'na', 'nb':'nb', 'nd':'nd', 'ne':'ne', 'ng':'ng', 'nl':'nl', 'nn':'nn', 'no':'no', 'nr':'nr', 'nv':'nv', 'ny':'ny',
56 'oc':'oc', 'oj':'oj', 'om':'om', 'or':'or', 'os':'os', 'pa':'pa', 'pi':'pi', 'pl':'pl', 'ps':'ps', 'pt':'pt',
57 'qu':'qu', 'rm':'rm', 'rn':'rn', 'ro':'ro', 'ru':'ru', 'rw':'rw',
58 'sa':'sa', 'sc':'sc', 'sd':'sd', 'se':'se', 'sg':'sg', 'sh':'sh', 'si':'si', 'sk':'sk', 'sl':'sl', 'sm':'sm', 'sn':'sn', 'so':'so', 'sq':'sq', 'sr':'sr', 'ss':'ss', 'st':'st', 'su':'su', 'sv':'sv', 'sw':'sw',
59 'ta':'ta', 'te':'te', 'tg':'tg', 'th':'th', 'ti':'ti', 'tk':'tk', 'tl':'tl', 'tn':'tn', 'to':'to', 'tr':'tr', 'ts':'ts', 'tt':'tt', 'tw':'tw', 'ty':'ty',
60 'ug':'ug', 'uk':'uk', 'ur':'ur', 'uz':'uz', 've':'ve', 'vi':'vi', 'vo':'vo',
61 'wa':'wa', 'wo':'wo', 'xh':'xh', 'yi':'yi', 'yo':'yo', 'za':'za', 'zh':'zh', 'zu':'zu',
62 'aar':'aar', 'abk':'abk', 'ave':'ave', 'afr':'afr', 'aka':'aka', 'amh':'amh', 'arg':'arg', 'ara':'ara', 'asm':'asm', 'ava':'ava', 'aym':'aym', 'aze':'aze',
63 'bak':'bak', 'bel':'bel', 'bul':'bul', 'bih':'bih', 'bis':'bis', 'bam':'bam', 'ben':'ben', 'tib':'tib', 'bod':'bod', 'bre':'bre', 'bos':'bos',
64 'cat':'cat', 'che':'che', 'cha':'cha', 'cos':'cos', 'cre':'cre', 'cze':'cze', 'ces':'ces', 'chu':'chu', 'chv':'chv', 'wel':'wel', 'cym':'cym',
65 'dan':'dan', 'ger':'ger', 'deu':'deu', 'div':'div', 'dzo':'dzo', 'ewe':'ewe', 'gre':'gre', 'ell':'ell', 'eng':'eng', 'epo':'epo', 'spa':'spa', 'est':'est', 'baq':'baq', 'eus':'eus', 'per':'per',
66 'fas':'fas', 'ful':'ful', 'fin':'fin', 'fij':'fij', 'fao':'fao', 'fre':'fre', 'fra':'fra', 'fry':'fry', 'gle':'gle', 'gla':'gla', 'glg':'glg', 'grn':'grn', 'guj':'guj', 'glv':'glv',
67 'hau':'hau', 'heb':'heb', 'hin':'hin', 'hmo':'hmo', 'hrv':'hrv', 'hat':'hat', 'hun':'hun', 'arm':'arm', 'hye':'hye', 'her':'her',
68 'ina':'ina', 'ind':'ind', 'ile':'ile', 'ibo':'ibo', 'iii':'iii', 'ipk':'ipk', 'ido':'ido', 'ice':'ice', 'isl':'isl', 'ita':'ita', 'iku':'iku',
69 'jpn':'jpn', 'jav':'jav', 'geo':'geo', 'kat':'kat', 'kon':'kon', 'kik':'kik', 'kua':'kua', 'kaz':'kaz', 'kal':'kal', 'khm':'khm', 'kan':'kan', 'kor':'kor', 'kau':'kau', 'kas':'kas', 'kur':'kur', 'kom':'kom', 'cor':'cor', 'kir':'kir',
70 'lat':'lat', 'ltz':'ltz', 'lug':'lug', 'lim':'lim', 'lin':'lin', 'lao':'lao', 'lit':'lit', 'lub':'lub', 'lav':'lav',
71 'mlg':'mlg', 'mah':'mah', 'mao':'mao', 'mri':'mri', 'mac':'mac', 'mkd':'mkd', 'mal':'mal', 'mon':'mon', 'mol':'mol', 'mar':'mar', 'may':'may', 'msa':'msa', 'mlt':'mlt', 'bur':'bur', 'mya':'mya',
72 'nau':'nau', 'nob':'nob', 'nde':'nde', 'nep':'nep', 'ndo':'ndo', 'dut':'dut', 'nld':'nld', 'nno':'nno', 'nor':'nor', 'nbl':'nbl', 'nav':'nav', 'nya':'nya',
73 'oci':'oci', 'oji':'oji', 'orm':'orm', 'ori':'ori', 'oss':'oss', 'pan':'pan', 'pli':'pli', 'pol':'pol', 'pus':'pus', 'por':'por', 'que':'que',
74 'roh':'roh', 'run':'run', 'rum':'rum', 'ron':'ron', 'rus':'rus', 'kin':'kin', 'san':'san', 'srd':'srd', 'snd':'snd', 'sme':'sme', 'sag':'sag', 'slo':'slo', 'sin':'sin', 'slk':'slk', 'slv':'slv', 'smo':'smo', 'sna':'sna', 'som':'som', 'alb':'alb', 'sqi':'sqi', 'srp':'srp', 'ssw':'ssw', 'sot':'sot', 'sun':'sun', 'swe':'swe', 'swa':'swa',
75 'tam':'tam', 'tel':'tel', 'tgk':'tgk', 'tha':'tha', 'tir':'tir', 'tuk':'tuk', 'tgl':'tgl', 'tsn':'tsn', 'ton':'ton', 'tur':'tur', 'tso':'tso', 'tat':'tat', 'twi':'twi', 'tah':'tah',
76 'uig':'uig', 'ukr':'ukr', 'urd':'urd', 'uzb':'uzb', 'ven':'ven', 'vie':'vie', 'vol':'vol', 'wln':'wln', 'wol':'wol', 'xho':'xho', 'yid':'yid', 'yor':'yor', 'zha':'zha', 'chi':'chi', 'zho':'zho', 'zul':'zul'};
78 var CMIString200
= '^[\\u0000-\\uFFFF]{0,200}$';
79 var CMIString250
= '^[\\u0000-\\uFFFF]{0,250}$';
80 var CMIString1000
= '^[\\u0000-\\uFFFF]{0,1000}$';
81 var CMIString4000
= '^[\\u0000-\\uFFFF]{0,4000}$';
82 var CMIString64000
= '^[\\u0000-\\uFFFF]{0,64000}$';
83 var CMILang
= '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$';
84 var CMILangString250
= '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?';
85 var CMILangcr
= '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\}))(.*?)$';
86 var CMILangString250cr
= '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\})?(.{0,250})?)?$';
87 var CMILangString4000
= '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,4000}$)?';
88 var CMITime
= '^(19[7-9]{1}[0-9]{1}|20[0-2]{1}[0-9]{1}|203[0-8]{1})((-(0[1-9]{1}|1[0-2]{1}))((-(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}))(T([0-1]{1}[0-9]{1}|2[0-3]{1})((:[0-5]{1}[0-9]{1})((:[0-5]{1}[0-9]{1})((\\.[0-9]{1,2})((Z|([+|-]([0-1]{1}[0-9]{1}|2[0-3]{1})))(:[0-5]{1}[0-9]{1})?)?)?)?)?)?)?)?$';
89 var CMITimespan
= '^P(\\d+Y)?(\\d+M)?(\\d+D)?(T(((\\d+H)(\\d+M)?(\\d+(\.\\d{1,2})?S)?)|((\\d+M)(\\d+(\.\\d{1,2})?S)?)|((\\d+(\.\\d{1,2})?S))))?$';
90 var CMIInteger
= '^\\d+$';
91 var CMISInteger
= '^-?([0-9]+)$';
92 var CMIDecimal
= '^-?([0-9]{1,5})(\\.[0-9]{1,18})?$';
93 var CMIIdentifier
= '^\\S{1,250}[a-zA-Z0-9]$';
94 var CMIShortIdentifier
= '^[\\w\.]{1,250}$';
95 var CMILongIdentifier
= '^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000})$';
96 var CMIFeedback
= '^.*$'; // This must be redefined
97 var CMIIndex
= '[._](\\d+).';
98 var CMIIndexStore
= '.N(\\d+).';
99 // Vocabulary Data Type Definition
100 var CMICStatus
= '^completed$|^incomplete$|^not attempted$|^unknown$';
101 var CMISStatus
= '^passed$|^failed$|^unknown$';
102 var CMIExit
= '^time-out$|^suspend$|^logout$|^normal$|^$';
103 var CMIType
= '^true-false$|^choice$|^(long-)?fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$|^other$';
104 var CMIResult
= '^correct$|^incorrect$|^unanticipated$|^neutral$|^-?([0-9]{1,4})(\\.[0-9]{1,18})?$';
105 var NAVEvent
= '^previous$|^continue$|^exit$|^exitAll$|^abandon$|^abandonAll$|^suspendAll$|^\{target=\\S{0,200}[a-zA-Z0-9]\}choice|jump$';
106 var NAVBoolean
= '^unknown$|^true$|^false$';
107 var NAVTarget
= '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$'
109 var cmi_children
= '_version,comments_from_learner,comments_from_lms,completion_status,credit,entry,exit,interactions,launch_data,learner_id,learner_name,learner_preference,location,max_time_allowed,mode,objectives,progress_measure,scaled_passing_score,score,session_time,success_status,suspend_data,time_limit_action,total_time';
110 var comments_children
= 'comment,timestamp,location';
111 var score_children
= 'max,raw,scaled,min';
112 var objectives_children
= 'progress_measure,completion_status,success_status,description,score,id';
113 var correct_responses_children
= 'pattern';
114 var student_data_children
= 'mastery_score,max_time_allowed,time_limit_action';
115 var student_preference_children
= 'audio_level,audio_captioning,delivery_speed,language';
116 var interactions_children
= 'id,type,objectives,timestamp,correct_responses,weighting,learner_response,result,latency,description';
118 var scaled_range
= '-1#1';
119 var audio_range
= '0#*';
120 var speed_range
= '0#*';
121 var text_range
= '-1#1';
122 var progress_range
= '0#1';
123 var learner_response
= {
124 'true-false':{'format':'^true$|^false$', 'max':1, 'delimiter':'', 'unique':false},
125 'choice':{'format':CMIShortIdentifier
, 'max':36, 'delimiter':'[,]', 'unique':true},
126 'fill-in':{'format':CMILangString250
, 'max':10, 'delimiter':'[,]', 'unique':false},
127 'long-fill-in':{'format':CMILangString4000
, 'max':1, 'delimiter':'', 'unique':false},
128 'matching':{'format':CMIShortIdentifier
, 'format2':CMIShortIdentifier
, 'max':36, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false},
129 'performance':{'format':'^$|'+CMIShortIdentifier
, 'format2':CMIDecimal+
'|^$|'+CMIShortIdentifier
, 'max':250, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false},
130 'sequencing':{'format':CMIShortIdentifier
, 'max':36, 'delimiter':'[,]', 'unique':false},
131 'likert':{'format':CMIShortIdentifier
, 'max':1, 'delimiter':'', 'unique':false},
132 'numeric':{'format':CMIDecimal
, 'max':1, 'delimiter':'', 'unique':false},
133 'other':{'format':CMIString4000
, 'max':1, 'delimiter':'', 'unique':false}
136 var correct_responses
= {
137 'true-false':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
138 'format':'^true$|^false$',
140 'choice':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':true, 'duplicate':false,
141 'format':CMIShortIdentifier
},
142 // 'fill-in':{'pre':'^(((\{case_matters=(true|false)\})(\{order_matters=(true|false)\})?)|((\{order_matters=(true|false)\})(\{case_matters=(true|false)\})?))(.*?)$',
144 'max':10, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
145 'format':CMILangString250cr
},
146 'long-fill-in':{'pre':'^(\{case_matters=(true|false)\})?', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':true,
147 'format':CMILangString4000
},
148 'matching':{'pre':'', 'max':36, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':false,
149 'format':CMIShortIdentifier
, 'format2':CMIShortIdentifier
},
150 'performance':{'pre':'^(\{order_matters=(true|false)\})?',
151 'max':250, 'delimiter':'[,]', 'delimiter2':'[.]', 'unique':false, 'duplicate':false,
152 'format':'^$|'+CMIShortIdentifier
, 'format2':CMIDecimal+
'|^$|'+CMIShortIdentifier
},
153 'sequencing':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':false, 'duplicate':false,
154 'format':CMIShortIdentifier
},
155 'likert':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
156 'format':CMIShortIdentifier
,
158 'numeric':{'pre':'', 'max':2, 'delimiter':'[:]', 'unique':false, 'duplicate':false,
161 'other':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
162 'format':CMIString4000
,
166 // The SCORM 1.3 data model
168 'cmi._children':{'defaultvalue':cmi_children
, 'mod':'r'},
169 'cmi._version':{'defaultvalue':'1.0', 'mod':'r'},
170 'cmi.comments_from_learner._children':{'defaultvalue':comments_children
, 'mod':'r'},
171 'cmi.comments_from_learner._count':{'mod':'r', 'defaultvalue':'0'},
172 'cmi.comments_from_learner.n.comment':{'format':CMILangString4000
, 'mod':'rw'},
173 'cmi.comments_from_learner.n.location':{'format':CMIString250
, 'mod':'rw'},
174 'cmi.comments_from_learner.n.timestamp':{'format':CMITime
, 'mod':'rw'},
175 'cmi.comments_from_lms._children':{'defaultvalue':comments_children
, 'mod':'r'},
176 'cmi.comments_from_lms._count':{'mod':'r', 'defaultvalue':'0'},
177 'cmi.comments_from_lms.n.comment':{'format':CMILangString4000
, 'mod':'r'},
178 'cmi.comments_from_lms.n.location':{'format':CMIString250
, 'mod':'r'},
179 'cmi.comments_from_lms.n.timestamp':{'format':CMITime
, 'mod':'r'},
180 'cmi.completion_status':{'defaultvalue':'<?php echo !empty($userdata->{'cmi
.completion_status
'})?$userdata->{'cmi
.completion_status
'}:'unknown
' ?>', 'format':CMICStatus
, 'mod':'rw'},
181 'cmi.completion_threshold':{'defaultvalue':<?php
echo !empty($userdata->threshold
)?
'\''.$userdata->threshold
.'\'':'null' ?
>, 'mod':'r'},
182 'cmi.credit':{'defaultvalue':'<?php echo !empty($userdata->credit)?$userdata->credit:'' ?>', 'mod':'r'},
183 'cmi.entry':{'defaultvalue':'<?php echo $userdata->entry ?>', 'mod':'r'},
184 'cmi.exit':{'defaultvalue':'<?php echo !empty($userdata->{'cmi
.exit'})?$userdata->{'cmi
.exit'}:'' ?>', 'format':CMIExit
, 'mod':'w'},
185 'cmi.interactions._children':{'defaultvalue':interactions_children
, 'mod':'r'},
186 'cmi.interactions._count':{'mod':'r', 'defaultvalue':'0'},
187 'cmi.interactions.n.id':{'pattern':CMIIndex
, 'format':CMILongIdentifier
, 'mod':'rw'},
188 'cmi.interactions.n.type':{'pattern':CMIIndex
, 'format':CMIType
, 'mod':'rw'},
189 'cmi.interactions.n.objectives._count':{'pattern':CMIIndex
, 'mod':'r', 'defaultvalue':'0'},
190 'cmi.interactions.n.objectives.n.id':{'pattern':CMIIndex
, 'format':CMILongIdentifier
, 'mod':'rw'},
191 'cmi.interactions.n.timestamp':{'pattern':CMIIndex
, 'format':CMITime
, 'mod':'rw'},
192 'cmi.interactions.n.correct_responses._count':{'defaultvalue':'0', 'pattern':CMIIndex
, 'mod':'r'},
193 'cmi.interactions.n.correct_responses.n.pattern':{'pattern':CMIIndex
, 'format':'CMIFeedback', 'mod':'rw'},
194 'cmi.interactions.n.weighting':{'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
195 'cmi.interactions.n.learner_response':{'pattern':CMIIndex
, 'format':'CMIFeedback', 'mod':'rw'},
196 'cmi.interactions.n.result':{'pattern':CMIIndex
, 'format':CMIResult
, 'mod':'rw'},
197 'cmi.interactions.n.latency':{'pattern':CMIIndex
, 'format':CMITimespan
, 'mod':'rw'},
198 'cmi.interactions.n.description':{'pattern':CMIIndex
, 'format':CMILangString250
, 'mod':'rw'},
199 'cmi.launch_data':{'defaultvalue':<?php
echo !empty($userdata->datafromlms
)?
'\''.$userdata->datafromlms
.'\'':'null' ?
>, 'mod':'r'},
200 'cmi.learner_id':{'defaultvalue':'<?php echo $userdata->student_id ?>', 'mod':'r'},
201 'cmi.learner_name':{'defaultvalue':'<?php echo $userdata->student_name ?>', 'mod':'r'},
202 'cmi.learner_preference._children':{'defaultvalue':student_preference_children
, 'mod':'r'},
203 'cmi.learner_preference.audio_level':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.learner_preference.audio_level'})?
'\''.$userdata->{'cmi.learner_preference.audio_level'}.'\'':'\'1\'' ?
>, 'format':CMIDecimal
, 'range':audio_range
, 'mod':'rw'},
204 'cmi.learner_preference.language':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.learner_preference.language'})?
'\''.$userdata->{'cmi.learner_preference.language'}.'\'':'\'\'' ?
>, 'format':CMILang
, 'mod':'rw'},
205 'cmi.learner_preference.delivery_speed':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.learner_preference.delivery_speed'})?
'\''.$userdata->{'cmi.learner_preference.delivery_speed'}.'\'':'\'1\'' ?
>, 'format':CMIDecimal
, 'range':speed_range
, 'mod':'rw'},
206 'cmi.learner_preference.audio_captioning':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.learner_preference.audio_captioning'})?
'\''.$userdata->{'cmi.learner_preference.audio_captioning'}.'\'':'\'0\'' ?
>, 'format':CMISInteger
, 'range':text_range
, 'mod':'rw'},
207 'cmi.location':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.location'})?
'\''.$userdata->{'cmi.location'}.'\'':'null' ?
>, 'format':CMIString1000
, 'mod':'rw'},
208 'cmi.max_time_allowed':{'defaultvalue':<?php
echo !empty($userdata->attemptAbsoluteDurationLimit
)?
'\''.$userdata->attemptAbsoluteDurationLimit
.'\'':'null' ?
>, 'mod':'r'},
209 'cmi.mode':{'defaultvalue':'<?php echo $userdata->mode ?>', 'mod':'r'},
210 'cmi.objectives._children':{'defaultvalue':objectives_children
, 'mod':'r'},
211 'cmi.objectives._count':{'mod':'r', 'defaultvalue':'0'},
212 'cmi.objectives.n.id':{'pattern':CMIIndex
, 'format':CMILongIdentifier
, 'mod':'rw'},
213 'cmi.objectives.n.score._children':{'defaultvalue':score_children
, 'pattern':CMIIndex
, 'mod':'r'},
214 'cmi.objectives.n.score.scaled':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'range':scaled_range
, 'mod':'rw'},
215 'cmi.objectives.n.score.raw':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
216 'cmi.objectives.n.score.min':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
217 'cmi.objectives.n.score.max':{'defaultvalue':null, 'pattern':CMIIndex
, 'format':CMIDecimal
, 'mod':'rw'},
218 'cmi.objectives.n.success_status':{'defaultvalue':'unknown', 'pattern':CMIIndex
, 'format':CMISStatus
, 'mod':'rw'},
219 'cmi.objectives.n.completion_status':{'defaultvalue':'unknown', 'pattern':CMIIndex
, 'format':CMICStatus
, 'mod':'rw'},
220 'cmi.objectives.n.progress_measure':{'defaultvalue':null, 'format':CMIDecimal
, 'range':progress_range
, 'mod':'rw'},
221 'cmi.objectives.n.description':{'pattern':CMIIndex
, 'format':CMILangString250
, 'mod':'rw'},
222 'cmi.progress_measure':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.progress_measure'})?
'\''.$userdata->{'cmi.progress_measure'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'range':progress_range
, 'mod':'rw'},
223 'cmi.scaled_passing_score':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.scaled_passing_score'})?
'\''.$userdata->{'cmi.scaled_passing_score'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'range':scaled_range
, 'mod':'r'},
224 'cmi.score._children':{'defaultvalue':score_children
, 'mod':'r'},
225 'cmi.score.scaled':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.score.scaled'})?
'\''.$userdata->{'cmi.score.scaled'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'range':scaled_range
, 'mod':'rw'},
226 'cmi.score.raw':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.score.raw'})?
'\''.$userdata->{'cmi.score.raw'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'mod':'rw'},
227 'cmi.score.min':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.score.min'})?
'\''.$userdata->{'cmi.score.min'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'mod':'rw'},
228 'cmi.score.max':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.score.max'})?
'\''.$userdata->{'cmi.score.max'}.'\'':'null' ?
>, 'format':CMIDecimal
, 'mod':'rw'},
229 'cmi.session_time':{'format':CMITimespan
, 'mod':'w', 'defaultvalue':'PT0H0M0S'},
230 'cmi.success_status':{'defaultvalue':'<?php echo !empty($userdata->{'cmi
.success_status
'})?$userdata->{'cmi
.success_status
'}:'unknown
' ?>', 'format':CMISStatus
, 'mod':'rw'},
231 'cmi.suspend_data':{'defaultvalue':<?php
echo !empty($userdata->{'cmi.suspend_data'})?
'\''.$userdata->{'cmi.suspend_data'}.'\'':'null' ?
>, 'format':CMIString64000
, 'mod':'rw'},
232 'cmi.time_limit_action':{'defaultvalue':<?php
echo !empty($userdata->timelimitaction
)?
'\''.$userdata->timelimitaction
.'\'':'null' ?
>, 'mod':'r'},
233 'cmi.total_time':{'defaultvalue':'<?php echo !empty($userdata->{'cmi
.total_time
'})?$userdata->{'cmi
.total_time
'}:'PT0H0M0S
' ?>', 'mod':'r'},
234 'adl.nav.request':{'defaultvalue':'_none_', 'format':NAVEvent
, 'mod':'rw'}
237 // Datamodel inizialization
239 var cmi
= new Object();
240 cmi
.comments_from_learner
= new Object();
241 cmi
.comments_from_learner
._count
= 0;
242 cmi
.comments_from_lms
= new Object();
243 cmi
.comments_from_lms
._count
= 0;
244 cmi
.interactions
= new Object();
245 cmi
.interactions
._count
= 0;
246 cmi
.learner_preference
= new Object();
247 cmi
.objectives
= new Object();
248 cmi
.objectives
._count
= 0;
249 cmi
.score
= new Object();
252 var adl
= new Object();
253 adl
.nav
= new Object();
254 adl
.nav
.request_valid
= new Array();
256 for (element in datamodel
) {
257 if (element
.match(/\
.n\
./) == null) {
258 if ((typeof
eval('datamodel["'+element+
'"].defaultvalue')) != 'undefined') {
259 eval(element+
' = datamodel["'+element+
'"].defaultvalue;');
261 eval(element+
' = "";');
267 // reconstitute objectives, comments_from_learner and comments_from_lms
268 scorm_reconstitute_array_element($scorm->version
, $userdata, 'cmi.objectives', array('score'));
269 scorm_reconstitute_array_element($scorm->version
, $userdata, 'cmi.interactions', array('objectives', 'correct_responses'));
270 scorm_reconstitute_array_element($scorm->version
, $userdata, 'cmi.comments_from_learner', array());
271 scorm_reconstitute_array_element($scorm->version
, $userdata, 'cmi.comments_from_lms', array());
274 if (cmi
.completion_status
== '') {
275 cmi
.completion_status
= 'not attempted';
279 // API Methods definition
281 var Initialized
= false;
282 var Terminated
= false;
286 function Initialize (param
) {
289 if ((!Initialized
) && (!Terminated
)) {
293 if (scorm_debugging($scorm)) {
294 echo 'LogAPICall("Initialize", param, "", errorCode);';
309 if (scorm_debugging($scorm)) {
310 echo 'LogAPICall("Initialize", param, "", errorCode);';
316 function Terminate (param
) {
319 if ((Initialized
) && (!Terminated
)) {
320 var AJAXResult
= StoreData(cmi
,true);
322 if (scorm_debugging($scorm)) {
323 echo 'LogAPICall("Terminate", "AJAXResult", AJAXResult, 0);';
326 result
= ('true' == AJAXResult
) ?
'true' : 'false';
327 errorCode
= ('true' == result
)?
'0' : '101'; // General exception for any AJAX fault
329 if (scorm_debugging($scorm)) {
330 echo 'LogAPICall("Terminate", "result", result, errorCode);';
333 if ('true' == result
) {
336 if (adl
.nav
.request
!= '_none_') {
337 switch (adl
.nav
.request
) {
339 setTimeout('mod_scorm_launch_next_sco();',500);
342 setTimeout('mod_scorm_launch_prev_sco();',500);
356 if (<?php
echo $scorm->auto ?
> == 1) {
357 setTimeout('mod_scorm_launch_next_sco();',500);
360 // trigger TOC update
361 var sURL
= "<?php echo $CFG->wwwroot; ?>" +
"/mod/scorm/prereqs.php?a=<?php echo $scorm->id ?>&scoid=<?php echo $scoid ?>&attempt=<?php echo $attempt ?>&mode=<?php echo $mode ?>¤torg=<?php echo $currentorg ?>&sesskey=<?php echo sesskey(); ?>";
362 var callback
= M
.mod_scorm
.connectPrereqCallback
;
363 YUI().use('io-base', function(Y
) {
364 Y
.on('io:complete', callback
.success
, Y
);
368 diagnostic
= "Failure calling the Terminate remote callback: the server replied with HTTP Status " + AJAXResult
;
382 if (scorm_debugging($scorm)) {
383 echo 'LogAPICall("Terminate", param, "", errorCode);';
389 function GetValue (element
) {
392 if ((Initialized
) && (!Terminated
)) {
394 var expression
= new RegExp(CMIIndex
,'g');
395 var elementmodel
= String(element
).replace(expression
,'.n.');
396 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
397 if (eval('datamodel["'+elementmodel+
'"].mod') != 'w') {
399 element
= String(element
).replace(/\
.(\d+
)\
./, ".N$1.");
400 element
= element
.replace(/\
.(\d+
)\
./, ".N$1.");
402 var elementIndexes
= element
.split('.');
403 var subelement
= element
.substr(0,3);
405 while ((i
< elementIndexes
.length
) && (typeof
eval(subelement
) != "undefined")) {
406 subelement +
= '.'+elementIndexes
[i++
];
409 if (subelement
== element
) {
411 if ((typeof
eval(subelement
) != "undefined") && (eval(subelement
) != null)) {
414 if (scorm_debugging($scorm)) {
415 echo 'LogAPICall("GetValue", element, eval(element), 0);';
418 return eval(element
);
426 //errorCode = eval('datamodel["'+elementmodel+'"].readerror');
430 var childrenstr
= '._children';
431 var countstr
= '._count';
432 var parentmodel
= '';
433 if (elementmodel
.substr(elementmodel
.length
-childrenstr
.length
,elementmodel
.length
) == childrenstr
) {
434 parentmodel
= elementmodel
.substr(0,elementmodel
.length
-childrenstr
.length
);
435 if ((typeof
eval('datamodel["'+parentmodel+
'"]')) != "undefined") {
437 diagnostic
= "Data Model Element Does Not Have Children";
441 } else if (elementmodel
.substr(elementmodel
.length
-countstr
.length
,elementmodel
.length
) == countstr
) {
442 parentmodel
= elementmodel
.substr(0,elementmodel
.length
-countstr
.length
);
443 if ((typeof
eval('datamodel["'+parentmodel+
'"]')) != "undefined") {
445 diagnostic
= "Data Model Element Cannot Have Count";
450 parentmodel
= 'adl.nav.request_valid.';
451 if (element
.substr(0,parentmodel
.length
) == parentmodel
) {
452 if (element
.substr(parentmodel
.length
).match(NAVTarget
) == null) {
455 if (adl
.nav
.request
== element
.substr(parentmodel
.length
)) {
457 } else if (adl
.nav
.request
== '_none_') {
479 if (scorm_debugging($scorm)) {
480 echo 'LogAPICall("GetValue", element, "", errorCode);';
486 function SetValue (element
,value
) {
489 if ((Initialized
) && (!Terminated
)) {
491 var expression
= new RegExp(CMIIndex
,'g');
492 var elementmodel
= String(element
).replace(expression
,'.n.');
493 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
494 if (eval('datamodel["'+elementmodel+
'"].mod') != 'r') {
495 if (eval('datamodel["'+elementmodel+
'"].format') != 'CMIFeedback') {
496 expression
= new RegExp(eval('datamodel["'+elementmodel+
'"].format'));
498 // cmi.interactions.n.type depending format accept everything at this stage
499 expression
= new RegExp(CMIFeedback
);
502 var matches
= value
.match(expression
);
503 if ((matches
!= null) && ((matches
.join('').length
> 0) ||
(value
.length
== 0))) {
504 // Value match dataelement format
506 if (element
!= elementmodel
) {
507 //This is a dynamic datamodel element
509 var elementIndexes
= element
.split('.');
510 var subelement
= 'cmi';
511 var parentelement
= 'cmi';
512 for (var i
=1;(i
< elementIndexes
.length
-1) && (errorCode
=="0");i++
) {
513 var elementIndex
= elementIndexes
[i
];
514 if (elementIndexes
[i+
1].match(/^\d+$
/)) {
515 if ((parseInt(elementIndexes
[i+
1]) > 0) && (elementIndexes
[i+
1].charAt(0) == 0)) {
516 // Index has a leading 0 (zero), this is not a number
519 parentelement
= subelement+
'.'+elementIndex
;
520 if ((typeof
eval(parentelement
) == "undefined") ||
(typeof
eval(parentelement+
'._count') == "undefined")) {
523 if (elementIndexes
[i+
1] > eval(parentelement+
'._count')) {
525 diagnostic
= "Data Model Element Collection Set Out Of Order";
527 subelement
= subelement
.concat('.'+elementIndex+
'.N'+elementIndexes
[i+
1]);
530 if (((typeof
eval(subelement
)) == "undefined") && (i
< elementIndexes
.length
-2)) {
535 subelement
= subelement
.concat('.'+elementIndex
);
539 if (errorCode
== "0") {
540 // Till now it's a real datamodel element
542 element
= subelement
.concat('.'+elementIndexes
[elementIndexes
.length
-1]);
544 if ((typeof
eval(subelement
)) == "undefined") {
545 switch (elementmodel
) {
546 case 'cmi.objectives.n.id':
547 if (!duplicatedID(element
,parentelement
,value
)) {
548 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
549 eval(parentelement+
'._count++;');
550 eval(subelement+
' = new Object();');
551 var subobject
= eval(subelement
);
552 subobject
.success_status
= datamodel
["cmi.objectives.n.success_status"].defaultvalue
;
553 subobject
.completion_status
= datamodel
["cmi.objectives.n.completion_status"].defaultvalue
;
554 subobject
.progress_measure
= datamodel
["cmi.objectives.n.progress_measure"].defaultvalue
;
555 subobject
.score
= new Object();
556 subobject
.score
._children
= score_children
;
557 subobject
.score
.scaled
= datamodel
["cmi.objectives.n.score.scaled"].defaultvalue
;
558 subobject
.score
.raw
= datamodel
["cmi.objectives.n.score.raw"].defaultvalue
;
559 subobject
.score
.min
= datamodel
["cmi.objectives.n.score.min"].defaultvalue
;
560 subobject
.score
.max
= datamodel
["cmi.objectives.n.score.max"].defaultvalue
;
564 diagnostic
= "Data Model Element ID Already Exists";
567 case 'cmi.interactions.n.id':
568 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
569 eval(parentelement+
'._count++;');
570 eval(subelement+
' = new Object();');
571 var subobject
= eval(subelement
);
572 subobject
.objectives
= new Object();
573 subobject
.objectives
._count
= 0;
576 case 'cmi.interactions.n.objectives.n.id':
577 if (typeof
eval(parentelement
) != "undefined") {
578 if (!duplicatedID(element
,parentelement
,value
)) {
579 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
580 eval(parentelement+
'._count++;');
581 eval(subelement+
' = new Object();');
585 diagnostic
= "Data Model Element ID Already Exists";
591 case 'cmi.interactions.n.correct_responses.n.pattern':
592 if (typeof
eval(parentelement
) != "undefined") {
593 // Use cmi.interactions.n.type value to check the right dataelement format
594 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
595 var interactiontype
= eval(String(parentelement
).replace('correct_responses','type'));
596 var interactioncount
= eval(parentelement+
'._count');
597 // trap duplicate values, which is not allowed for type choice
598 if (interactiontype
== 'choice') {
599 for (var i
=0; (i
< interactioncount
) && (errorCode
=="0"); i++
) {
600 if (eval(parentelement+
'.N'+i+
'.pattern') == value
) {
605 if ((typeof correct_responses
[interactiontype
].limit
== 'undefined') ||
606 (eval(parentelement+
'._count') < correct_responses
[interactiontype
].limit
)) {
607 var nodes
= new Array();
608 if (correct_responses
[interactiontype
].delimiter
!= '') {
609 nodes
= value
.split(correct_responses
[interactiontype
].delimiter
);
613 if ((nodes
.length
> 0) && (nodes
.length
<= correct_responses
[interactiontype
].max
)) {
614 errorCode
= CRcheckValueNodes (element
, interactiontype
, nodes
, value
, errorCode
);
615 } else if (nodes
.length
> correct_responses
[interactiontype
].max
) {
617 diagnostic
= "Data Model Element Pattern Too Long";
619 if ((errorCode
== "0") && ((correct_responses
[interactiontype
].duplicate
== false) ||
620 (!duplicatedPA(element
,parentelement
,value
))) ||
(errorCode
== "0" && value
== "")) {
621 eval(parentelement+
'._count++;');
622 eval(subelement+
' = new Object();');
624 if (errorCode
== "0") {
626 diagnostic
= "Data Model Element Pattern Already Exists";
631 diagnostic
= "Data Model Element Collection Limit Reached";
635 diagnostic
= "Data Model Element Collection Set Out Of Order";
642 if ((parentelement
!= 'cmi.objectives') && (parentelement
!= 'cmi.interactions') && (typeof
eval(parentelement
) != "undefined")) {
643 if (elementIndexes
[elementIndexes
.length
-2] == eval(parentelement+
'._count')) {
644 eval(parentelement+
'._count++;');
645 eval(subelement+
' = new Object();');
648 diagnostic
= "Data Model Element Collection Set Out Of Order";
656 switch (elementmodel
) {
657 case 'cmi.objectives.n.id':
658 if (eval(element
) != value
) {
660 diagnostic
= "Write Once Violation";
663 case 'cmi.interactions.n.objectives.n.id':
664 if (duplicatedID(element
,parentelement
,value
)) {
666 diagnostic
= "Data Model Element ID Already Exists";
669 case 'cmi.interactions.n.type':
670 var subobject
= eval(subelement
);
671 subobject
.correct_responses
= new Object();
672 subobject
.correct_responses
._count
= 0;
674 case 'cmi.interactions.n.learner_response':
675 if (typeof
eval(subelement+
'.type') == "undefined") {
678 // Use cmi.interactions.n.type value to check the right dataelement format
679 interactiontype
= eval(subelement+
'.type');
680 var nodes
= new Array();
681 if (learner_response
[interactiontype
].delimiter
!= '') {
682 nodes
= value
.split(learner_response
[interactiontype
].delimiter
);
686 if ((nodes
.length
> 0) && (nodes
.length
<= learner_response
[interactiontype
].max
)) {
687 expression
= new RegExp(learner_response
[interactiontype
].format
);
688 for (var i
=0; (i
< nodes
.length
) && (errorCode
=="0"); i++
) {
689 if (typeof learner_response
[interactiontype
].delimiter2
!= 'undefined') {
690 values
= nodes
[i
].split(learner_response
[interactiontype
].delimiter2
);
691 if (values
.length
== 2) {
692 matches
= values
[0].match(expression
);
693 if (matches
== null) {
696 var expression2
= new RegExp(learner_response
[interactiontype
].format2
);
697 matches
= values
[1].match(expression2
);
698 if (matches
== null) {
706 matches
= nodes
[i
].match(expression
);
707 if (matches
== null) {
710 if ((nodes
[i
] != '') && (learner_response
[interactiontype
].unique
)) {
711 for (var j
=0; (j
<i
) && (errorCode
=="0"); j++
) {
712 if (nodes
[i
] == nodes
[j
]) {
720 } else if (nodes
.length
> learner_response
[interactiontype
].max
) {
722 diagnostic
= "Data Model Element Pattern Too Long";
726 case 'cmi.interactions.n.correct_responses.n.pattern':
727 subel
= subelement
.split('.');
728 subel1
= 'cmi.interactions.'+subel
[2];
730 if (typeof
eval(subel1+
'.type') == "undefined") {
733 // Use cmi.interactions.n.type value to check the right //dataelement format
734 var interactiontype
= eval(subel1+
'.type');
735 var interactioncount
= eval(parentelement+
'._count');
736 // trap duplicate values, which is not allowed for type choice
737 if (interactiontype
== 'choice') {
738 for (var i
=0; (i
< interactioncount
) && (errorCode
=="0"); i++
) {
739 if (eval(parentelement+
'.N'+i+
'.pattern') == value
) {
744 var nodes
= new Array();
745 if (correct_responses
[interactiontype
].delimiter
!= '') {
746 nodes
= value
.split(correct_responses
[interactiontype
].delimiter
);
751 if ((nodes
.length
> 0) && (nodes
.length
<= correct_responses
[interactiontype
].max
)) {
752 errorCode
= CRcheckValueNodes (element
, interactiontype
, nodes
, value
, errorCode
);
753 } else if (nodes
.length
> correct_responses
[interactiontype
].max
) {
755 diagnostic
= "Data Model Element Pattern Too Long";
764 if (errorCode
== "0") {
766 if ((typeof
eval('datamodel["'+elementmodel+
'"].range')) != "undefined") {
767 range
= eval('datamodel["'+elementmodel+
'"].range');
768 ranges
= range
.split('#');
770 if (value
>= ranges
[0]) {
771 if ((ranges
[1] == '*') ||
(value
<= ranges
[1])) {
772 eval(element+
'=value;');
775 if (scorm_debugging($scorm)) {
776 echo 'LogAPICall("SetValue", element, value, errorCode);';
787 eval(element+
'=value;');
790 if (scorm_debugging($scorm)) {
791 echo 'LogAPICall("SetValue", element, value, errorCode);';
817 if (scorm_debugging($scorm)) {
818 echo 'LogAPICall("SetValue", element, value, errorCode);';
825 function CRremovePrefixes (node
) {
826 // check for prefixes lang, case, order
827 // case and then order
828 var seenOrder
= false;
829 var seenCase
= false;
830 var seenLang
= false;
832 while (matches
= node
.match('^(\{(lang|case_matters|order_matters)=([^\}]+)\})')) {
833 switch (matches
[2]) {
835 // check for language prefix on each node
836 langmatches
= node
.match(CMILangcr
);
837 if (langmatches
!= null) {
838 lang
= langmatches
[3];
839 // check that language string definition is valid
840 if (lang
.length
> 0 && lang
!= undefined
) {
841 if (validLanguages
[lang
.toLowerCase()] == undefined
) {
850 // check for correct case answer
851 if (! seenLang
&& ! seenOrder
&& ! seenCase
) {
852 if (matches
[3] != 'true' && matches
[3] != 'false') {
859 case 'order_matters':
860 // check for correct case answer
861 if (! seenCase
&& ! seenLang
&& ! seenOrder
) {
862 if (matches
[3] != 'true' && matches
[3] != 'false') {
872 node
= node
.substr(matches
[1].length
);
874 return {'errorCode': errorCode
, 'node': node
};
878 function CRcheckValueNodes(element
, interactiontype
, nodes
, value
, errorCode
) {
879 expression
= new RegExp(correct_responses
[interactiontype
].format
);
880 for (var i
=0; (i
< nodes
.length
) && (errorCode
=="0"); i++
) {
881 if (interactiontype
.match('^(fill-in|long-fill-in|matching|performance|sequencing)$')) {
882 result
= CRremovePrefixes(nodes
[i
]);
883 errorCode
= result
.errorCode
;
884 nodes
[i
] = result
.node
;
887 // check for prefix on each node
888 if (correct_responses
[interactiontype
].pre
!= '') {
889 matches
= nodes
[i
].match(correct_responses
[interactiontype
].pre
);
890 if (matches
!= null) {
891 nodes
[i
] = nodes
[i
].substr(matches
[1].length
);
895 if (correct_responses
[interactiontype
].delimiter2
!= undefined
) {
896 values
= nodes
[i
].split(correct_responses
[interactiontype
].delimiter2
);
897 if (values
.length
== 2) {
898 matches
= values
[0].match(expression
);
899 if (matches
== null) {
902 var expression2
= new RegExp(correct_responses
[interactiontype
].format2
);
903 matches
= values
[1].match(expression2
);
904 if (matches
== null) {
912 matches
= nodes
[i
].match(expression
);
913 //if ((matches == null) || (matches.join('').length == 0)) {
914 if ((matches
== null && value
!= "")||
(matches
== null && interactiontype
=="true-false")){
917 // numeric range - left must be <= right
918 if (interactiontype
== 'numeric' && nodes
.length
> 1) {
919 if (parseFloat(nodes
[0]) > parseFloat(nodes
[1])) {
923 if ((nodes
[i
] != '') && (correct_responses
[interactiontype
].unique
)) {
924 for (var j
=0; (j
< i
) && (errorCode
=="0"); j++
) {
925 if (nodes
[i
] == nodes
[j
]) {
933 } // end of for each nodes
938 function Commit (param
) {
941 if ((Initialized
) && (!Terminated
)) {
942 var AJAXResult
= StoreData(cmi
,false);
944 if (scorm_debugging($scorm)) {
945 echo 'LogAPICall("Commit", "AJAXResult", AJAXResult, 0);';
948 var result
= ('true' == AJAXResult
) ?
'true' : 'false';
949 errorCode
= ('true' == result
)?
'0' : '101'; // General exception for any AJAX fault
951 if (scorm_debugging($scorm)) {
952 echo 'LogAPICall("Commit", "result", result, errorCode);';
955 if ('false' == result
) {
956 diagnostic
= "Failure calling the Commit remote callback: the server replied with HTTP Status " + AJAXResult
;
970 if (scorm_debugging($scorm)) {
971 echo 'LogAPICall("Commit", param, "", errorCode);';
977 function GetLastError () {
979 if (scorm_debugging($scorm)) {
980 echo 'LogAPICall("GetLastError", "", "", errorCode);';
986 function GetErrorString (param
) {
988 var errorString
= "";
991 errorString
= "No error";
994 errorString
= "General exception";
997 errorString
= "General Inizialization Failure";
1000 errorString
= "Already Initialized";
1003 errorString
= "Content Instance Terminated";
1006 errorString
= "General Termination Failure";
1009 errorString
= "Termination Before Inizialization";
1012 errorString
= "Termination After Termination";
1015 errorString
= "Retrieve Data Before Initialization";
1018 errorString
= "Retrieve Data After Termination";
1021 errorString
= "Store Data Before Inizialization";
1024 errorString
= "Store Data After Termination";
1027 errorString
= "Commit Before Inizialization";
1030 errorString
= "Commit After Termination";
1033 errorString
= "General Argument Error";
1036 errorString
= "General Get Failure";
1039 errorString
= "General Set Failure";
1042 errorString
= "General Commit Failure";
1045 errorString
= "Undefinited Data Model";
1048 errorString
= "Unimplemented Data Model Element";
1051 errorString
= "Data Model Element Value Not Initialized";
1054 errorString
= "Data Model Element Is Read Only";
1057 errorString
= "Data Model Element Is Write Only";
1060 errorString
= "Data Model Element Type Mismatch";
1063 errorString
= "Data Model Element Value Out Of Range";
1066 errorString
= "Data Model Dependency Not Established";
1070 if (scorm_debugging($scorm)) {
1071 echo 'LogAPICall("GetErrorString", param, errorString, 0);';
1077 if (scorm_debugging($scorm)) {
1078 echo 'LogAPICall("GetErrorString", param, "No error string found!", 0);';
1085 function GetDiagnostic (param
) {
1086 if (diagnostic
!= "") {
1088 if (scorm_debugging($scorm)) {
1089 echo 'LogAPICall("GetDiagnostic", param, diagnostic, 0);';
1095 if (scorm_debugging($scorm)) {
1096 echo 'LogAPICall("GetDiagnostic", param, param, 0);';
1102 function duplicatedID (element
, parent
, value
) {
1104 var elements
= eval(parent+
'._count');
1105 for (var n
=0;(n
< elements
) && (!found
);n++
) {
1106 if ((parent+
'.N'+n+
'.id' != element
) && (eval(parent+
'.N'+n+
'.id') == value
)) {
1113 function duplicatedPA (element
, parent
, value
) {
1115 var elements
= eval(parent+
'._count');
1116 for (var n
=0;(n
< elements
) && (!found
);n++
) {
1117 if ((parent+
'.N'+n+
'.pattern' != element
) && (eval(parent+
'.N'+n+
'.pattern') == value
)) {
1124 function getElementModel(element
) {
1125 if (typeof datamodel
[element
] != "undefined") {
1128 var expression
= new RegExp(CMIIndex
,'g');
1129 var elementmodel
= String(element
).replace(expression
,'.n.');
1130 if (typeof datamodel
[elementmodel
] != "undefined") {
1131 return elementmodel
;
1137 function AddTime (first
, second
) {
1139 // if (scorm_debugging($scorm)) {
1140 // echo 'alert("AddTime: "+first+" + "+second);';
1143 var timestring
= 'P';
1144 var matchexpr
= /^
P((\d+
)Y
)?
((\d+
)M
)?
((\d+
)D
)?
(T((\d+
)H
)?
((\d+
)M
)?
((\d+
(\
.\d
{1,2})?
)S
)?
)?$
/;
1145 var firstarray
= first
.match(matchexpr
);
1146 var secondarray
= second
.match(matchexpr
);
1147 if ((firstarray
!= null) && (secondarray
!= null)) {
1149 if(parseFloat(firstarray
[13],10)>0){ firstsecs
=parseFloat(firstarray
[13],10); }
1151 if(parseFloat(secondarray
[13],10)>0){ secondsecs
=parseFloat(secondarray
[13],10); }
1152 var secs
= firstsecs+secondsecs
; //Seconds
1153 var change
= Math
.floor(secs
/60);
1154 secs
= Math
.round((secs
-(change
*60))*100)/100;
1156 if(parseInt(firstarray
[11],10)>0){ firstmins
=parseInt(firstarray
[11],10); }
1158 if(parseInt(secondarray
[11],10)>0){ secondmins
=parseInt(secondarray
[11],10); }
1159 var mins
= firstmins+secondmins+change
; //Minutes
1160 change
= Math
.floor(mins
/ 60);
1161 mins
= Math
.round(mins
-(change
*60));
1163 if(parseInt(firstarray
[9],10)>0){ firsthours
=parseInt(firstarray
[9],10); }
1165 if(parseInt(secondarray
[9],10)>0){ secondhours
=parseInt(secondarray
[9],10); }
1166 var hours
= firsthours+secondhours+change
; //Hours
1167 change
= Math
.floor(hours
/24);
1168 hours
= Math
.round(hours
-(change
*24));
1170 if(parseInt(firstarray
[6],10)>0){ firstdays
=parseInt(firstarray
[6],10); }
1172 if(parseInt(secondarray
[6],10)>0){ firstdays
=parseInt(secondarray
[6],10); }
1173 var days
= Math
.round(firstdays+seconddays+change
); // Days
1175 if(parseInt(firstarray
[4],10)>0){ firstmonths
=parseInt(firstarray
[4],10); }
1177 if(parseInt(secondarray
[4],10)>0){ secondmonths
=parseInt(secondarray
[4],10); }
1178 var months
= Math
.round(firstmonths+secondmonths
);
1180 if(parseInt(firstarray
[2],10)>0){ firstyears
=parseInt(firstarray
[2],10); }
1182 if(parseInt(secondarray
[2],10)>0){ secondyears
=parseInt(secondarray
[2],10); }
1183 var years
= Math
.round(firstyears+secondyears
);
1186 timestring +
= years +
'Y';
1189 timestring +
= months +
'M';
1192 timestring +
= days +
'D';
1194 if ((hours
> 0) ||
(mins
> 0) ||
(secs
> 0)) {
1197 timestring +
= hours +
'H';
1200 timestring +
= mins +
'M';
1203 timestring +
= secs +
'S';
1209 function TotalTime() {
1210 var total_time
= AddTime(cmi
.total_time
, cmi
.session_time
);
1211 return '&'+
underscore('cmi.total_time')+
'='+
encodeURIComponent(total_time
);
1214 function CollectData(data
,parent
) {
1215 var datastring
= '';
1216 for (property in data
) {
1217 if (typeof data
[property
] == 'object') {
1218 datastring +
= CollectData(data
[property
],parent+
'.'+property
);
1220 var element
= parent+
'.'+property
;
1221 var expression
= new RegExp(CMIIndexStore
,'g');
1222 var elementmodel
= String(element
).replace(expression
,'.n.');
1223 if ((typeof
eval('datamodel["'+elementmodel+
'"]')) != "undefined") {
1224 if (eval('datamodel["'+elementmodel+
'"].mod') != 'r') {
1225 var elementstring
= '&'+
underscore(element
)+
'='+
encodeURIComponent(data
[property
]);
1226 if ((typeof
eval('datamodel["'+elementmodel+
'"].defaultvalue')) != "undefined") {
1227 if (eval('datamodel["'+elementmodel+
'"].defaultvalue') != data
[property
] ||
eval('typeof(datamodel["'+elementmodel+
'"].defaultvalue)') != typeof(data
[property
])) {
1228 datastring +
= elementstring
;
1231 datastring +
= elementstring
;
1240 function StoreData(data
,storetotaltime
) {
1241 var datastring
= '';
1242 if (storetotaltime
) {
1243 if (cmi
.mode
== 'normal') {
1244 if (cmi
.credit
== 'credit') {
1245 if ((cmi
.completion_threshold
!= null) && (cmi
.progress_measure
!= null)) {
1246 if (cmi
.progress_measure
>= cmi
.completion_threshold
) {
1247 cmi
.completion_status
= 'completed';
1249 cmi
.completion_status
= 'incomplete';
1252 if ((cmi
.scaled_passed_score
!= null) && (cmi
.score
.scaled
!= '')) {
1253 if (cmi
.score
.scaled
>= cmi
.scaled_passed_score
) {
1254 cmi
.success_status
= 'passed';
1256 cmi
.success_status
= 'failed';
1261 datastring +
= TotalTime();
1263 datastring +
= CollectData(data
,'cmi');
1264 var element
= 'adl.nav.request';
1265 var navrequest
= eval(element
) != datamodel
[element
].defaultvalue ?
'&'+
underscore(element
)+
'='+
encodeURIComponent(eval(element
)) : '';
1266 datastring +
= navrequest
;
1267 datastring +
= '&attempt=<?php echo $attempt ?>';
1268 datastring +
= '&scoid=<?php echo $scoid ?>';
1269 var myRequest
= NewHttpReq();
1270 var result
= DoRequest(myRequest
,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&a=<?php p($a) ?>&sesskey=<?php echo sesskey() ?>"+datastring
);
1271 var results
= String(result
).split('\n');
1272 if ((results
.length
> 2) && (navrequest
!= '')) {
1275 errorCode
= results
[1];
1279 this
.Initialize
= Initialize
;
1280 this
.Terminate
= Terminate
;
1281 this
.GetValue
= GetValue
;
1282 this
.SetValue
= SetValue
;
1283 this
.Commit
= Commit
;
1284 this
.GetLastError
= GetLastError
;
1285 this
.GetErrorString
= GetErrorString
;
1286 this
.GetDiagnostic
= GetDiagnostic
;
1287 this
.version
= '1.0';
1290 var API_1484_11
= new SCORMapi1_3();
1293 // pull in the debugging utilities
1294 if (scorm_debugging($scorm)) {
1295 include_once($CFG->dirroot
.'/mod/scorm/datamodels/debug.js.php');
1296 echo 'AppendToLog("Moodle SCORM 1.3 API Loaded, Activity: '.$scorm->name
.', SCO: '.$sco->identifier
.'", 0);';