Some bug fixes, added new score view (thanks Matt) and added a new validation procedure

This commit is contained in:
bobopinna 2004-07-19 14:53:43 +00:00
parent 485913f784
commit 1a12b1f1d1
16 changed files with 487 additions and 235 deletions

View File

@ -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 (<?php echo $navObj ?>cmi.document.theform) {
cmiform = <?php echo $navObj ?>cmi.document.forms[0];
cmiform.scoid.value = "<?php echo $sco->id; ?>";
cmiform.cmi_core_total_time.value = cmi.core.total_time;
cmiform.submit();
}
if (nav.event != "") {
<?php
if ($sco != $last) {
@ -344,19 +336,13 @@ function SCORMapi() {
var change = 0;
var secs = (Math.round((parseFloat(sFirst[2],10)+parseFloat(sSecond[2],10))*100))/100; //Seconds
if (secs > 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 (<?php echo $navObj ?>cmi.document.forms[0]) {
cmiform = <?php echo $navObj ?>cmi.document.forms[0];
cmiform.reset();
cmiform.scoid.value = "<?php echo $sco->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;

View File

@ -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));
}

View File

@ -1,55 +1,61 @@
<?php
require_once("../../config.php");
require_once("lib.php");
require_once('../../config.php');
require_once('lib.php');
optional_variable($id); // Course Module ID, or
optional_variable($a); // scorm ID
if ($id) {
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
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 (! $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 @@
<input type="hidden" name="cmi_core_lesson_location" />
<input type="hidden" name="cmi_core_lesson_status" />
<input type="hidden" name="cmi_core_exit" />
<input type="hidden" name="cmi_core_session_time" />
<input type="hidden" name="cmi_core_total_time" />
<input type="hidden" name="cmi_core_score_raw" />
<input type="hidden" name="cmi_suspend_data" />
</form>
</body>
</html>

View File

@ -1,6 +1,25 @@
<form method="post" action="module.php" name="form">
<table cellpadding=9 cellspacing=0 >
<tr valign=top>
<td align=right><p>scorm_validate:</td>
<td>
<?php
unset($choices);
$choices[""] = get_string("none");
if (extension_loaded('domxml')) {
$choices["domxml"] = get_string("domxml","scorm");
}
if (version_compare(phpversion(),"5.0.0",">=")) {
$choices["php5"] = get_string("php5","scorm");
}
choose_from_menu ($choices, "scorm_validate", $CFG->scorm_validate, "");
?>
</td>
<td>
<?php print_string("validationtype", "scorm") ?>
</td>
</tr>
<tr valign=top>
<td align=right><p>scorm_framesize:</td>
<td>
@ -43,7 +62,8 @@
?>
<tr>
<td colspan=3 align=center>
<input type="submit" value="<?php print_string("savechanges") ?>"></td>
<input type="submit" value="<?php print_string("savechanges") ?>">
</td>
</tr>
</table>

View File

@ -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;
}

View File

@ -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 '',

View File

@ -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;
}

View File

@ -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 '',

View File

@ -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 " <tr><td align=\"right\" nowrap><p><b>$strname:</b></p></td><td><p>$form->name</p></a></td></tr>\n";
echo " <tr><td align=\"right\" nowrap><p><b>".get_string("validation","scorm").":</b></p></td><td><p>".get_string($result,"scorm")."</p></a></td></tr>\n";
if ($errorlogs != '') {
//$lines = round(count($error_array)/4);
//echo " <tr><td align=\"right\" nowrap><p><b>".get_string("errorlogs","scorm").":</b></p></td><td><textarea rows=\"".$lines."\" readonly>".$errorlogs."</textarea></a></td></tr>\n";
$lines = round(count($errors)/4);
if ($lines < 5) {
$lines = 5;
}
echo " <tr><td align=\"right\" nowrap><p><b>".get_string("errorlogs","scorm").":</b></p></td><td><textarea rows=\"".$lines."\" cols=\"30\" readonly>".$errorlogs."</textarea></a></td></tr>\n";
}
if (($form->mode == "update") && ($form->launch == 0) && (get_records("scorm_sco_users","scormid",$form->instance)))
echo " <tr><td align=\"center\" colspan=\"2\" nowrap><p><b>".get_string("trackingloose","scorm")."</b></p></td></tr>\n";
echo "</table>\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 "<form name=\"theform\" method=\"post\" action=\"$form->destination\">\n";
//$form->popup = $CFG->scorm_popup;
@ -139,12 +150,39 @@
?>
<table cellpadding="5" align="center">
<tr valign=top>
<td align=right><p><b><?php print_string("grademethod", "scorm") ?>:</b></p></td>
<td>
<?php
$options = array();
$options[0] = get_string("gradescoes", "scorm");
$options[1] = get_string("gradehighest", "scorm");
$options[2] = get_string("gradeaverage", "scorm");
choose_from_menu($SCORM_GRADE_METHOD, "grademethod", "$form->grademethod", "");
helpbutton("grademethod", get_string("grademethod","scorm"), "scorm");
?>
</td>
</tr>
<tr valign=top>
<td align=right><p><b><?php print_string("maximumgrade") ?>:</b></p></td>
<td>
<?php
for ($i=100; $i>=1; $i--) {
$grades[$i] = $i;
}
choose_from_menu($grades, "maxgrade", "$form->maxgrade", "");
helpbutton("maxgrade", get_string("maximumgrade"), "scorm");
?>
</td>
</tr>
<tr valign=top>
<td align=right><p><b><?php print_string("autocontinue","scorm") ?>:</b></p></td>
<td>
<?php
$options[]=get_string("no");
$options[]=get_string("yes");
$options = array();
$options[0]=get_string("no");
$options[1]=get_string("yes");
choose_from_menu ($options, "auto", $form->auto);
?>
</td>

View File

@ -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;
}
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")) {
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'");
$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="";
$result='';
$data = current($user_data);
foreach ($user_data as $data) {
if ($data->cmi_core_lesson_status=="passed")
if ($data->cmi_core_lesson_status=='passed')
$scores->completed++;
else
$scores->{scorm_remove_spaces($data->cmi_core_lesson_status)}++;
}
if ($scores->completed)
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/completed.gif\" alt=\"".get_string("completed","scorm")."\" title=\"".get_string("completed","scorm")."\"> $scores->completed ";
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/completed.gif\" alt=\"".get_string('completed','scorm')."\" title=\"".get_string('completed','scorm')."\"> $scores->completed ";
if ($scores->incomplete)
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/incomplete.gif\" alt=\"".get_string("incomplete","scorm")."\" title=\"".get_string("incomplete","scorm")."\"> $scores->incomplete ";
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/incomplete.gif\" alt=\"".get_string('incomplete','scorm')."\" title=\"".get_string('incomplete','scorm')."\"> $scores->incomplete ";
if ($scores->failed)
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/failed.gif\" alt=\"".get_string("failed","scorm")."\" title=\"".get_string("failed","scorm")."\"> $scores->failed ";
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/failed.gif\" alt=\"".get_string('failed','scorm')."\" title=\"".get_string('failed','scorm')."\"> $scores->failed ";
if ($scores->browsed)
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/browsed.gif\" alt=\"".get_string("browsed","scorm")."\" title=\"".get_string("browsed","scorm")."\"> $scores->browsed ";
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/browsed.gif\" alt=\"".get_string('browsed','scorm')."\" title=\"".get_string('browsed','scorm')."\"> $scores->browsed ";
if ($scores->notattempted)
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" title=\"".get_string("notattempted","scorm")."\"> $scores->notattempted ";
$result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/notattempted.gif\" alt=\"".get_string('notattempted','scorm')."\" title=\"".get_string('notattempted','scorm')."\"> $scores->notattempted ";
$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 <item> deve corrispondere
// un attributo ID di <resource>
// 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,12 +373,14 @@ function scorm_delete_files($directory)
$handle=opendir($directory);
while (($file = readdir($handle)) != '')
{
if ($file != "." && $file != "..")
if ($file != '.' && $file != '..')
{
if (!is_dir($directory."/".$file))
unlink($directory."/".$file);
else
scorm_delete_files($directory."/".$file);
if (!is_dir($directory.'/'.$file)) {
//chmod($directory.'/'.$file,0777);
unlink($directory.'/'.$file);
} else {
scorm_delete_files($directory.'/'.$file);
}
}
}
rmdir($directory);
@ -277,40 +388,51 @@ function scorm_delete_files($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") {
$resources[$attrs["IDENTIFIER"]]["href"]=$attrs["HREF"];
$resources[$attrs["IDENTIFIER"]]["type"]=$attrs["ADLCP:SCORMTYPE"];
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 == '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,46 +471,63 @@ 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);
if (isset($scoes[1])) {
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->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 = $manifest[$j]["datafromlms"];
$sco->datafromlms = $scoes[$j]['datafromlms'];
if (!isset($resources[($manifest[$j]["identifierref"])]["href"])) {
$resources[($manifest[$j]["identifierref"])]["href"] = "";
if (!isset($resources[($scoes[$j]['identifierref'])]['href'])) {
$resources[($scoes[$j]['identifierref'])]['href'] = '';
}
$sco->launch = $resources[($manifest[$j]["identifierref"])]["href"];
$sco->launch = $resources[($scoes[$j]['identifierref'])]['href'];
if (!isset($resources[($manifest[$j]["identifierref"])]["type"])) {
$resources[($manifest[$j]["identifierref"])]["type"] = "";
if (!isset($resources[($scoes[$j]['identifierref'])]['type'])) {
$resources[($scoes[$j]['identifierref'])]['type'] = '';
}
$sco->type = $resources[($manifest[$j]["identifierref"])]["type"];
$sco->type = $resources[($scoes[$j]['identifierref'])]['type'];
if (!isset($manifest[$j]["previous"])) {
$manifest[$j]["previous"] = 0;
if (!isset($scoes[$j]['previous'])) {
$scoes[$j]['previous'] = 0;
}
$sco->previous = $manifest[$j]["previous"];
$sco->previous = $scoes[$j]['previous'];
if (!isset($manifest[$j]["continue"])) {
$manifest[$j]["continue"] = 0;
if (!isset($scoes[$j]['continue'])) {
$scoes[$j]['continue'] = 0;
}
$sco->next = $manifest[$j]["continue"];
$sco->next = $scoes[$j]['continue'];
if (scorm_remove_spaces($manifest[$j]["isvisible"]) != "false") {
$id = insert_record("scorm_scoes",$sco);
if (scorm_remove_spaces($scoes[$j]['isvisible']) != 'false') {
$id = insert_record('scorm_scoes',$sco);
}
if ($launch==0 && $sco->launch) {
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<strlen($sourcestr); $i++) {
if ($sourcestr[$i]!=' ')
$newstr .=$sourcestr[$i];
@ -418,7 +559,7 @@ function scorm_string_round($stringa) {
// Crop a string to $len character and set an anchor title to the full string
$len=11;
if ( strlen($stringa)>$len ) {
return "<A name=\"\" title=\"$stringa\">".substr($stringa,0,$len-4)."...".substr($stringa,strlen($stringa)-1,1)."</A>";
return "<A name=\"\" title=\"$stringa\">".substr($stringa,0,$len-4).'...'.substr($stringa,strlen($stringa)-1,1).'</A>';
} 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;
}

View File

@ -61,6 +61,8 @@
<input type="hidden" name=launch value="<?php p($form->launch) ?>">
<input type="hidden" name=popup value="<?php p($form->popup) ?>">
<input type="hidden" name=auto value="<?php p($form->auto) ?>">
<input type="hidden" name="maxgrade" value="<?php p($form->maxgrade) ?>" />
<input type="hidden" name="grademethod" value="<?php p($form->grademethod) ?>" />
<input type="hidden" name=section value="<?php p($form->section) ?>">
<input type="hidden" name=module value="<?php p($form->module) ?>">
<input type="hidden" name=modulename value="<?php p($form->modulename) ?>">

View File

@ -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 <a target=\"{$CFG->framename}\" href=\"view.php?id=$cm->id\" title=\"$scorm->summary\">$scorm->name</a>",
"", "", 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 "<table width=\"100%\">\n <tr><td align=\"center\">".text_to_html($scorm->summary, true, false)."</td>\n";
if ($mode == "browse")
@ -241,15 +245,6 @@
</td>\n";
echo "</tr>\n</table>\n";
if ($scorm->popup != "") {
?>
<script language="Javascript">
SCOInitialize();
</script>
<?php
}
echo "</body>\n</html>\n";
} else {
if ($scorm->popup == "") {
@ -259,7 +254,7 @@
echo "<html>\n";
echo "<head><title>$course->shortname: $scorm->name</title></head>\n";
echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&mode=".$mode.$scoid."\"></script>\n";
echo "<frameset rows=\"$CFG->scorm_framesize,*\" onLoad=\"SCOInitialize();\">\n";
echo "<frameset rows=\"$CFG->scorm_framesize,*\" onLoad=\"SCOInitialize();\" onUnload=\"API.SaveTotalTime();\" onbeforeUnload=\"API.SaveTotalTime();\">\n";
echo "\t <frame name=\"navigation\" src=\"playscorm.php?id=$cm->id&mode=".$mode."&frameset=top\">\n";
echo "\t <frame name=\"main\" src=\"\">\n";
echo "</frameset>\n";

View File

@ -79,7 +79,11 @@
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);
$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)) {

View File

@ -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);

View File

@ -177,7 +177,11 @@ 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";
}
?>
}
@ -191,3 +195,12 @@ function changeSco(direction) {
//alert ("Prev: <?php echo $prevsco; ?>\nNext: <?php echo $nextsco; ?>\nNew SCO: "+<?php echo $navObj ?>document.navform.scoid.value);
<?php echo $navObj ?>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();
}

View File

@ -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)?