From 92a489eb6a554a54f202de063f08e902ed2c2be7 Mon Sep 17 00:00:00 2001 From: bobopinna Date: Thu, 17 Feb 2005 16:04:42 +0000 Subject: [PATCH] First step to SCORM2004, new communication subsystem --- mod/scorm/api.php | 8 ++-- mod/scorm/datamodel.php | 46 ++------------------ mod/scorm/index.php | 4 +- mod/scorm/lib.php | 7 +-- mod/scorm/mod.html | 13 +++--- mod/scorm/playscorm.php | 11 ++--- mod/scorm/validate.php | 96 +++++++++++++++++++++++------------------ 7 files changed, 77 insertions(+), 108 deletions(-) diff --git a/mod/scorm/api.php b/mod/scorm/api.php index 4d2d54b188e..ef7a3f0a1f6 100644 --- a/mod/scorm/api.php +++ b/mod/scorm/api.php @@ -54,13 +54,13 @@ function closeMain() { var errorCode = "0"; function SCORM_Call (call,param,value) { - if (arguments.caller.length < 2) { + if (arguments.length < 2) { alert ("Invalid SCORM_Call function call: too few arguments.\nYou need pass at least 2 parameters"); - } else if (arguments.caller.length == 3) { + } else if (arguments.length == 3) { param = param.concat("&value=",value); } var myRequest = NewHttpReq(); - result = DoRequest(myRequest,"wwwroot) ?>/mod/scorm/datamodel.php?id=&sesskey=sesskey) ?>¶m="+param); + result = DoRequest(myRequest,"wwwroot) ?>/mod/scorm/datamodel.php?id=&sesskey=sesskey) ?>&call="+call+"¶m="+param); results = result.split('\n'); errorCode = results[1]; @@ -180,7 +180,7 @@ function SCORMapi2004() { 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["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"; diff --git a/mod/scorm/datamodel.php b/mod/scorm/datamodel.php index 1cfed79507a..05805080523 100755 --- a/mod/scorm/datamodel.php +++ b/mod/scorm/datamodel.php @@ -31,47 +31,9 @@ } require_login($course->id, false, $cm); - 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_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'])) { - 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'])) { - 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'])) { - 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"; - } - if (!empty($_POST['cmi_core_total_time'])) { - set_field('scorm_sco_users','cmi_core_total_time',$_POST['cmi_core_total_time'],'scoid',$_POST['scoid'],'userid',$USER->id); - //echo 'cmi_core_total_time: '.$_POST['cmi_core_total_time']."\n"; - } + + if (isset($_POST['call']) && confirm_sesskey()) { + } ?> - - - cmi - - -
- - - - - - - -
- - + diff --git a/mod/scorm/index.php b/mod/scorm/index.php index 13607c1ef48..7bd56e4c0c4 100755 --- a/mod/scorm/index.php +++ b/mod/scorm/index.php @@ -8,7 +8,7 @@ error("Course ID is incorrect"); } - require_course_login($course->id, false, $cm); + require_course_login($course->id); add_to_log($course->id, "scorm", "view all", "index.php?id=$course->id", ""); @@ -20,7 +20,7 @@ $strsummary = get_string("summary"); $strlastmodified = get_string("lastmodified"); - print_header_simple("$strscorms", "", "$navigation $strscorms", + print_header_simple("$strscorms", "", "$strscorms", "", "", true, "", navmenu($course)); if ($course->format == "weeks" or $course->format == "topics") { diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index a6888eababb..81d98e89719 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -115,19 +115,16 @@ function scorm_update_instance($scorm) { $scorm->auto = '0'; } - $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); + $scorm->launch = scorm_parse($basedir,$scormdir.$scorm->datadir."/imsmanifest.xml",$scorm->id); } - return $id; + return update_record('scorm', $scorm); } diff --git a/mod/scorm/mod.html b/mod/scorm/mod.html index 30c34c7fdbf..5a5946fa73f 100755 --- a/mod/scorm/mod.html +++ b/mod/scorm/mod.html @@ -43,12 +43,17 @@ function validate_scorm(theform,filename) { //alert(filename); var myRequest = NewHttpReq(); - result = DoRequest(myRequest,"wwwroot) ?>/mod/scorm/validate.php?id=course) ?>&reference="+filename+""); + result = DoRequest(myRequest,"wwwroot) ?>/mod/scorm/validate.php?id=course) ?>&reference="+filename+""); //alert(result); results = result.split('\n'); if ((results[0] == "found") || (results[0] == "regular")) { - theform.launch.value = results[1]; theform.datadir.value = results[2]; + if (results[1] == 0) { + theform.launch.value = results[1]; + if ('' != '') { + return confirm(''); + } + } return true; } else { result = ': '+ results[0] + '\n'; @@ -140,10 +145,6 @@ : grademethod", ""); helpbutton("grademethod", get_string("grademethod","scorm"), "scorm"); ?> diff --git a/mod/scorm/playscorm.php b/mod/scorm/playscorm.php index d96f98afda7..4e498f351fb 100755 --- a/mod/scorm/playscorm.php +++ b/mod/scorm/playscorm.php @@ -102,10 +102,7 @@ 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", + 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"; @@ -275,7 +272,7 @@ $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();"); + choose_from_menu($options, "courseStructure", "", $scoid, "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();"); } echo "  \n"; echo " @@ -296,8 +293,8 @@ echo "$course->shortname: $scorm->name\n"; echo "\n"; echo "\n"; - echo "scorm_framesize,*\" onLoad=\"SCOInitialize();\" onUnload=\"SCOFinish();\">\n"; - echo "\t id".$modestring.$currentorgstring."&frameset=top\">\n"; + echo "scorm_framesize,*\" onUnload=\"SCOFinish();\">\n"; + echo "\t id".$modestring.$currentorgstring.$scoidstring."&frameset=top\">\n"; echo "\t id$scoidstring\">\n"; echo "\n"; echo "\n"; diff --git a/mod/scorm/validate.php b/mod/scorm/validate.php index 510f11ca3da..84daf04b886 100755 --- a/mod/scorm/validate.php +++ b/mod/scorm/validate.php @@ -5,57 +5,70 @@ require_login(); - // - // Create a temporary directory to unzip package and validate imsmanifest - // - + $reference = clean_param($_GET["reference"], PARAM_PATH); $courseid = $_GET["id"]; $datadir = ''; - $launch = 0; if (isset($_GET["datadir"])) { $datadir = $_GET["datadir"]; } + + $scormid = 0; + $launch = 0; $result = ''; - if ($scormdir = make_upload_directory("$courseid/$CFG->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")) { - $result = get_string($result,'scorm'); - if ($CFG->scorm_validate == 'domxml') { - foreach ($errors as $error) { - $errorlogs .= get_string($error->type,"scorm",$error->data) . ".\n"; + if (isset($_GET["instance"])) { + $scormid = $_GET["instance"]; + $launch = 1; + $fp = fopen($CFG->dataroot.'/'.$courseid.'/'.$reference,"r"); + $fstat = fstat($fp); + fclose($fp); + if ($scorm = get_record("scorm","id",$scormid)) { + if ((($scorm->timemodified < $fstat["mtime"]) && ($scorm->reference == $reference)) || ($scorm->reference != $reference)) { + // This is a new package + $launch = 0; + } else { + // Old package already validated + $result = 'found'; + } + } + } + if ($launch == 0) { + // + // Package must be validated + // + + // Create a temporary directory to unzip package and validate imsmanifest + $tempdir = ''; + $scormdir = ''; + if ($scormdir = make_upload_directory("$courseid/$CFG->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"; + } + if (($result != "regular") && ($result != "found")) { + // Generate error log string + $result = get_string($result,'scorm'); + if ($CFG->scorm_validate == 'domxml') { + foreach ($errors as $error) { + $errorlogs .= get_string($error->type,"scorm",$error->data) . ".\n"; + } + } + if (is_dir($tempdir)) { + // Delete files and temporary directory + scorm_delete_files($tempdir); + } else { + // Delete package file + unlink ($tempdir."/".basename($reference)); } - } - // - // 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; - } - } + $datadir = substr($tempdir,strlen($scormdir)); } } // @@ -63,7 +76,6 @@ // echo $result . "\n"; echo $launch . "\n"; - $datadir = substr($tempdir,strlen($scormdir)); echo $datadir . "\n"; if ($errorlogs != '') { echo $errorlogs; -- 2.43.0
".text_to_html($scorm->summary, true, false)."