Fixed a problem during scorm update.

Now only the lost scoes tracks are deleted
Added support to IMS CP repository
This commit is contained in:
bobopinna 2006-08-11 12:26:06 +00:00
parent 57f4a71feb
commit 5c1ac70c63
5 changed files with 469 additions and 345 deletions

View File

@ -47,6 +47,12 @@ if (!isset($CFG->scorm_framewidth)) {
set_config('scorm_framewidth','100%');
}
//
// Repository configurations
//
$repositoryconfigfile = $CFG->dirroot.'/mod/resource/type/ims/repository_config.php';
$repositorybrowser = '/mod/resource/type/ims/finder.php';
/**
* Given an object containing all the necessary data,
* (defined by the form in mod.html) this function
@ -73,14 +79,14 @@ function scorm_add_instance($scorm) {
$id = insert_record('scorm', $scorm);
if (basename($scorm->reference) != 'imsmanifest.xml') {
if ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) {
// Rename temp scorm dir to scorm id
$scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id);
}
// Parse scorm manifest
if ($scorm->launch == 0) {
if ($scorm->parse == 1) {
require_once('locallib.php');
$scorm->id = $id;
$scorm->launch = scorm_parse($scorm);
@ -111,34 +117,29 @@ function scorm_update_instance($scorm) {
$scorm->height = str_replace('%','',$scorm->height);
// Check if scorm manifest needs to be reparsed
if ($scorm->launch == 0) {
//$f = "D:\\test.txt";
//@$ft = fopen($f,"a");
//fwrite($ft,"\n Xu ly trong update trong lib.php \n");
//fwrite($ft,"\n Lauch co gia tri \n".($scorm->launch));
// Delete old related records
delete_records('scorm_scoes','scorm',$scorm->id);
delete_records('scorm_scoes_track','scormid',$scorm->id);
delete_records('scorm_sequencing_controlmode','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprules','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprule','scormid',$scorm->id);
delete_records('scorm_sequencing_rollupruleconditions','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprulecondition','scormid',$scorm->id);
delete_records('scorm_sequencing_ruleconditions','scormid',$scorm->id);
delete_records('scorm_sequencing_rulecondition','scormid',$scorm->id);
if ($scorm->parse == 1) {
require_once('locallib.php');
$scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) && (basename($scorm->reference) != 'imsmanifest.xml')) {
if (is_dir($scorm->dir.'/'.$scorm->id)) {
scorm_delete_files($scorm->dir.'/'.$scorm->id);
}
if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) &&
(basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) {
rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id);
}
require_once('locallib.php');
/* // Delete old related records
delete_records('scorm_scoes','scorm',$scorm->id);
delete_records('scorm_scoes_track','scormid',$scorm->id);
delete_records('scorm_sequencing_controlmode','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprules','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprule','scormid',$scorm->id);
delete_records('scorm_sequencing_rollupruleconditions','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprulecondition','scormid',$scorm->id);
delete_records('scorm_sequencing_ruleconditions','scormid',$scorm->id);
delete_records('scorm_sequencing_rulecondition','scormid',$scorm->id);
*/
$scorm->launch = scorm_parse($scorm);
}
return update_record('scorm', $scorm);
}
@ -161,6 +162,7 @@ function scorm_delete_instance($id) {
$result = true;
// Delete any dependent files
require_once('locallib.php');
scorm_delete_files($CFG->dataroot.'/'.$scorm->course.'/moddata/scorm/'.$scorm->id);
// Delete any dependent records
@ -220,8 +222,8 @@ function scorm_user_outline($course, $user, $mod, $scorm) {
require_once('locallib.php');
foreach ($scoes as $sco) {
if ($sco->launch!='') {
$scores->count++;
if ($userdata = scorm_get_tracks($sco->id, $user->id)) {
$scores->count++;
if ($userdata = scorm_get_tracks($sco->id, $user->id)) {
if (!isset($scores->{$userdata->status})) {
$scores->{$userdata->status} = 1;
} else {
@ -240,7 +242,7 @@ function scorm_user_outline($course, $user, $mod, $scorm) {
}
switch ($scorm->grademethod) {
case GRADEHIGHEST:
if ($scores->values > 0) {
if ($scores->values > 0) {
$return->info = get_string('score','scorm').': '.$scores->max;
$return->time = $scores->lastmodify;
}
@ -261,30 +263,30 @@ function scorm_user_outline($course, $user, $mod, $scorm) {
$return->info = '';
$scores->notattempted = $scores->count;
if (isset($scores->completed)) {
$return->info .= get_string('completed','scorm').':&nbsp;'.$scores->completed.'<br />';
$return->info .= get_string('completed','scorm').':&nbsp;'.$scores->completed.'<br />';
$scores->notattempted -= $scores->completed;
}
if (isset($scores->passed)) {
$return->info .= get_string('passed','scorm').':&nbsp;'.$scores->passed.'<br />';
$return->info .= get_string('passed','scorm').':&nbsp;'.$scores->passed.'<br />';
$scores->notattempted -= $scores->passed;
}
if (isset($scores->failed)) {
$return->info .= get_string('failed','scorm').':&nbsp;'.$scores->failed.'<br />';
$return->info .= get_string('failed','scorm').':&nbsp;'.$scores->failed.'<br />';
$scores->notattempted -= $scores->failed;
}
if (isset($scores->incomplete)) {
$return->info .= get_string('incomplete','scorm').':&nbsp;'.$scores->incomplete.'<br />';
$return->info .= get_string('incomplete','scorm').':&nbsp;'.$scores->incomplete.'<br />';
$scores->notattempted -= $scores->incomplete;
}
if (isset($scores->browsed)) {
$return->info .= get_string('browsed','scorm').':&nbsp;'.$scores->browsed.'<br />';
$return->info .= get_string('browsed','scorm').':&nbsp;'.$scores->browsed.'<br />';
$scores->notattempted -= $scores->browsed;
}
$return->time = $scores->lastmodify;
if ($return->info == '') {
$return = NULL;
} else {
$return->info .= get_string('notattempted','scorm').':&nbsp;'.$scores->notattempted.'<br />';
$return->info .= get_string('notattempted','scorm').':&nbsp;'.$scores->notattempted.'<br />';
}
break;
}
@ -473,7 +475,7 @@ function scorm_grades($scormid) {
return NULL;
}
if ($scorm->grademethod == VALUESCOES) {
if ($scorm->grademethod == GRADESCOES) {
if (!$return->maxgrade = count_records_select('scorm_scoes',"scorm='$scormid' AND launch<>''")) {
return NULL;
}
@ -499,54 +501,6 @@ function scorm_get_post_actions() {
return array();
}
/**
* This function will permanently delete the given
* directory and all files and subdirectories.
*
* @param string $directory The directory to remove
* @return boolean
*/
function scorm_delete_files($directory) {
if (is_dir($directory)) {
$files=scorm_scandir($directory);
foreach($files as $file) {
if (($file != '.') && ($file != '..')) {
if (!is_dir($directory.'/'.$file)) {
unlink($directory.'/'.$file);
} else {
scorm_delete_files($directory.'/'.$file);
}
}
set_time_limit(5);
}
rmdir($directory);
return true;
}
return false;
}
/**
* Given a diretory path returns the file list
*
* @param string $directory
* @return array
*/
function scorm_scandir($directory) {
if (version_compare(phpversion(),'5.0.0','>=')) {
return scandir($directory);
} else {
$files = array();
if ($dh = opendir($directory)) {
while (($file = readdir($dh)) !== false) {
$files[] = $file;
}
closedir($dh);
}
return $files;
}
}
function scorm_option2text($scorm) {
global $SCORM_POPUP_OPTIONS;
@ -571,4 +525,4 @@ function scorm_option2text($scorm) {
return $scorm;
}
?>
?>

View File

@ -1,10 +1,10 @@
<?php
require_once("../../config.php");
require_once('locallib.php');
$id = optional_param('id', '', PARAM_INT); // Course Module ID, or
$a = optional_param('a', '', PARAM_INT); // scorm ID
$scoid = required_param('scoid', PARAM_INT); // sco ID
$scoid = required_param('scoid', PARAM_INT); // sco ID
if (!empty($id)) {
if (! $cm = get_coursemodule_from_id('scorm', $id)) {
@ -33,11 +33,11 @@
require_login($course->id, false, $cm);
if (!empty($scoid)) {
//
// Dinh huong yeu cau cua SCO
// Direct SCO request
//
if ($sco = get_record("scorm_scoes","id",$scoid)) {
if ($sco->launch == '') {
// Tim kiem SCO co the trien khai tiep theo
// Search for the next launchable sco
if ($scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' AND id>".$sco->id,"id ASC")) {
$sco = current($scoes);
}
@ -79,6 +79,9 @@
if (scorm_external_link($sco->launch)) {
$result = $launcher;
} else if ($scorm->reference[0] == '#') {
require_once($repositoryconfigfile);
$result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
} else {
if (basename($scorm->reference) == 'imsmanifest.xml') {
$basedir = dirname($scorm->reference);

View File

@ -5,226 +5,62 @@ define("VALUEHIGHEST",1);
define("VALUEAVERAGE",2);
define("VALUESUM",3);
// Functions added by Pham Minh Duc
function scorm_get_score_from_parent($sco,$userid,$grademethod=VALUESCOES) {
$scores = NULL;
$scores->scoes = 0;
$scores->values = 0;
$scores->scaled = 0;
$scores->max = 0;
$scores->sum = 0;
//
// Repository configurations
//
$repositoryconfigfile = $CFG->dirroot.'/mod/resource/type/ims/repository_config.php';
$repositorybrowser = '/mod/resource/type/ims/finder.php';
$scoes_total = 0;
$scoes_count = 0;
$attempt = scorm_get_last_attempt($sco->scorm, $userid);
$scoes = get_records('scorm_scoes', 'parent', $sco->identifier);
foreach ($scoes as $sco)
{
$scoes_total++;
if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
$scoes_count++;
}
$scoreraw = $userdata->score_raw;
if (!empty($userdata->score_raw)) {
$scores->values++;
$scores->sum += $userdata->score_raw;
$scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
}
if (!empty($userdata->score_scaled)) {
$scores->scaled = $scores->scaled + $userdata->score_scaled;
}
}
}
if ($scoes_count > 0) {
$scores->scaled = ($scores->scaled)/($scoes_count);
}
switch ($grademethod) {
case VALUEHIGHEST:
return $scores->max;
break;
case VALUEAVERAGE:
if ($scores->values > 0) {
return $scores->sum/$scores->values;
} else {
return 0;
}
break;
case VALUESUM:
return $scores->sum;
break;
case VALUESCOES:
return $scores->scaled;
break;
}
}
function scorm_get_user_sco_count($scormid, $userid) {
$scoes_count = 0;
$attempt = scorm_get_last_attempt($current->scorm, $userid);
$scoes = get_records('scorm_scoes', 'scorm', $scormid);
foreach ($scoes as $sco) {
if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
$scoes_count++;
}
}
}
return $scoes_count;
}
function scorm_grade_user_new($scoes, $userid, $grademethod=VALUESCOES) {
$scores = NULL;
$scores->scoes = 0;
$scores->values = 0;
$scores->scaled = 0;
$scores->max = 0;
$scores->sum = 0;
if (!$scoes) {
return '';
}
$current = current($scoes);
$attempt = scorm_get_last_attempt($current->scorm, $userid);
foreach ($scoes as $sco) {
if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
$scores->scoes++;
}
$scaled = $userdata->score_scaled;
$scoreraw = $userdata->score_raw;
if ($scaled ==0){
$scores->scaled = $scores->scaled / $scores->scoes;
}
if (!empty($userdata->score_raw)) {
$scores->values++;
$scores->sum += $userdata->score_raw;
$scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
}
if (!empty($scaled)) {
$scores->scaled = (($scores->scaled) * ($scores->scoes-1) + $scaled)/($scores->scoes);
}
}
}
switch ($grademethod) {
case VALUEHIGHEST:
return $scores->max;
break;
case VALUEAVERAGE:
if ($scores->values > 0) {
return $scores->sum/$scores->values;
} else {
return 0;
}
break;
case VALUESUM:
return $scores->sum;
break;
case VALUESCOES:
return $scores->scaled;
break;
}
}
function scorm_insert_statistic($statisticInput){
$id = null;
if ($statistic = get_record_select('scorm_statistic',"userid='$statisticInput->userid' AND scormid='$statisticInput->scormid'")) {
$statistic->durationtime = $statisticInput->duration;
$statistic->accesstime = $statisticInput->accesstime;
$statistic->status = $statisticInput->status;
$statistic->attemptnumber = $statisticInput->attemptnumber;
$id = update_record('scorm_statistic',$statistic);
} else {
$id = insert_record('scorm_statistic',$statisticInput);
}
return $id;
}
function scorm_insert_trackmodel($userid,$scormid,$scoid,$attempt) {
$id = null;
if ($suspendtrack = get_record_select('scorm_suspendtrack',"userid='$userid' AND scormid='$scormid'")) {
$suspendtrack->suspendscoid = $scoid;
$suspendtrack->attempt = $attempt;
$id = update_record('scorm_suspendtrack',$suspendtrack);
} else {
$suspendtrack->scormid = $scormid;
$suspendtrack->suspendscoid = $scoid;
$suspendtrack->userid = $userid;
$suspendtrack->attempt = $attempt;
$id = insert_record('scorm_suspendtrack',$suspendtrack);
}
return $id;
}
function scorm_get_suspendscoid($scormid,$userid) {
if ($sco = get_record("scorm_suspendtrack","scormid",$scormid,"userid",$userid)) {
$suspendscoid = $sco->suspendscoid;
return $suspendscoid;
} else {
return 0;
}
}
function scorm_set_attempt($scoid,$userid) {
if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) {
$attempt = scorm_get_last_attempt($scormid,$userid);
} else {
$attempt = 1;
}
$scormtype = get_field('scorm_scoes','scormtype','id',$scoid) ;
if ($scormtype == 'sco'){
$element = 'cmi.attempt_status';
$value = 'attempted';
scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value);
}
}
function scorm_get_AbsoluteTimeLimit($scoid){
$sco = get_record("scorm_scoes","id",$scoid);
if (!empty($sco)){
return $sco->attemptAbsoluteDurationLimit;
}
return 0;
}
function scorm_update_status($scormid,$scoid)
{
}
function scorm_get_nextsco($scormid,$scoid)
{
}
function scorm_get_presco($scormid,$scoid)
{
}
function scorm_isChoice($scormid,$scoid)
{
$sco = get_record("scorm_sequencing_controlmode","scormid",$scormid,"scoid",$scoid);
$scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);
return $scoparent->choice;
}
function scorm_isChoiceexit($scormid,$scoid)
{
$sco = get_record("scorm_sequencing_controlmode","scormid",$scormid,"scoid",$scoid);
$scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);
return $scoparent->choiceexit;
}
// End add
/// Local Library of functions and constants for module scorm
/**
* This function will permanently delete the given
* directory and all files and subdirectories.
*
* @param string $directory The directory to remove
* @return boolean
*/
function scorm_delete_files($directory) {
if (is_dir($directory)) {
$files=scorm_scandir($directory);
foreach($files as $file) {
if (($file != '.') && ($file != '..')) {
if (!is_dir($directory.'/'.$file)) {
unlink($directory.'/'.$file);
} else {
scorm_delete_files($directory.'/'.$file);
}
}
set_time_limit(5);
}
rmdir($directory);
return true;
}
return false;
}
/**
* Given a diretory path returns the file list
*
* @param string $directory
* @return array
*/
function scorm_scandir($directory) {
if (version_compare(phpversion(),'5.0.0','>=')) {
return scandir($directory);
} else {
$files = array();
if ($dh = opendir($directory)) {
while (($file = readdir($dh)) !== false) {
$files[] = $file;
}
closedir($dh);
}
return $files;
}
}
/**
* Create a new temporary subdirectory with a random name in the given path
*
@ -267,7 +103,6 @@ function scorm_datadir($strPath)
* @return mixed
*/
function scorm_validate($packagedir) {
$validation = new stdClass();
if (is_file($packagedir.'/imsmanifest.xml')) {
$validation->result = 'found';
@ -645,8 +480,10 @@ function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='n
$attempt = scorm_get_last_attempt($scorm->id, $user->id);
}
$result->attemptleft = $scorm->maxattempt - $attempt;
if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
//
// Retrieve user tracking data for each learning object
//
$usertracks = array();
foreach ($scoes as $sco) {
if (!empty($sco->launch)) {
@ -716,6 +553,7 @@ function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='n
if (empty($scoid) && ($mode != 'normal')) {
$scoid = $sco->id;
}
// Modified by Pham Minh Duc
if ($suspendscoid == $sco->id){
$result->toc .= '<img src="'.$scormpixdir.'/suspend.gif" alt="Dang tam dung o day" title="Dang dung o day" />';
} else {
@ -745,6 +583,7 @@ function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='n
}
}
}
// End Modify
if ($sco->id == $scoid) {
$startbold = '<b>';
$endbold = '</b>';
@ -921,23 +760,29 @@ function scorm_get_tracks($scoid,$userid,$attempt='') {
}
}
//-----------------------------------------------------
/// Library of functions and constants for parsing packages
function scorm_parse($scorm) {
global $CFG;
global $CFG,$repositoryconfigfile;
// Parse scorm manifest
if ($scorm->pkgtype == 'AICC') {
$scorm->launch = scorm_parse_aicc($scorm->dir.'/'.$scorm->id,$scorm->id);
} else {
if (basename($scorm->reference) != 'imsmanifest.xml') {
$reference = $scorm->reference;
if ($scorm->reference[0] == '#') {
require_once($repositoryconfigfile);
$reference = $CFG->repository.substr($scorm->reference,1).'/imsmanifest.xml';
} else if (substr($reference,0,7) != 'http://') {
$reference = $CFG->dataroot.'/'.$scorm->course.'/'.$scorm->reference;
}
if (basename($reference) != 'imsmanifest.xml') {
$scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id);
} else {
$scorm->launch = scorm_parse_scorm($CFG->dataroot.'/'.$scorm->course.'/'.dirname($scorm->reference),$scorm->id);
$scorm->launch = scorm_parse_scorm(dirname($reference),$scorm->id);
}
}
return $scorm->launch;
}
@ -984,7 +829,7 @@ function scorm_forge_cols_regexp($columns,$remodule='(".*")?,') {
return $regexp;
}
function scorm_parse_aicc($pkgdir,$scormid){
function scorm_parse_aicc($pkgdir,$scormid) {
$version = 'AICC';
$ids = array();
$courses = array();
@ -1081,6 +926,9 @@ function scorm_parse_aicc($pkgdir,$scormid){
}
}
//print_r($courses);
$oldscoes = get_records('scorm_scoes','scorm',$scormid);
$launch = 0;
if (isset($courses)) {
foreach ($courses as $course) {
@ -1092,8 +940,15 @@ function scorm_parse_aicc($pkgdir,$scormid){
$sco->parent = '/';
$sco->launch = '';
$sco->scormtype = '';
//print_r($sco);
$id = insert_record('scorm_scoes',$sco);
if (get_record('scorm_scoes','scorm',$scormid,'identifier',$sco->identifier)) {
$id = update_record('scorm_scoes',$sco);
unset($oldscoes[$id]);
} else {
$id = insert_record('scorm_scoes',$sco);
}
if ($launch == 0) {
$launch = $id;
}
@ -1134,7 +989,13 @@ function scorm_parse_aicc($pkgdir,$scormid){
$sco->masteryscore = $element->mastery_score;
$sco->previous = 0;
$sco->next = 0;
$id = insert_record('scorm_scoes',$sco);
if ($oldscoid = scorm_array_search('identifier',$sco->identifier,$oldscoes)) {
$sco->id = $oldscoid;
$id = update_record('scorm_scoes',$sco);
unset($oldscoes[$oldscoid]);
} else {
$id = insert_record('scorm_scoes',$sco);
}
if ($launch==0) {
$launch = $id;
}
@ -1142,11 +1003,18 @@ function scorm_parse_aicc($pkgdir,$scormid){
}
}
}
if (!empty($oldscoes)) {
foreach($oldscoes as $oldsco) {
delete_records('scorm_scoes','id',$oldsco->id);
delete_records('scorm_scoes_track','scoid',$oldsco->id);
}
}
set_field('scorm','version','AICC','id',$scormid);
return $launch;
}
function scorm_get_resources($blocks) {
$resources = array();
foreach ($blocks as $block) {
if ($block['name'] == 'RESOURCES') {
foreach ($block['children'] as $resource) {
@ -1259,7 +1127,7 @@ function scorm_get_manifest($blocks,$scoes) {
}
$scoes->elements[$manifest][$organization][$identifier]->scormtype = addslashes($resources[$idref]['ADLCP:SCORMTYPE']);
}
$parent = new stdClass();
$parent->identifier = $identifier;
$parent->organization = $organization;
@ -1581,19 +1449,26 @@ function scorm_parse_scorm($pkgdir,$scormid) {
$xmlstring = file_get_contents($manifestfile);
$objXML = new xml2Array();
$manifests = $objXML->parse($xmlstring);
// print_r($manifests);
$scoes = new stdClass();
$scoes->version = '';
$scoes = scorm_get_manifest($manifests,$scoes);
if (count($scoes->elements) > 0) {
$olditems = get_records('scorm_scoes','scorm',$scormid);
foreach ($scoes->elements as $manifest => $organizations) {
foreach ($organizations as $organization => $items) {
foreach ($items as $identifier => $item) {
$item->scorm = $scormid;
$item->manifest = $manifest;
$item->organization = $organization;
$id = insert_record('scorm_scoes',$item);
if ($olditemid = scorm_array_search('identifier',$item->identifier,$olditems)) {
$item->id = $olditemid;
$id = update_record('scorm_scoes',$item);
unset($olditems[$olditemid]);
} else {
$id = insert_record('scorm_scoes',$item);
}
// Added by Pham Minh Duc
$item->scormid = $scormid;
$item->scoid = $id;
@ -1638,6 +1513,12 @@ function scorm_parse_scorm($pkgdir,$scormid) {
}
}
}
if (!empty($olditems)) {
foreach($olditems as $olditem) {
delete_records('scorm_scoes','id',$olditem->id);
delete_records('scorm_scoes_track','scoid',$olditem->id);
}
}
set_field('scorm','version',$scoes->version,'id',$scormid);
}
}
@ -1645,6 +1526,23 @@ function scorm_parse_scorm($pkgdir,$scormid) {
return $launch;
}
function scorm_array_search($item, $needle, $haystacks, $strict=false) {
if (!empty($haystacks)) {
foreach ($haystacks as $key => $element) {
if ($strict) {
if ($element->{$item} === $needle) {
return $key;
}
} else {
if ($element->{$item} == $needle) {
return $key;
}
}
}
}
return false;
}
function scorm_course_format_display($user,$course) {
global $CFG;
@ -1696,6 +1594,7 @@ function scorm_course_format_display($user,$course) {
function scorm_view_display ($user, $scorm, $action, $cm, $blockwidth='') {
global $CFG;
$organization = optional_param('organization', '', PARAM_INT);
print_simple_box_start('center',$blockwidth);
@ -1885,4 +1784,223 @@ class xml2Array {
}
}
//
// Functions added by Pham Minh Duc
//
function scorm_get_score_from_parent($sco,$userid,$grademethod=VALUESCOES) {
$scores = NULL;
$scores->scoes = 0;
$scores->values = 0;
$scores->scaled = 0;
$scores->max = 0;
$scores->sum = 0;
$scoes_total = 0;
$scoes_count = 0;
$attempt = scorm_get_last_attempt($sco->scorm, $userid);
$scoes = get_records('scorm_scoes', 'parent', $sco->identifier);
foreach ($scoes as $sco)
{
$scoes_total++;
if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
$scoes_count++;
}
$scoreraw = $userdata->score_raw;
if (!empty($userdata->score_raw)) {
$scores->values++;
$scores->sum += $userdata->score_raw;
$scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
}
if (!empty($userdata->score_scaled)) {
$scores->scaled = $scores->scaled + $userdata->score_scaled;
}
}
}
if ($scoes_count > 0) {
$scores->scaled = ($scores->scaled)/($scoes_count);
}
switch ($grademethod) {
case VALUEHIGHEST:
return $scores->max;
break;
case VALUEAVERAGE:
if ($scores->values > 0) {
return $scores->sum/$scores->values;
} else {
return 0;
}
break;
case VALUESUM:
return $scores->sum;
break;
case VALUESCOES:
return $scores->scaled;
break;
}
}
function scorm_get_user_sco_count($scormid, $userid) {
$scoes_count = 0;
$attempt = scorm_get_last_attempt($current->scorm, $userid);
$scoes = get_records('scorm_scoes', 'scorm', $scormid);
foreach ($scoes as $sco) {
if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
$scoes_count++;
}
}
}
return $scoes_count;
}
function scorm_grade_user_new($scoes, $userid, $grademethod=VALUESCOES) {
$scores = NULL;
$scores->scoes = 0;
$scores->values = 0;
$scores->scaled = 0;
$scores->max = 0;
$scores->sum = 0;
if (!$scoes) {
return '';
}
$current = current($scoes);
$attempt = scorm_get_last_attempt($current->scorm, $userid);
foreach ($scoes as $sco) {
if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
$scores->scoes++;
}
$scaled = $userdata->score_scaled;
$scoreraw = $userdata->score_raw;
if ($scaled ==0){
$scores->scaled = $scores->scaled / $scores->scoes;
}
if (!empty($userdata->score_raw)) {
$scores->values++;
$scores->sum += $userdata->score_raw;
$scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
}
if (!empty($scaled)) {
$scores->scaled = (($scores->scaled) * ($scores->scoes-1) + $scaled)/($scores->scoes);
}
}
}
switch ($grademethod) {
case VALUEHIGHEST:
return $scores->max;
break;
case VALUEAVERAGE:
if ($scores->values > 0) {
return $scores->sum/$scores->values;
} else {
return 0;
}
break;
case VALUESUM:
return $scores->sum;
break;
case VALUESCOES:
return $scores->scaled;
break;
}
}
function scorm_insert_statistic($statisticInput){
$id = null;
if ($statistic = get_record_select('scorm_statistic',"userid='$statisticInput->userid' AND scormid='$statisticInput->scormid'")) {
$statistic->durationtime = $statisticInput->duration;
$statistic->accesstime = $statisticInput->accesstime;
$statistic->status = $statisticInput->status;
$statistic->attemptnumber = $statisticInput->attemptnumber;
$id = update_record('scorm_statistic',$statistic);
} else {
$id = insert_record('scorm_statistic',$statisticInput);
}
return $id;
}
function scorm_insert_trackmodel($userid,$scormid,$scoid,$attempt) {
$id = null;
if ($suspendtrack = get_record_select('scorm_suspendtrack',"userid='$userid' AND scormid='$scormid'")) {
$suspendtrack->suspendscoid = $scoid;
$suspendtrack->attempt = $attempt;
$id = update_record('scorm_suspendtrack',$suspendtrack);
} else {
$suspendtrack->scormid = $scormid;
$suspendtrack->suspendscoid = $scoid;
$suspendtrack->userid = $userid;
$suspendtrack->attempt = $attempt;
$id = insert_record('scorm_suspendtrack',$suspendtrack);
}
return $id;
}
function scorm_get_suspendscoid($scormid,$userid) {
if ($sco = get_record("scorm_suspendtrack","scormid",$scormid,"userid",$userid)) {
$suspendscoid = $sco->suspendscoid;
return $suspendscoid;
} else {
return 0;
}
}
function scorm_set_attempt($scoid,$userid) {
if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) {
$attempt = scorm_get_last_attempt($scormid,$userid);
} else {
$attempt = 1;
}
$scormtype = get_field('scorm_scoes','scormtype','id',$scoid) ;
if ($scormtype == 'sco'){
$element = 'cmi.attempt_status';
$value = 'attempted';
scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value);
}
}
function scorm_get_AbsoluteTimeLimit($scoid){
$sco = get_record("scorm_scoes","id",$scoid);
if (!empty($sco)){
return $sco->attemptAbsoluteDurationLimit;
}
return 0;
}
function scorm_update_status($scormid,$scoid)
{
}
function scorm_get_nextsco($scormid,$scoid)
{
}
function scorm_get_presco($scormid,$scoid)
{
}
function scorm_isChoice($scormid,$scoid)
{
$sco = get_record("scorm_sequencing_controlmode","scormid",$scormid,"scoid",$scoid);
$scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);
return $scoparent->choice;
}
function scorm_isChoiceexit($scormid,$scoid)
{
$sco = get_record("scorm_sequencing_controlmode","scormid",$scormid,"scoid",$scoid);
$scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);
return $scoparent->choiceexit;
}
// End add
?>

View File

@ -79,6 +79,7 @@
$strfilename = get_string('coursepacket', 'scorm');
$strchooseafile = get_string('chooseapacket', 'scorm');
$strbrowserepository = get_string('browserepository', 'scorm');
$striframe = get_string('iframe', 'scorm');
$striframedisplay = get_string('iframedisplay', 'scorm');
$strnewwindow = get_string('popup', 'scorm');
@ -96,10 +97,15 @@
<script type="text/javascript" src="<?php p($CFG->wwwroot) ?>/mod/scorm/request.js" ></script>
<script type="text/javascript">
function validate_scorm(theform,filename) {
function validate_scorm(theform,filename,confirmed) {
var confirmedstr = '';
if (confirmed == true) {
confirmedstr = '&confirmed=true';
}
var myRequest = NewHttpReq();
result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php","id=<?php p($form->course) ?>&reference="+filename+"<?php echo $sessionkey.$scormid.$datadir ?>");
alert("Scorm validating....");
//alert(result);
results = result.split('\n');
result = '';
errorlogs = '';
@ -133,22 +139,28 @@
theform.datadir.value = datadir;
theform.pkgtype.value = pkgtype;
theform.launch.value = launch;
if (launch == 0) {
if ('<?php echo $scormid ?>' != '') {
return confirm('<?php print_string('trackingloose','scorm') ?>');
}
if (theform.mode.value == 'add') {
theform.parse.value = 1;
} else if (launch == 0) {
theform.parse.value = 1;
}
return true;
} else {
result = '<?php print_string('validation','scorm') ?>: '+ result + '\n';
if (errorlogs != '') {
result.concat('<?php print_string('errorlogs','scorm') ?>:\n'+errorlogs);
if (result == "confirm") {
response = confirm("<?php print_string('confirmloosetracks','scorm') ?>");
if (response == true) {
return validate_scorm(theform,filename,true);
} else {
return false;
}
} else {
result = '<?php print_string('validation','scorm') ?>: '+ result + '\n';
if (errorlogs != '') {
result.concat('<?php print_string('errorlogs','scorm') ?>:\n'+errorlogs);
}
alert(result);
return false;
}
alert(result);
alert("Khong tuan chuan Scorm");
document.form.name.focus();
return false;
}
}
@ -186,9 +198,7 @@
}
</script>
<form name="form" method="post" action="mod.php?goto=" onsubmit="return validate_scorm(document.form,document.form.reference.value);">
<form name="form" method="post" action="mod.php?goto=" onsubmit="return validate_scorm(document.form,document.form.reference.value,false,false);">
<table cellpadding="5">
<tr valign="top">
<td align="right"><b><?php print_string('name') ?>:</b></td>
@ -213,6 +223,11 @@
<?php
button_to_popup_window ('/files/index.php?id='.$course->id.'&amp;choose=form.reference',
'coursefiles', $strchooseafile, 500, 750, $strchooseafile);
require_once($repositoryconfigfile);
if ($CFG->repositoryactivate) {
button_to_popup_window ($repositorybrowser.'?choose=form.reference',
'browserepository', $strbrowserepository, 500, 750, $strbrowserepository);
}
helpbutton('package', get_string('coursepacket', 'scorm'), 'scorm', true);
?>
</td>
@ -406,6 +421,7 @@
<input type="hidden" name="datadir" value="<?php p($form->datadir) ?>" />
<input type="hidden" name="pkgtype" value="<?php p($form->pkgtype) ?>" />
<input type="hidden" name="launch" value="<?php p($form->launch) ?>" />
<input type="hidden" name="parse" value="0" />
<?php
$scorms = get_all_instances_in_course('scorm', $course);
$coursescorm = current($scorms);

View File

@ -2,34 +2,67 @@
require_once("../../config.php");
require_once('locallib.php');
require_once('lib.php');
$courseid = required_param('id', PARAM_INT); // Course Module ID, or
$reference = required_param('reference', PARAM_PATH); // Package path
$scormid = optional_param('instance', '', PARAM_INT); // scorm ID
$courseid = required_param('id', PARAM_INT); // Course Module ID
$reference = required_param('reference', PARAM_PATH); // Package path
$scormid = optional_param('instance', '', PARAM_INT); // scorm ID
$confirmed = optional_param('confirmed', false, PARAM_BOOL); // This package is changed and some tracks could be lost.
// Has the editor confirmed to continue?
require_login($courseid, false);
if (confirm_sesskey() && !empty($courseid)) {
$launch = 0;
$validation = new stdClass();
$referencefield = $reference;
if (empty($reference)) {
$launch = -1;
$validation->result = "packagefile";
} else if ($reference[0] == '#') {
require_once($repositoryconfigfile);
if ($CFG->repositoryactivate) {
$referencefield = $reference.'/imsmanfest.xml';
$reference = $CFG->repository.substr($reference,1).'/imsmanifest.xml';
} else {
$launch = -1;
$validation->result = "packagefile";
}
} else if (substr($reference,0,7) != 'http://') {
$reference = $CFG->dataroot.'/'.$courseid.'/'.$reference;
}
if (!empty($scormid)) {
//
// SCORM Update
//
if (is_file($CFG->dataroot.'/'.$courseid.'/'.$reference)) {
$fp = fopen($CFG->dataroot.'/'.$courseid.'/'.$reference,"r");
if (($launch != -1) && is_file($reference)) {
$fp = fopen($reference,"r");
$fstat = fstat($fp);
fclose($fp);
if ($scorm = get_record("scorm","id",$scormid)) {
if ($scorm->reference[0] == '#') {
require_once($repositoryconfigfile);
if ($CFG->repositoryactivate) {
$oldreference = $CFG->repository.substr($scorm->reference,1).'/imsmanifest.xml';
} else {
$oldreference = $scorm->reference;
}
} else if (substr($reference,0,7) != 'http://') {
$oldreference = $CFG->dataroot.'/'.$courseid.'/'.$scorm->reference;
}
$launch = $scorm->launch;
if ((($scorm->timemodified < $fstat["mtime"]) && ($scorm->reference == $reference)) || ($scorm->reference != $reference)) {
// This is a new package
$launch = 0;
if ((($scorm->timemodified < $fstat["mtime"]) && ($oldreference == $reference)) || ($oldreference != $reference)) {
// This is a new or a modified package
if (!$confirmed) {
if ($tracks = get_records('scorm_scoes_track','scormid',$scormid)) {
$validation->result='confirm';
$launch = -1;
} else {
$launch = 0;
}
} else {
$launch = 0;
}
} else {
// Old package already validated
$validation->result = 'found';
@ -63,7 +96,7 @@ if (confirm_sesskey() && !empty($courseid)) {
$scormdir = '';
if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
if ($tempdir = scorm_datadir($scormdir)) {
copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference));
copy ("$reference", $tempdir."/".basename($reference));
unzip_file($tempdir."/".basename($reference), $tempdir, false);
unlink ($tempdir."/".basename($reference));
$validation = scorm_validate($tempdir);
@ -76,7 +109,7 @@ if (confirm_sesskey() && !empty($courseid)) {
break;
case '.xml':
if (basename($reference) == 'imsmanifest.xml') {
$validation = scorm_validate("$CFG->dataroot/$courseid/".dirname($reference));
$validation = scorm_validate(dirname($reference));
} else {
$validation->result = "manifestfile";
}
@ -93,7 +126,7 @@ if (confirm_sesskey() && !empty($courseid)) {
}
} else {
if ($ext == '.xml') {
$datadir = dirname($reference);
$datadir = dirname($referencefield);
} else {
$datadir = substr($tempdir,strlen($scormdir));
}