From: piers Date: Fri, 9 Jan 2009 00:56:32 +0000 (+0000) Subject: MDL-17821 - fix incorrect data validation regexs for 2004. thanks Peter Chamberlin. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=faa0e87572eaa4059d4b7023c711b50896899248;p=moodle.git MDL-17821 - fix incorrect data validation regexs for 2004. thanks Peter Chamberlin. --- diff --git a/mod/scorm/datamodels/scorm_13.js.php b/mod/scorm/datamodels/scorm_13.js.php index d075ea6726..8928b51d9c 100644 --- a/mod/scorm/datamodels/scorm_13.js.php +++ b/mod/scorm/datamodels/scorm_13.js.php @@ -1,8 +1,8 @@ dirroot.'/mod/scorm/locallib.php'); - + if (isset($userdata->status)) { - if (!isset($userdata->{'cmi.exit'}) || (($userdata->{'cmi.exit'} == 'time-out') || ($userdata->{'cmi.exit'} == 'normal'))) { + if (!isset($userdata->{'cmi.exit'}) || (($userdata->{'cmi.exit'} == 'time-out') || ($userdata->{'cmi.exit'} == 'normal'))) { $userdata->entry = 'ab-initio'; } else { if (isset($userdata->{'cmi.exit'}) && (($userdata->{'cmi.exit'} == 'suspend') || ($userdata->{'cmi.exit'} == 'logout'))) { @@ -15,18 +15,18 @@ ?> // Used need to debug cmi content (if you uncomment this, you must comment the definition inside SCORMapi1_3) -//var cmi = new Object(); +//var cmi = new Object(); // // SCORM 1.3 API Implementation // function SCORMapi1_3() { // Standard Data Type Definition - + // language key has to be checked for language dependent strings - 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', + 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', 'ba':'ba', 'be':'be', 'bg':'bg', 'bh':'bh', 'bi':'bi', 'bm':'bm', 'bn':'bn', 'bo':'bo', 'br':'br', 'bs':'bs', - 'ca':'ca', 'ce':'ce', 'ch':'ch', 'co':'co', 'cr':'cr', 'cs':'cs', 'cu':'cu', 'cv':'cv', 'cy':'cy', + 'ca':'ca', 'ce':'ce', 'ch':'ch', 'co':'co', 'cr':'cr', 'cs':'cs', 'cu':'cu', 'cv':'cv', 'cy':'cy', 'da':'da', 'de':'de', 'dv':'dv', 'dz':'dz', 'ee':'ee', 'el':'el', 'en':'en', 'eo':'eo', 'es':'es', 'et':'et', 'eu':'eu', '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', 'ha':'ha', 'he':'he', 'hi':'hi', 'ho':'ho', 'hr':'hr', 'ht':'ht', 'hu':'hu', 'hy':'hy', 'hz':'hz', @@ -57,11 +57,11 @@ function SCORMapi1_3() { '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', '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'}; - var CMIString200 = '^.{0,200}$'; - var CMIString250 = '^.{0,250}$'; - var CMIString1000 = '^.{0,1500}$'; - var CMIString4000 = '^.{0,4000}$'; - var CMIString64000 = '^.{0,64000}$'; + var CMIString200 = '^[\\u0000-\\uFFFF]{0,200}$$'; + var CMIString250 = '^[\\u0000-\\uFFFF]{0,250}$'; + var CMIString1000 = '^[\\u0000-\\uFFFF]{0,1000}$'; + var CMIString4000 = '^[\\u0000-\\uFFFF]{0,4000}$'; + var CMIString64000 = '^[\\u0000-\\uFFFF]{0,64000}$'; var CMILang = '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$'; var CMILangString250 = '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?'; var CMILangcr = '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\}))(.*?)$'; @@ -114,10 +114,10 @@ function SCORMapi1_3() { 'numeric':{'format':CMIDecimal, 'max':1, 'delimiter':'', 'unique':false}, 'other':{'format':CMIString4000, 'max':1, 'delimiter':'', 'unique':false} } - + var correct_responses = { 'true-false':{'pre':'', 'max':1, 'delimiter':'', 'unique':false, 'duplicate':false, - 'format':'^true$|^false$', + 'format':'^true$|^false$', 'limit':1}, 'choice':{'pre':'', 'max':36, 'delimiter':'[,]', 'unique':true, 'duplicate':false, 'format':CMIShortIdentifier}, @@ -255,8 +255,8 @@ function SCORMapi1_3() { if (cmi.completion_status == '') { cmi.completion_status = 'not attempted'; - } - + } + // // API Methods definition // @@ -270,7 +270,7 @@ function SCORMapi1_3() { if ((!Initialized) && (!Terminated)) { Initialized = true; errorCode = "0"; - return "false"; } - + function Terminate (param) { errorCode = "0"; if (param == "") { if ((Initialized) && (!Terminated)) { - auto ?> == 1) { setTimeout('top.nextSCO();',500); } - } + } return "true"; } else { if (Terminated) { @@ -344,14 +344,14 @@ function SCORMapi1_3() { } else { errorCode = "201"; } - return "false"; } - + function GetValue (element) { errorCode = "0"; diagnostic = ""; @@ -376,7 +376,7 @@ function SCORMapi1_3() { if ((typeof eval(subelement) != "undefined") && (eval(subelement) != null)) { errorCode = "0"; - "+eval(element));'; echo 'LogAPICall("GetValue", element, eval(element), 0);'; @@ -436,13 +436,13 @@ function SCORMapi1_3() { errorCode = "301"; } } else { - if (Terminated) { + if (Terminated) { errorCode = "123"; } else { errorCode = "122"; } } - "+GetErrorString(errorCode));'; echo 'LogAPICall("GetValue", element, "", errorCode);'; @@ -450,7 +450,7 @@ function SCORMapi1_3() { ?> return ""; } - + function SetValue (element,value) { errorCode = "0"; diagnostic = ""; @@ -511,7 +511,7 @@ function SCORMapi1_3() { if ((typeof eval(subelement)) == "undefined") { switch (elementmodel) { - case 'cmi.objectives.n.id': + case 'cmi.objectives.n.id': if (!duplicatedID(element,parentelement,value)) { if (elementIndexes[elementIndexes.length-2] == eval(parentelement+'._count')) { eval(parentelement+'._count++;'); @@ -539,7 +539,7 @@ function SCORMapi1_3() { var subobject = eval(subelement); subobject.objectives = new Object(); subobject.objectives._count = 0; - } + } break; case 'cmi.interactions.n.objectives.n.id': if (typeof eval(parentelement) != "undefined") { @@ -587,7 +587,7 @@ function SCORMapi1_3() { errorCode = "351"; diagnostic = "Data Model Element Pattern Too Long"; } - if ((errorCode == "0") && ((correct_responses[interactiontype].duplicate == false) || + if ((errorCode == "0") && ((correct_responses[interactiontype].duplicate == false) || (!duplicatedPA(element,parentelement,value))) || (errorCode == "0" && value == "")) { eval(parentelement+'._count++;'); eval(subelement+' = new Object();'); @@ -617,7 +617,7 @@ function SCORMapi1_3() { } else { errorCode="351"; diagnostic = "Data Model Element Collection Set Out Of Order"; - } + } } else { errorCode="408"; } @@ -630,7 +630,7 @@ function SCORMapi1_3() { errorCode = "351"; diagnostic = "Write Once Violation"; } - break; + break; case 'cmi.interactions.n.objectives.n.id': if (duplicatedID(element,parentelement,value)) { errorCode = "351"; @@ -718,7 +718,7 @@ function SCORMapi1_3() { } else { nodes[0] = value; } - + if ((nodes.length > 0) && (nodes.length <= correct_responses[interactiontype].max)) { errorCode = CRcheckValueNodes (element, interactiontype, nodes, value, errorCode); } else if (nodes.length > correct_responses[interactiontype].max) { @@ -727,7 +727,7 @@ function SCORMapi1_3() { } } break; - } + } } } } @@ -742,7 +742,7 @@ function SCORMapi1_3() { if ((ranges[1] == '*') || (value <= ranges[1])) { eval(element+'=value;'); errorCode = "0"; - OK");'; echo 'LogAPICall("SetValue", element, value, errorCode);'; @@ -757,8 +757,8 @@ function SCORMapi1_3() { } } else { eval(element+'=value;'); - errorCode = "0"; - OK");'; echo 'LogAPICall("SetValue", element, value, errorCode);'; @@ -786,7 +786,7 @@ function SCORMapi1_3() { errorCode = "132"; } } - return "false"; } - + function GetLastError () { - return errorCode; } - + function GetErrorString (param) { if (param != "") { var errorString = ""; @@ -1031,14 +1031,14 @@ function SCORMapi1_3() { errorString = "Data Model Dependency Not Established"; break; } - return errorString; } else { - return diagnostic; } - 0){ firsthours=parseInt(firstarray[9],10); } var secondhours=0; if(parseInt(secondarray[9],10)>0){ secondhours=parseInt(secondarray[9],10); } - var hours = firsthours+secondhours+change; //Hours + var hours = firsthours+secondhours+change; //Hours change = Math.floor(hours/24); hours = Math.round(hours-(change*24)); var firstdays=0; @@ -1250,7 +1250,7 @@ function SCORMapi1_3() { errorCode = results[1]; return results[0]; } - + this.Initialize = Initialize; this.Terminate = Terminate; this.GetValue = GetValue;