From: bobopinna Date: Mon, 19 Jul 2004 14:53:43 +0000 (+0000) Subject: Some bug fixes, added new score view (thanks Matt) and added a new validation procedure X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1a12b1f1d1f9417ea365fa2711688e139c692ffd;p=moodle.git Some bug fixes, added new score view (thanks Matt) and added a new validation procedure --- diff --git a/mod/scorm/api1_2.php b/mod/scorm/api1_2.php index b3f4708385..2888a132be 100644 --- a/mod/scorm/api1_2.php +++ b/mod/scorm/api1_2.php @@ -145,7 +145,7 @@ function SCORMapi() { 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[2]>=0) && (parsedtime[2]<=59) && (parsedtime[3]>=0) && (parsedtime[3]<=59)) { + if (((parsedtime.length == 4) || (parsedtime.length == 5)) && (parsedtime[3]>=0) && (parsedtime[3]<=59)) { eval(param+'="'+value+'";'); errorCode = "0"; return "true"; @@ -291,15 +291,7 @@ function SCORMapi() { } else { Initialized = false; errorCode = "0"; - cmi.core.total_time = AddTime(cmi.core.total_time, cmi.core.session_time); - //top.alert(cmi.core.total_time); - if (cmi.document.theform) { - cmiform = cmi.document.forms[0]; - cmiform.scoid.value = "id; ?>"; - cmiform.cmi_core_total_time.value = cmi.core.total_time; - cmiform.submit(); - - } + if (nav.event != "") { 60) { - secs = secs - 60; - change = 1; - } else { - change = 0; - } + 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 - if (mins > 60) - change = 1; - else - change = 0; + 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 @@ -365,6 +351,21 @@ function SCORMapi() { 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; diff --git a/mod/scorm/backuplib.php b/mod/scorm/backuplib.php index 9b6959aaf5..8075e53da7 100755 --- a/mod/scorm/backuplib.php +++ b/mod/scorm/backuplib.php @@ -43,6 +43,8 @@ fwrite ($bf,full_tag("MODTYPE",4,false,"scorm")); fwrite ($bf,full_tag("NAME",4,false,$scorm->name)); fwrite ($bf,full_tag("REFERENCE",4,false,$scorm->reference)); + fwrite ($bf,full_tag("MAXGRADE",4,false,$scorm->reference)); + fwrite ($bf,full_tag("GRADEMETHOD",4,false,$scorm->reference)); fwrite ($bf,full_tag("DATADIR",4,false,$scorm->datadir)); fwrite ($bf,full_tag("LAUNCH",4,false,$scorm->launch)); fwrite ($bf,full_tag("SUMMARY",4,false,$scorm->summary)); @@ -87,11 +89,14 @@ $status =fwrite ($bf,start_tag("SCO",5,true)); //Print submission contents fwrite ($bf,full_tag("ID",6,false,$sco->id)); + fwrite ($bf,full_tag("MANIFEST",6,false,$sco->manifest)); + fwrite ($bf,full_tag("ORGANIZATION",6,false,$sco->organization)); fwrite ($bf,full_tag("PARENT",6,false,$sco->parent)); fwrite ($bf,full_tag("IDENTIFIER",6,false,$sco->identifier)); fwrite ($bf,full_tag("LAUNCH",6,false,$sco->launch)); fwrite ($bf,full_tag("TYPE",6,false,$sco->type)); fwrite ($bf,full_tag("TITLE",6,false,$sco->title)); + fwrite ($bf,full_tag("DATAFROMLMS",6,false,$sco->datafromlms)); fwrite ($bf,full_tag("NEXT",6,false,$sco->next)); fwrite ($bf,full_tag("PREVIOUS",6,false,$sco->previous)); //End sco @@ -130,7 +135,6 @@ fwrite ($bf,full_tag("CMI_CORE_SESSION_TIME",6,false,$sco_user->cmi_core_session_time)); fwrite ($bf,full_tag("CMI_CORE_SCORE_RAW",6,false,$sco_user->cmi_core_score_raw)); fwrite ($bf,full_tag("CMI_SUSPEND_DATA",6,false,$sco_user->cmi_suspend_data)); - fwrite ($bf,full_tag("CMI_LAUNCH_DATA",6,false,$sco_user->cmi_launch_data)); //End sco $status =fwrite ($bf,end_tag("SCO_USER",5,true)); } diff --git a/mod/scorm/cmi.php b/mod/scorm/cmi.php index 2c6716f36f..254dd4aedf 100755 --- a/mod/scorm/cmi.php +++ b/mod/scorm/cmi.php @@ -1,55 +1,61 @@ course)) { - error("Course is misconfigured"); + 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"); + 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 (! $scorm = get_record('scorm', 'id', $a)) { + error('Course module is incorrect'); } - if (! $course = get_record("course", "id", $scorm->course)) { - error("Course is misconfigured"); + 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"); + if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) { + error('Course Module ID was incorrect'); } } require_login($course->id); - - if (!empty($_POST["scoid"])) { - 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); + 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); + 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); + 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_total_time"])) { - set_field("scorm_sco_users","cmi_core_total_time",$_POST["cmi_core_total_time"],"scoid",$_POST["scoid"],"userid",$USER->id); + 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_core_score_raw"])) { - set_field("scorm_sco_users","cmi_core_score_raw",$_POST["cmi_core_score_raw"],"scoid",$_POST["scoid"],"userid",$USER->id); + 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_suspend_data"])) { - set_field("scorm_sco_users","cmi_suspend_data",$_POST["cmi_suspend_data"],"scoid",$_POST["scoid"],"userid",$USER->id); + 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"; } } ?> @@ -63,10 +69,10 @@ - + diff --git a/mod/scorm/config.html b/mod/scorm/config.html index b4c8e24829..cc56c38d39 100755 --- a/mod/scorm/config.html +++ b/mod/scorm/config.html @@ -2,17 +2,36 @@ - - + + + + + + - - + + "> +

scorm_framesize:

- +

scorm_validate:

+ =")) { + $choices["php5"] = get_string("php5","scorm"); + } + choose_from_menu ($choices, "scorm_validate", $CFG->scorm_validate, ""); + ?> + + +

scorm_framesize:

+

scorm_popup:

+

scorm_popup:

- ">
diff --git a/mod/scorm/db/mysql.php b/mod/scorm/db/mysql.php index dc057fa901..1286643277 100755 --- a/mod/scorm/db/mysql.php +++ b/mod/scorm/db/mysql.php @@ -18,6 +18,14 @@ function scorm_upgrade($oldversion) { table_column("scorm_scoes", "", "datafromlms", "TEXT", "", "", "", "NOT NULL", "title"); modify_database("", "ALTER TABLE `{$CFG->prefix}scorm_sco_users` DROP `cmi_launch_data`;"); } + if ($oldversion < 2004071700) { + table_column("scorm_scoes", "", "manifest", "VARCHAR", "255", "", "", "NOT NULL", "scorm"); + table_column("scorm_scoes", "", "organization", "VARCHAR", "255", "", "", "NOT NULL", "manifest"); + } + if ($oldversion < 2004071900) { + table_column("scorm", "", "maxgrade", "FLOAT", "3", "", "0", "NOT NULL", "reference"); + table_column("scorm", "", "grademethod", "TINYINT", "2", "", "0", "NOT NULL", "maxgrade"); + } return true; } diff --git a/mod/scorm/db/mysql.sql b/mod/scorm/db/mysql.sql index f6bb9643f5..c2ff87444c 100755 --- a/mod/scorm/db/mysql.sql +++ b/mod/scorm/db/mysql.sql @@ -7,6 +7,8 @@ CREATE TABLE prefix_scorm ( course int(10) unsigned NOT NULL default '0', name varchar(255) NOT NULL default '', reference varchar(255) NOT NULL default '', + maxgrade float(3) NOT NULL default '0', + grademethod tinyint(2) NOT NULL default '0', datadir varchar(255) NOT NULL default '', launch int(10) unsigned NOT NULL default 0, summary text NOT NULL, @@ -20,6 +22,8 @@ CREATE TABLE prefix_scorm ( CREATE TABLE prefix_scorm_scoes ( id int(10) unsigned NOT NULL auto_increment, scorm int(10) unsigned NOT NULL default '0', + manifest varchar(255) NOT NULL default '', + organization varchar(255) NOT NULL default '', parent varchar(255) NOT NULL default '', identifier varchar(255) NOT NULL default '', launch varchar(255) NOT NULL default '', diff --git a/mod/scorm/db/postgres7.php b/mod/scorm/db/postgres7.php index f83857cc22..f27436e563 100755 --- a/mod/scorm/db/postgres7.php +++ b/mod/scorm/db/postgres7.php @@ -18,6 +18,14 @@ function scorm_upgrade($oldversion) { table_column("scorm_scoes", "", "datafromlms", "TEXT", "", "", "", "NOT NULL", "title"); modify_database("", "ALTER TABLE `{$CFG->prefix}scorm_sco_users` DROP `cmi_launch_data`;"); } + if ($oldversion < 2004071700) { + table_column("scorm_scoes", "", "manifest", "VARCHAR", "255", "", "", "NOT NULL", "scorm"); + table_column("scorm_scoes", "", "organization", "VARCHAR", "255", "", "", "NOT NULL", "manifest"); + } + if ($oldversion < 2004071900) { + table_column("scorm", "", "maxgrade", "real", "3", "", "0", "NOT NULL", "reference"); + table_column("scorm", "", "grademethod", "integer", "", "", "0", "NOT NULL", "maxgrade"); + } return true; } diff --git a/mod/scorm/db/postgres7.sql b/mod/scorm/db/postgres7.sql index 9d84b1d2a5..387f532ea1 100755 --- a/mod/scorm/db/postgres7.sql +++ b/mod/scorm/db/postgres7.sql @@ -7,6 +7,8 @@ CREATE TABLE prefix_scorm ( course integer NOT NULL default '0', name varchar(255) NOT NULL default '', reference varchar(255) NOT NULL default '', + maxgrade real NOT NULL default '0', + grademethod integer NOT NULL default '0', datadir varchar(255) NOT NULL default '', launch integer NOT NULL default '0', summary text NOT NULL default '', @@ -18,6 +20,8 @@ CREATE TABLE prefix_scorm ( CREATE TABLE prefix_scorm_scoes ( id SERIAL PRIMARY KEY, scorm integer NOT NULL default '0', + manifest varchar(255) NOT NULL default '', + organization varchar(255) NOT NULL default '', parent varchar(255) NOT NULL default '', identifier varchar(255) NOT NULL default '', launch varchar(255) NOT NULL default '', diff --git a/mod/scorm/details.php b/mod/scorm/details.php index f059048287..e86943f1ba 100755 --- a/mod/scorm/details.php +++ b/mod/scorm/details.php @@ -53,10 +53,12 @@ $result = "datadir"; } $errorlogs = ''; - if ($result != "regular") { - /*foreach ($error_array as $errormsg) { - $errorlogs .= get_string($errormsg->type,"scorm",$errormsg->data) . "\n"; - }*/ + 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 // @@ -83,16 +85,25 @@ echo "

$strname:

$form->name

\n"; echo "

".get_string("validation","scorm").":

".get_string($result,"scorm")."

\n"; if ($errorlogs != '') { - //$lines = round(count($error_array)/4); - //echo "

".get_string("errorlogs","scorm").":

\n"; + $lines = round(count($errors)/4); + if ($lines < 5) { + $lines = 5; + } + echo "

".get_string("errorlogs","scorm").":

\n"; } if (($form->mode == "update") && ($form->launch == 0) && (get_records("scorm_sco_users","scormid",$form->instance))) echo "

".get_string("trackingloose","scorm")."

\n"; echo "\n"; - if ($result == "regular") { + 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; @@ -139,12 +150,39 @@ ?> + + + + + + + + diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 91339f2920..f4ab32dd15 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -3,27 +3,46 @@ /// Library of functions and constants for module scorm /// (replace scorm with the name of your module and delete this line) -$SCORM_WINDOW_OPTIONS = array("resizable", "scrollbars", "status", "height", "width"); +define('VALUESCOES', '0'); +define('VALUEHIGHEST', '1'); +define('VALUEAVERAGE', '2'); +define('VALUESUM', '3'); +$SCORM_GRADE_METHOD = array (VALUESCOES => get_string("gradescoes", "scorm"), + VALUEHIGHEST => get_string("gradehighest", "scorm"), + VALUEAVERAGE => get_string("gradeaverage", "scorm"), + VALUESUM => get_string("gradesum", "scorm")); + +$SCORM_WINDOW_OPTIONS = array('resizable', 'scrollbars', 'status', 'height', 'width'); if (!isset($CFG->scorm_popup)) { - set_config("scorm_popup", ""); -} + set_config('scorm_popup', ''); +} +if (!isset($CFG->scorm_validate)) { + $scorm_validate = 'none'; + if (extension_loaded('domxml')) { + $scorm_validate = 'domxml'; + } + if (version_compare(phpversion(),'5.0.0','>=')) { + $scorm_validate = 'php5'; + } + set_config('scorm_validate', $scorm_validate); +} foreach ($SCORM_WINDOW_OPTIONS as $popupoption) { $popupoption = "scorm_popup$popupoption"; if (!isset($CFG->$popupoption)) { - if ($popupoption == "scorm_popupheight") { + if ($popupoption == 'scorm_popupheight') { set_config($popupoption, 450); - } else if ($popupoption == "scorm_popupwidth") { + } else if ($popupoption == 'scorm_popupwidth') { set_config($popupoption, 620); } else { - set_config($popupoption, "checked"); + set_config($popupoption, 'checked'); } } } if (!isset($CFG->scorm_framesize)) { - set_config("scorm_framesize", 140); + set_config('scorm_framesize', 140); } function scorm_add_instance($scorm) { @@ -37,23 +56,23 @@ function scorm_add_instance($scorm) { # May have to add extra stuff in here # global $SCORM_WINDOW_OPTIONS; - $scorm->popup = ""; + $scorm->popup = ''; $optionlist = array(); foreach ($SCORM_WINDOW_OPTIONS as $option) { if (isset($scorm->$option)) { - $optionlist[] = $option."=".$scorm->$option; + $optionlist[] = $option.'='.$scorm->$option; } } $scorm->popup = implode(',', $optionlist); - if ($scorm->popup != "") { + if ($scorm->popup != '') { $scorm->popup .= ',location=0,menubar=0,toolbar=0'; $scorm->auto = '0'; } - return insert_record("scorm", $scorm); + return insert_record('scorm', $scorm); } @@ -68,21 +87,21 @@ function scorm_update_instance($scorm) { # May have to add extra stuff in here # global $SCORM_WINDOW_OPTIONS; - $scorm->popup = ""; + $scorm->popup = ''; $optionlist = array(); foreach ($SCORM_WINDOW_OPTIONS as $option) { if (isset($scorm->$option)) { - $optionlist[] = $option."=".$scorm->$option; + $optionlist[] = $option.'='.$scorm->$option; } } $scorm->popup = implode(',', $optionlist); - if ($scorm->popup != "") { + if ($scorm->popup != '') { $scorm->popup .= ',location=0,menubar=0,toolbar=0'; $scorm->auto = '0'; } - return update_record("scorm", $scorm); + return update_record('scorm', $scorm); } @@ -93,23 +112,23 @@ function scorm_delete_instance($id) { require('../config.php'); - if (! $scorm = get_record("scorm", "id", "$id")) { + if (! $scorm = get_record('scorm', 'id', $id)) { return false; } $result = true; # Delete any dependent files # - scorm_delete_files($CFG->dataroot."/".$scorm->course."/moddata/scorm".$scorm->datadir); + scorm_delete_files($CFG->dataroot.'/'.$scorm->course.'/moddata/scorm'.$scorm->datadir); # Delete any dependent records here # - if (! delete_records("scorm_sco_users", "scormid", "$scorm->id")) { + if (! delete_records('scorm_sco_users', 'scormid', $scorm->id)) { $result = false; } - if (! delete_records("scorm_scoes", "scorm", "$scorm->id")) { + if (! delete_records('scorm_scoes', 'scorm', $scorm->id)) { $result = false; } - if (! delete_records("scorm", "id", "$scorm->id")) { + if (! delete_records('scorm', 'id', $scorm->id)) { $result = false; } @@ -163,44 +182,84 @@ function scorm_grades($scormid) { global $CFG; - if (!$return->maxgrade = count_records_select("scorm_scoes","scorm='$scormid' AND launch<>''")) { + if (!$scorm = get_record("scorm", "id", $scormid)) { return NULL; } - $return->grades = NULL; - if ($sco_users=get_records_select("scorm_sco_users", "scormid='$scormid' GROUP BY userid")) { - foreach ($sco_users as $sco_user) { - $user_data=get_records_select("scorm_sco_users","scormid='$scormid' AND userid='$sco_user->userid'"); - $scores->completed=0; - $scores->browsed=0; - $scores->incomplete=0; - $scores->failed=0; - $scores->notattempted=0; - $result=""; - $data = current($user_data); - foreach ($user_data as $data) { - if ($data->cmi_core_lesson_status=="passed") - $scores->completed++; - else - $scores->{scorm_remove_spaces($data->cmi_core_lesson_status)}++; - - } - if ($scores->completed) - $result.="wwwroot/mod/scorm/pix/completed.gif\" alt=\"".get_string("completed","scorm")."\" title=\"".get_string("completed","scorm")."\"> $scores->completed "; - if ($scores->incomplete) - $result.="wwwroot/mod/scorm/pix/incomplete.gif\" alt=\"".get_string("incomplete","scorm")."\" title=\"".get_string("incomplete","scorm")."\"> $scores->incomplete "; - if ($scores->failed) - $result.="wwwroot/mod/scorm/pix/failed.gif\" alt=\"".get_string("failed","scorm")."\" title=\"".get_string("failed","scorm")."\"> $scores->failed "; - if ($scores->browsed) - $result.="wwwroot/mod/scorm/pix/browsed.gif\" alt=\"".get_string("browsed","scorm")."\" title=\"".get_string("browsed","scorm")."\"> $scores->browsed "; - if ($scores->notattempted) - $result.="wwwroot/mod/scorm/pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" title=\"".get_string("notattempted","scorm")."\"> $scores->notattempted "; + if ($scorm->grademethod == VALUESCOES) { + if (!$return->maxgrade = count_records_select('scorm_scoes',"scorm='$scormid' AND launch<>''")) { + return NULL; + } + + $return->grades = NULL; + if ($sco_users=get_records_select('scorm_sco_users', "scormid='$scormid' GROUP BY userid")) { + foreach ($sco_users as $sco_user) { + $user_data=get_records_select('scorm_sco_users',"scormid='$scormid' AND userid='$sco_user->userid'"); + $scores->completed=0; + $scores->browsed=0; + $scores->incomplete=0; + $scores->failed=0; + $scores->notattempted=0; + $result=''; + $data = current($user_data); + foreach ($user_data as $data) { + if ($data->cmi_core_lesson_status=='passed') + $scores->completed++; + else + $scores->{scorm_remove_spaces($data->cmi_core_lesson_status)}++; + } + if ($scores->completed) + $result.="wwwroot/mod/scorm/pix/completed.gif\" alt=\"".get_string('completed','scorm')."\" title=\"".get_string('completed','scorm')."\"> $scores->completed "; + if ($scores->incomplete) + $result.="wwwroot/mod/scorm/pix/incomplete.gif\" alt=\"".get_string('incomplete','scorm')."\" title=\"".get_string('incomplete','scorm')."\"> $scores->incomplete "; + if ($scores->failed) + $result.="wwwroot/mod/scorm/pix/failed.gif\" alt=\"".get_string('failed','scorm')."\" title=\"".get_string('failed','scorm')."\"> $scores->failed "; + if ($scores->browsed) + $result.="wwwroot/mod/scorm/pix/browsed.gif\" alt=\"".get_string('browsed','scorm')."\" title=\"".get_string('browsed','scorm')."\"> $scores->browsed "; + if ($scores->notattempted) + $result.="wwwroot/mod/scorm/pix/notattempted.gif\" alt=\"".get_string('notattempted','scorm')."\" title=\"".get_string('notattempted','scorm')."\"> $scores->notattempted "; - $return->grades[$sco_user->userid]=$result; - } + $return->grades[$sco_user->userid]=$result; + } + } + } else { + $grades = get_records_select("scorm_sco_users", "scormid=$scormid AND cmi_core_score_raw>0","","id,userid,cmi_core_score_raw"); + //$grades = get_records_menu("scorm_sco_users", "scormid",$scormid,"","userid,cmi_core_score_raw"); + $valutations = array(); + foreach ($grades as $grade) { + if (!isset($valutations[$grade->userid])) { + if ($scorm->grademethod == VALUEAVERAGE) { + $values = array(); + $values[$grade->userid]->grade = 0; + $values[$grade->userid]->values = 0; + } + $valutations[$grade->userid] = 0; + } + switch ($scorm->grademethod) { + case VALUEHIGHEST: + if ($grade->cmi_core_score_raw > $valutations[$grade->userid]) { + $valutations[$grade->userid] = $grade->cmi_core_score_raw; + } + break; + case VALUEAVERAGE: + $values[$grade->userid]->grade += $grade->cmi_core_score_raw; + $values[$grade->userid]->values++; + break; + case VALUESUM: + $valutations[$grade->userid] += $grade->cmi_core_score_raw; + break; + } + } + if ($scorm->grademethod == VALUEAVERAGE) { + foreach($values as $userid => $value) { + $valutations[$userid] = $value->grade/$value->values; + } + } + //print_r($grades); + $return->grades = $valutations; + $return->maxgrade = $scorm->maxgrade; } - return $return; } @@ -210,12 +269,13 @@ function scorm_grades($scormid) { /// starts with scorm_ -function scorm_randstring($len = "8") +function scorm_randstring($len = '8') { $rstring = NULL; + $lchar = ''; for($i=0; $i<$len; $i++) { $char = chr(rand(48,122)); - while (!ereg("[a-zA-Z0-9]", $char)){ + while (!ereg('[a-zA-Z0-9]', $char)){ if($char == $lchar) continue; $char = chr(rand(48,90)); } @@ -226,16 +286,16 @@ function scorm_randstring($len = "8") } -function scorm_datadir($strPath, $existingdir="", $prefix = "SCORM") +function scorm_datadir($strPath, $existingdir='', $prefix = 'SCORM') { global $CFG; - if (($existingdir!="") && (is_dir($strPath.$existingdir))) + if (($existingdir!='') && (is_dir($strPath.$existingdir))) return $strPath.$existingdir; if (is_dir($strPath)) { do { - $datadir="/".$prefix.scorm_randstring(); + $datadir='/'.$prefix.scorm_randstring(); } while (file_exists($strPath.$datadir)); mkdir($strPath.$datadir, $CFG->directorypermissions); @chmod($strPath.$datadir, $CFG->directorypermissions); // Just in case mkdir didn't do it @@ -245,15 +305,64 @@ function scorm_datadir($strPath, $existingdir="", $prefix = "SCORM") } } +if ($CFG->scorm_validate == 'domxml') { + require_once('validatordomxml.php'); +} + function scorm_validate($manifest) { + global $CFG; + + global $item_idref_array; + global $idres_array; + global $def_org_array; + global $id_org_array; + if (is_file ($manifest)) { - if (file_exists($manifest)) - { - return "regular"; - } + if (file_exists($manifest)) { + if ($CFG->scorm_validate == 'domxml') { + $manifest_string = file_get_contents($manifest); + + /* Elimino i caratteri speciali di spaziatura e ritorno a capo dal file xml */ + + $spec = array('\n', '\r', '\t', '\0', '\x0B'); + $content = str_replace($spec, '', $manifest_string); + + if ($xmldoc = domxml_open_mem($content)) { + $root = $xmldoc->document_element(); + if (!testRoot($root)) { + return 'syntax'; + } + if (testNode($root)) { + // Nel corpo di questo if si controllano le corrispondenze fra gli attributi + // Nello Standard SCORM ad ogni attributo idRef di deve corrispondere + // un attributo ID di + // Gli array degli attributi sono stati dichiarati globali in validator.php + // pertanto possono essere utilizzati direttamente all'interno di main.php + + foreach($item_idref_array as $elem_it) { + if (array_search($elem_it, $idres_array) === false) { + return 'mismatch'; + } + } + + foreach($def_org_array as $elem_def) { + if (array_search($elem_it, $id_org_array) === false) { + return 'mismatch'; + } + } + + } else { + return 'badmanifest'; + } + } + return 'regular'; + } else { + return 'found'; + } + } } else { - return "nomanifest"; + return 'nomanifest'; } } @@ -264,53 +373,66 @@ function scorm_delete_files($directory) $handle=opendir($directory); while (($file = readdir($handle)) != '') { - if ($file != "." && $file != "..") - { - if (!is_dir($directory."/".$file)) - unlink($directory."/".$file); - else - scorm_delete_files($directory."/".$file); - } + if ($file != '.' && $file != '..') + { + if (!is_dir($directory.'/'.$file)) { + //chmod($directory.'/'.$file,0777); + unlink($directory.'/'.$file); + } else { + scorm_delete_files($directory.'/'.$file); + } + } } rmdir($directory); } } function scorm_startElement($parser, $name, $attrs) { - global $manifest,$i,$resources,$parent,$level; - if ($name == "ITEM") { + global $scoes,$i,$resources,$parent,$level,$organization,$manifest,$defaultorg; + if ($name == 'ITEM') { $i++; - $manifest[$i]["identifier"] = $attrs["IDENTIFIER"]; - if (empty($attrs["IDENTIFIERREF"])) - $attrs["IDENTIFIERREF"] = ""; - $manifest[$i]["identifierref"] = $attrs["IDENTIFIERREF"]; - if (empty($attrs["ISVISIBLE"])) - $attrs["ISVISIBLE"] = ""; - $manifest[$i]["isvisible"] = $attrs["ISVISIBLE"]; - $manifest[$i]["parent"] = $parent[$level]; + $scoes[$i]['manifest'] = $manifest; + $scoes[$i]['organization'] = $organization; + $scoes[$i]['identifier'] = $attrs['IDENTIFIER']; + if (empty($attrs['IDENTIFIERREF'])) + $attrs['IDENTIFIERREF'] = ''; + $scoes[$i]['identifierref'] = $attrs['IDENTIFIERREF']; + if (empty($attrs['ISVISIBLE'])) + $attrs['ISVISIBLE'] = ''; + $scoes[$i]['isvisible'] = $attrs['ISVISIBLE']; + $scoes[$i]['parent'] = $parent[$level]; $level++; - $parent[$level] = $attrs["IDENTIFIER"]; + $parent[$level] = $attrs['IDENTIFIER']; + } + if ($name == 'RESOURCE') { + if (!isset($attrs['HREF'])) { + $attrs['HREF'] = ''; + } + $resources[$attrs['IDENTIFIER']]['href']=$attrs['HREF']; + $resources[$attrs['IDENTIFIER']]['type']=$attrs['ADLCP:SCORMTYPE']; + } + if ($name == 'ORGANIZATION') { + $organization = $attrs['IDENTIFIER']; + } + if ($name == 'MANIFEST') { + $manifest = $attrs['IDENTIFIER']; } - if ($name == "RESOURCE") { - $resources[$attrs["IDENTIFIER"]]["href"]=$attrs["HREF"]; - $resources[$attrs["IDENTIFIER"]]["type"]=$attrs["ADLCP:SCORMTYPE"]; + if ($name == 'ORGANIZATIONS') { + $defaultorg = $attrs['DEFAULT']; } } function scorm_endElement($parser, $name) { - global $manifest,$i,$level,$datacontent,$navigation; - if ($name == "ITEM") { + global $scoes,$i,$level,$datacontent,$navigation; + if ($name == 'ITEM') { $level--; } - if ($name == "TITLE" && $level>0) { - $manifest[$i]["title"] = $datacontent; - } - if ($name == "ADLCP:HIDERTSUI") { - $manifest[$i][$datacontent] = 1; - } - if ($name == "ORGANIZATION") { - $level = 0; - } + if ($name == 'TITLE' && $level>0) + $scoes[$i]['title'] = $datacontent; + if ($name == 'ADLCP:HIDERTSUI') + $scoes[$i][$datacontent] = 1; + if ($name == 'ADLCP:DATAFROMLMS') + $scoes[$i]['datafromlms'] = $datacontent; } function scorm_characterData($parser, $data) { @@ -319,26 +441,28 @@ function scorm_characterData($parser, $data) { } function scorm_parse($basedir,$file,$scorm_id) { - global $manifest,$i,$resources,$parent,$level; - $datacontent = ""; - $manifest[][] = ""; - $resources[] = ""; + global $scoes,$i,$resources,$parent,$level,$defaultorg; + $datacontent = ''; + $scoes[][] = ''; + $resources[] = ''; + $organization = ''; + $defaultorg = ''; $i = 0; $level = 0; - $parent[$level] = "/"; + $parent[$level] = '/'; $xml_parser = xml_parser_create(); // use case-folding so we are sure to find the tag in $map_array xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true); - xml_set_element_handler($xml_parser, "scorm_startElement", "scorm_endElement"); - xml_set_character_data_handler($xml_parser, "scorm_characterData"); - if (!($fp = fopen($basedir.$file, "r"))) { - die("could not open XML input"); + xml_set_element_handler($xml_parser, 'scorm_startElement', 'scorm_endElement'); + xml_set_character_data_handler($xml_parser, 'scorm_characterData'); + if (!($fp = fopen($basedir.$file, 'r'))) { + die('could not open XML input'); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { - die(sprintf("XML error: %s at line %d", + die(sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } @@ -347,45 +471,62 @@ function scorm_parse($basedir,$file,$scorm_id) { $launch = 0; $sco->scorm = $scorm_id; - delete_records("scorm_scoes","scorm",$scorm_id); - delete_records("scorm_sco_users","scormid",$scorm_id); + delete_records('scorm_scoes','scorm',$scorm_id); + delete_records('scorm_sco_users','scormid',$scorm_id); - for ($j=1; $j<=$i; $j++) { - $sco->identifier = $manifest[$j]["identifier"]; - $sco->parent = $manifest[$j]["parent"]; - $sco->title = $manifest[$j]["title"]; - if (!isset($manifest[$j]["datafromlms"])) { - $manifest[$j]["datafromlms"] = ""; - } - $sco->datafromlms = $manifest[$j]["datafromlms"]; + if (isset($scoes[1])) { + for ($j=1; $j<=$i; $j++) { + $sco->identifier = $scoes[$j]['identifier']; + $sco->parent = $scoes[$j]['parent']; + $sco->title = $scoes[$j]['title']; + $sco->organization = $scoes[$j]['organization']; + if (!isset($scoes[$j]['datafromlms'])) { + $scoes[$j]['datafromlms'] = ''; + } + $sco->datafromlms = $scoes[$j]['datafromlms']; - if (!isset($resources[($manifest[$j]["identifierref"])]["href"])) { - $resources[($manifest[$j]["identifierref"])]["href"] = ""; - } - $sco->launch = $resources[($manifest[$j]["identifierref"])]["href"]; + if (!isset($resources[($scoes[$j]['identifierref'])]['href'])) { + $resources[($scoes[$j]['identifierref'])]['href'] = ''; + } + $sco->launch = $resources[($scoes[$j]['identifierref'])]['href']; - if (!isset($resources[($manifest[$j]["identifierref"])]["type"])) { - $resources[($manifest[$j]["identifierref"])]["type"] = ""; - } - $sco->type = $resources[($manifest[$j]["identifierref"])]["type"]; + if (!isset($resources[($scoes[$j]['identifierref'])]['type'])) { + $resources[($scoes[$j]['identifierref'])]['type'] = ''; + } + $sco->type = $resources[($scoes[$j]['identifierref'])]['type']; - if (!isset($manifest[$j]["previous"])) { - $manifest[$j]["previous"] = 0; - } - $sco->previous = $manifest[$j]["previous"]; + if (!isset($scoes[$j]['previous'])) { + $scoes[$j]['previous'] = 0; + } + $sco->previous = $scoes[$j]['previous']; - if (!isset($manifest[$j]["continue"])) { - $manifest[$j]["continue"] = 0; - } - $sco->next = $manifest[$j]["continue"]; + if (!isset($scoes[$j]['continue'])) { + $scoes[$j]['continue'] = 0; + } + $sco->next = $scoes[$j]['continue']; - if (scorm_remove_spaces($manifest[$j]["isvisible"]) != "false") { - $id = insert_record("scorm_scoes",$sco); - } - - if ($launch==0 && $sco->launch) { - $launch = $id; - } + if (scorm_remove_spaces($scoes[$j]['isvisible']) != 'false') { + $id = insert_record('scorm_scoes',$sco); + } + if (($launch==0) && (isset($sco->launch)) && ($defaultorg==$sco->organization)) { + $launch = $id; + } + } + } else { + foreach ($resources as $label => $resource) { + if ((isset($resource['type'])) && ($resource['type'] == 'sco')) { + $sco->identifier = $label; + $sco->title = $label; + $sco->parent = '/'; + $sco->launch = $resource['href']; + $sco->type = $resource['type']; + $id = insert_record('scorm_scoes',$sco); + + if ($launch == 0) { + $launch = $id; + } + } + } } return $launch; } @@ -406,7 +547,7 @@ function scorm_get_scoes_records($sco_user) { function scorm_remove_spaces($sourcestr) { // Remove blank space from a string - $newstr=""; + $newstr=''; for( $i=0; $i$len ) { - return "".substr($stringa,0,$len-4)."...".substr($stringa,strlen($stringa)-1,1).""; + return "".substr($stringa,0,$len-4).'...'.substr($stringa,strlen($stringa)-1,1).''; } else return $stringa; } @@ -427,19 +568,19 @@ function scorm_external_link($link) { // check if a link is external $result = false; $link = strtolower($link); - if (substr($link,0,7) == "http://") + if (substr($link,0,7) == 'http://') $result = true; - else if (substr($link,0,8) == "https://") + else if (substr($link,0,8) == 'https://') $result = true; - else if (substr($link,0,4) == "www.") + else if (substr($link,0,4) == 'www.') $result = true; - /*else if (substr($link,0,7) == "rstp://") + /*else if (substr($link,0,7) == 'rstp://') $result = true; - else if (substr($link,0,6) == "rtp://") + else if (substr($link,0,6) == 'rtp://') $result = true; - else if (substr($link,0,6) == "ftp://") + else if (substr($link,0,6) == 'ftp://') $result = true; - else if (substr($link,0,9) == "gopher://") + else if (substr($link,0,9) == 'gopher://') $result = true; */ return $result; } diff --git a/mod/scorm/mod.html b/mod/scorm/mod.html index 582c3a5583..8ad4671845 100755 --- a/mod/scorm/mod.html +++ b/mod/scorm/mod.html @@ -61,6 +61,8 @@ + + diff --git a/mod/scorm/playscorm.php b/mod/scorm/playscorm.php index 14939c65ef..a2ad50b378 100755 --- a/mod/scorm/playscorm.php +++ b/mod/scorm/playscorm.php @@ -68,9 +68,13 @@ // // Print the page header // + $bodyscripts = ""; + if ($scorm->popup != "") { + $bodyscripts = "onLoad='SCOInitialize();' onUnload='API.SaveTotalTime(); closeMain();' onbeforeUnload='API.SaveTotalTime();'"; + } 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')); + "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top'),"",$bodyscripts); echo "

:

+ 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); ?>
\n \n"; if ($mode == "browse") @@ -241,15 +245,6 @@ \n"; echo "\n
".text_to_html($scorm->summary, true, false)."
\n"; - - if ($scorm->popup != "") { - ?> - - \n\n"; } else { if ($scorm->popup == "") { @@ -259,7 +254,7 @@ echo "\n"; echo "$course->shortname: $scorm->name\n"; echo "\n"; - echo "scorm_framesize,*\" onLoad=\"SCOInitialize();\">\n"; + echo "scorm_framesize,*\" onLoad=\"SCOInitialize();\" onUnload=\"API.SaveTotalTime();\" onbeforeUnload=\"API.SaveTotalTime();\">\n"; echo "\t id&mode=".$mode."&frameset=top\">\n"; echo "\t \n"; echo "\n"; diff --git a/mod/scorm/report.php b/mod/scorm/report.php index 42c7a43b81..ca0bc7a66f 100755 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -79,8 +79,12 @@ foreach ($sco_users as $sco_user) { $user_data=scorm_get_scoes_records($sco_user); - $picture = print_user_picture($sco_user->userid, $course->id, $user_data->picture, false, true); - $row=""; + $userpict = ""; + if (isset($user_data->picture)) { + $userpict = $user_data->picture; + } + $picture = print_user_picture($sco_user->userid, $course->id, $userpict, false, true); + $row=""; $row[] = $picture; if (is_array($user_data)) { $data = current($user_data); @@ -98,7 +102,7 @@ .$data->cmi_core_total_time.$scoreview; } } - $table->data[] = $row; + $table->data[] = $row; } print_table($table); diff --git a/mod/scorm/restorelib.php b/mod/scorm/restorelib.php index bb8f41d528..f3e20f6187 100755 --- a/mod/scorm/restorelib.php +++ b/mod/scorm/restorelib.php @@ -47,6 +47,8 @@ $scorm->course = $restore->course_id; $scorm->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); $scorm->reference = backup_todb($info['MOD']['#']['REFERENCE']['0']['#']); + $scorm->reference = backup_todb($info['MOD']['#']['MAXGRADE']['0']['#']); + $scorm->reference = backup_todb($info['MOD']['#']['GRADEMETHOD']['0']['#']); $scorm->datadir = backup_todb($info['MOD']['#']['DATADIR']['0']['#']); $scorm->launch = backup_todb($info['MOD']['#']['LAUNCH']['0']['#']); $scorm->summary = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']); @@ -110,11 +112,14 @@ //Now, build the scorm_scoes record structure $sco->scorm = $scorm_id; + $sco->manifest = backup_todb($sub_info['#']['MANIFEST']['0']['#']); + $sco->organization = backup_todb($sub_info['#']['ORGANIZATION']['0']['#']); $sco->parent = backup_todb($sub_info['#']['PARENT']['0']['#']); $sco->identifier = backup_todb($sub_info['#']['IDENTIFIER']['0']['#']); $sco->launch = backup_todb($sub_info['#']['LAUNCH']['0']['#']); $sco->type = backup_todb($sub_info['#']['TYPE']['0']['#']); $sco->title = backup_todb($sub_info['#']['TITLE']['0']['#']); + $sco->datafromlms = backup_todb($sub_info['#']['DATAFROMLMS']['0']['#']); $sco->next = backup_todb($sub_info['#']['NEXT']['0']['#']); $sco->previous = backup_todb($sub_info['#']['PREVIOUS']['0']['#']); @@ -173,7 +178,6 @@ $sco_user->cmi_core_session_time = backup_todb($sub_info['#']['CMI_CORE_SESSION_TIME']['0']['#']); $sco_user->cmi_core_score_raw = backup_todb($sub_info['#']['CMI_CORE_SCORE_RAW']['0']['#']); $sco_user->cmi_suspend_data = backup_todb($sub_info['#']['CMI_SUSPEND_DATA']['0']['#']); - $sco_user->cmi_launch_data = backup_todb($sub_info['#']['CMI_LAUNCH_DATA']['0']['#']); //We have to recode the userid field $user = backup_getid($restore->backup_unique_code,"user",$sco_user->userid); diff --git a/mod/scorm/scormAPI.php b/mod/scorm/scormAPI.php index f5d6403041..5d43cebed6 100755 --- a/mod/scorm/scormAPI.php +++ b/mod/scorm/scormAPI.php @@ -177,17 +177,30 @@ function SCOInitialize() { echo "\t top.main.location=\"$result\";\n"; echo "\t hilightcurrent(".$navObj."document.navform.courseStructure);\n"; } else { - echo "\t top.main = window.open('$result','main','$scorm->popup');\n"; + $popuplocation = ''; + if (isset($_COOKIE["SCORMpopup"])) { + $popuplocation = $_COOKIE["SCORMpopup"]; + } + echo "\t top.main = window.open('$result','main','$scorm->popup$popuplocation');\n"; } ?> } function changeSco(direction) { - if (direction == "previous") - document.navform.scoid.value=""; - else - document.navform.scoid.value=""; + if (direction == "previous") + document.navform.scoid.value=""; + else + document.navform.scoid.value=""; - //alert ("Prev: \nNext: \nNew SCO: "+document.navform.scoid.value); - document.navform.submit(); -} \ No newline at end of file + //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/version.php b/mod/scorm/version.php index 955095ade5..2d4e9034ec 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 = 2004070800; // The (date) version of this module +$module->version = 2004071900; // The (date) version of this module $module->requires = 2004051600; // The version of Moodle that is required $module->cron = 0; // How often should cron check this module (seconds)?