PageRenderTime 403ms CodeModel.GetById 52ms app.highlight 192ms RepoModel.GetById 49ms app.codeStats 4ms

/mod/scorm/datamodels/scorm_13.js.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 1297 lines | 1183 code | 54 blank | 60 comment | 438 complexity | 655ac3d3e8cc587d2e0bbab3c183c2ca MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1<?php
  2// This file is part of Moodle - http://moodle.org/
  3//
  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.
  8//
  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.
 13//
 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/>.
 16
 17require_once($CFG->dirroot.'/mod/scorm/locallib.php');
 18
 19if (isset($userdata->status)) {
 20    if (!isset($userdata->{'cmi.exit'}) || (($userdata->{'cmi.exit'} == 'time-out') || ($userdata->{'cmi.exit'} == 'normal'))) {
 21            $userdata->entry = 'ab-initio';
 22    } else {
 23        if (isset($userdata->{'cmi.exit'}) && (($userdata->{'cmi.exit'} == 'suspend') || ($userdata->{'cmi.exit'} == 'logout'))) {
 24            $userdata->entry = 'resume';
 25        } else {
 26            $userdata->entry = '';
 27        }
 28    }
 29}
 30if (!isset($currentorg)) {
 31    $currentorg = '';
 32}
 33?>
 34
 35// Used need to debug cmi content (if you uncomment this, you must comment the definition inside SCORMapi1_3)
 36//var cmi = new Object();
 37
 38//
 39// SCORM 1.3 API Implementation
 40//
 41function SCORMapi1_3() {
 42    // Standard Data Type Definition
 43
 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'};
 77
 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]}$'
108    // Children lists
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';
117    // Data ranges
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}
134    }
135
136    var correct_responses = {
137        'true-false':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
138                      'format':'^true$|^false$',
139                      'limit':1},
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)\})?))(.*?)$',
143        'fill-in':{'pre':'',
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,
157                  'limit':1},
158        'numeric':{'pre':'', 'max':2, 'delimiter':'[:]', 'unique':false, 'duplicate':false,
159                   'format':CMIDecimal,
160                   'limit':1},
161        'other':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false,
162                 'format':CMIString4000,
163                 'limit':1}
164    }
165
166    // The SCORM 1.3 data model
167    var datamodel =  {
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'}
235    };
236    //
237    // Datamodel inizialization
238    //
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();
250
251    // Navigation Object
252    var adl = new Object();
253        adl.nav = new Object();
254        adl.nav.request_valid = new Array();
255
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;');
260            } else {
261                eval(element+' = "";');
262            }
263        }
264    }
265
266<?php
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());
272?>
273
274    if (cmi.completion_status == '') {
275        cmi.completion_status = 'not attempted';
276    }
277
278    //
279    // API Methods definition
280    //
281    var Initialized = false;
282    var Terminated = false;
283    var diagnostic = "";
284    var errorCode = "0";
285
286    function Initialize (param) {
287        errorCode = "0";
288        if (param == "") {
289            if ((!Initialized) && (!Terminated)) {
290                Initialized = true;
291                errorCode = "0";
292                <?php
293                    if (scorm_debugging($scorm)) {
294                        echo 'LogAPICall("Initialize", param, "", errorCode);';
295                    }
296                ?>
297                return "true";
298            } else {
299                if (Initialized) {
300                    errorCode = "103";
301                } else {
302                    errorCode = "104";
303                }
304            }
305        } else {
306            errorCode = "201";
307        }
308        <?php
309            if (scorm_debugging($scorm)) {
310                echo 'LogAPICall("Initialize", param, "", errorCode);';
311            }
312        ?>
313        return "false";
314    }
315
316    function Terminate (param) {
317        errorCode = "0";
318        if (param == "") {
319            if ((Initialized) && (!Terminated)) {
320                var AJAXResult = StoreData(cmi,true);
321                <?php
322                    if (scorm_debugging($scorm)) {
323                        echo 'LogAPICall("Terminate", "AJAXResult", AJAXResult, 0);';
324                    }
325                ?>
326                result = ('true' == AJAXResult) ? 'true' : 'false';
327                errorCode = ('true' == result)? '0' : '101'; // General exception for any AJAX fault
328                <?php
329                    if (scorm_debugging($scorm)) {
330                        echo 'LogAPICall("Terminate", "result", result, errorCode);';
331                    }
332                ?>
333                if ('true' == result) {
334                    Initialized = false;
335                    Terminated = true;
336                    if (adl.nav.request != '_none_') {
337                        switch (adl.nav.request) {
338                            case 'continue':
339                                setTimeout('mod_scorm_launch_next_sco();',500);
340                            break;
341                            case 'previous':
342                                setTimeout('mod_scorm_launch_prev_sco();',500);
343                            break;
344                            case 'choice':
345                            break;
346                            case 'exit':
347                            break;
348                            case 'exitAll':
349                            break;
350                            case 'abandon':
351                            break;
352                            case 'abandonAll':
353                            break;
354                        }
355                    } else {
356                        if (<?php echo $scorm->auto ?> == 1) {
357                            setTimeout('mod_scorm_launch_next_sco();',500);
358                        }
359                    }
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 ?>&currentorg=<?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);
365                        Y.io(sURL);
366                    });
367                } else {
368                    diagnostic = "Failure calling the Terminate remote callback: the server replied with HTTP Status " + AJAXResult;
369                }
370                return result;
371            } else {
372                if (Terminated) {
373                    errorCode = "113";
374                } else {
375                    errorCode = "112";
376                }
377            }
378        } else {
379            errorCode = "201";
380        }
381        <?php
382            if (scorm_debugging($scorm)) {
383                echo 'LogAPICall("Terminate", param, "", errorCode);';
384            }
385        ?>
386        return "false";
387    }
388
389    function GetValue (element) {
390        errorCode = "0";
391        diagnostic = "";
392        if ((Initialized) && (!Terminated)) {
393            if (element !="") {
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') {
398
399                        element = String(element).replace(/\.(\d+)\./, ".N$1.");
400                        element = element.replace(/\.(\d+)\./, ".N$1.");
401
402                        var elementIndexes = element.split('.');
403                        var subelement = element.substr(0,3);
404                        var i = 1;
405                        while ((i < elementIndexes.length) && (typeof eval(subelement) != "undefined")) {
406                            subelement += '.'+elementIndexes[i++];
407                        }
408
409                        if (subelement == element) {
410
411                            if ((typeof eval(subelement) != "undefined") && (eval(subelement) != null)) {
412                                errorCode = "0";
413                                <?php
414                                    if (scorm_debugging($scorm)) {
415                                        echo 'LogAPICall("GetValue", element, eval(element), 0);';
416                                    }
417                                ?>
418                                return eval(element);
419                            } else {
420                                errorCode = "403";
421                            }
422                        } else {
423                            errorCode = "301";
424                        }
425                    } else {
426                        //errorCode = eval('datamodel["'+elementmodel+'"].readerror');
427                        errorCode = "405";
428                    }
429                } else {
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") {
436                            errorCode = "301";
437                            diagnostic = "Data Model Element Does Not Have Children";
438                        } else {
439                            errorCode = "401";
440                        }
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") {
444                            errorCode = "301";
445                            diagnostic = "Data Model Element Cannot Have Count";
446                        } else {
447                            errorCode = "401";
448                        }
449                    } else {
450                        parentmodel = 'adl.nav.request_valid.';
451                        if (element.substr(0,parentmodel.length) == parentmodel) {
452                            if (element.substr(parentmodel.length).match(NAVTarget) == null) {
453                                errorCode = "301";
454                            } else {
455                                if (adl.nav.request == element.substr(parentmodel.length)) {
456                                    return "true";
457                                } else if (adl.nav.request == '_none_') {
458                                    return "unknown";
459                                } else {
460                                    return "false";
461                                }
462                            }
463                        } else {
464                            errorCode = "401";
465                        }
466                    }
467                }
468            } else {
469                errorCode = "301";
470            }
471        } else {
472            if (Terminated) {
473                errorCode = "123";
474            } else {
475                errorCode = "122";
476            }
477        }
478        <?php
479            if (scorm_debugging($scorm)) {
480                echo 'LogAPICall("GetValue", element, "", errorCode);';
481            }
482        ?>
483        return "";
484    }
485
486    function SetValue (element,value) {
487        errorCode = "0";
488        diagnostic = "";
489        if ((Initialized) && (!Terminated)) {
490            if (element != "") {
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'));
497                        } else {
498                            // cmi.interactions.n.type depending format accept everything at this stage
499                            expression = new RegExp(CMIFeedback);
500                        }
501                        value = value+'';
502                        var matches = value.match(expression);
503                        if ((matches != null) && ((matches.join('').length > 0) || (value.length == 0))) {
504                            // Value match dataelement format
505
506                            if (element != elementmodel) {
507                                //This is a dynamic datamodel element
508
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
517                                            errorCode = "351";
518                                        }
519                                        parentelement = subelement+'.'+elementIndex;
520                                        if ((typeof eval(parentelement) == "undefined") || (typeof eval(parentelement+'._count') == "undefined")) {
521                                            errorCode="408";
522                                        } else {
523                                            if (elementIndexes[i+1] > eval(parentelement+'._count')) {
524                                                errorCode = "351";
525                                                diagnostic = "Data Model Element Collection Set Out Of Order";
526                                            }
527                                            subelement = subelement.concat('.'+elementIndex+'.N'+elementIndexes[i+1]);
528                                            i++;
529
530                                            if (((typeof eval(subelement)) == "undefined") && (i < elementIndexes.length-2)) {
531                                                errorCode="408";
532                                            }
533                                        }
534                                    } else {
535                                        subelement = subelement.concat('.'+elementIndex);
536                                    }
537                                }
538
539                                if (errorCode == "0") {
540                                    // Till now it's a real datamodel element
541
542                                    element = subelement.concat('.'+elementIndexes[elementIndexes.length-1]);
543
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;
561                                                    }
562                                                } else {
563                                                    errorCode="351";
564                                                    diagnostic = "Data Model Element ID Already Exists";
565                                                }
566                                            break;
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;
574                                                }
575                                            break;
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();');
582                                                        }
583                                                    } else {
584                                                        errorCode="351";
585                                                        diagnostic = "Data Model Element ID Already Exists";
586                                                    }
587                                                } else {
588                                                    errorCode="408";
589                                                }
590                                            break;
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) {
601                                                                   errorCode = "351";
602                                                               }
603                                                            }
604                                                        }
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);
610                                                            } else {
611                                                                nodes[0] = value;
612                                                            }
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) {
616                                                                errorCode = "351";
617                                                                diagnostic = "Data Model Element Pattern Too Long";
618                                                            }
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();');
623                                                            } else {
624                                                                if (errorCode == "0") {
625                                                                    errorCode="351";
626                                                                    diagnostic = "Data Model Element Pattern Already Exists";
627                                                                }
628                                                            }
629                                                        } else {
630                                                            errorCode="351";
631                                                            diagnostic = "Data Model Element Collection Limit Reached";
632                                                        }
633                                                    } else {
634                                                        errorCode="351";
635                                                        diagnostic = "Data Model Element Collection Set Out Of Order";
636                                                    }
637                                                } else {
638                                                    errorCode="408";
639                                                }
640                                            break;
641                                            default:
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();');
646                                                    } else {
647                                                        errorCode="351";
648                                                        diagnostic = "Data Model Element Collection Set Out Of Order";
649                                                    }
650                                                } else {
651                                                    errorCode="408";
652                                                }
653                                            break;
654                                        }
655                                    } else {
656                                        switch (elementmodel) {
657                                            case 'cmi.objectives.n.id':
658                                                if (eval(element) != value) {
659                                                    errorCode = "351";
660                                                    diagnostic = "Write Once Violation";
661                                                }
662                                            break;
663                                            case 'cmi.interactions.n.objectives.n.id':
664                                                if (duplicatedID(element,parentelement,value)) {
665                                                    errorCode = "351";
666                                                    diagnostic = "Data Model Element ID Already Exists";
667                                                }
668                                            break;
669                                            case 'cmi.interactions.n.type':
670                                                var subobject = eval(subelement);
671                                                subobject.correct_responses = new Object();
672                                                subobject.correct_responses._count = 0;
673                                            break;
674                                            case 'cmi.interactions.n.learner_response':
675                                                if (typeof eval(subelement+'.type') == "undefined") {
676                                                    errorCode="408";
677                                                } else {
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);
683                                                    } else {
684                                                        nodes[0] = value;
685                                                    }
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) {
694                                                                        errorCode = "406";
695                                                                    } else {
696                                                                        var expression2 = new RegExp(learner_response[interactiontype].format2);
697                                                                        matches = values[1].match(expression2);
698                                                                        if (matches == null) {
699                                                                            errorCode = "406";
700                                                                        }
701                                                                    }
702        

Large files files are truncated, but you can click here to view the full file