]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed a problem during scorm update.
authorbobopinna <bobopinna>
Fri, 11 Aug 2006 12:26:06 +0000 (12:26 +0000)
committerbobopinna <bobopinna>
Fri, 11 Aug 2006 12:26:06 +0000 (12:26 +0000)
Now only the lost scoes tracks are deleted
Added support to IMS CP repository

mod/scorm/lib.php
mod/scorm/loadSCO.php
mod/scorm/locallib.php
mod/scorm/mod.html
mod/scorm/validate.php

index 2701282c09e7d8eeea8858948bc4bc3e22033a8c..52490d3f093bd896ce5671754f1a8d787f57f6fb 100755 (executable)
@@ -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').':&nbsp;'.$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;
 }
 
-?>
\ No newline at end of file
+?>
index ee77d8a3e9f315113ffa660fa272a7375752d591..b538a5fd0b5ed4c24a1224a4daf266a8428552e2 100755 (executable)
@@ -1,10 +1,10 @@
 <?php\r
     require_once("../../config.php");\r
     require_once('locallib.php');\r
-    \r
+\r
     $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or\r
     $a = optional_param('a', '', PARAM_INT);         // scorm ID\r
-    $scoid = required_param('scoid', PARAM_INT); // sco ID\r
+    $scoid = required_param('scoid', PARAM_INT);     // sco ID\r
 \r
     if (!empty($id)) {\r
         if (! $cm = get_coursemodule_from_id('scorm', $id)) {\r
     require_login($course->id, false, $cm);\r
     if (!empty($scoid)) {\r
     //\r
-    // Dinh huong yeu cau cua SCO\r
+    // Direct SCO request\r
     //\r
         if ($sco = get_record("scorm_scoes","id",$scoid)) {\r
             if ($sco->launch == '') {\r
-                // Tim kiem SCO co the trien khai tiep theo\r
+                // Search for the next launchable sco\r
                 if ($scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' AND id>".$sco->id,"id ASC")) {\r
                     $sco = current($scoes);\r
                 }\r
@@ -79,6 +79,9 @@
     \r
     if (scorm_external_link($sco->launch)) {\r
         $result = $launcher;\r
+    } else if ($scorm->reference[0] == '#') {\r
+        require_once($repositoryconfigfile);\r
+        $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;\r
     } else {\r
         if (basename($scorm->reference) == 'imsmanifest.xml') {\r
             $basedir = dirname($scorm->reference);\r
index d744cbc4cd055fd802a7320da015e8092ab14168..8507ded5e01a827eb7a15cfbe57bff71d34cd0a3 100755 (executable)
@@ -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;
-
-    $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++;
-            }
+//
+// Repository configurations
+//
+$repositoryconfigfile = $CFG->dirroot.'/mod/resource/type/ims/repository_config.php';
+$repositorybrowser = '/mod/resource/type/ims/finder.php';
 
-            $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);
+/// Local Library of functions and constants for module scorm
 
-    foreach ($scoes as $sco) {
-        if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
-            if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
-                $scoes_count++;
+/**
+* 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 $scoes_count;
+    return false;
 }
 
-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);
+/**
+* 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 {
-        $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;
+        $files = array();
+        if ($dh = opendir($directory)) {
+            while (($file = readdir($dh)) !== false) {
+               $files[] = $file;
+            }
+            closedir($dh);
+        }
+        return $files;
     }
-    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
-
 /**
 * 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
 ?>
index 8d707b83b07ff29eb3537d0ca83dbfb8b694612d..0e0f55121a0a486fd47c215b4f26abc11a850344 100755 (executable)
@@ -79,6 +79,7 @@
 \r
     $strfilename = get_string('coursepacket', 'scorm');\r
     $strchooseafile = get_string('chooseapacket', 'scorm');\r
+    $strbrowserepository = get_string('browserepository', 'scorm');\r
     $striframe = get_string('iframe', 'scorm');\r
     $striframedisplay = get_string('iframedisplay', 'scorm');\r
     $strnewwindow = get_string('popup', 'scorm');\r
 \r
 <script type="text/javascript" src="<?php p($CFG->wwwroot) ?>/mod/scorm/request.js" ></script>\r
 <script type="text/javascript">\r
-    function validate_scorm(theform,filename) {\r
+    function validate_scorm(theform,filename,confirmed) {\r
+        var confirmedstr = '';\r
+        if (confirmed == true) {\r
+           confirmedstr = '&confirmed=true';\r
+        }\r
+\r
         var myRequest = NewHttpReq();\r
         result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php","id=<?php p($form->course) ?>&reference="+filename+"<?php echo $sessionkey.$scormid.$datadir ?>");\r
-        alert("Scorm validating....");\r
+        //alert(result);\r
         results = result.split('\n');\r
         result = '';\r
         errorlogs = '';\r
             theform.datadir.value = datadir;\r
             theform.pkgtype.value = pkgtype;\r
             theform.launch.value = launch;\r
-            if (launch == 0) {\r
-                if ('<?php echo $scormid ?>' != '') {\r
-                    return confirm('<?php print_string('trackingloose','scorm') ?>');\r
-                }\r
+            if (theform.mode.value == 'add') {\r
+                theform.parse.value = 1;\r
+            } else if (launch == 0) {\r
+                theform.parse.value = 1;\r
             }\r
             return true;\r
         } else {\r
-            result = '<?php print_string('validation','scorm') ?>: '+ result + '\n';\r
-            if (errorlogs != '') {\r
-               result.concat('<?php print_string('errorlogs','scorm') ?>:\n'+errorlogs);\r
+            if (result == "confirm") {\r
+                response = confirm("<?php print_string('confirmloosetracks','scorm') ?>");\r
+                if (response == true) {\r
+                    return validate_scorm(theform,filename,true);\r
+                } else {\r
+                    return false;\r
+                }\r
+            } else {\r
+                result = '<?php print_string('validation','scorm') ?>: '+ result + '\n';\r
+                if (errorlogs != '') {\r
+                    result.concat('<?php print_string('errorlogs','scorm') ?>:\n'+errorlogs);\r
+                }\r
+                alert(result);\r
+                return false;\r
             }\r
-            alert(result);\r
-            alert("Khong tuan chuan Scorm");\r
-            document.form.name.focus();\r
-\r
-            return false;\r
         }\r
     }\r
 \r
     }\r
 </script>\r
 \r
-<form name="form" method="post" action="mod.php?goto=" onsubmit="return validate_scorm(document.form,document.form.reference.value);">\r
-\r
-\r
+<form name="form" method="post" action="mod.php?goto=" onsubmit="return validate_scorm(document.form,document.form.reference.value,false,false);">\r
     <table cellpadding="5">\r
         <tr valign="top">\r
             <td align="right"><b><?php print_string('name') ?>:</b></td>\r
                 <?php\r
                     button_to_popup_window ('/files/index.php?id='.$course->id.'&amp;choose=form.reference',\r
                                             'coursefiles', $strchooseafile, 500, 750, $strchooseafile);\r
+                    require_once($repositoryconfigfile);\r
+                    if ($CFG->repositoryactivate) {\r
+                        button_to_popup_window ($repositorybrowser.'?choose=form.reference',\r
+                                                'browserepository', $strbrowserepository, 500, 750, $strbrowserepository);\r
+                    }\r
                     helpbutton('package', get_string('coursepacket', 'scorm'), 'scorm', true);\r
                 ?>\r
             </td>\r
     <input type="hidden" name="datadir" value="<?php p($form->datadir) ?>" />\r
     <input type="hidden" name="pkgtype" value="<?php p($form->pkgtype) ?>" />\r
     <input type="hidden" name="launch"  value="<?php p($form->launch) ?>" />\r
+    <input type="hidden" name="parse"  value="0" />\r
     <?php\r
         $scorms = get_all_instances_in_course('scorm', $course);\r
         $coursescorm = current($scorms);\r
index f2ee7b3d9ce1e00246d36b2099f053267bf1c529..429c36786ed40b5a38d189c5bffc3737a44e88cb 100755 (executable)
@@ -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));
             }