From 2a0407b7f6244b76c3648c0f1201840038207e72 Mon Sep 17 00:00:00 2001 From: bobopinna Date: Thu, 17 Feb 2005 08:52:54 +0000 Subject: [PATCH] First step for SCORM2004, new communication subsystem --- mod/scorm/api.php | 205 ++++++++++++ mod/scorm/api1_2.php | 393 ----------------------- mod/scorm/config.html | 14 + mod/scorm/{cmi.php => datamodel.php} | 36 +-- mod/scorm/details.php | 271 ---------------- mod/scorm/index.php | 2 +- mod/scorm/lib.php | 38 ++- mod/scorm/loadSCO.php | 145 +++++++++ mod/scorm/mod.html | 336 ++++++++++++++++---- mod/scorm/playscorm.php | 446 ++++++++++++++------------- mod/scorm/report.php | 2 +- mod/scorm/request.js | 30 ++ mod/scorm/scormAPI.php | 215 ------------- mod/scorm/validate.php | 71 +++++ mod/scorm/version.php | 2 +- mod/scorm/view.php | 290 +++++++++-------- 16 files changed, 1173 insertions(+), 1323 deletions(-) create mode 100644 mod/scorm/api.php delete mode 100644 mod/scorm/api1_2.php rename mod/scorm/{cmi.php => datamodel.php} (74%) delete mode 100755 mod/scorm/details.php create mode 100755 mod/scorm/loadSCO.php create mode 100644 mod/scorm/request.js delete mode 100755 mod/scorm/scormAPI.php create mode 100755 mod/scorm/validate.php diff --git a/mod/scorm/api.php b/mod/scorm/api.php new file mode 100644 index 00000000000..4d2d54b188e --- /dev/null +++ b/mod/scorm/api.php @@ -0,0 +1,205 @@ +course)) { + error("Course is misconfigured"); + } + + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + + } else { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } + + require_login($course->id, false, $cm); +?> + +function SCOFinish(){ + /*if (typeof API != "undefined") { + API.SaveTotalTime(); + } */ +} + +function closeMain() { + if (document.all) { + document.cookie = "SCORMpopup=" + escape(",top="+top.main.screenTop+",left="+top.main.screenLeft); + } else { + document.cookie = "SCORMpopup=" + escape(",top="+top.main.screenY+",left="+top.main.screenX); + } + top.main.close(); +} + +// +// SCORM API Implementation Call +// +var errorCode = "0"; + +function SCORM_Call (call,param,value) { + if (arguments.caller.length < 2) { + alert ("Invalid SCORM_Call function call: too few arguments.\nYou need pass at least 2 parameters"); + } else if (arguments.caller.length == 3) { + param = param.concat("&value=",value); + } + var myRequest = NewHttpReq(); + result = DoRequest(myRequest,"wwwroot) ?>/mod/scorm/datamodel.php?id=&sesskey=sesskey) ?>¶m="+param); + results = result.split('\n'); + + errorCode = results[1]; + return results[0]; +} + +// +// SCORM 1.2 API Implementation +// +function SCORMapi1_2() { + + function LMSInitialize (param) { + return SCORM_Call('LMSInitialize',param); + } + + function LMSFinish (param) { + return SCORM_Call('LMSGetValue',param); + } + + function LMSGetValue (element) { + return SCORM_Call('LMSGetValue',element); + } + + function LMSSetValue (element,value) { + return SCORM_Call('LMSGetValue',element,value); + } + + function LMSCommit (param) { + return SCORM_Call('LMSGetValue',param); + } + + function LMSGetLastError () { + return errorCode; + } + + function LMSGetErrorString (param) { + var errorString = new Array(); + errorString["0"] = "No error"; + errorString["101"] = "General exception"; + errorString["201"] = "Invalid argument error"; + errorString["202"] = "Element cannot have children"; + errorString["203"] = "Element not an array - cannot have count"; + errorString["301"] = "Not initialized"; + errorString["401"] = "Not implemented error"; + errorString["402"] = "Invalid set value, element is a keyword"; + errorString["403"] = "Element is read only"; + errorString["404"] = "Element is write only"; + errorString["405"] = "Incorrect data type"; + return errorString[param]; + } + + function LMSGetDiagnostic (param) { + return param; + } + + this.LMSInitialize = LMSInitialize; + this.LMSFinish = LMSFinish; + this.LMSGetValue = LMSGetValue; + this.LMSSetValue = LMSSetValue; + this.LMSCommit = LMSCommit; + this.LMSGetLastError = LMSGetLastError; + this.LMSGetErrorString = LMSGetErrorString; + this.LMSGetDiagnostic = LMSGetDiagnostic; +} + +var API = new SCORMapi1_2(); + +// +// SCORM 2004 API Implementation +// +function SCORMapi2004() { + + function Initialize (param) { + return SCORM_Call('Initialize',param); + } + + function Terminate (param) { + return SCORM_Call('Terminate',param); + } + + function GetValue (element) { + return SCORM_Call('GetValue',element); + } + + function SetValue (element, value) { + return SCORM_Call('SetValue',element,value); + } + + function Commit (param) { + return SCORM_Call('Commit',param); + } + + function GetLastError () { + return errorCode; + } + + function GetErrorString (param) { + var errorString = new Array(); + errorString["0"] = "No error"; + errorString["101"] = "General exception"; + errorString["102"] = "General Inizialization Failure"; + errorString["103"] = "Already Initialized"; + errorString["104"] = "Content Instance Terminated"; + errorString["111"] = "General Termination Failure"; + errorString["112"] = "Termination Before Inizialization"; + errorString["113"] = "Termination After Termination"; + errorString["122"] = "Retrieve Data Before Initialization"; + errorString["123"] = "Retrieve Data After Termination"; + errorString["132"] = "Store Data Before Inizialization"; + errorString["133"] = "Store Data After Termination"; + errorString["142"] = "Commit Before Inizialization"; + errorString["143"] = "Commit After Termination"; + errorString["201"] = "General Argument Error"; + errorString["301"] = "General Get Failure"; + errorString["351"] = "General Set Failure"; + errorString["391"] = "General Commit Failure"; + errorString["401"] = "Undefinited Data Model"; + errorString["402"] = "Unimplemented Data Model Element"; + errorString["403"] = "Data Model Element Value Not Initialized"; + errorString["404"] = "Data Model Element Is Read Only; + errorString["405"] = "Data Model Element Is Write Only"; + errorString["406"] = "Data Model Element Type Mismatch"; + errorString["407"] = "Data Model Element Value Out Of Range"; + errorString["408"] = "Data Model Dependency Not Established"; + return errorString[param]; + } + + function GetDiagnostic (param) { + return SCORM_Call('GetDiagnostic',param); + } + + this.Initialize = Initialize; + this.Terminate = Terminate; + this.GetValue = GetValue; + this.SetValue = SetValue; + this.Commit = Commit; + this.GetLastError = GetLastError; + this.GetErrorString = GetErrorString; + this.GetDiagnostic = GetDiagnostic; +} + +var API_1484_11 = new SCORMapi2004(); \ No newline at end of file diff --git a/mod/scorm/api1_2.php b/mod/scorm/api1_2.php deleted file mode 100644 index 0c8c170e10a..00000000000 --- a/mod/scorm/api1_2.php +++ /dev/null @@ -1,393 +0,0 @@ -// -// SCORM API 1.2 Implementation -// - -function SCORMapi() { - var cmi= new Object(); - var nav = new Object(); - - var errorCode = "0"; - - var Initialized = false; - - function LMSInitialize (param) { - if (param != "") { - errorCode = "201"; - return "false"; - } - if (!Initialized) { - Initialized = true; - errorCode = "0"; - - // - // CMI Initialization SCORM 1.2 - // - cmi.core = new Object(); - cmi.core._children = "student_id,student_name,lesson_location,credit,lesson_status,exit,entry,session_time,total_time,lesson_mode,score,suspend_data,launch_data"; - cmi.core.student_id = "username; ?>"; - cmi.core.student_name = "lastname.", ".$USER->firstname; ?>"; - cmi.core.lesson_location = "cmi_core_lesson_location; ?>"; - cmi.core.credit = ""; - cmi.core.lesson_status = "cmi_core_lesson_status; ?>"; - cmi.core.exit = "cmi_core_exit ?>"; - cmi.core.entry = "cmi_core_lesson_status == 'not attempted') { - echo 'ab-initio'; - } else { - if ($sco_user->cmi_core_lesson_status != 'completed') { - echo 'resume'; - } else { - echo ''; - } - }?>"; - cmi.core.session_time = "00:00:00"; - cmi.core.total_time = "cmi_core_total_time; ?>"; - cmi.core.lesson_mode = ""; - cmi.core.score = new Object(); - cmi.core.score._children = "raw,min,max"; - cmi.core.score.raw = "cmi_core_score_raw; ?>"; - cmi.core.score.min = ""; - cmi.core.score.max = ""; - cmi.suspend_data = "cmi_suspend_data; ?>"; - cmi.launch_data = "datafromlms; ?>"; - cmi.comments = ""; - cmi.comments_from_lms = ""; - // - // end CMI Initialization - // - - // Navigation Object - auto) { - echo 'nav.event = "continue";'."\n"; - } else { - echo 'nav.event = "";'."\n"; - } - ?> - - return "true"; - } else { - errorCode = "101"; - return "false"; - } - } - - function LMSGetValue (param) { - if (Initialized) { - //top.alert("GET "+param); - switch (param) { - case "cmi.core._children": - case "cmi.core.student_id": - case "cmi.core.student_name": - case "cmi.core.lesson_location": - case "cmi.core.credit": - case "cmi.core.lesson_status": - case "cmi.core.entry": - case "cmi.core.total_time": - case "cmi.core.lesson_mode": - case "cmi.core.score._children": - case "cmi.core.score.raw": - case "cmi.core.score.min": - case "cmi.core.score.max": - case "cmi.launch_data": - case "cmi.suspend_data": - case "cmi.comments": - case "cmi.comments_from_lms": - errorCode = "0"; - return eval(param); - break; - case "cmi.core.exit": - case "cmi.core.session_time": - errorCode = "404"; - return ""; - break; - default: - errorCode = "401"; - param = param.replace(/.(\d+)./g,"[$1]."); - - children = param.match(/._children$/); - if (children != null) { - objType = typeof eval(children[1]); - //alert (param+" :"+objType); - if (objType != "undefined") { - - errorCode = "202"; - } - } - - counted = param.match(/._count$/); - if (counted != null) { - objType = typeof eval(counted[1]); - //alert (param+" :"+objType); - if (objType != "undefined") { - errorCode = "203"; - } - } - //alert(param+": "+errorCode); - return ""; - break; - } - } else { - errorCode = "301"; - return ""; - } - } - - function LMSSetValue (param,value) { - if (Initialized) { - //top.alert("SET "+param+" = "+value); - switch (param) { - case "cmi.core.session_time": - if (typeof(value) == "string") { - var parsedtime = value.match(/^([0-9]{2,4}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$/); - if (parsedtime != null) { - //top.alert(parsedtime); - if (((parsedtime.length == 4) || (parsedtime.length == 5)) && (parsedtime[3]>=0) && (parsedtime[3]<=59)) { - eval(param+'="'+value+'";'); - errorCode = "0"; - return "true"; - } else { - errorCode = "405"; - return "false"; - } - } else { - errorCode = "405"; - return "false"; - } - } else { - errorCode = "405"; - return "false"; - } - break; - case "cmi.core.lesson_status": - if ((value!="passed")&&(value!="completed")&&(value!="failed")&&(value!="incomplete")&&(value!="browsed")) { - errorCode = "405"; - return "false"; - } - eval(param+'="'+value+'";'); - errorCode = "0"; - return "true"; - break; - case "cmi.core.score.raw": - case "cmi.core.score.min": - case "cmi.core.score.max": - if (value != "") { - if ((parseFloat(value,10)).toString() != value) { - errorCode = "405"; - return "false"; - } else { - rawvalue = parseFloat(value,10); - if ((rawvalue<0) || (rawvalue>100)) { - errorCode = "405"; - return "false"; - } - } - } - eval(param+'="'+value+'";'); - errorCode = "0"; - return "true"; - break; - case "cmi.core.exit": - if ((value!="time-out")&&(value!="suspend")&&(value!="logout")&&(value!="")) { - errorCode = "405"; - return "false"; - } - eval(param+'="'+value+'";'); - errorCode = "0"; - return "true"; - break; - case "cmi.core.lesson_location": - if (value.length > 255) { - errorCode = "405"; - return "false"; - } - eval(param+'="'+value+'";'); - errorCode = "0"; - return "true"; - break; - case "cmi.comments": - if ((value.length + cmi.comments.length) > 4096) { - errorCode = "405"; - return "false"; - } - eval(param+'=cmi.comments + "'+value+'";'); - errorCode = "0"; - return "true"; - break; - case "cmi.suspend_data": - if (value.length > 4096) { - errorCode = "405"; - return "false"; - } - eval(param+'="'+value+'";'); - errorCode = "0"; - return "true"; - break; - case "cmi.core._children": - case "cmi.core.score._children": - errorCode = "402"; - return "false"; - break; - case "cmi.core.student_id": - case "cmi.core.student_name": - case "cmi.core.credit": - case "cmi.core.entry": - case "cmi.core.total_time": - case "cmi.core.lesson_mode": - case "cmi.launch_data": - case "cmi.comments_from_lms": - errorCode = "403"; - return "false"; - break; - case "nav.event": - if ((value == "previous") || (value == "continue")) { - eval(param+'="'+value+'";'); - errorCode = "0"; - return "true"; - } else { - erroCode = "405"; - return "false"; - } - break; - default: - errorCode = "401"; //This is more correct but may have problem with some SCOes - //errorCode = "0"; // With this disable any possible SCO errors alert - return "false"; - break; - } - } else { - errorCode = "301"; - return "false"; - } - } - - function LMSCommit (param) { - if (param != "") { - errorCode = "201"; - return "false"; - } - if (Initialized) { - if (cmi.document.theform) { - cmiform = cmi.document.forms[0]; - cmiform.scoid.value = "id; ?>"; - cmiform.cmi_core_lesson_location.value = cmi.core.lesson_location; - cmiform.cmi_core_lesson_status.value = cmi.core.lesson_status; - cmiform.cmi_core_exit.value = cmi.core.exit; - cmiform.cmi_core_score_raw.value = cmi.core.score.raw; - cmiform.cmi_suspend_data.value = cmi.suspend_data; - cmiform.submit(); - } - errorCode = "0"; - return "true"; - } else { - errorCode = "301"; - return "false"; - } - } - - function LMSFinish (param) { - if (param != "") { - errorCode = "201"; - return "false"; - } - if (!Initialized) { - errorCode = "301"; - return "false"; - } else { - Initialized = false; - errorCode = "0"; - - if (nav.event != "") { - - if (nav.event == 'previous') { - setTimeout('top.changeSco("previous");',500); - } else { - setTimeout('top.changeSco("continue");',500); - } -wwwroot."/mod/scorm/view.php?id=".$cm->id."';\n"; - echo "setTimeout('top.location = exitloc;',500);\n"; - } - ?> - } - return "true"; - } - } - - function LMSGetLastError () { - return errorCode; - } - - function LMSGetErrorString (param) { - var errorString = new Array(); - errorString["0"] = "No error"; - errorString["101"] = "General exception"; - errorString["201"] = "Invalid argument error"; - errorString["202"] = "Element cannot have children"; - errorString["203"] = "Element not an array - cannot have count"; - errorString["301"] = "Not initialized"; - errorString["401"] = "Not implemented error"; - errorString["402"] = "Invalid set value, element is a keyword"; - errorString["403"] = "Element is read only"; - errorString["404"] = "Element is write only"; - errorString["405"] = "Incorrect data type"; - return errorString[param]; - } - - function LMSGetDiagnostic (param) { - return param; - } - - function AddTime (first, second) { - var sFirst = first.split(":"); - var sSecond = second.split(":"); - var change = 0; - - var secs = (Math.round((parseFloat(sFirst[2],10)+parseFloat(sSecond[2],10))*100))/100; //Seconds - change = Math.floor(secs / 60); - secs = secs - (change * 60); - if (Math.floor(secs) < 10) secs = "0" + secs.toString(); - - mins = parseInt(sFirst[1],10)+parseInt(sSecond[1],10)+change; //Minutes - change = Math.floor(mins / 60); - mins = mins - (change * 60); - if (mins < 10) mins = "0" + mins.toString(); - - hours = parseInt(sFirst[0],10)+parseInt(sSecond[0],10)+change; //Hours - if (hours < 10) hours = "0" + hours.toString(); - - return hours + ":" + mins + ":" + secs; - } - - function SaveTotalTime() { - cmi.core.total_time = AddTime(cmi.core.total_time, cmi.core.session_time); - //top.alert(cmi.core.total_time); - if (cmi.document.forms[0]) { - cmiform = cmi.document.forms[0]; - cmiform.reset(); - cmiform.scoid.value = "id; ?>"; - cmiform.cmi_core_total_time.value = cmi.core.total_time; - cmiform.submit(); - //top.alert(cmi.core.total_time); - } - } - - this.SaveTotalTime = SaveTotalTime; - - this.LMSInitialize = LMSInitialize; - this.LMSGetValue = LMSGetValue; - this.LMSSetValue = LMSSetValue; - this.LMSCommit = LMSCommit; - this.LMSFinish = LMSFinish; - this.LMSGetLastError = LMSGetLastError; - this.LMSGetErrorString = LMSGetErrorString; - this.LMSGetDiagnostic = LMSGetDiagnostic; -} - -var API = new SCORMapi(); diff --git a/mod/scorm/config.html b/mod/scorm/config.html index 817f296177c..8ba36bcff64 100755 --- a/mod/scorm/config.html +++ b/mod/scorm/config.html @@ -61,6 +61,20 @@ echo ""; } ?> + +

scorm_windowsettings: + + scorm_windowsettings, ""); + ?> + + + + + " /> diff --git a/mod/scorm/cmi.php b/mod/scorm/datamodel.php similarity index 74% rename from mod/scorm/cmi.php rename to mod/scorm/datamodel.php index 2840d6f9735..1cfed79507a 100755 --- a/mod/scorm/cmi.php +++ b/mod/scorm/datamodel.php @@ -1,7 +1,7 @@ course)) { error('Course is misconfigured'); } - + if (! $scorm = get_record('scorm', 'id', $cm->instance)) { error('Course module is incorrect'); } @@ -34,22 +34,22 @@ if (!empty($_POST['scoid'])) { //echo 'scoid: '.$_POST['scoid']."\n"; if (!empty($_POST['cmi_core_lesson_location'])) { - set_field('scorm_sco_users','cmi_core_lesson_location',$_POST['cmi_core_lesson_location'],'scoid',$_POST['scoid'],'userid',$USER->id); - //echo 'cmi_core_lesson_location: '.$_POST['cmi_core_lesson_location']."\n"; - } - if (!empty($_POST['cmi_core_lesson_status'])) { + set_field('scorm_sco_users','cmi_core_lesson_location',$_POST['cmi_core_lesson_location'],'scoid',$_POST['scoid'],'userid',$USER->id); + //echo 'cmi_core_lesson_location: '.$_POST['cmi_core_lesson_location']."\n"; + } + if (!empty($_POST['cmi_core_lesson_status'])) { set_field('scorm_sco_users','cmi_core_lesson_status',$_POST['cmi_core_lesson_status'],'scoid',$_POST['scoid'],'userid',$USER->id); //echo 'cmi_core_lesson_status: '.$_POST['cmi_core_lesson_status']."\n"; } - if (!empty($_POST['cmi_core_exit'])) { + if (!empty($_POST['cmi_core_exit'])) { set_field('scorm_sco_users','cmi_core_exit',$_POST['cmi_core_exit'],'scoid',$_POST['scoid'],'userid',$USER->id); //echo 'cmi_core_exit: '.$_POST['cmi_core_exit']."\n"; } - if (!empty($_POST['cmi_core_score_raw'])) { + if (!empty($_POST['cmi_core_score_raw'])) { set_field('scorm_sco_users','cmi_core_score_raw',$_POST['cmi_core_score_raw'],'scoid',$_POST['scoid'],'userid',$USER->id); //echo 'cmi_core_score_raw: '.$_POST['cmi_core_score_raw']."\n"; } - if (!empty($_POST['cmi_suspend_data'])) { + if (!empty($_POST['cmi_suspend_data'])) { set_field('scorm_sco_users','cmi_suspend_data',$_POST['cmi_suspend_data'],'scoid',$_POST['scoid'],'userid',$USER->id); //echo 'cmi_suspend_data: '.$_POST['cmi_suspend_data']."\n"; } @@ -64,14 +64,14 @@ cmi -

- - - - - - - + + + + + + + +
diff --git a/mod/scorm/details.php b/mod/scorm/details.php deleted file mode 100755 index db3c66482b7..00000000000 --- a/mod/scorm/details.php +++ /dev/null @@ -1,271 +0,0 @@ -course)) { - error("This course doesn't exist"); - } - - require_login($course->id); - - if (!isteacher($course->id)) { - error("You can't modify this course!"); - } - - $strediting = get_string("validateascorm", "scorm"); - $strname = get_string("name"); - - print_header_simple("$strediting", "$strediting", - "$strediting"); - - if (!$form->name or !$form->reference or !$form->summary) { - error(get_string("filloutallfields"), $_SERVER["HTTP_REFERER"]); - } - - // - // Create a temporary directory to unzip package and validate imsmanifest - // - - $coursedir = "$CFG->dataroot/$course->id"; - $form->reference = clean_param($form->reference, PARAM_PATH); - - if ($scormdir = make_upload_directory("$course->id/$CFG->moddata/scorm")) { - if ($tempdir = scorm_datadir($scormdir, $form->datadir)) { - copy ("$coursedir/$form->reference", $tempdir."/".basename($form->reference)); - unzip_file($tempdir."/".basename($form->reference), $tempdir, false); - $result = scorm_validate($tempdir."/imsmanifest.xml"); - } else { - $result = "packagedir"; - } - } else { - $result = "datadir"; - } - $errorlogs = ''; - if (($result != "regular") && ($result != "found")) { - if ($CFG->scorm_validate == 'domxml') { - foreach ($errors as $error) { - $errorlogs .= get_string($error->type,"scorm",$error->data) . ".\n"; - } - } - // - // Delete files and temporary directory - // - if (is_dir($tempdir)) - scorm_delete_files($tempdir); - } else { - // - // Delete package file - // - unlink ($tempdir."/".basename($form->reference)); - if ($form->mode == "update") { - $fp = fopen($coursedir."/".$form->reference,"r"); - $fstat = fstat($fp); - fclose($fp); - if (get_field("scorm","timemodified","id",$form->instance) < $fstat["mtime"]) { - $form->launch = 0; - } - } - } - // - // Print validation result - // - print_simple_box_start('center'); - echo "\n"; - echo " \n"; - echo " \n"; - if ($errorlogs != '') { - $lines = round(count($errors)/4); - if ($lines < 5) { - $lines = 5; - } - echo " \n"; - } - if (($form->mode == "update") && ($form->launch == 0) && (get_records("scorm_sco_users","scormid",$form->instance))) { - echo " \n"; - } - echo "
$strname:$form->name
".get_string("validation","scorm").":".get_string($result,"scorm")."
".get_string("errorlogs","scorm").":
".get_string("trackingloose","scorm")."
\n"; - if (($result == "regular") || ($result == "found")) { - if (empty($form->auto)) { - $form->auto = ""; - } - if (empty($form->maxgrade)) { - $form->maxgrade = ""; - } - if (empty($form->grademethod)) { - $form->grademethod = "0"; - } - echo "
destination\">\n"; - - //$form->popup = $CFG->scorm_popup; - $strnewwindow = get_string("newwindow", "scorm"); - $strnewwindowopen = get_string("newwindowopen", "scorm"); - foreach ($SCORM_WINDOW_OPTIONS as $optionname) { - $stringname = "str$optionname"; - $$stringname = get_string("new$optionname", "scorm"); - $window->$optionname = ""; - $jsoption[] = "\"$optionname\""; - } - $alljsoptions = implode(",", $jsoption); - - if ($form->instance) { // Re-editing - if ($form->popup == "") { - $newwindow = ""; // Disable the new window - foreach ($SCORM_WINDOW_OPTIONS as $optionname) { - $defaultvalue = "scorm_popup$optionname"; - $window->$optionname = $CFG->$defaultvalue; - } - } else { - $newwindow = "checked"; - $rawoptions = explode(',', $form->popup); - foreach ($rawoptions as $rawoption) { - $option = explode('=', trim($rawoption)); - if (($option[0] != 'location') && ($option[0] != 'menubar') && ($option[0] != 'toolbar')) { - $optionname = $option[0]; - $optionvalue = $option[1]; - if ($optionname == "height" or $optionname == "width") { - $window->$optionname = $optionvalue; - } else if ($optionvalue == 1) { - $window->$optionname = "checked"; - } - } - } - } - } else { - foreach ($SCORM_WINDOW_OPTIONS as $optionname) { - $defaultvalue = "scorm_popup$optionname"; - $window->$optionname = $CFG->$defaultvalue; - } - $newwindow = $CFG->scorm_popup; - } -?> - - - - - - - - - - - - - - - - - -
: - grademethod", ""); - helpbutton("grademethod", get_string("grademethod","scorm"), "scorm"); - ?> -
: - =1; $i--) { - $grades[$i] = $i; - } - - choose_from_menu($grades, "maxgrade", "$form->maxgrade", ""); - helpbutton("maxgrade", get_string("maximumgrade"), "scorm"); - ?> -
: - auto); - ?> -
- : - - - - /> - -
  • - $value) { - if ($name == "height" or $name == "width") { - continue; - } - echo "\t\t\n"; - if ($window->$name == 'checked') { - $window->$name = 'checked="checked"'; - } - echo "\t\t$name." /> "; - $stringname = "str$name"; - echo $$stringname."
    \n"; - } - ?> - - -
    - -
    - \n\n"; - } - ?> -
-
- - - - - - - - - - - - - -
- " /> - " /> -
-
- -
- " onclick="document.location='wwwroot ?>/course/view.php?id=id ?>';" /> -
- diff --git a/mod/scorm/index.php b/mod/scorm/index.php index 194e6f7d1bc..13607c1ef48 100755 --- a/mod/scorm/index.php +++ b/mod/scorm/index.php @@ -8,7 +8,7 @@ error("Course ID is incorrect"); } - require_course_login($course); + require_course_login($course->id, false, $cm); add_to_log($course->id, "scorm", "view all", "index.php?id=$course->id", ""); diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 813efcfa26b..a6888eababb 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -56,10 +56,10 @@ function scorm_add_instance($scorm) { $scorm->timemodified = time(); # May have to add extra stuff in here # - global $SCORM_WINDOW_OPTIONS; + global $CFG,$SCORM_WINDOW_OPTIONS; $scorm->popup = ''; - + $optionlist = array(); foreach ($SCORM_WINDOW_OPTIONS as $option) { if (isset($scorm->$option)) { @@ -73,8 +73,19 @@ function scorm_add_instance($scorm) { $scorm->popup .= ',location=0,menubar=0,toolbar=0'; $scorm->auto = '0'; } + $id = insert_record('scorm', $scorm); - return insert_record('scorm', $scorm); + // + // Parse scorm manifest + // + if ($scorm->launch == 0) { + $basedir = $CFG->dataroot."/".$scorm->course; + $scormdir = "/moddata/scorm"; + $scorm->launch = scorm_parse($basedir,$scormdir.$scorm->datadir."/imsmanifest.xml",$id); + set_field("scorm","launch",$scorm->launch,"id",$id); + } + + return $id; } @@ -87,7 +98,7 @@ function scorm_update_instance($scorm) { $scorm->id = $scorm->instance; # May have to add extra stuff in here # - global $SCORM_WINDOW_OPTIONS; + global $CFG,$SCORM_WINDOW_OPTIONS; $scorm->popup = ''; @@ -103,7 +114,20 @@ function scorm_update_instance($scorm) { $scorm->popup .= ',location=0,menubar=0,toolbar=0'; $scorm->auto = '0'; } - return update_record('scorm', $scorm); + + $id = update_record('scorm', $scorm); + + // + // Check if scorm manifest needs to be reparsed + // + if ($scorm->launch == 0) { + $basedir = $CFG->dataroot."/".$scorm->course; + $scormdir = "/moddata/scorm"; + $scorm->launch = scorm_parse($basedir,$scormdir.$scorm->datadir."/imsmanifest.xml",$id); + set_field("scorm","launch",$scorm->launch,"id",$id); + } + + return $id; } @@ -112,7 +136,7 @@ function scorm_delete_instance($id) { /// this function will permanently delete the instance /// and any data that depends on it. - global $CFG; + require('../config.php'); if (! $scorm = get_record('scorm', 'id', $id)) { return false; @@ -145,8 +169,6 @@ function scorm_user_outline($course, $user, $mod, $scorm) { /// $return->time = the time they did it /// $return->info = a short text description - $return = NULL; - return $return; } diff --git a/mod/scorm/loadSCO.php b/mod/scorm/loadSCO.php new file mode 100755 index 00000000000..29452e2d3d2 --- /dev/null +++ b/mod/scorm/loadSCO.php @@ -0,0 +1,145 @@ +course)) { + error("Course is misconfigured"); + } + + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + + } else { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } + + require_login($course->id, false, $cm); + + if ( $scoes_user = get_records_select("scorm_sco_users","userid = ".$USER->id." AND scormid = ".$scorm->id,"scoid ASC") ) { + // + // Already user + // + if (!empty($scoid)) { + // + // Direct sco request + // + if ($sco = get_record("scorm_scoes","id",$scoid)) { + if ($sco->launch == '') { + // Search for th first launchable sco + if ($scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC")) { + $sco = current($scoes); + while ($sco->id < $scoid) { + $sco = next($scoes); + } + while ($sco->launch == '') { + $sco = next($scoes); + } + } + } + } + } else { + // + // Search for first incomplete sco + // + foreach ( $scoes_user as $sco_user ) { + if (($sco_user->cmi_core_lesson_status != "completed") && ($sco_user->cmi_core_lesson_status != "passed") && ($sco_user->cmi_core_lesson_status != "failed")) { + $sco = get_record("scorm_scoes","id",$sco_user->scoid); + break; + } else { + // If review mode get the first + if ($mode == "review") { + $sco = get_record("scorm_scoes","id",$sco_user->scoid); + break; + } + } + } + } + // + // If no sco was found get the first of SCORM package + // + if (!isset($sco)) { + $scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' order by id ASC"); + $sco = each($scoes); + } + } else { + // + // A new user + // + if ($scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC")) { + // + // Create user scoes records + // + foreach ($scoes as $sco) { + if (($sco->launch != "") && ($sco->type != "sca") && ($sco->type != "asset")){ + if (!isset($first)) { + $first = $sco; + } + $sco_user->userid = $USER->id; + $sco_user->scoid = $sco->id; + $sco_user->scormid = $scorm->id; + $element = "cmi_core_lesson_status"; + $sco_user->$element = "not attempted"; + $ident = insert_record("scorm_sco_users",$sco_user); + } + } + if (isset($first)) { + $sco = $first; + } + if (!empty($scoid)) { + if ($sco = get_record("scorm_scoes","id",$scoid)) { + unset($first); + } + } + } + } + // + // Forge SCO URL + // + if (scorm_external_link($sco->launch)) { + $result = $sco->launch; + } else { + if ($CFG->slasharguments) { + $result = "$CFG->wwwroot/file.php/$scorm->course/moddata/scorm$scorm->datadir/$sco->launch"; + } else { + $result = "$CFG->wwwroot/file.php?file=/$scorm->course/moddata/scorm$scorm->datadir/$sco->launch"; + } + } +?> + + + LoadSCO + + + + + \ No newline at end of file diff --git a/mod/scorm/mod.html b/mod/scorm/mod.html index a09c62a0060..23f9b1e5d74 100755 --- a/mod/scorm/mod.html +++ b/mod/scorm/mod.html @@ -1,77 +1,301 @@ dirroot/mod/scorm/lib.php"); if (empty($form->name)) { - $form->name = ""; + $form->name = ""; } if (empty($form->reference)) { - $form->reference = ""; + $form->reference = ""; } if (empty($form->summary)) { - $form->summary = ""; + $form->summary = ""; } if (empty($form->launch)) { - $form->launch = ""; + $form->launch = ""; + } + if (empty($form->auto)) { + $form->auto = ""; + } + if (empty($form->datadir)) { + $form->datadir = ""; + } + if (empty($form->popup)) { + $form->popup = ""; + } + if (empty($form->maxgrade)) { + $form->maxgrade = ""; + } + if (empty($form->grademethod)) { + $form->grademethod = "0"; + } + $scormid =''; + if (!empty($form->instance)) { + $scormid = '&instance='.$form->instance; + } + $datadir =''; + if (!empty($form->datadir)) { + $datadir = '&datadir='.$form->datadir; } ?> + + -
+ - - - - + + + + - - - - - - - - - + + + + + + + + +$optionname = ""; + $jsoption[] = "\"$optionname\""; + } + $alljsoptions = implode(",", $jsoption); + + if ($form->instance) { // Re-editing + if ($form->popup == "") { + $newwindow = ""; // Disable the new window + foreach ($SCORM_WINDOW_OPTIONS as $optionname) { + $defaultvalue = "scorm_popup$optionname"; + $window->$optionname = $CFG->$defaultvalue; + } + } else { + $newwindow = "checked"; + $rawoptions = explode(',', $form->popup); + foreach ($rawoptions as $rawoption) { + $option = explode('=', trim($rawoption)); + if (($option[0] != 'location') && ($option[0] != 'menubar') && ($option[0] != 'toolbar')) { + $optionname = $option[0]; + $optionvalue = $option[1]; + if ($optionname == "height" or $optionname == "width") { + $window->$optionname = $optionvalue; + } else if ($optionvalue == 1) { + $window->$optionname = "checked"; + } + } + } + } + } else { + foreach ($SCORM_WINDOW_OPTIONS as $optionname) { + $defaultvalue = "scorm_popup$optionname"; + $window->$optionname = $CFG->$defaultvalue; + } + $newwindow = $CFG->scorm_popup; + } +?> + + + + + + + + + + + +
: - " /> -
: + " /> +
- : - - reference\" alt=\"$strfilename\" /> "; - button_to_popup_window ("/files/index.php?id=$course->id&choose=form.reference", - "coursefiles", $strchooseafile, 500, 750, $strchooseafile); - ?> -
:
- - "; - helpbutton("writing", get_string("helpwriting"), "moodle", true, true); - echo "
"; - helpbutton("text", get_string("helptext"), "moodle", true, true); - ?> -
-
- summary); ?> -
:
+ + + +
+ summary); ?> +
+ : + + reference\" alt=\"$strfilename\" /> "; + button_to_popup_window ("/files/index.php?id=$course->id&choose=form.reference", + "coursefiles", $strchooseafile, 500, 750, $strchooseafile); + helpbutton("package", get_string("coursepacket", "scorm"), "scorm", true); + ?> +
: + grademethod", ""); + helpbutton("grademethod", get_string("grademethod","scorm"), "scorm"); + ?> +
: + =1; $i--) { + $grades[$i] = $i; + } + + choose_from_menu($grades, "maxgrade", "$form->maxgrade", ""); + helpbutton("maxgrade", get_string("maximumgrade"), "scorm"); + ?> +
: + + + +
- - - - - - - - - - - - - - - + + +
+ + + + + +
+ : + + + /> + +
  • + $value) { + if ($name == "height" or $name == "width") { + continue; + } + echo "\t\t\n"; + if ($window->$name == 'checked') { + $window->$name = 'checked="checked"'; + } + echo "\t\t$name." /> "; + $stringname = "str$name"; + echo $$stringname."
    \n"; + } + ?> + + +
    + +
    + \n\n"; + } + ?> +
+
+
+ + + + + +
: + auto); + helpbutton("autocontinue", get_string("autocontinue", "scorm"), "scorm", true); + ?> +
+
+
+ + + + + + + + + + + + + + + +
- " /> + " /> + " />
diff --git a/mod/scorm/playscorm.php b/mod/scorm/playscorm.php index c46d7c9e670..d96f98afda7 100755 --- a/mod/scorm/playscorm.php +++ b/mod/scorm/playscorm.php @@ -1,4 +1,4 @@ -course)) { error("Course is misconfigured"); } - + if (! $scorm = get_record("scorm", "id", $cm->instance)) { error("Course module is incorrect"); } @@ -37,10 +37,10 @@ require_login($course->id, false, $cm); - + $strscorms = get_string("modulenameplural", "scorm"); $strscorm = get_string("modulename", "scorm"); - + if ($course->category) { $navigation = "framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname -> framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; @@ -51,228 +51,254 @@ $pagetitle = strip_tags("$course->shortname: $scorm->name"); if (!$cm->visible and !isteacher($course->id)) { - print_header($pagetitle, "$course->fullname", "$navigation $scorm->name", "", "", true, + print_header($pagetitle, "$course->fullname", "$navigation $scorm->name", "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm)); notice(get_string("activityiscurrentlyhidden")); } - - if (!empty($_POST["scoid"])) - $scoid = "&scoid=".$_POST["scoid"]; - if (!empty($_POST['currentorg'])) { - $currentorg = $_POST['currentorg']; - } - if (($scorm->popup != "") && (!empty($_POST["mode"]))) - $mode = $_POST["mode"]; - if (($scorm->popup == "") && (!empty($_GET["mode"]))) - $mode = $_GET["mode"]; - - if (($frameset == "top") || ($scorm->popup != "")) { - add_to_log($course->id, "scorm", "view", "playscorm.php?id=$cm->id", "$scorm->id"); + // - // Print the page header + // Checkin script parameters // - $bodyscripts = ""; - if ($scorm->popup != "") { - $bodyscripts = "onload='SCOInitialize();' onunload='SCOFinish(); closeMain();'"; + $mode = ''; + $scoid=''; + $currentorg=''; + $modestring = ''; + $scoidstring = ''; + $currentorgstring = ''; + if (($scorm->popup == "") && ($frameset == "top")) { + if (!empty($_GET["mode"])) { + $mode = $_GET["mode"]; + $modestring = '&mode='.$mode; + } + if (!empty($_GET["scoid"])) { + $scoid = $_GET["scoid"]; + $scoidstring = '&scoid='.$scoid; + } + if (!empty($_GET['currentorg'])) { + $currentorg = $_GET['currentorg']; + $currentorgstring = '¤torg='.$currentorg; + } + } else { + if (!empty($_POST["mode"])) { + $mode = $_POST["mode"]; + $modestring = '&mode='.$mode; + } + if (!empty($_POST["scoid"])) { + $scoid = $_POST["scoid"]; + $scoidstring = '&scoid='.$scoid; + } + if (!empty($_POST['currentorg'])) { + $currentorg = $_POST['currentorg']; + $currentorgstring = '¤torg='.$currentorg; + } } - print_header($pagetitle, "$course->fullname", - "$navigation framename}\" href=\"view.php?id=$cm->id\" title=\"$scorm->summary\">$scorm->name", - "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top'),"",$bodyscripts); - - echo "\n \n"; - if ($mode == "browse") - echo "\n"; - echo " \n
".text_to_html($scorm->summary, true, false)."".get_string("browsemode","scorm")."
\n"; - - if ($scorm->popup != "") { - echo "\n"; - $currentSCO = ""; - if (!empty($_POST['scoid'])) - $currentSCO = $_POST['scoid']; + + if (($frameset == "top") || ($scorm->popup != "")) { + add_to_log($course->id, "scorm", "view", "playscorm.php?id=$cm->id", "$scorm->id"); + // + // Print the page header + // + $bodyscripts = ""; + if ($scorm->popup != "") { + $bodyscripts = "onUnload='SCOFinish(); closeMain();' "; + } + //print_header($pagetitle, "$course->fullname", + // "$navigation framename}\" href=\"view.php?id=$cm->id\">$scorm->name", + // "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top'),"",$bodyscripts); + print_header($pagetitle, "$course->fullname", + "$navigation framename}\" href=\"view.php?id=$cm->id\">$scorm->name", + "", "", true, update_module_button($cm->id, $course->id, $strscorm), "", "", $bodyscripts); + echo "\n \n"; + if ($mode == "browse") + echo "\n"; + echo " \n
".text_to_html($scorm->summary, true, false)."".get_string("browsemode","scorm")."
\n"; + + if ($scorm->popup != "") { + echo "\n"; + echo "\n"; ?>
- + \n"; - echo " ".get_string("coursestruct","scorm")."\n"; - echo " \n\n"; - $level--; - } else { - $i = $level; - $closelist = ""; - while (($i > 0) && ($parents[$level] != $sco->parent)) { - $closelist .= " \n"; - $i--; - } - if (($i == 0) && ($sco->parent != $currentorg)) { - echo "
  • \n"; - } - } - echo "\n"; - echo "\n"; - print_simple_box_end(); - - } - - echo "\n \n"; - echo " \n"; - - echo "\n
    - -
    id\" target=\"_top\"> - - - -  \n"; - - if ($scorm->popup == "") { - $currentorg = ''; - if (isset($_GET['currentorg'])) { - $currentorg = $_GET['currentorg']; + print_simple_box_start("CENTER"); + echo "\n"; + echo " \n"; + echo " \n"; + echo "
    ".get_string("coursestruct","scorm")."
    \n
      \n"; + $incomplete = false; + if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$currentorg' order by id ASC")){ + $level=0; + $sublist=0; + $parents[$level]="/"; + foreach ($scoes as $sco) { + if ($parents[$level]!=$sco->parent) { + if ($level>0 && $parents[$level-1]==$sco->parent) { + echo "
    \n"; + $level--; + } else { + $i = $level; + $closelist = ""; + while (($i > 0) && ($parents[$level] != $sco->parent)) { + $closelist .= " \n"; + $i--; + } + if (($i == 0) && ($sco->parent != $currentorg)) { + echo "
    • \n"; + $level++; + } else { + echo $closelist; + $level = $i; + } + $parents[$level]=$sco->parent; + } + } + echo "
    • \n"; + $nextsco = next($scoes); + if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) { + $sublist++; + echo " \n"; + } else { + echo " \n"; + } + + if ($sco->launch) { + $startbold = ''; + $endbold = ''; + if ($sco->id == $scoid) { + $startbold = '-> '; + $endbold = ' <-'; + } + if (($scoid == "") && ($mode != "normal")) { + $scoid = $sco->id; + $startbold = '-> '; + $endbold = ' <-'; + } + $score = ""; + if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) { + if ( $sco_user->cmi_core_lesson_status == "") { + $sco_user->cmi_core_lesson_status = "not attempted"; + } + echo " cmi_core_lesson_status).".gif\" alt=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" title=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" />\n"; + if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete")) { + if ($scoid == "") { + $incomplete = true; + $scoid = $sco->id; + $startbold = '-> '; + $endbold = ' <-'; + } + } + if ($sco_user->cmi_core_score_raw > 0) { + $score = "(".get_string("score","scorm").": ".$sco_user->cmi_core_score_raw.")"; + } + } else { + if ($sco->type == 'sco') { + echo " \"".get_string("notattempted","scorm")."\""; + $incomplete = true; + } else { + echo " \"".get_string("asset","scorm")."\""; + } + } + echo "  $startboldid.");\">$sco->title $score$endbold\n
    • \n"; + } else { + echo "  $sco->title\n \n"; + } + } + for ($i=0;$i<$level;$i++){ + echo "
  • \n"; + } + } + echo "
    \n"; + print_simple_box_end(); + } - if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$currentorg' order by id ASC")){ - $level=0; - $parents[$level]="/"; - foreach ($scoes as $sco) { - if ($parents[$level]!=$sco->parent) { - if ($level>0 && $parents[$level-1]==$sco->parent) { - $level--; - } else { - $i = $level; - while (($i > 0) && ($parents[$level] != $sco->parent)) { - $i--; - } - if (($i == 0) && ($sco->parent != $currentorg)) { - $level++; - } else { - $level = $i; - } - $parents[$level]=$sco->parent; - } - } - $indenting = ""; - for ($i=0;$i<$level;$i++) { - $indenting .= "-"; - } - $options[$sco->id] = $indenting."> ".$sco->title; - } - } - choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();"); - } - echo "  \n"; - echo "
    -
    \n"; - if ($scorm->popup == "") { - echo "\n\n"; - } else { - print_footer($course); - } + + echo "\n \n"; + echo " \n"; + + echo "\n
    + +
    id\" target=\"_top\"> + + + +  \n"; + + if ($scorm->popup == "") { + if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$currentorg' order by id ASC")){ + $level=0; + $parents[$level]="/"; + foreach ($scoes as $sco) { + if ($parents[$level]!=$sco->parent) { + if ($level>0 && $parents[$level-1]==$sco->parent) { + $level--; + } else { + $i = $level; + while (($i > 0) && ($parents[$level] != $sco->parent)) { + $i--; + } + if (($i == 0) && ($sco->parent != $currentorg)) { + $level++; + } else { + $level = $i; + } + $parents[$level]=$sco->parent; + } + } + $indenting = ""; + for ($i=0;$i<$level;$i++) { + $indenting .= "-"; + } + $options[$sco->id] = $indenting."> ".$sco->title; + } + } + choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();"); + } + echo "  \n"; + echo "
    +
    \n"; + if ($scorm->popup == "") { + echo "\n\n"; + } else { + print_footer($course); + } } else { if ($scorm->popup == "") { - // - // Frameset - // - echo "\n"; + // + // Frameset + // + echo "\n"; echo "$course->shortname: $scorm->name\n"; - echo "\n"; - echo "scorm_framesize,*\" onLoad=\"SCOInitialize();\" onUnload=\"SCOFinish();\">\n"; - echo "\t id&mode=".$mode.'&currentorg='.$currentorg."&frameset=top\">\n"; - echo "\t \n"; + echo "\n"; + echo "\n"; + echo "scorm_framesize,*\" onLoad=\"SCOInitialize();\" onUnload=\"SCOFinish();\">\n"; + echo "\t id".$modestring.$currentorgstring."&frameset=top\">\n"; + echo "\t id$scoidstring\">\n"; echo "\n"; echo "\n"; } diff --git a/mod/scorm/report.php b/mod/scorm/report.php index 7b32c74c04f..973b16d5dec 100755 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -32,7 +32,7 @@ } } - require_login($course->id, false); + require_login($course->id, false, $cm); if (!isteacher($course->id)) { error("You are not allowed to use this script"); diff --git a/mod/scorm/request.js b/mod/scorm/request.js new file mode 100644 index 00000000000..eac3951a955 --- /dev/null +++ b/mod/scorm/request.js @@ -0,0 +1,30 @@ +function NewHttpReq() { + var httpReq = false; + if (typeof XMLHttpRequest!='undefined') { + httpReq = new XMLHttpRequest(); + } else { + try { + httpReq = new ActiveXObject("Msxml2.XMLHTTP.4.0"); + } catch (e) { + try { + httpReq = new ActiveXObject("Msxml2.XMLHTTP"); + } catch (ee) { + try { + httpReq = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (eee) { + httpReq = false; + } + } + } + } + return httpReq; +} + +function DoRequest(httpReq,url) { + // + // httpReq.open (Method("get","post"), URL(string), Asyncronous(true,false)) + // + httpReq.open("get", url,false); + httpReq.send(null); + return httpReq.responseText; +} \ No newline at end of file diff --git a/mod/scorm/scormAPI.php b/mod/scorm/scormAPI.php deleted file mode 100755 index f9306f8fe9a..00000000000 --- a/mod/scorm/scormAPI.php +++ /dev/null @@ -1,215 +0,0 @@ -course)) { - error("Course is misconfigured"); - } - - if (! $scorm = get_record("scorm", "id", $cm->instance)) { - error("Course module is incorrect"); - } - - } else { - if (! $scorm = get_record("scorm", "id", $a)) { - error("Course module is incorrect"); - } - if (! $course = get_record("course", "id", $scorm->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { - error("Course Module ID was incorrect"); - } - } - - require_login($course->id, false, $cm); - - if ( $scoes_user = get_records_select("scorm_sco_users","userid = ".$USER->id." AND scormid = ".$scorm->id,"scoid ASC") ) { - // - // Already user - // - if (!empty($scoid)) { - // Direct sco request - //$sco = get_record("scorm_scoes","id",$scoid); - if ($sco = get_record("scorm_scoes","id",$scoid)) { - if ($sco->launch == '') { - // Search for th first launchable sco - if ($scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC")) { - $sco = current($scoes); - while ($sco->id < $scoid) { - $sco = next($scoes); - } - while ($sco->launch == '') { - $sco = next($scoes); - } - } - } - } - } else { - // Search for first incomplete sco - foreach ( $scoes_user as $sco_user ) { - if (($sco_user->cmi_core_lesson_status != "completed") && ($sco_user->cmi_core_lesson_status != "passed") && ($sco_user->cmi_core_lesson_status != "failed")) { - $sco = get_record("scorm_scoes","id",$sco_user->scoid); - break; - } else { - // If review mode get the first - if ($mode == "review") { - $sco = get_record("scorm_scoes","id",$sco_user->scoid); - break; - } - } - } - } - if (!isset($sco)) { // If no sco was found get the first of SCORM package - $scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' order by id ASC"); - $sco = each($scoes); - } - } else { - // - // A new user - // - if ($scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC")) { - // - // Create user scoes records - // - foreach ($scoes as $sco) { - if (($sco->launch != "") && ($sco->type != "sca") && ($sco->type != "asset")){ - if (!isset($first)) { - $first = $sco; - } - $sco_user->userid = $USER->id; - $sco_user->scoid = $sco->id; - $sco_user->scormid = $scorm->id; - $element = "cmi_core_lesson_status"; - $sco_user->$element = "not attempted"; - $ident = insert_record("scorm_sco_users",$sco_user); - } - } - if (isset($first)) { - $sco = $first; - } - if (!empty($scoid)) { - if ($sco = get_record("scorm_scoes","id",$scoid)) { - unset($first); - } - } - } - } - // - // Get first, last, prev and next scoes - // - $scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC"); - $min = 0; - $max = 0; - $prevsco = 0; - $nextsco = 0; - foreach ($scoes as $fsco) { - if ($fsco->launch != "") { - if (!$min || ($min > $fsco->id)) - $min = $fsco->id; - if (!$max || ($max < $fsco->id)) - $max = $fsco->id; - if ((!$prevsco) || ($sco->id > $fsco->id)) { - $prevsco = $fsco->id; - } - if ((!$nextsco) && ($sco->id < $fsco->id)) { - $nextsco = $fsco->id; - } - } - } - $first = NULL; - $last = NULL; - if ($sco->id == $min) - $first = $sco; - if ($sco->id == $max) - $last = $sco; - - // Get current sco User data - $sco_user = get_record("scorm_sco_users","userid",$USER->id,"scoid",$sco->id); - - if (scorm_external_link($sco->launch)) { - $result = $sco->launch; - } else { - if ($CFG->slasharguments) { - $result = "$CFG->wwwroot/file.php/$scorm->course/moddata/scorm$scorm->datadir/$sco->launch"; - } else { - $result = "$CFG->wwwroot/file.php?file=/$scorm->course/moddata/scorm$scorm->datadir/$sco->launch"; - } - } - $navObj = "top."; - if ($scorm->popup == "") { - $navObj = "top.navigation."; - } - - if ($sco->type == 'sco') { - include("api1_2.php"); - } - -?> - -function hilightcurrent(popupmenu) { - for (i=0;i < popupmenu.options.length;i++) { - if ( popupmenu.options[i].value == id; ?> ) - popupmenu.options[i].selected = true; - } -} - -function SCOInitialize() { -previous || $first) { - print "\t".$navObj."document.navform.prev.disabled = true;\n"; - print "\t".$navObj."document.navform.prev.style.display = 'none';\n"; - } - if ( $sco->next || $last) { - print "\t".$navObj."document.navform.next.disabled = true;\n"; - print "\t".$navObj."document.navform.next.style.display = 'none';\n"; - } -?> -popup == "") { - echo "\t top.main.location=\"$result\";\n"; - echo "\t hilightcurrent(".$navObj."document.navform.courseStructure);\n"; - } else { - $popuplocation = ''; - if (isset($_COOKIE["SCORMpopup"])) { - $popuplocation = $_COOKIE["SCORMpopup"]; - } - echo "\t top.main = window.open('$result','main','$scorm->popup$popuplocation');\n"; - } -?> -} - -function SCOFinish(){ - if (typeof API != "undefined") { - API.SaveTotalTime(); - } -} - -function changeSco(direction) { - if (direction == "previous") - document.navform.scoid.value=""; - else - document.navform.scoid.value=""; - - //alert ("Prev: \nNext: \nNew SCO: "+document.navform.scoid.value); - document.navform.submit(); -} - -function closeMain() { - if (document.all) { - document.cookie = "SCORMpopup=" + escape(",top="+top.main.screenTop+",left="+top.main.screenLeft); - } else { - document.cookie = "SCORMpopup=" + escape(",top="+top.main.screenY+",left="+top.main.screenX); - } - top.main.close(); -} \ No newline at end of file diff --git a/mod/scorm/validate.php b/mod/scorm/validate.php new file mode 100755 index 00000000000..adf346f21e8 --- /dev/null +++ b/mod/scorm/validate.php @@ -0,0 +1,71 @@ +moddata/scorm")) { + if ($tempdir = scorm_datadir($scormdir, $datadir)) { + copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference)); + unzip_file($tempdir."/".basename($reference), $tempdir, false); + $result = scorm_validate($tempdir."/imsmanifest.xml"); + } else { + $result = "packagedir"; + } + } else { + $result = "datadir"; + } + $errorlogs = ''; + if (($result != "regular") && ($result != "found")) { + if ($CFG->scorm_validate == 'domxml') { + foreach ($errors as $error) { + $errorlogs .= get_string($error->type,"scorm",$error->data) . ".\n"; + } + } + // + // Delete files and temporary directory + // + if (is_dir($tempdir)) + scorm_delete_files($tempdir); + } else { + // + // Delete package file + // + unlink ($tempdir."/".basename($reference)); + if (isset($_GET["instance"])) { + $fp = fopen($CFG->dataroot.'/'.$reference,"r"); + $fstat = fstat($fp); + fclose($fp); + if ($scorm = get_record("scorm","id",$_GET["instance"])) { + $launch = $scorm->launch; + if ($scorm->timemodified < $fstat["mtime"]) { + $launch = 0; + } + } + } + } + // + // Print validation result + // + echo $result . "\n"; + echo $launch . "\n"; + $datadir = substr($tempdir,strlen($scormdir)); + echo $datadir . "\n"; + if ($errorlogs != '') { + echo $errorlogs; + } +?> + \ No newline at end of file diff --git a/mod/scorm/version.php b/mod/scorm/version.php index b1630020b1d..8eb78aa9b5f 100755 --- a/mod/scorm/version.php +++ b/mod/scorm/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2005021600; // The (date) version of this module +$module->version = 2005021700; // The (date) version of this module $module->requires = 2005021600; // The version of Moodle that is required $module->cron = 0; // How often should cron check this module (seconds)? diff --git a/mod/scorm/view.php b/mod/scorm/view.php index 7da65b563f4..7d9254c1ef2 100755 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -13,11 +13,11 @@ if (! $cm = get_record("course_modules", "id", $id)) { error("Course Module ID was incorrect"); } - + if (! $course = get_record("course", "id", $cm->course)) { error("Course is misconfigured"); } - + if (! $scorm = get_record("scorm", "id", $cm->instance)) { error("Course module is incorrect"); } @@ -36,10 +36,10 @@ require_login($course->id, false, $cm); - + $strscorms = get_string("modulenameplural", "scorm"); $strscorm = get_string("modulename", "scorm"); - + if ($course->category) { $navigation = "framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname -> framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; @@ -48,184 +48,176 @@ } $pagetitle = strip_tags("$course->shortname: $scorm->name"); - + add_to_log($course->id, "scorm", "pre-view", "view.php?id=$cm->id", "$scorm->id"); - // - // Checking if parsed scorm manifest - // - if ($scorm->launch == 0) { - $basedir = $CFG->dataroot."/".$course->id; - $scormdir = "/moddata/scorm"; - $scorm->launch = scorm_parse($basedir,$scormdir.$scorm->datadir."/imsmanifest.xml",$scorm->id); - set_field("scorm","launch",$scorm->launch,"id",$scorm->id); - } + // // Print the page header // if (!$cm->visible and !isteacher($course->id)) { - print_header($pagetitle, "$course->fullname", "$navigation $scorm->name", "", "", true, - update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm)); + print_header($pagetitle, "$course->fullname", "$navigation $scorm->name", "", "", true, + update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm)); notice(get_string("activityiscurrentlyhidden")); } else { - print_header($pagetitle, "$course->fullname","$navigation framename}\" href=\"$ME?id=$cm->id\" title=\"$scorm->summary\">$scorm->name", - "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm)); - - if (isteacher($course->id)) { - if ($sco_users = get_records_select("scorm_sco_users", "scormid='$scorm->id' GROUP BY userid")) { - echo "

    framename}\" href=\"report.php?id=$cm->id\">".get_string("viewallreports","scorm",count($sco_users))."

    "; + print_header($pagetitle, "$course->fullname","$navigation framename}\" href=\"$ME?id=$cm->id\" title=\"$scorm->summary\">$scorm->name", + "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm)); + + if (isteacher($course->id)) { + if ($sco_users = get_records_select("scorm_sco_users", "scormid='$scorm->id' GROUP BY userid")) { + echo "

    framename}\" href=\"report.php?id=$cm->id\">".get_string("viewallreports","scorm",count($sco_users))."

    "; } else { - echo "

    ".get_string("noreports","scorm")."

    "; + echo "

    ".get_string("noreports","scorm")."

    "; } - } - // Print the main part of the page + } + // Print the main part of the page - print_heading($scorm->name); + print_heading($scorm->name); - print_simple_box(text_to_html($scorm->summary), "center"); + print_simple_box(text_to_html($scorm->summary), "center"); - if (isguest()) { + if (isguest()) { print_heading(get_string("guestsno", "scorm")); print_footer($course); exit; - } + } echo "
    "; $liststyle = "style=\"list-style-type:none;\""; print_simple_box_start("center"); - echo "\n"; - echo " \n"; - $organization = $scorm->launch; - if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) { - if (count($orgs) > 1) { - if (isset($_POST['organization'])) { - $organization = $_POST['organization']; - } - echo "\n"; - } - } - $orgidentifier = ''; - if ($org = get_record('scorm_scoes','id',$organization)) { - if (($org->organization == '') && ($org->launch == '')) { - $orgidentifier = $org->identifier; - } else { - $orgidentifier = $org->organization; - } - } - echo " \n"; - echo "
    ".get_string("coursestruct","scorm")."
    ".get_string('organizations','scorm').": \n"; - choose_from_menu($orgs, 'organization', "$organization", '','submit()'); - echo "
    \n
      \n"; - $incomplete = false; - if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$orgidentifier' order by id ASC")){ - $level=0; - $sublist=0; - $parents[$level]="/"; - foreach ($scoes as $sco) { - if ($parents[$level]!=$sco->parent) { - if ($level>0 && $parents[$level-1]==$sco->parent) { - echo "
    \n"; - $level--; - } else { - $i = $level; - $closelist = ""; - while (($i > 0) && ($parents[$level] != $sco->parent)) { - $closelist .= " \n"; - $i--; - } - if (($i == 0) && ($sco->parent != $orgidentifier)) { - echo "
    • \n"; - $level++; - } else { - echo $closelist; - $level = $i; - } - $parents[$level]=$sco->parent; - } - } - - echo "
    • \n"; - $nextsco = next($scoes); - if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) { - $sublist++; - echo " \"-\"\n"; - } else { - echo " \"\n"; - } - if ($sco->launch) { - $score = ""; - if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) { - if ( $sco_user->cmi_core_lesson_status == "") { - $sco_user->cmi_core_lesson_status = "not attempted"; - } - echo " cmi_core_lesson_status).".gif\" alt=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" title=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" />\n"; - if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete")) { - $incomplete = true; - } - if ($sco_user->cmi_core_score_raw > 0) { - $score = "(".get_string("score","scorm").": ".$sco_user->cmi_core_score_raw.")"; - } - } else { - if ($sco->type == 'sco') { - echo " \"".get_string("notattempted","scorm")."\""; - $incomplete = true; - } else { - echo " \"".get_string("asset","scorm")."\""; - } - } - echo "  id.")\">$sco->title $score\n
    • \n"; - } else { - echo "  $sco->title\n \n"; - } - } - for ($i=0;$i<$level;$i++){ - echo "
  • \n"; - } - } - echo "
    \n"; - print_simple_box_end(); - echo "
    id\">\n"; - echo "\n\n
    "; - print_string("mode","scorm"); + echo "\n"; + echo " \n"; + $organization = $scorm->launch; + if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) { + if (count($orgs) > 1) { + if (isset($_POST['organization'])) { + $organization = $_POST['organization']; + } + echo "\n"; + } + } + $orgidentifier = ''; + if ($org = get_record('scorm_scoes','id',$organization)) { + if (($org->organization == '') && ($org->launch == '')) { + $orgidentifier = $org->identifier; + } else { + $orgidentifier = $org->organization; + } + } + echo " \n"; + echo "
    ".get_string("coursestruct","scorm")."
    ".get_string('organizations','scorm').": \n"; + choose_from_menu($orgs, 'organization', "$organization", '','submit()'); + echo "
    \n
      \n"; + $incomplete = false; + if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$orgidentifier' order by id ASC")){ + $level=0; + $sublist=0; + $parents[$level]="/"; + foreach ($scoes as $sco) { + if ($parents[$level]!=$sco->parent) { + if ($level>0 && $parents[$level-1]==$sco->parent) { + echo "
    \n"; + $level--; + } else { + $i = $level; + $closelist = ""; + while (($i > 0) && ($parents[$level] != $sco->parent)) { + $closelist .= " \n"; + $i--; + } + if (($i == 0) && ($sco->parent != $orgidentifier)) { + echo "
    • \n"; + $level++; + } else { + echo $closelist; + $level = $i; + } + $parents[$level]=$sco->parent; + } + } + + echo "
    • \n"; + $nextsco = next($scoes); + if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) { + $sublist++; + echo " \"-\"\n"; + } else { + echo " \"\n"; + } + if ($sco->launch) { + $score = ""; + if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) { + if ( $sco_user->cmi_core_lesson_status == "") { + $sco_user->cmi_core_lesson_status = "not attempted"; + } + echo " cmi_core_lesson_status).".gif\" alt=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" title=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" />\n"; + if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete")) { + $incomplete = true; + } + if ($sco_user->cmi_core_score_raw > 0) { + $score = "(".get_string("score","scorm").": ".$sco_user->cmi_core_score_raw.")"; + } + } else { + if ($sco->type == 'sco') { + echo " \"".get_string("notattempted","scorm")."\""; + $incomplete = true; + } else { + echo " \"".get_string("asset","scorm")."\""; + } + } + echo "  id.")\">$sco->title $score\n
    • \n"; + } else { + echo "  $sco->title\n \n"; + } + } + for ($i=0;$i<$level;$i++){ + echo "
  • \n"; + } + } + echo "
    \n"; + print_simple_box_end(); + echo "
    id\">\n"; + echo "\n\n\n\n\n\n\n\n
    "; + print_string("mode","scorm"); echo ": \n"; if ($incomplete === true) { echo "\n"; } else { echo "\n"; - } - echo "
    "; - echo ' - - '; + } + echo "
    "; + echo ' + + '; echo "\n
    \n

    "; ?> -- 2.43.0