General review to support XHTML Strict
authorbobopinna <bobopinna>
Tue, 15 Nov 2005 08:10:26 +0000 (08:10 +0000)
committerbobopinna <bobopinna>
Tue, 15 Nov 2005 08:10:26 +0000 (08:10 +0000)
First step in multi-attempt feature (requested by SCORM 2004)
Removed javascript use as much as possible in button and link

20 files changed:
mod/scorm/README.txt
mod/scorm/aicc.php
mod/scorm/api.php
mod/scorm/config.html
mod/scorm/datamodel.php
mod/scorm/datamodels/scorm1_2.js.php
mod/scorm/db/mysql.php
mod/scorm/db/mysql.sql
mod/scorm/index.php
mod/scorm/lib.php
mod/scorm/loadSCO.php
mod/scorm/locallib.php [new file with mode: 0755]
mod/scorm/mod.html
mod/scorm/player.php [moved from mod/scorm/playscorm.php with 59% similarity]
mod/scorm/report.php
mod/scorm/styles.php
mod/scorm/validate.php
mod/scorm/version.php
mod/scorm/view.php
mod/scorm/xml2array.class.php [deleted file]

index 1c5e2d5..d27630a 100644 (file)
@@ -54,7 +54,7 @@ view.php
    ||
    ||
    \/
-playscorm.php -- load --> request.js
+player.php -- load --> request.js
    ||                     api.php -- include --> datamodels/(SCORM1_2.js.php || SCORM1_3.js.php || AICC.js.php)
    ||                       /\
  iframe                     ||
index db31d85..4433291 100755 (executable)
@@ -1,6 +1,6 @@
 <?php
     require_once('../../config.php');
-    require_once('lib.php');
+    require_once('locallib.php');
 
     $command = required_param('command', '', PARAM_ALPHA);
     $sessionid = required_param('session_id', '', PARAM_ALPHANUM);
         if (isset($SESSION->scorm_status)) {
             $status = $SESSION->scorm_status;
         }
+        if (isset($SESSION->newattempt)) {
+            $newattempt = $SESSION->newattempt;
+            $SESSION->newattempt = '';
+        } else {
+            $newattempt = '';
+        }
+        if ($lastattempt = get_record('scorm_sco_tracks', 'user', $USER->id, 'scorm', $scorm->id, 'sco', $scoid,'max(attempt) as a')) {
+            if ($newattempt == 'new') {
+                $attempt = $lastattempt['a']+1;
+            } else {
+                $attempt = $lastattempt['a'];
+            }
+        } else {
+            $attempt = 1;
+        }
+
         if ($sco = get_record('scorm_scoes','id',$scoid)) {
             if (!$scorm = get_record('scorm','id',$sco->scorm)) {
                 error('Invalid script call');
                                         $element = $datamodel[$element];
                                         switch ($element) {
                                             case 'cmi.core.lesson_location':
-                                                $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $element, $value);
+                                                $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
                                             break;
                                             case 'cmi.core.lesson_status':
                                                 $statuses = array(
                                                 }
                                                 if (empty($value) || isset($exites[$value])) {
                                                     $subelement = 'cmi.core.exit';
-                                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $subelement, $value);
+                                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
                                                 }
                                                 $value = trim(strtolower($values[0]));
                                                 if (isset($statuses[$value]) && ($mode == 'normal')) {
                                                     $value = $statuses[$value];
-                                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $element, $value);
+                                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
                                                 }
                                                 $lessonstatus = $value;
                                             break;
                                                  if ((count($values) > 1) && ($values[1] >= $values[0]) && is_numeric($values[1])) {
                                                      $subelement = 'cmi.core.score.max';
                                                      $value = trim($values[1]);
-                                                     $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $subelement, $value);
+                                                     $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
                                                      if ((count($values) == 3) && ($values[2] <= $values[0]) && is_numeric($values[2])) {
                                                          $subelement = 'cmi.core.score.min';
                                                          $value = trim($values[2]);
-                                                         $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $subelement, $value);
+                                                         $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);
                                                      }
                                                  }
                                               
                                                  $value = '';
                                                  if (is_numeric($values[0])) {
                                                      $value = trim($values[0]);
-                                                     $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $element, $value);
+                                                     $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
                                                  }
                                                  $score = $value;
                                             break;
                                             $value .= $datarow;
                                             next($datarows);
                                         }
-                                        $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $element, $value);
+                                        $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
                                     }
                                 }                               
                             }
                             if (($mode == 'browse') && ($initlessonstatus == 'not attempted')){
                                 $lessonstatus = 'browsed';
-                                $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, 'cmi.core.lesson_status', 'browsed');
+                                $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', 'browsed');
                             }
                             if ($mode == 'normal') {
                                 if ($lessonstatus == 'completed') {
                                     } else {
                                         $lessonstatus = 'failed';
                                     }
-                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, 'cmi.core.lesson_status', $lessonstatus);
+                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', $lessonstatus);
                                 }
                             }                  
                         }
index 4496540..e416ba6 100644 (file)
@@ -1,12 +1,13 @@
 <?php
 
     require_once("../../config.php");
-    require_once("lib.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
     $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
+    $attempt = optional_param('attempt', '', PARAM_ALPHA); // new attempt
 
     if (!empty($id)) {
         if (! $cm = get_record("course_modules", "id", $id)) {
         $userdata = $usertrack;
     } else {
         $userdata->status = '';
-        $userdata->scorre_raw = '';
+        $userdata->score_raw = '';
     }
-    $userdata->student_id = $USER->username;
-    $userdata->student_name = $USER->lastname .', '. $USER->firstname;
+    $userdata->student_id = addslashes($USER->username);
+    $userdata->student_name = addslashes($USER->lastname .', '. $USER->firstname);
     $userdata->mode = 'normal';
     if (isset($mode)) {
         $userdata->mode = $mode;
index e7789ea..ce0c86c 100755 (executable)
@@ -1,9 +1,9 @@
 <?php
     if (empty($CFG->scorm_frameheight)) {
-        $CFG->scorm_frameheight = 600;
+        $CFG->scorm_frameheight = '500';
     }
     if (empty($CFG->scorm_framewidth)) {
-        $CFG->scorm_structurewidth = 800;
+        $CFG->scorm_framewidth = '100%';
     }
 ?>
 
@@ -33,7 +33,7 @@
 <tr valign="top">
     <td align="right">scorm_framewidth:</td>
     <td>
-        <input type="text" name="scorm_framewidth" value="<?php echo $CFG->scorm_framewidth ?>" size="3" />
+        <input type="text" name="scorm_framewidth" value="<?php echo $CFG->scorm_framewidth ?>" size="5" />
     </td>
     <td>
         <?php print_string("framewidth", "scorm") ?>
@@ -42,7 +42,7 @@
 <tr valign="top">
     <td align="right">scorm_frameheight:</td>
     <td>
-        <input type="text" name="scorm_frameheight" value="<?php echo $CFG->scorm_frameheight ?>" size="4" />
+        <input type="text" name="scorm_frameheight" value="<?php echo $CFG->scorm_frameheight ?>" size="5" />
     </td>
     <td>
         <?php print_string("frameheight", "scorm") ?>
index 29e0ce0..59853cb 100755 (executable)
@@ -1,10 +1,11 @@
 <?php
     require_once('../../config.php');
-    require_once('lib.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
+    $newattempt = optional_param('attempt', '', PARAM_ALPHA);  // new attempt ?
 
     if (!empty($id)) {
         if (! $cm = get_record("course_modules", "id", $id)) {
     if (confirm_sesskey() && (!empty($scoid))) {
         $result = true;
         if (isstudent($course->id) || (isteacher($course->id) && !isadmin()) {
+            if ($lastattempt = get_record('scorm_sco_tracks', 'user', $USER->id, 'scorm', $scorm->id, 'sco', $scoid,'max(attempt) as a')) {
+                if ($newattempt == 'new') {
+                    $attempt = $lastattempt['a']+1;
+                } else {
+                    $attempt = $lastattempt['a'];
+                }
+            } else {
+                $attempt = 1;
+            }
             foreach ($_POST as $element => $value) {
                 if (substr($element,0,3) == 'cmi') {
                     $element = str_replace('__','.',$element);
                     $element = preg_replace('/_(\d+)/',".\$1",$element);
-                    $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $element, $value) && $result;
+                    $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $element, $value) && $result;
                 }
             }
         }
index fd9e87c..790d045 100644 (file)
@@ -529,6 +529,11 @@ function SCORMapi1_2() {
             datastring = CollectData(data,'cmi');
         }
         datastring += '&scoid=<?php echo $sco->id ?>';
+        <?php
+            if (!empty($attempt)) {
+                echo "datastring += '&attempt=$attempt';";
+            }
+        ?>
         //popupwin(datastring);
         var myRequest = NewHttpReq();
         result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php","id=<?php p($id) ?>&sesskey=<?php p($USER->sesskey) ?>"+datastring);
index f9ee538..04675d1 100755 (executable)
@@ -197,11 +197,17 @@ function scorm_upgrade($oldversion) {
         }
     }
 
-
     if ($oldversion < 2005092500) {
         table_column("scorm", "", "hidenav", "TINYINT", "1", "UNSIGNED", "0", "NOT NULL", "hidetoc"); 
         table_column("scorm", "", "options", "VARCHAR", "255", "", "", "NOT NULL","popup");
     }
+
+    if ($oldversion < 2005092600) {
+        table_column("scorm_scoes_track", "", "attempt", "INT", "10", "UNSIGNED", "1", "NOT NULL", "scoid"); 
+        execute_sql("ALTER TABLE {$CFG->prefix}scorm_scoes_track DROP INDEX track");
+        modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD UNIQUE track (userid,scormid,scoid,attempt,element);');
+    }
+
     return true;
 }
 ?>
index c455d11..bdea7c0 100755 (executable)
@@ -54,6 +54,7 @@ CREATE TABLE prefix_scorm_scoes_track (
   userid int(10) unsigned NOT NULL default '0',
   scormid int(10) NOT NULL default '0',
   scoid int(10) unsigned NOT NULL default '0',
+  attempt int(10) unsigned NOT NULL default '1',
   element varchar(255) NOT NULL default '',
   value longtext NOT NULL default '',
   timemodified int(10) unsigned NOT NULL default '0',
@@ -61,8 +62,8 @@ CREATE TABLE prefix_scorm_scoes_track (
   KEY userid (userid),
   KEY scormid (scormid),
   KEY scoid (scoid),
-  KEY elemeny (element),
-  UNIQUE track (userid, scormid, scoid, element)
+  KEY element (element),
+  UNIQUE track (userid, scormid, scoid, attempt, element)
 ) TYPE=MyISAM;
 
 #
index 415ede1..098b52c 100755 (executable)
@@ -22,6 +22,7 @@
     $strtopic = get_string("topic");
     $strname = get_string("name");
     $strsummary = get_string("summary");
+    $strreport = get_string("report",'scorm');
     $strlastmodified = get_string("lastmodified");
 
     print_header_simple("$strscorms", "", "$strscorms",
     }
 
     if ($course->format == "weeks") {
-        $table->head  = array ($strweek, $strname, $strsummary);
-        $table->align = array ("center", "left", "left");
+        $table->head  = array ($strweek, $strname, $strsummary, $strreport);
+        $table->align = array ("center", "left", "left", "left");
     } else if ($course->format == "topics") {
-        $table->head  = array ($strtopic, $strname, $strsummary);
-        $table->align = array ("center", "left", "left");
+        $table->head  = array ($strtopic, $strname, $strsummary, $strreport);
+        $table->align = array ("center", "left", "left", "left");
     } else {
-        $table->head  = array ($strlastmodified, $strname, $strsummary);
-        $table->align = array ("left", "left", "left");
+        $table->head  = array ($strlastmodified, $strname, $strsummary, $strreport);
+        $table->align = array ("left", "left", "left", "left");
     }
 
     foreach ($scorms as $scorm) {
                 $tt = "$scorm->section";
             }
         } else {
-            $tt = "<font size=\"1\">".userdate($scorm->timemodified);
+            $tt = userdate($scorm->timemodified);
+        }
+        $report = '&nbsp;';
+        if (isteacher($course->id)) {
+            $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');
+            if ($trackedusers->c > 0) {
+                $report = '<a href="report.php?a='.$scorm->id.'">'.get_string('viewallreports','scorm',$trackedusers->c).'</a></div>';
+            } else {
+                $report = get_string('noreports','scorm');
+            }
+        } else if (isstudent($course->id)) {
+           require_once('locallib.php');
+           $report = scorm_grade_user(get_records('scorm_scoes','scorm',$scorm->id), $USER->id, $scorm->grademethod);
         }
         if (!$scorm->visible) {
            //Show dimmed if the mod is hidden
            $table->data[] = array ($tt, "<a class=\"dimmed\" href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name,true)."</a>",
-                                   format_text($scorm->summary));
+                                   format_text($scorm->summary), $report);
         } else {
            //Show normal if the mod is visible
            $table->data[] = array ($tt, "<a href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name,true)."</a>",
-                                   format_text($scorm->summary));
+                                   format_text($scorm->summary), $report);
         }
     }
 
index 56171d3..2c7258f 100755 (executable)
@@ -20,23 +20,12 @@ foreach ($SCORM_POPUP_OPTIONS as $popupopt) {
     }
 }
 
-/*if (!isset($CFG->scorm_validate)) {
-    $scormvalidate = 'none';
-    if (extension_loaded('domxml') && version_compare(phpversion(),'5.0.0','<')) {
-        $scormvalidate = 'domxml';
-    }
-    if (version_compare(phpversion(),'5.0.0','>=')) {
-        $scormvalidate = 'php5';
-    }
-    set_config('scorm_validate', $scormvalidate);
-}*/
-
 if (!isset($CFG->scorm_frameheight)) {
-    set_config('scorm_frameheight','600');
+    set_config('scorm_frameheight','500');
 }
 
 if (!isset($CFG->scorm_framewidth)) {
-    set_config('scorm_framewidth','800');
+    set_config('scorm_framewidth','100%');
 }
 
 /**
@@ -53,46 +42,22 @@ function scorm_add_instance($scorm) {
     global $CFG,$SCORM_POPUP_OPTIONS;
     $scorm->timemodified = time();
 
-    if (isset($scorm->popup)) {
-        if ($scorm->popup) {
-            $optionlist = array();
-            foreach ($SCORM_POPUP_OPTIONS as $option) {
-                if (isset($scorm->$option)) {
-                    $optionlist[] = $option.'='.$scorm->$option;
-                } else {
-                    $optionlist[] = $option.'=0';
-                }
-            }       
-            $scorm->options = implode(',', $optionlist);
-        } else {
-            $scorm->options = '';
-        } 
-    } else {
-        $scorm->popup = 0;
-        $scorm->options = '';
-    }
+    $scorm = scorm_option2text($scorm);
 
     $id = insert_record('scorm', $scorm);
 
     if (basename($scorm->reference) != 'imsmanifest.xml') {
         // Rename temp scorm dir to scorm id
-        $scormdir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
-        rename($scormdir.$scorm->datadir,$scormdir.'/'.$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->pkgtype == 'AICC') {
-            $scorm->launch = scorm_parse_aicc($scormdir.'/'.$id,$id);
-        } else {
-            if (basename($scorm->reference) != 'imsmanifest.xml') {
-                $scorm->launch = scorm_parse_scorm($scormdir.'/'.$id,$id);
-            } else {
-                $scorm->launch = scorm_parse_scorm($CFG->dataroot.'/'.$scorm->course.'/'.dirname($scorm->reference),$id);
-            }
-        }
-        set_field('scorm','launch',$scorm->launch,'id',$id);
+        require_once('locallib.php');
+        $scorm->id = $id;
+        $scorm->launch = scorm_parse($scorm);
+        set_field('scorm','launch',$scorm->launch,'id',$scorm->id);
     }
 
     return $id;
@@ -113,24 +78,7 @@ function scorm_update_instance($scorm) {
     $scorm->timemodified = time();
     $scorm->id = $scorm->instance;
 
-    if (isset($scorm->popup)) {
-        if ($scorm->popup) {
-            $optionlist = array();
-            foreach ($SCORM_POPUP_OPTIONS as $option) {
-                if (isset($scorm->$option)) {
-                    $optionlist[] = $option.'='.$scorm->$option;
-                } else {
-                    $optionlist[] = $option.'=0';
-                }       
-            }       
-            $scorm->options = implode(',', $optionlist);
-        } else {
-            $scorm->options = '';
-        } 
-    } else {
-        $scorm->popup = 0;
-        $scorm->options = '';
-    }
+    $scorm = scorm_option2text($scorm);
 
     // Check if scorm manifest needs to be reparsed
     if ($scorm->launch == 0) {
@@ -138,21 +86,14 @@ function scorm_update_instance($scorm) {
         delete_records('scorm_scoes','scorm',$scorm->id);
         delete_records('scorm_scoes_track','scormid',$scorm->id);
         
-        $scormdir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
+        $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
         if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) && (basename($scorm->reference) != 'imsmanifest.xml')) {
-            scorm_delete_files($scormdir.'/'.$scorm->id);
-            rename($scormdir.$scorm->datadir,$scormdir.'/'.$scorm->id);
+            scorm_delete_files($scorm->dir.'/'.$scorm->id);
+            rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id);
         }
         
-        if ($scorm->pkgtype == 'AICC') {
-            $scorm->launch = scorm_parse_aicc($scormdir.'/'.$scorm->id,$scorm->id);
-        } else {
-            if (basename($scorm->reference) != 'imsmanifest.xml') {
-                $scorm->launch = scorm_parse_scorm($scormdir.'/'.$scorm->id,$scorm->id);
-            } else {
-                $scorm->launch = scorm_parse_scorm($CFG->dataroot.'/'.$scorm->course.'/'.dirname($scorm->reference),$scorm->id);
-            }
-        }
+        require_once('locallib.php');
+        $scorm->launch = scorm_parse($scorm);
     }
 
     return update_record('scorm', $scorm);
@@ -213,6 +154,7 @@ function scorm_user_outline($course, $user, $mod, $scorm) {
     $scores->lastmodify = 0;
     $scores->count = 0;
     if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) {
+        require_once('locallib.php');
         foreach ($scoes as $sco) {
             if ($sco->launch!='') {
                $scores->count++;
@@ -358,6 +300,7 @@ function scorm_user_complete($course, $user, $mod, $scorm) {
                     }
 
                     if ($sco->launch) {
+                        require_once('locallib.php');
                         $score = '';
                         $totaltime = '';
                         if ($usertrack=scorm_get_tracks($sco->id,$user->id)) {
@@ -477,112 +420,20 @@ function scorm_grades($scormid) {
 
     $return->grades = NULL;
     if ($scousers=get_records_select('scorm_scoes_track', "scormid='$scormid' GROUP BY userid", "", "userid,null")) {
+        require_once('locallib.php');
         foreach ($scousers as $scouser) {
-            $scores = NULL;
-            $scores->scoes = 0;
-            $scores->values = 0;
-            $scores->max = 0;
-            $scores->sum = 0;
-
-            foreach ($scoes as $sco) {
-                if ($userdata=scorm_get_tracks($sco->id, $scouser->userid)) {
-                    if (($userdata->status == 'completed') || ($userdata->status == 'passed')) {
-                        $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;
-                    }
-                }
-            }
-            switch ($scorm->grademethod) {
-                case VALUEHIGHEST:
-                    $return->grades[$scouser->userid] = $scores->max;
-                break;
-                case VALUEAVERAGE:
-                    if ($scores->values > 0) {
-                        $return->grades[$scouser->userid] = $scores->sum/$scores->values;
-                    } else {
-                        $return->grades[$scouser->userid] = 0;
-                    }
-                break;
-                case VALUESUM:
-                    $return->grades[$scouser->userid] = $scores->sum;
-                break;
-                case VALUESCOES:
-                    $return->grades[$scouser->userid] = $scores->scoes;
-                break;
-            }
-       }
+            $return->grades[$scouser->userid] = scorm_grade_user($scoes, $scouser->userid, $scorm->grademethod);
+        }
     }
     return $return;
 }
 
-/**
-* Create a new temporary subdirectory with a random name in the given path
-*
-* @param string $strpath The scorm data directory
-* @return string/boolean
-*/
-function scorm_datadir($strPath)
-{
-    global $CFG;
-
-    if (is_dir($strPath)) {
-        do {
-            // Create a random string of 8 chars
-            $randstring = NULL;
-            $lchar = '';
-            $len = 8;
-            for ($i=0; $i<$len; $i++) {
-                $char = chr(rand(48,122));
-                while (!ereg('[a-zA-Z0-9]', $char)){
-                    if ($char == $lchar) continue;
-                        $char = chr(rand(48,90));
-                    }
-                    $randstring .= $char;
-                    $lchar = $char;
-            } 
-            $datadir='/'.randstring;
-        } while (file_exists($strPath.$datadir));
-        mkdir($strPath.$datadir, $CFG->directorypermissions);
-        @chmod($strPath.$datadir, $CFG->directorypermissions);  // Just in case mkdir didn't do it
-        return $strPath.$datadir;
-    } else {
-        return false;
-    }
+function scorm_get_view_actions() {
+    return array('pre-view','view','view all','report');
 }
 
-/**
-* Given a package directory, this function will check if the package is valid
-*
-* @param string $packagedir The package directory
-* @return mixed
-*/
-function scorm_validate($packagedir) {
-    $validation = new stdClass();
-    if (is_file($packagedir.'/imsmanifest.xml')) {
-        $validation->result = 'found';
-        $validation->pkgtype = 'SCORM';
-    } else {
-        if ($handle = opendir($packagedir)) {
-            while (($file = readdir($handle)) !== false) {
-                $ext = substr($file,strrpos($file,'.'));
-                if (strtolower($ext) == '.cst') {
-                    $validation->result = 'found';
-                    $validation->pkgtype = 'AICC';
-                    break;
-                }
-            }
-            closedir($handle);
-        }
-        if (!isset($validation)) {
-            $validation->result = 'nomanifest';
-            $validation->pkgtype = 'SCORM';
-        }
-    }
-    return $validation;
+function scorm_get_post_actions() {
+    return array();
 }
 
 /**
@@ -631,902 +482,26 @@ function scorm_scandir($directory) {
     }
 }
 
-/**
-* Take the header row of an AICC definition file
-* and returns sequence of columns and a pointer to
-* the sco identifier column.
-*
-* @param string $row AICC header row
-* @param string $mastername AICC sco identifier column
-* @return mixed
-*/
-function scorm_get_aicc_columns($row,$mastername='system_id') {
-    $tok = strtok(strtolower($row),"\",\n\r");
-    $result->columns = array();
-    $i=0;
-    while ($tok) {
-        if ($tok !='') {
-            $result->columns[] = $tok;
-            if ($tok == $mastername) {
-                $result->mastercol = $i;
-            }
-            $i++;
-        }
-        $tok = strtok("\",\n\r");
-    }
-    return $result;
-}
-
-/**
-* Given a colums array return a string containing the regular
-* expression to match the columns in a text row.
-*
-* @param array $column The header columns
-* @param string $remodule The regular expression module for a single column
-* @return string
-*/
-function scorm_forge_cols_regexp($columns,$remodule='(".*")?,') {
-    $regexp = '/^';
-    foreach ($columns as $column) {
-        $regexp .= $remodule;
-    }
-    $regexp = substr($regexp,0,-1) . '/';
-    return $regexp;
-}
-
-
-function scorm_parse_aicc($pkgdir,$scormid){
-    $version = 'AICC';
-    $ids = array();
-    $courses = array();
-    if ($handle = opendir($pkgdir)) {
-        while (($file = readdir($handle)) !== false) {
-            $ext = substr($file,strrpos($file,'.'));
-            $extension = strtolower(substr($ext,1));
-            $id = strtolower(basename($file,$ext));
-            $ids[$id]->$extension = $file;
-        }
-        closedir($handle);
-    }
-    foreach ($ids as $courseid => $id) {
-        if (isset($id->crs)) {
-            if (is_file($pkgdir.'/'.$id->crs)) {
-                $rows = file($pkgdir.'/'.$id->crs);
-                foreach ($rows as $row) {
-                    if (preg_match("/^(.+)=(.+)$/",$row,$matches)) {
-                        switch (strtolower(trim($matches[1]))) {
-                            case 'course_id':
-                                $courses[$courseid]->id = trim($matches[2]);
-                            break;
-                            case 'course_title':
-                                $courses[$courseid]->title = trim($matches[2]);
-                            break;
-                            case 'version':
-                                $courses[$courseid]->version = 'AICC_'.trim($matches[2]);
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-        if (isset($id->des)) {
-            $rows = file($pkgdir.'/'.$id->des);
-            $columns = scorm_get_aicc_columns($rows[0]);
-            $regexp = scorm_forge_cols_regexp($columns->columns);
-            for ($i=1;$i<count($rows);$i++) {
-                if (preg_match($regexp,$rows[$i],$matches)) {
-                    for ($j=0;$j<count($columns->columns);$j++) {
-                        $column = $columns->columns[$j];
-                        $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1);
-                    }
-                }
-            }
-        }
-        if (isset($id->au)) {
-            $rows = file($pkgdir.'/'.$id->au);
-            $columns = scorm_get_aicc_columns($rows[0]);
-            $regexp = scorm_forge_cols_regexp($columns->columns);
-            for ($i=1;$i<count($rows);$i++) {
-                if (preg_match($regexp,$rows[$i],$matches)) {
-                    for ($j=0;$j<count($columns->columns);$j++) {
-                        $column = $columns->columns[$j];
-                        $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1);
-                    }
-                }
-            }
-        }
-        if (isset($id->cst)) {
-            $rows = file($pkgdir.'/'.$id->cst);
-            $columns = scorm_get_aicc_columns($rows[0],'block');
-            $regexp = scorm_forge_cols_regexp($columns->columns,'(.+)?,');
-            for ($i=1;$i<count($rows);$i++) {
-                if (preg_match($regexp,$rows[$i],$matches)) {
-                    for ($j=0;$j<count($columns->columns);$j++) {
-                        if ($j != $columns->mastercol) {
-                            $courses[$courseid]->elements[substr(trim($matches[$j+1]),1,-1)]->parent = substr(trim($matches[$columns->mastercol+1]),1,-1);
-                        }
-                    }
-                }
-            }
-        }
-        if (isset($id->ort)) {
-            $rows = file($pkgdir.'/'.$id->ort);
-        }
-        if (isset($id->pre)) {
-            $rows = file($pkgdir.'/'.$id->pre);
-            $columns = scorm_get_aicc_columns($rows[0],'structure_element');
-            $regexp = scorm_forge_cols_regexp($columns->columns,'(.+),');
-            for ($i=1;$i<count($rows);$i++) {
-                if (preg_match($regexp,$rows[$i],$matches)) {
-                    $courses[$courseid]->elements[$columns->mastercol+1]->prerequisites = substr(trim($matches[1-$columns->mastercol+1]),1,-1);
-                }
-            }
-        }
-        if (isset($id->cmp)) {
-            $rows = file($pkgdir.'/'.$id->cmp);
-        }
-    }
-    //print_r($courses);
-    $launch = 0;
-    if (isset($courses)) {
-        foreach ($courses as $course) {
-            unset($sco);
-            $sco->identifier = $course->id;
-            $sco->scorm = $scormid;
-            $sco->organization = '';
-            $sco->title = $course->title;
-            $sco->parent = '/';
-            $sco->launch = '';
-            $sco->scormtype = '';
-            //print_r($sco);
-            $id = insert_record('scorm_scoes',$sco);
-            if ($launch == 0) {
-                $launch = $id;
-            }
-            if (isset($course->elements)) {
-                foreach($course->elements as $element) {
-                    unset($sco);
-                    $sco->identifier = $element->system_id;
-                    $sco->scorm = $scormid;
-                    $sco->organization = $course->id;
-                    $sco->title = $element->title;
-                    if (strtolower($element->parent) == 'root') {
-                        $sco->parent = '/';
-                    } else {
-                        $sco->parent = $element->parent;
-                    }
-                    if (isset($element->file_name)) {
-                        $sco->launch = $element->file_name;
-                        $sco->scormtype = 'sco';
-                    } else {
-                        $element->file_name = '';
-                        $sco->scormtype = '';
-                    }
-                    if (!isset($element->prerequisites)) {
-                        $element->prerequisites = '';
-                    }
-                    $sco->prerequisites = $element->prerequisites;
-                    if (!isset($element->max_time_allowed)) {
-                        $element->max_time_allowed = '';
-                    }
-                    $sco->maxtimeallowed = $element->max_time_allowed;
-                    if (!isset($element->time_limit_action)) {
-                        $element->time_limit_action = '';
-                    }
-                    $sco->timelimitaction = $element->time_limit_action;
-                    if (!isset($element->mastery_score)) {
-                        $element->mastery_score = '';
-                    }
-                    $sco->masteryscore = $element->mastery_score;
-                    $sco->previous = 0;
-                    $sco->next = 0;
-                    $id = insert_record('scorm_scoes',$sco);
-                    if ($launch==0) {
-                        $launch = $id;
-                    }
-                }
-            }
-        }
-    }
-    set_field('scorm','version','AICC','id',$scormid);
-    return $launch;
-}
-
-
-function scorm_get_resources($blocks) {
-    foreach ($blocks as $block) {
-        if ($block['name'] == 'RESOURCES') {
-            foreach ($block['children'] as $resource) {
-                if ($resource['name'] == 'RESOURCE') {
-                    $resources[addslashes($resource['attrs']['IDENTIFIER'])] = $resource['attrs'];
-                }
-            }
-        }
-    }
-    return $resources;
-}
-
-
-function scorm_get_manifest($blocks,$scoes) {
-    static $parents = array();
-    static $resources;
-
-    static $manifest;
-    static $organization;
-
-    if (count($blocks) > 0) {
-        foreach ($blocks as $block) {
-            switch ($block['name']) {
-                case 'METADATA':
-                    if (isset($block['children'])) {
-                        foreach ($block['children'] as $metadata) {
-                            if ($metadata['name'] == 'SCHEMAVERSION') {
-                                if (empty($scoes->version)) {
-                                    if (preg_match("/^(1\.2)$|^(CAM )?(1\.3)$/",$metadata['tagData'],$matches)) {
-                                        $scoes->version = 'SCORM_'.$matches[count($matches)-1];
-                                    } else {
-                                        $scoes->version = 'SCORM_1.2';
-                                    }
-                                }
-                            }
-                        }
-                    }
-                break;
-                case 'MANIFEST':
-                    $manifest = addslashes($block['attrs']['IDENTIFIER']);
-                    $organization = '';
-                    $resources = array();
-                    $resources = scorm_get_resources($block['children']);
-                    $scoes = scorm_get_manifest($block['children'],$scoes);
-                    if (count($scoes->elements) <= 0) {
-                        foreach ($resources as $item => $resource) {
-                            if (!empty($resource['HREF'])) {
-                                $sco = new stdClass();
-                                $sco->identifier = $item;
-                                $sco->title = $item;
-                                $sco->parent = '/';
-                                $sco->launch = addslashes($resource['HREF']);
-                                $sco->scormtype = addslashes($resource['ADLCP:SCORMTYPE']);
-                                $scoes->elements[$manifest][$organization][$item] = $sco;
-                            }
-                        }
-                    }
-                break;
-                case 'ORGANIZATIONS':
-                    if (!isset($scoes->defaultorg)) {
-                        $scoes->defaultorg = addslashes($block['attrs']['DEFAULT']);
-                    }
-                    $scoes = scorm_get_manifest($block['children'],$scoes);
-                break;
-                case 'ORGANIZATION':
-                    $identifier = addslashes($block['attrs']['IDENTIFIER']);
-                    $organization = '';
-                    $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier;
-                    $scoes->elements[$manifest][$organization][$identifier]->parent = '/';
-                    $scoes->elements[$manifest][$organization][$identifier]->launch = '';
-                    $scoes->elements[$manifest][$organization][$identifier]->scormtype = '';
-
-                    $parents = array();
-                    $parent = new stdClass();
-                    $parent->identifier = $identifier;
-                    $parent->organization = $organization;
-                    array_push($parents, $parent);
-                    $organization = $identifier;
-
-                    $scoes = scorm_get_manifest($block['children'],$scoes);
-                    
-                    array_pop($parents);
-                break;
-                case 'ITEM':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    
-                    $identifier = addslashes($block['attrs']['IDENTIFIER']);
-                    $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier;
-                    $scoes->elements[$manifest][$organization][$identifier]->parent = $parent->identifier;
-                    if (!isset($block['attrs']['ISVISIBLE'])) {
-                        $block['attrs']['ISVISIBLE'] = 'true';
-                    }
-                    $scoes->elements[$manifest][$organization][$identifier]->isvisible = addslashes($block['attrs']['ISVISIBLE']);
-                    if (!isset($block['attrs']['PARAMETERS'])) {
-                        $block['attrs']['PARAMETERS'] = '';
-                    }
-                    $scoes->elements[$manifest][$organization][$identifier]->parameters = addslashes($block['attrs']['PARAMETERS']);
-                    if (!isset($block['attrs']['IDENTIFIERREF'])) {
-                        $scoes->elements[$manifest][$organization][$identifier]->launch = '';
-                        $scoes->elements[$manifest][$organization][$identifier]->scormtype = 'asset';
-                    } else {
-                        $idref = addslashes($block['attrs']['IDENTIFIERREF']);
-                        $base = '';
-                        if (isset($resources[$idref]['XML:BASE'])) {
-                            $base = $resources[$idref]['XML:BASE'];
-                        }
-                        $scoes->elements[$manifest][$organization][$identifier]->launch = addslashes($base.$resources[$idref]['HREF']);
-                        if (empty($resources[$idref]['ADLCP:SCORMTYPE'])) {
-                            $resources[$idref]['ADLCP:SCORMTYPE'] = 'asset';
-                        }
-                        $scoes->elements[$manifest][$organization][$identifier]->scormtype = addslashes($resources[$idref]['ADLCP:SCORMTYPE']);
-                    }
-
-                    $parent = new stdClass();
-                    $parent->identifier = $identifier;
-                    $parent->organization = $organization;
-                    array_push($parents, $parent);
-
-                    $scoes = scorm_get_manifest($block['children'],$scoes);
-                    
-                    array_pop($parents);
-                break;
-                case 'TITLE':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->title = addslashes($block['tagData']);
-                break;
-                case 'ADLCP:PREREQUISITES':
-                    if ($block['attrs']['TYPE'] == 'aicc_script') {
-                        $parent = array_pop($parents);
-                        array_push($parents, $parent);
-                        $scoes->elements[$manifest][$parent->organization][$parent->identifier]->prerequisites = addslashes($block['tagData']);
-                    }
-                break;
-                case 'ADLCP:MAXTIMEALLOWED':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->maxtimeallowed = addslashes($block['tagData']);
-                break;
-                case 'ADLCP:TIMELIMITACTION':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->timelimitaction = addslashes($block['tagData']);
-                break;
-                case 'ADLCP:DATAFROMLMS':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->datafromlms = addslashes($block['tagData']);
-                break;
-                case 'ADLCP:MASTERYSCORE':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->masteryscore = addslashes($block['tagData']);
-                break;
-            }
-        }
-    }
-
-    return $scoes;
-}
-
-
-function scorm_parse_scorm($pkgdir,$scormid) {
-    global $CFG;
-    
-    $launch = 0;
-    $manifestfile = $pkgdir.'/imsmanifest.xml';
-
-    if (is_file($manifestfile)) {
-    
-        require_once($CFG->dirroot.'/mod/scorm/xml2array.class.php');
-        
-        $xmlstring = file_get_contents($manifestfile);
-        $objXML = new xml2Array();
-        $manifests = $objXML->parse($xmlstring);
-            
-        $scoes = new stdClass();
-        $scoes->version = '';
-        $scoes = scorm_get_manifest($manifests,$scoes);
-
-        if (count($scoes->elements) > 0) {
-            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 (($launch == 0) && ((empty($scoes->defaultorg)) || ($scoes->defaultorg == $identifier))) {
-                            $launch = $id;
-                        }
-                    }
-                }
-            }
-            set_field('scorm','version',$scoes->version,'id',$scormid);
-        }
-    } 
-    
-    return $launch;
-}
-
-
-function scorm_get_tracks($scoid,$userid) {
-/// Gets all tracks of specified sco and user
-    global $CFG;
-
-    if ($tracks = get_records_select('scorm_scoes_track',"userid=$userid AND scoid=$scoid",'element ASC')) {
-        $usertrack->userid = $userid;
-        $usertrack->scoid = $scoid;
-        $usertrack->score_raw = '';
-        $usertrack->status = '';
-        $usertrack->total_time = '00:00:00';
-        $usertrack->session_time = '00:00:00';
-        $usertrack->timemodified = 0;
-        foreach ($tracks as $track) {
-            $element = $track->element;
-            $usertrack->{$element} = $track->value;
-            switch ($element) {
-                case 'cmi.core.lesson_status':
-                case 'cmi.completion_status':
-                    if ($track->value == 'not attempted') {
-                        $track->value = 'notattempted';
-                    }
-                    $usertrack->status = $track->value;
-                break;
-                case 'cmi.core.score.raw':
-                case 'cmi.score.raw':
-                    $usertrack->score_raw = $track->value;
-                break;
-                case 'cmi.core.session_time':
-                case 'cmi.session_time':
-                    $usertrack->session_time = $track->value;
-                break;
-                case 'cmi.core.total_time':
-                case 'cmi.total_time':
-                    $usertrack->total_time = $track->value;
-                break;
-            }
-            if (isset($track->timemodified) && ($track->timemodified > $usertrack->timemodified)) {
-                $usertrack->timemodified = $track->timemodified;
-            }
-        }
-        return $usertrack;
-    } else {
-        return false;
-    }
-}
-
-
-function scorm_get_user_data($userid) {
-/// Gets user info required to display the table of scorm results
-/// for report.php
-
-    return get_record('user','id',$userid,'','','','','firstname, lastname, picture');
-}
-
-
-function scorm_string_wrap($stringa, $len=15) {
-// Crop the given string into max $len characters lines
-    if (strlen($stringa) > $len) {
-        $words = explode(' ', $stringa);
-        $newstring = '';
-        $substring = '';
-        foreach ($words as $word) {
-           if ((strlen($substring)+strlen($word)+1) < $len) {
-               $substring .= ' '.$word;
-           } else {
-               $newstring .= ' '.$substring.'<br />';
-               $substring = $word;
-           }
-        }
-        if (!empty($substring)) {
-            $newstring .= ' '.$substring;
-        }
-        return $newstring;
-    } else {
-        return $stringa;
-    }
-}
-
-
-function scorm_eval_prerequisites($prerequisites,$usertracks) {
-    $element = '';
-    $stack = array();
-    $statuses = array(
-                'passed' => 'passed',
-                'completed' => 'completed',
-                'failed' => 'failed',
-                'incomplete' => 'incomplete',
-                'browsed' => 'browsed',
-                'not attempted' => 'notattempted',
-                'p' => 'passed',
-                'c' => 'completed',
-                'f' => 'failed',
-                'i' => 'incomplete',
-                'b' => 'browsed',
-                'n' => 'notattempted'
-                );
-    $i=0;  
-    while ($i<strlen($prerequisites)) {
-        $symbol = $prerequisites[$i];
-        switch ($symbol) {
-            case '&':
-            case '|':
-                $symbol .= $symbol;
-            case '~':
-            case '(':
-            case ')':
-            case '*':
-            //case '{':
-            //case '}':
-            //case ',':
-                $element = trim($element);
-                
-                if (!empty($element)) {
-                    $element = trim($element);
-                    if (isset($usertracks[$element])) {
-                        $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '.
-                                  '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; 
-                    } else if (($operator = strpos($element,'=')) !== false) {
-                        $item = trim(substr($element,0,$operator));
-                        if (!isset($usertracks[$item])) {
-                            return false;
-                        }
-                        
-                        $value = trim(trim(substr($element,$operator+1)),'"');
-                        if (isset($statuses[$value])) {
-                            $status = $statuses[$value];
-                        } else {
-                            return false;
-                        }
-                                              
-                        $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')';
-                    } else if (($operator = strpos($element,'<>')) !== false) {
-                        $item = trim(substr($element,0,$operator));
-                        if (!isset($usertracks[$item])) {
-                            return false;
-                        }
-                        
-                        $value = trim(trim(substr($element,$operator+2)),'"');
-                        if (isset($statuses[$value])) {
-                            $status = $statuses[$value];
-                        } else {
-                            return false;
-                        }
-                        
-                        $element = '(\''.$usertracks[$item]->status.'\' != \''.$status.'\')';
-                    } else if (is_numeric($element)) {
-                        if ($symbol == '*') {
-                            $symbol = '';
-                            $open = strpos($prerequisites,'{',$i);
-                            $opened = 1;
-                            $closed = 0;
-                            for ($close=$open+1; (($opened > $closed) && ($close<strlen($prerequisites))); $close++) { 
-                                 if ($prerequisites[$close] == '}') {
-                                     $closed++;
-                                 } else if ($prerequisites[$close] == '{') {
-                                     $opened++;
-                                 }
-                            } 
-                            $i = $close;
-                            
-                            $setelements = explode(',', substr($prerequisites, $open+1, $close-($open+1)-1));
-                            $settrue = 0;
-                            foreach ($setelements as $setelement) {
-                                if (scorm_eval_prerequisites($setelement,$usertracks)) {
-                                    $settrue++;
-                                }
-                            }
-                            
-                            if ($settrue >= $element) {
-                                $element = 'true'; 
-                            } else {
-                                $element = 'false';
-                            }
-                        }
-                    } else {
-                        return false;
-                    }
-                    
-                    array_push($stack,$element);
-                    $element = '';
-                }
-                if ($symbol == '~') {
-                    $symbol = '!';
-                }
-                if (!empty($symbol)) {
-                    array_push($stack,$symbol);
-                }
-            break;
-            default:
-                $element .= $symbol;
-            break;
-        }
-        $i++;
-    }
-    if (!empty($element)) {
-        $element = trim($element);
-        if (isset($usertracks[$element])) {
-            $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '.
-                       '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; 
-        } else if (($operator = strpos($element,'=')) !== false) {
-            $item = trim(substr($element,0,$operator));
-            if (!isset($usertracks[$item])) {
-                return false;
-            }
-            
-            $value = trim(trim(substr($element,$operator+1)),'"');
-            if (isset($statuses[$value])) {
-                $status = $statuses[$value];
-            } else {
-                return false;
-            }
-            
-            $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')';
-        } else if (($operator = strpos($element,'<>')) !== false) {
-            $item = trim(substr($element,0,$operator));
-            if (!isset($usertracks[$item])) {
-                return false;
-            }
-            
-            $value = trim(trim(substr($element,$operator+1)),'"');
-            if (isset($statuses[$value])) {
-                $status = $statuses[$value];
-            } else {
-                return false;
-            }
-            
-            $element = '(\''.$usertracks[$item]->status.'\' != \''.trim($status).'\')';
-        } else {
-            return false;
-        }
-        
-        array_push($stack,$element);
-    }
-    return eval('return '.implode($stack).';');
-}
-
-
-function scorm_insert_track($userid,$scormid,$scoid,$element,$value) {
-    $id = null;
-    if ($track = get_record_select('scorm_scoes_track',"userid='$userid' AND scormid='$scormid' AND scoid='$scoid' AND element='$element'")) {
-        $track->value = $value;
-        $track->timemodified = time();
-        $id = update_record('scorm_scoes_track',$track);
-    } else {
-        $track->userid = $userid;
-        $track->scormid = $scormid;
-        $track->scoid = $scoid;
-        $track->element = $element;
-        $track->value = $value;
-        $track->timemodified = time();
-        $id = insert_record('scorm_scoes_track',$track);
-    }
-    return $id;
-}
-
-
-function scorm_add_time($a, $b) {
-    $aes = explode(':',$a);
-    $bes = explode(':',$b);
-    $aseconds = explode('.',$aes[2]);
-    $bseconds = explode('.',$bes[2]);
-    $change = 0;
-
-    $acents = 0;  //Cents
-    if (count($aseconds) > 1) {
-        $acents = $aseconds[1];
-    }
-    $bcents = 0;
-    if (count($bseconds) > 1) {
-        $bcents = $bseconds[1];
-    }
-    $cents = $acents + $bcents;
-    $change = floor($cents / 100);
-    $cents = $cents - ($change * 100);
-    if (floor($cents) < 10) {
-        $cents = '0'. $cents;
-    }
-
-    $secs = $aseconds[0] + $bseconds[0] + $change;  //Seconds
-    $change = floor($secs / 60);
-    $secs = $secs - ($change * 60);
-    if (floor($secs) < 10) {
-        $secs = '0'. $secs;
-    }
-
-    $mins = $aes[1] + $bes[1] + $change;   //Minutes
-    $change = floor($mins / 60);
-    $mins = $mins - ($change * 60);
-    if ($mins < 10) {
-        $mins = '0' .  $mins;
-    }
-
-    $hours = $aes[0] + $bes[0] + $change;  //Hours
-    if ($hours < 10) {
-        $hours = '0' . $hours;
-    }
-
-    if ($cents != '0') {
-        return $hours . ":" . $mins . ":" . $secs . '.' . $cents;
-    } else {
-        return $hours . ":" . $mins . ":" . $secs;
-    }
-}
-
-
-function scorm_external_link($link) {
-// check if a link is external
-    $result = false;
-    $link = strtolower($link);
-    if (substr($link,0,7) == 'http://') {
-        $result = true;
-    } else if (substr($link,0,8) == 'https://') {
-        $result = true;
-    } else if (substr($link,0,4) == 'www.') {
-        $result = true;
-    }
-    return $result;
-}
-
-
-function scorm_count_launchable($scormid,$organization) {
-    return count_records_select('scorm_scoes',"scorm=$scormid AND organization='$organization' AND launch<>''");
-}
-
-
-function scorm_get_toc($scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$play=false) {
-    global $USER, $CFG;
-
-    $strexpand = get_string('expcoll','scorm');
-    
-    $result = new stdClass();
-    $result->toc = "<ul id='0' class='$liststyle'>\n";
-    $result->prerequisites = true;
-    $incomplete = false;
-    $organizationsql = '';
-    
-    if (!empty($currentorg)) {
-        if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id,'identifier',$currentorg)) != '') {
-            $result->toc .= "\t<li>$organizationtitle</li>\n";
-        }
-        $organizationsql = "AND organization='$currentorg'";
-    }
-    if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
-        $usertracks = array();
-        foreach ($scoes as $sco) {
-            if (!empty($sco->launch)) {
-                if ($usertrack=scorm_get_tracks($sco->id,$USER->id)) {
-                    if ($usertrack->status == '') {
-                        $usertrack->status = 'notattempted';
-                    }
-                    $usertracks[$sco->identifier] = $usertrack;
-                }
-            }
-        }
-
-        $level=0;
-        $sublist=1;
-        $previd = 0;
-        $nextid = 0;
-        $findnext = false;
-        $parents[$level]='/';
-        
-        foreach ($scoes as $sco) {
-            if ($parents[$level]!=$sco->parent) {
-                if ($newlevel = array_search($sco->parent,$parents)) {
-                    for ($i=0; $i<($level-$newlevel); $i++) {
-                        $result->toc .= "\t\t</ul></li>\n";
-                    }
-                    $level = $newlevel;
-                } else {
-                    $i = $level;
-                    $closelist = '';
-                    while (($i > 0) && ($parents[$level] != $sco->parent)) {
-                        $closelist .= "\t\t</ul></li>\n";
-                        $i--;
-                    }
-                    if (($i == 0) && ($sco->parent != $currentorg)) {
-                        $result->toc .= "\t\t<li><ul id='$sublist' class='$liststyle'>\n";
-                        $level++;
-                    } else {
-                        $result->toc .= $closelist;
-                        $level = $i;
-                    }
-                    $parents[$level]=$sco->parent;
-                }
-            }
-            $result->toc .= "\t\t<li>";
-            $nextsco = next($scoes);
-            if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
-                $sublist++;
-                $result->toc .= '<a href="#" onClick="expandCollide(img'.$sublist.','.$sublist.');"><img id="img'.$sublist.'" src="'.$CFG->wwwroot.'/mod/scorm/pix/minus.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
-            } else {
-                $result->toc .= '<img src="'.$CFG->wwwroot.'/mod/scorm/pix/spacer.gif" />';
-            }
-            if (empty($sco->title)) {
-                $sco->title = $sco->identifier;
-            }
-            if (!empty($sco->launch)) {
-                $startbold = '';
-                $endbold = '';
-                $score = '';
-                if (empty($scoid) && ($mode != 'normal')) {
-                    $scoid = $sco->id;
-                }
-                if (isset($usertracks[$sco->identifier])) {
-                    $usertrack = $usertracks[$sco->identifier];
-                    $strstatus = get_string($usertrack->status,'scorm');
-                    $result->toc .= "<img src='".$CFG->wwwroot."/mod/scorm/pix/".$usertrack->status.".gif' alt='$strstatus' title='$strstatus' />";
-                    if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
-                        $incomplete = true;
-                        if ($play && empty($scoid)) {
-                            $scoid = $sco->id;
-                        }
-                    }
-                    if ($usertrack->score_raw != '') {
-                        $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
-                    }
-                } else {
-                    if ($play && empty($scoid)) {
-                        $scoid = $sco->id;
-                    }
-                    if ($sco->scormtype == 'sco') {
-                        $result->toc .= '<img src="'.$CFG->wwwroot.'/mod/scorm/pix/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
-                        $incomplete = true;
-                    } else {
-                        $result->toc .= '<img src="'.$CFG->wwwroot.'/mod/scorm/pix/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
-                    }
-                }
-                if ($sco->id == $scoid) {
-                    $startbold = '<b>';
-                    $endbold = '</b>';
-                    $findnext = true;
-                    $shownext = $sco->next;
-                    $showprev = $sco->previous;
-                }
-                
-                if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
-                    if (!empty($sco->launch)) {
-                        $previd = $sco->id;
-                    }
-                }
-                if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) {
-                    if ($sco->id == $scoid) {
-                        $result->prerequisites = true;
-                    }
-                    $result->toc .= "&nbsp;$startbold<a href='javascript:playSCO(".$sco->id.");'>".format_string($sco->title)."</a> $score$endbold</li>\n";
+function scorm_option2text($scorm) {
+    if (isset($scorm->popup)) {
+        if ($scorm->popup) {
+            $optionlist = array();
+            foreach ($SCORM_POPUP_OPTIONS as $option) {
+                if (isset($scorm->$option)) {
+                    $optionlist[] = $option.'='.$scorm->$option;
                 } else {
-                    if ($sco->id == $scoid) {
-                        $result->prerequisites = false;
-                    }
-                    $result->toc .= "&nbsp;$sco->title</li>\n";
-                }
-            } else {
-                $result->toc .= "&nbsp;$sco->title</li>\n";
-            }
-            if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
-                if (!empty($nextsco->launch)) {
-                    $nextid = $nextsco->id;
+                    $optionlist[] = $option.'=0';
                 }
-            }
-        }
-        for ($i=0;$i<$level;$i++) {
-            $result->toc .= "\t\t</ul></li>\n";
-        }
-        
-        if ($play) {
-            $sco = new stdClass();
-            $sco->id = $scoid;
-            $sco->prev = $previd;
-            $sco->next = $nextid;
-            $sco->showprev = $showprev;
-            $sco->shownext = $shownext;
-            $result->sco = $sco;
-            $result->incomplete = $incomplete;
+            }       
+            $scorm->options = implode(',', $optionlist);
         } else {
-            $result->incomplete = $incomplete;
-        }
+            $scorm->options = '';
+        } 
+    } else {
+        $scorm->popup = 0;
+        $scorm->options = '';
     }
-    $result->toc .= "\t</ul>\n";
-    
-    return $result;
-}
-
-function scorm_get_view_actions() {
-    return array('pre-view','view','view all','report');
-}
-
-function scorm_get_post_actions() {
-    return array();
+    return $scorm;
 }
 
 ?>
index 307460d..3a971c1 100755 (executable)
@@ -1,6 +1,6 @@
 <?php
     require_once("../../config.php");
-    require_once("lib.php");
+    require_once('locallib.php');
 
     $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or
     $a = optional_param('a', '', PARAM_INT);         // scorm ID
             setTimeout('document.location = "<?php echo $result ?>";',1000);
         -->
         </script>
+        <noscript>
+            <meta http-equiv="refresh" content="1;url=<?php echo $result ?>" />
+        </noscript> 
     </head>
     <body>
         &nbsp;
diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php
new file mode 100755 (executable)
index 0000000..bd59b17
--- /dev/null
@@ -0,0 +1,1105 @@
+<?php  // $Id$
+
+/// Local Library of functions and constants for module scorm
+
+/**
+* Create a new temporary subdirectory with a random name in the given path
+*
+* @param string $strpath The scorm data directory
+* @return string/boolean
+*/
+function scorm_datadir($strPath)
+{
+    global $CFG;
+
+    if (is_dir($strPath)) {
+        do {
+            // Create a random string of 8 chars
+            $randstring = NULL;
+            $lchar = '';
+            $len = 8;
+            for ($i=0; $i<$len; $i++) {
+                $char = chr(rand(48,122));
+                while (!ereg('[a-zA-Z0-9]', $char)){
+                    if ($char == $lchar) continue;
+                        $char = chr(rand(48,90));
+                    }
+                    $randstring .= $char;
+                    $lchar = $char;
+            } 
+            $datadir='/'.randstring;
+        } while (file_exists($strPath.$datadir));
+        mkdir($strPath.$datadir, $CFG->directorypermissions);
+        @chmod($strPath.$datadir, $CFG->directorypermissions);  // Just in case mkdir didn't do it
+        return $strPath.$datadir;
+    } else {
+        return false;
+    }
+}
+
+/**
+* Given a package directory, this function will check if the package is valid
+*
+* @param string $packagedir The package directory
+* @return mixed
+*/
+function scorm_validate($packagedir) {
+    $validation = new stdClass();
+    if (is_file($packagedir.'/imsmanifest.xml')) {
+        $validation->result = 'found';
+        $validation->pkgtype = 'SCORM';
+    } else {
+        if ($handle = opendir($packagedir)) {
+            while (($file = readdir($handle)) !== false) {
+                $ext = substr($file,strrpos($file,'.'));
+                if (strtolower($ext) == '.cst') {
+                    $validation->result = 'found';
+                    $validation->pkgtype = 'AICC';
+                    break;
+                }
+            }
+            closedir($handle);
+        }
+        if (!isset($validation)) {
+            $validation->result = 'nomanifest';
+            $validation->pkgtype = 'SCORM';
+        }
+    }
+    return $validation;
+}
+
+function scorm_get_user_data($userid) {
+/// Gets user info required to display the table of scorm results
+/// for report.php
+
+    return get_record('user','id',$userid,'','','','','firstname, lastname, picture');
+}
+
+function scorm_string_wrap($stringa, $len=15) {
+// Crop the given string into max $len characters lines
+    if (strlen($stringa) > $len) {
+        $words = explode(' ', $stringa);
+        $newstring = '';
+        $substring = '';
+        foreach ($words as $word) {
+           if ((strlen($substring)+strlen($word)+1) < $len) {
+               $substring .= ' '.$word;
+           } else {
+               $newstring .= ' '.$substring.'<br />';
+               $substring = $word;
+           }
+        }
+        if (!empty($substring)) {
+            $newstring .= ' '.$substring;
+        }
+        return $newstring;
+    } else {
+        return $stringa;
+    }
+}
+
+function scorm_eval_prerequisites($prerequisites,$usertracks) {
+    $element = '';
+    $stack = array();
+    $statuses = array(
+                'passed' => 'passed',
+                'completed' => 'completed',
+                'failed' => 'failed',
+                'incomplete' => 'incomplete',
+                'browsed' => 'browsed',
+                'not attempted' => 'notattempted',
+                'p' => 'passed',
+                'c' => 'completed',
+                'f' => 'failed',
+                'i' => 'incomplete',
+                'b' => 'browsed',
+                'n' => 'notattempted'
+                );
+    $i=0;  
+    while ($i<strlen($prerequisites)) {
+        $symbol = $prerequisites[$i];
+        switch ($symbol) {
+            case '&':
+            case '|':
+                $symbol .= $symbol;
+            case '~':
+            case '(':
+            case ')':
+            case '*':
+            //case '{':
+            //case '}':
+            //case ',':
+                $element = trim($element);
+                
+                if (!empty($element)) {
+                    $element = trim($element);
+                    if (isset($usertracks[$element])) {
+                        $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '.
+                                  '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; 
+                    } else if (($operator = strpos($element,'=')) !== false) {
+                        $item = trim(substr($element,0,$operator));
+                        if (!isset($usertracks[$item])) {
+                            return false;
+                        }
+                        
+                        $value = trim(trim(substr($element,$operator+1)),'"');
+                        if (isset($statuses[$value])) {
+                            $status = $statuses[$value];
+                        } else {
+                            return false;
+                        }
+                                              
+                        $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')';
+                    } else if (($operator = strpos($element,'<>')) !== false) {
+                        $item = trim(substr($element,0,$operator));
+                        if (!isset($usertracks[$item])) {
+                            return false;
+                        }
+                        
+                        $value = trim(trim(substr($element,$operator+2)),'"');
+                        if (isset($statuses[$value])) {
+                            $status = $statuses[$value];
+                        } else {
+                            return false;
+                        }
+                        
+                        $element = '(\''.$usertracks[$item]->status.'\' != \''.$status.'\')';
+                    } else if (is_numeric($element)) {
+                        if ($symbol == '*') {
+                            $symbol = '';
+                            $open = strpos($prerequisites,'{',$i);
+                            $opened = 1;
+                            $closed = 0;
+                            for ($close=$open+1; (($opened > $closed) && ($close<strlen($prerequisites))); $close++) { 
+                                 if ($prerequisites[$close] == '}') {
+                                     $closed++;
+                                 } else if ($prerequisites[$close] == '{') {
+                                     $opened++;
+                                 }
+                            } 
+                            $i = $close;
+                            
+                            $setelements = explode(',', substr($prerequisites, $open+1, $close-($open+1)-1));
+                            $settrue = 0;
+                            foreach ($setelements as $setelement) {
+                                if (scorm_eval_prerequisites($setelement,$usertracks)) {
+                                    $settrue++;
+                                }
+                            }
+                            
+                            if ($settrue >= $element) {
+                                $element = 'true'; 
+                            } else {
+                                $element = 'false';
+                            }
+                        }
+                    } else {
+                        return false;
+                    }
+                    
+                    array_push($stack,$element);
+                    $element = '';
+                }
+                if ($symbol == '~') {
+                    $symbol = '!';
+                }
+                if (!empty($symbol)) {
+                    array_push($stack,$symbol);
+                }
+            break;
+            default:
+                $element .= $symbol;
+            break;
+        }
+        $i++;
+    }
+    if (!empty($element)) {
+        $element = trim($element);
+        if (isset($usertracks[$element])) {
+            $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '.
+                       '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; 
+        } else if (($operator = strpos($element,'=')) !== false) {
+            $item = trim(substr($element,0,$operator));
+            if (!isset($usertracks[$item])) {
+                return false;
+            }
+            
+            $value = trim(trim(substr($element,$operator+1)),'"');
+            if (isset($statuses[$value])) {
+                $status = $statuses[$value];
+            } else {
+                return false;
+            }
+            
+            $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')';
+        } else if (($operator = strpos($element,'<>')) !== false) {
+            $item = trim(substr($element,0,$operator));
+            if (!isset($usertracks[$item])) {
+                return false;
+            }
+            
+            $value = trim(trim(substr($element,$operator+1)),'"');
+            if (isset($statuses[$value])) {
+                $status = $statuses[$value];
+            } else {
+                return false;
+            }
+            
+            $element = '(\''.$usertracks[$item]->status.'\' != \''.trim($status).'\')';
+        } else {
+            return false;
+        }
+        
+        array_push($stack,$element);
+    }
+    return eval('return '.implode($stack).';');
+}
+
+
+function scorm_insert_track($userid,$scormid,$scoid,$element,$value) {
+    $id = null;
+    if ($track = get_record_select('scorm_scoes_track',"userid='$userid' AND scormid='$scormid' AND scoid='$scoid' AND element='$element'")) {
+        $track->value = $value;
+        $track->timemodified = time();
+        $id = update_record('scorm_scoes_track',$track);
+    } else {
+        $track->userid = $userid;
+        $track->scormid = $scormid;
+        $track->scoid = $scoid;
+        $track->element = $element;
+        $track->value = addslashes($value);
+        $track->timemodified = time();
+        $id = insert_record('scorm_scoes_track',$track);
+    }
+    return $id;
+}
+
+
+function scorm_add_time($a, $b) {
+    $aes = explode(':',$a);
+    $bes = explode(':',$b);
+    $aseconds = explode('.',$aes[2]);
+    $bseconds = explode('.',$bes[2]);
+    $change = 0;
+
+    $acents = 0;  //Cents
+    if (count($aseconds) > 1) {
+        $acents = $aseconds[1];
+    }
+    $bcents = 0;
+    if (count($bseconds) > 1) {
+        $bcents = $bseconds[1];
+    }
+    $cents = $acents + $bcents;
+    $change = floor($cents / 100);
+    $cents = $cents - ($change * 100);
+    if (floor($cents) < 10) {
+        $cents = '0'. $cents;
+    }
+
+    $secs = $aseconds[0] + $bseconds[0] + $change;  //Seconds
+    $change = floor($secs / 60);
+    $secs = $secs - ($change * 60);
+    if (floor($secs) < 10) {
+        $secs = '0'. $secs;
+    }
+
+    $mins = $aes[1] + $bes[1] + $change;   //Minutes
+    $change = floor($mins / 60);
+    $mins = $mins - ($change * 60);
+    if ($mins < 10) {
+        $mins = '0' .  $mins;
+    }
+
+    $hours = $aes[0] + $bes[0] + $change;  //Hours
+    if ($hours < 10) {
+        $hours = '0' . $hours;
+    }
+
+    if ($cents != '0') {
+        return $hours . ":" . $mins . ":" . $secs . '.' . $cents;
+    } else {
+        return $hours . ":" . $mins . ":" . $secs;
+    }
+}
+
+function scorm_external_link($link) {
+// check if a link is external
+    $result = false;
+    $link = strtolower($link);
+    if (substr($link,0,7) == 'http://') {
+        $result = true;
+    } else if (substr($link,0,8) == 'https://') {
+        $result = true;
+    } else if (substr($link,0,4) == 'www.') {
+        $result = true;
+    }
+    return $result;
+}
+
+function scorm_grade_user($scoes, $userid, $grademethod=VALUESCOES) {
+    $scores = NULL; 
+    $scores->scoes = 0;
+    $scores->values = 0;
+    $scores->max = 0;
+    $scores->sum = 0;
+
+    if (!$scoes) {
+        return '';
+    }
+
+    foreach ($scoes as $sco) { 
+        if ($userdata=scorm_get_tracks($sco->id, $userid)) {
+            if (($userdata->status == 'completed') || ($userdata->status == 'passed')) {
+                $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;
+            }       
+        }       
+    }
+    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->scoes;
+        break;  
+    }
+}
+
+function scorm_count_launchable($scormid,$organization) {
+    return count_records_select('scorm_scoes',"scorm=$scormid AND organization='$organization' AND launch<>''");
+}
+
+function scorm_get_toc($scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$play=false) {
+    global $USER, $CFG;
+
+    $strexpand = get_string('expcoll','scorm');
+    
+    $result = new stdClass();
+    $result->toc = "<ul id='0' class='$liststyle'>\n";
+    $result->prerequisites = true;
+    $incomplete = false;
+    $organizationsql = '';
+    
+    if (!empty($currentorg)) {
+        if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id,'identifier',$currentorg)) != '') {
+            $result->toc .= "\t<li>$organizationtitle</li>\n";
+        }
+        $organizationsql = "AND organization='$currentorg'";
+    }
+    if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
+        $usertracks = array();
+        foreach ($scoes as $sco) {
+            if (!empty($sco->launch)) {
+                if ($usertrack=scorm_get_tracks($sco->id,$USER->id)) {
+                    if ($usertrack->status == '') {
+                        $usertrack->status = 'notattempted';
+                    }
+                    $usertracks[$sco->identifier] = $usertrack;
+                }
+            }
+        }
+
+        $level=0;
+        $sublist=1;
+        $previd = 0;
+        $nextid = 0;
+        $findnext = false;
+        $parents[$level]='/';
+        
+        foreach ($scoes as $sco) {
+            if ($parents[$level]!=$sco->parent) {
+                if ($newlevel = array_search($sco->parent,$parents)) {
+                    for ($i=0; $i<($level-$newlevel); $i++) {
+                        $result->toc .= "\t\t</ul></li>\n";
+                    }
+                    $level = $newlevel;
+                } else {
+                    $i = $level;
+                    $closelist = '';
+                    while (($i > 0) && ($parents[$level] != $sco->parent)) {
+                        $closelist .= "\t\t</ul></li>\n";
+                        $i--;
+                    }
+                    if (($i == 0) && ($sco->parent != $currentorg)) {
+                        $result->toc .= "\t\t<li><ul id='$sublist' class='$liststyle'>\n";
+                        $level++;
+                    } else {
+                        $result->toc .= $closelist;
+                        $level = $i;
+                    }
+                    $parents[$level]=$sco->parent;
+                }
+            }
+            $result->toc .= "\t\t<li>";
+            $nextsco = next($scoes);
+            if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
+                $sublist++;
+                $result->toc .= '<a href="javascript:expandCollide(img'.$sublist.','.$sublist.');"><img id="img'.$sublist.'" src="'.$CFG->wwwroot.'/mod/scorm/pix/minus.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
+            } else {
+                $result->toc .= '<img src="'.$CFG->wwwroot.'/mod/scorm/pix/spacer.gif" />';
+            }
+            if (empty($sco->title)) {
+                $sco->title = $sco->identifier;
+            }
+            if (!empty($sco->launch)) {
+                $startbold = '';
+                $endbold = '';
+                $score = '';
+                if (empty($scoid) && ($mode != 'normal')) {
+                    $scoid = $sco->id;
+                }
+                if (isset($usertracks[$sco->identifier])) {
+                    $usertrack = $usertracks[$sco->identifier];
+                    $strstatus = get_string($usertrack->status,'scorm');
+                    $result->toc .= "<img src='".$CFG->wwwroot."/mod/scorm/pix/".$usertrack->status.".gif' alt='$strstatus' title='$strstatus' />";
+                    if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
+                        $incomplete = true;
+                        if ($play && empty($scoid)) {
+                            $scoid = $sco->id;
+                        }
+                    }
+                    if ($usertrack->score_raw != '') {
+                        $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
+                    }
+                } else {
+                    if ($play && empty($scoid)) {
+                        $scoid = $sco->id;
+                    }
+                    if ($sco->scormtype == 'sco') {
+                        $result->toc .= '<img src="'.$CFG->wwwroot.'/mod/scorm/pix/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
+                        $incomplete = true;
+                    } else {
+                        $result->toc .= '<img src="'.$CFG->wwwroot.'/mod/scorm/pix/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
+                    }
+                }
+                if ($sco->id == $scoid) {
+                    $startbold = '<b>';
+                    $endbold = '</b>';
+                    $findnext = true;
+                    $shownext = $sco->next;
+                    $showprev = $sco->previous;
+                }
+                
+                if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
+                    if (!empty($sco->launch)) {
+                        $previd = $sco->id;
+                    }
+                }
+                if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) {
+                    if ($sco->id == $scoid) {
+                        $result->prerequisites = true;
+                    }
+                    $result->toc .= '&nbsp'.$startbold.'<a href="'.$CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.'&mode='.$mode.'&scoid='.$sco->id.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
+                } else {
+                    if ($sco->id == $scoid) {
+                        $result->prerequisites = false;
+                    }
+                    $result->toc .= '&nbsp;'.$sco->title."</li>\n";
+                }
+            } else {
+                $result->toc .= '&nbsp;'.$sco->title."</li>\n";
+            }
+            if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
+                if (!empty($nextsco->launch)) {
+                    $nextid = $nextsco->id;
+                }
+            }
+        }
+        for ($i=0;$i<$level;$i++) {
+            $result->toc .= "\t\t</ul></li>\n";
+        }
+        
+        if ($play) {
+            $sco = get_record('scorm_scoes','id',$scoid);
+            $sco->previd = $previd;
+            $sco->nextid = $nextid;
+            $result->sco = $sco;
+            $result->incomplete = $incomplete;
+        } else {
+            $result->incomplete = $incomplete;
+        }
+    }
+    $result->toc .= "\t</ul>\n";
+    
+    return $result;
+}
+
+function scorm_get_tracks($scoid,$userid) {
+/// Gets all tracks of specified sco and user
+    global $CFG;
+
+    $attemptsql = '';
+    if ($lastattempt = get_record('scorm_sco_tracks', 'user', $USER->id, 'scorm', $scorm->id, '', '', 'max(attempt) as a')) {
+        $attemptsql = ' AND attempt='.$lastattempt;
+    }
+    if ($tracks = get_records_select('scorm_scoes_track',"userid=$userid AND scoid=$scoid".$attemptsql,'element ASC')) {
+        $usertrack->userid = $userid;
+        $usertrack->scoid = $scoid; 
+        $usertrack->score_raw = '';
+        $usertrack->status = '';
+        $usertrack->total_time = '00:00:00';
+        $usertrack->session_time = '00:00:00';
+        $usertrack->timemodified = 0;
+        foreach ($tracks as $track) {
+            $element = $track->element;
+            $usertrack->{$element} = $track->value;
+            switch ($element) {
+                case 'cmi.core.lesson_status':
+                case 'cmi.completion_status':
+                    if ($track->value == 'not attempted') {
+                        $track->value = 'notattempted';
+                    }       
+                    $usertrack->status = $track->value;
+                break;  
+                case 'cmi.core.score.raw':
+                case 'cmi.score.raw':
+                    $usertrack->score_raw = $track->value;
+                break;  
+                case 'cmi.core.session_time':
+                case 'cmi.session_time':
+                    $usertrack->session_time = $track->value;
+                break;  
+                case 'cmi.core.total_time':
+                case 'cmi.total_time':
+                    $usertrack->total_time = $track->value;
+                break;  
+            }       
+            if (isset($track->timemodified) && ($track->timemodified > $usertrack->timemodified)) {
+                $usertrack->timemodified = $track->timemodified;
+            }       
+        }       
+        return $usertrack;
+    } else {
+        return false;
+    }
+}
+
+
+/// Library of functions and constants for parsing packages
+
+function scorm_parse($scorm) {
+    global $CFG;
+
+    // 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') {
+            $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);
+        }
+    }
+
+    return $scorm->launch;
+}
+
+/**
+* Take the header row of an AICC definition file
+* and returns sequence of columns and a pointer to
+* the sco identifier column.
+*
+* @param string $row AICC header row
+* @param string $mastername AICC sco identifier column
+* @return mixed
+*/
+function scorm_get_aicc_columns($row,$mastername='system_id') {
+    $tok = strtok(strtolower($row),"\",\n\r");
+    $result->columns = array();
+    $i=0;
+    while ($tok) {
+        if ($tok !='') {
+            $result->columns[] = $tok;
+            if ($tok == $mastername) {
+                $result->mastercol = $i;
+            }
+            $i++;
+        }
+        $tok = strtok("\",\n\r");
+    }
+    return $result;
+}
+
+/**
+* Given a colums array return a string containing the regular
+* expression to match the columns in a text row.
+*
+* @param array $column The header columns
+* @param string $remodule The regular expression module for a single column
+* @return string
+*/
+function scorm_forge_cols_regexp($columns,$remodule='(".*")?,') {
+    $regexp = '/^';
+    foreach ($columns as $column) {
+        $regexp .= $remodule;
+    }
+    $regexp = substr($regexp,0,-1) . '/';
+    return $regexp;
+}
+
+function scorm_parse_aicc($pkgdir,$scormid){
+    $version = 'AICC';
+    $ids = array();
+    $courses = array();
+    if ($handle = opendir($pkgdir)) {
+        while (($file = readdir($handle)) !== false) {
+            $ext = substr($file,strrpos($file,'.'));
+            $extension = strtolower(substr($ext,1));
+            $id = strtolower(basename($file,$ext));
+            $ids[$id]->$extension = $file;
+        }
+        closedir($handle);
+    }
+    foreach ($ids as $courseid => $id) {
+        if (isset($id->crs)) {
+            if (is_file($pkgdir.'/'.$id->crs)) {
+                $rows = file($pkgdir.'/'.$id->crs);
+                foreach ($rows as $row) {
+                    if (preg_match("/^(.+)=(.+)$/",$row,$matches)) {
+                        switch (strtolower(trim($matches[1]))) {
+                            case 'course_id':
+                                $courses[$courseid]->id = trim($matches[2]);
+                            break;
+                            case 'course_title':
+                                $courses[$courseid]->title = trim($matches[2]);
+                            break;
+                            case 'version':
+                                $courses[$courseid]->version = 'AICC_'.trim($matches[2]);
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+        if (isset($id->des)) {
+            $rows = file($pkgdir.'/'.$id->des);
+            $columns = scorm_get_aicc_columns($rows[0]);
+            $regexp = scorm_forge_cols_regexp($columns->columns);
+            for ($i=1;$i<count($rows);$i++) {
+                if (preg_match($regexp,$rows[$i],$matches)) {
+                    for ($j=0;$j<count($columns->columns);$j++) {
+                        $column = $columns->columns[$j];
+                        $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1);
+                    }
+                }
+            }
+        }
+        if (isset($id->au)) {
+            $rows = file($pkgdir.'/'.$id->au);
+            $columns = scorm_get_aicc_columns($rows[0]);
+            $regexp = scorm_forge_cols_regexp($columns->columns);
+            for ($i=1;$i<count($rows);$i++) {
+                if (preg_match($regexp,$rows[$i],$matches)) {
+                    for ($j=0;$j<count($columns->columns);$j++) {
+                        $column = $columns->columns[$j];
+                        $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1);
+                    }
+                }
+            }
+        }
+        if (isset($id->cst)) {
+            $rows = file($pkgdir.'/'.$id->cst);
+            $columns = scorm_get_aicc_columns($rows[0],'block');
+            $regexp = scorm_forge_cols_regexp($columns->columns,'(.+)?,');
+            for ($i=1;$i<count($rows);$i++) {
+                if (preg_match($regexp,$rows[$i],$matches)) {
+                    for ($j=0;$j<count($columns->columns);$j++) {
+                        if ($j != $columns->mastercol) {
+                            $courses[$courseid]->elements[substr(trim($matches[$j+1]),1,-1)]->parent = substr(trim($matches[$columns->mastercol+1]),1,-1);
+                        }
+                    }
+                }
+            }
+        }
+        if (isset($id->ort)) {
+            $rows = file($pkgdir.'/'.$id->ort);
+        }
+        if (isset($id->pre)) {
+            $rows = file($pkgdir.'/'.$id->pre);
+            $columns = scorm_get_aicc_columns($rows[0],'structure_element');
+            $regexp = scorm_forge_cols_regexp($columns->columns,'(.+),');
+            for ($i=1;$i<count($rows);$i++) {
+                if (preg_match($regexp,$rows[$i],$matches)) {
+                    $courses[$courseid]->elements[$columns->mastercol+1]->prerequisites = substr(trim($matches[1-$columns->mastercol+1]),1,-1);
+                }
+            }
+        }
+        if (isset($id->cmp)) {
+            $rows = file($pkgdir.'/'.$id->cmp);
+        }
+    }
+    //print_r($courses);
+    $launch = 0;
+    if (isset($courses)) {
+        foreach ($courses as $course) {
+            unset($sco);
+            $sco->identifier = $course->id;
+            $sco->scorm = $scormid;
+            $sco->organization = '';
+            $sco->title = $course->title;
+            $sco->parent = '/';
+            $sco->launch = '';
+            $sco->scormtype = '';
+            //print_r($sco);
+            $id = insert_record('scorm_scoes',$sco);
+            if ($launch == 0) {
+                $launch = $id;
+            }
+            if (isset($course->elements)) {
+                foreach($course->elements as $element) {
+                    unset($sco);
+                    $sco->identifier = $element->system_id;
+                    $sco->scorm = $scormid;
+                    $sco->organization = $course->id;
+                    $sco->title = $element->title;
+                    if (strtolower($element->parent) == 'root') {
+                        $sco->parent = '/';
+                    } else {
+                        $sco->parent = $element->parent;
+                    }
+                    if (isset($element->file_name)) {
+                        $sco->launch = $element->file_name;
+                        $sco->scormtype = 'sco';
+                    } else {
+                        $element->file_name = '';
+                        $sco->scormtype = '';
+                    }
+                    if (!isset($element->prerequisites)) {
+                        $element->prerequisites = '';
+                    }
+                    $sco->prerequisites = $element->prerequisites;
+                    if (!isset($element->max_time_allowed)) {
+                        $element->max_time_allowed = '';
+                    }
+                    $sco->maxtimeallowed = $element->max_time_allowed;
+                    if (!isset($element->time_limit_action)) {
+                        $element->time_limit_action = '';
+                    }
+                    $sco->timelimitaction = $element->time_limit_action;
+                    if (!isset($element->mastery_score)) {
+                        $element->mastery_score = '';
+                    }
+                    $sco->masteryscore = $element->mastery_score;
+                    $sco->previous = 0;
+                    $sco->next = 0;
+                    $id = insert_record('scorm_scoes',$sco);
+                    if ($launch==0) {
+                        $launch = $id;
+                    }
+                }
+            }
+        }
+    }
+    set_field('scorm','version','AICC','id',$scormid);
+    return $launch;
+}
+
+function scorm_get_resources($blocks) {
+    foreach ($blocks as $block) {
+        if ($block['name'] == 'RESOURCES') {
+            foreach ($block['children'] as $resource) {
+                if ($resource['name'] == 'RESOURCE') {
+                    $resources[addslashes($resource['attrs']['IDENTIFIER'])] = $resource['attrs'];
+                }
+            }
+        }
+    }
+    return $resources;
+}
+
+function scorm_get_manifest($blocks,$scoes) {
+    static $parents = array();
+    static $resources;
+
+    static $manifest;
+    static $organization;
+
+    if (count($blocks) > 0) {
+        foreach ($blocks as $block) {
+            switch ($block['name']) {
+                case 'METADATA':
+                    if (isset($block['children'])) {
+                        foreach ($block['children'] as $metadata) {
+                            if ($metadata['name'] == 'SCHEMAVERSION') {
+                                if (empty($scoes->version)) {
+                                    if (preg_match("/^(1\.2)$|^(CAM )?(1\.3)$/",$metadata['tagData'],$matches)) {
+                                        $scoes->version = 'SCORM_'.$matches[count($matches)-1];
+                                    } else {
+                                        $scoes->version = 'SCORM_1.2';
+                                    }
+                                }
+                            }
+                        }
+                    }
+                break;
+                case 'MANIFEST':
+                    $manifest = addslashes($block['attrs']['IDENTIFIER']);
+                    $organization = '';
+                    $resources = array();
+                    $resources = scorm_get_resources($block['children']);
+                    $scoes = scorm_get_manifest($block['children'],$scoes);
+                    if (count($scoes->elements) <= 0) {
+                        foreach ($resources as $item => $resource) {
+                            if (!empty($resource['HREF'])) {
+                                $sco = new stdClass();
+                                $sco->identifier = $item;
+                                $sco->title = $item;
+                                $sco->parent = '/';
+                                $sco->launch = addslashes($resource['HREF']);
+                                $sco->scormtype = addslashes($resource['ADLCP:SCORMTYPE']);
+                                $scoes->elements[$manifest][$organization][$item] = $sco;
+                            }
+                        }
+                    }
+                break;
+                case 'ORGANIZATIONS':
+                    if (!isset($scoes->defaultorg)) {
+                        $scoes->defaultorg = addslashes($block['attrs']['DEFAULT']);
+                    }
+                    $scoes = scorm_get_manifest($block['children'],$scoes);
+                break;
+                case 'ORGANIZATION':
+                    $identifier = addslashes($block['attrs']['IDENTIFIER']);
+                    $organization = '';
+                    $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier;
+                    $scoes->elements[$manifest][$organization][$identifier]->parent = '/';
+                    $scoes->elements[$manifest][$organization][$identifier]->launch = '';
+                    $scoes->elements[$manifest][$organization][$identifier]->scormtype = '';
+
+                    $parents = array();
+                    $parent = new stdClass();
+                    $parent->identifier = $identifier;
+                    $parent->organization = $organization;
+                    array_push($parents, $parent);
+                    $organization = $identifier;
+
+                    $scoes = scorm_get_manifest($block['children'],$scoes);
+                    
+                    array_pop($parents);
+                break;
+                case 'ITEM':
+                    $parent = array_pop($parents);
+                    array_push($parents, $parent);
+                    
+                    $identifier = addslashes($block['attrs']['IDENTIFIER']);
+                    $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier;
+                    $scoes->elements[$manifest][$organization][$identifier]->parent = $parent->identifier;
+                    if (!isset($block['attrs']['ISVISIBLE'])) {
+                        $block['attrs']['ISVISIBLE'] = 'true';
+                    }
+                    $scoes->elements[$manifest][$organization][$identifier]->isvisible = addslashes($block['attrs']['ISVISIBLE']);
+                    if (!isset($block['attrs']['PARAMETERS'])) {
+                        $block['attrs']['PARAMETERS'] = '';
+                    }
+                    $scoes->elements[$manifest][$organization][$identifier]->parameters = addslashes($block['attrs']['PARAMETERS']);
+                    if (!isset($block['attrs']['IDENTIFIERREF'])) {
+                        $scoes->elements[$manifest][$organization][$identifier]->launch = '';
+                        $scoes->elements[$manifest][$organization][$identifier]->scormtype = 'asset';
+                    } else {
+                        $idref = addslashes($block['attrs']['IDENTIFIERREF']);
+                        $base = '';
+                        if (isset($resources[$idref]['XML:BASE'])) {
+                            $base = $resources[$idref]['XML:BASE'];
+                        }
+                        $scoes->elements[$manifest][$organization][$identifier]->launch = addslashes($base.$resources[$idref]['HREF']);
+                        if (empty($resources[$idref]['ADLCP:SCORMTYPE'])) {
+                            $resources[$idref]['ADLCP:SCORMTYPE'] = 'asset';
+                        }
+                        $scoes->elements[$manifest][$organization][$identifier]->scormtype = addslashes($resources[$idref]['ADLCP:SCORMTYPE']);
+                    }
+
+                    $parent = new stdClass();
+                    $parent->identifier = $identifier;
+                    $parent->organization = $organization;
+                    array_push($parents, $parent);
+
+                    $scoes = scorm_get_manifest($block['children'],$scoes);
+                    
+                    array_pop($parents);
+                break;
+                case 'TITLE':
+                    $parent = array_pop($parents);
+                    array_push($parents, $parent);
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->title = addslashes($block['tagData']);
+                break;
+                case 'ADLCP:PREREQUISITES':
+                    if ($block['attrs']['TYPE'] == 'aicc_script') {
+                        $parent = array_pop($parents);
+                        array_push($parents, $parent);
+                        $scoes->elements[$manifest][$parent->organization][$parent->identifier]->prerequisites = addslashes($block['tagData']);
+                    }
+                break;
+                case 'ADLCP:MAXTIMEALLOWED':
+                    $parent = array_pop($parents);
+                    array_push($parents, $parent);
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->maxtimeallowed = addslashes($block['tagData']);
+                break;
+                case 'ADLCP:TIMELIMITACTION':
+                    $parent = array_pop($parents);
+                    array_push($parents, $parent);
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->timelimitaction = addslashes($block['tagData']);
+                break;
+                case 'ADLCP:DATAFROMLMS':
+                    $parent = array_pop($parents);
+                    array_push($parents, $parent);
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->datafromlms = addslashes($block['tagData']);
+                break;
+                case 'ADLCP:MASTERYSCORE':
+                    $parent = array_pop($parents);
+                    array_push($parents, $parent);
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->masteryscore = addslashes($block['tagData']);
+                break;
+            }
+        }
+    }
+
+    return $scoes;
+}
+
+function scorm_parse_scorm($pkgdir,$scormid) {
+    global $CFG;
+    
+    $launch = 0;
+    $manifestfile = $pkgdir.'/imsmanifest.xml';
+
+    if (is_file($manifestfile)) {
+    
+        $xmlstring = file_get_contents($manifestfile);
+        $objXML = new xml2Array();
+        $manifests = $objXML->parse($xmlstring);
+            
+        $scoes = new stdClass();
+        $scoes->version = '';
+        $scoes = scorm_get_manifest($manifests,$scoes);
+
+        if (count($scoes->elements) > 0) {
+            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 (($launch == 0) && ((empty($scoes->defaultorg)) || ($scoes->defaultorg == $identifier))) {
+                            $launch = $id;
+                        }
+                    }
+                }
+            }
+            set_field('scorm','version',$scoes->version,'id',$scormid);
+        }
+    } 
+    
+    return $launch;
+}
+
+
+/* Usage
+ Grab some XML data, either from a file, URL, etc. however you want. Assume storage in $strYourXML;
+
+ $objXML = new xml2Array();
+ $arrOutput = $objXML->parse($strYourXML);
+ print_r($arrOutput); //print it out, or do whatever!
+  
+*/
+class xml2Array {
+   
+   var $arrOutput = array();
+   var $resParser;
+   var $strXmlData;
+   
+   /**
+   * Convert a utf-8 string to html entities
+   *
+   * @param string $str The UTF-8 string
+   * @return string
+   */
+   function utf8_to_entities($str) {
+       $entities = '';
+       $values = array();
+       $lookingfor = 1;
+
+       for ($i = 0; $i < strlen($str); $i++) {
+           $thisvalue = ord($str[$i]);
+           if ($thisvalue < 128) {
+               $entities .= $str[$i]; // Leave ASCII chars unchanged 
+           } else {
+               if (count($values) == 0) {
+                   $lookingfor = ($thisvalue < 224) ? 2 : 3;
+               }
+               $values[] = $thisvalue;
+               if (count($values) == $lookingfor) {
+                   $number = ($lookingfor == 3) ?
+                       (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64):
+                       (($values[0] % 32) * 64) + ($values[1] % 64);
+                   $entities .= '&#' . $number . ';';
+                   $values = array();
+                   $lookingfor = 1;
+               }
+           }
+       }
+       return $entities;
+   }
+
+   /**
+   * Parse an XML text string and create an array tree that rapresent the XML structure
+   *
+   * @param string $strInputXML The XML string
+   * @return array
+   */
+   function parse($strInputXML) {
+           $this->resParser = xml_parser_create ('UTF-8');
+           xml_set_object($this->resParser,$this);
+           xml_set_element_handler($this->resParser, "tagOpen", "tagClosed");
+           
+           xml_set_character_data_handler($this->resParser, "tagData");
+       
+           $this->strXmlData = xml_parse($this->resParser,$strInputXML );
+           if(!$this->strXmlData) {
+               die(sprintf("XML error: %s at line %d",
+                           xml_error_string(xml_get_error_code($this->resParser)),
+                           xml_get_current_line_number($this->resParser)));
+           }
+                           
+           xml_parser_free($this->resParser);
+           
+           return $this->arrOutput;
+   }
+   
+   function tagOpen($parser, $name, $attrs) {
+       $tag=array("name"=>$name,"attrs"=>$attrs); 
+       array_push($this->arrOutput,$tag);
+   }
+   
+   function tagData($parser, $tagData) {
+       if(trim($tagData)) {
+           if(isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) {
+               $this->arrOutput[count($this->arrOutput)-1]['tagData'] .= $this->utf8_to_entities($tagData);
+           } else {
+               $this->arrOutput[count($this->arrOutput)-1]['tagData'] = $this->utf8_to_entities($tagData);
+           }
+       }
+   }
+   
+   function tagClosed($parser, $name) {
+       $this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1];
+       array_pop($this->arrOutput);
+   }
+}
+?>
index 1eaf038..2cf4206 100755 (executable)
@@ -1,40 +1,40 @@
 <?php
-    require_once("$CFG->dirroot/mod/scorm/lib.php");
+    require_once($CFG->dirroot.'/mod/scorm/lib.php');
     if (empty($form->name)) {
-        $form->name = "";
+        $form->name = '';
     }
     if (empty($form->reference)) {
-        $form->reference = "";
+        $form->reference = '';
     }
     if (empty($form->summary)) {
-        $form->summary = "";
+        $form->summary = '';
     }
     if (empty($form->launch)) {
-        $form->launch = "";
+        $form->launch = '';
     }
     if (empty($form->auto)) {
-        $form->auto = "";
+        $form->auto = '';
     }
     if (empty($form->popup)) {
-        $form->popup = "0";
+        $form->popup = '0';
     }
     if (empty($form->datadir)) {
-        $form->datadir = "";
+        $form->datadir = '';
     }
     if (empty($form->maxgrade)) {
-        $form->maxgrade = "";
+        $form->maxgrade = '';
     }
     if (empty($form->grademethod)) {
-        $form->grademethod = "0";
+        $form->grademethod = '0';
     }
     if (empty($form->hidebrowse)) {
-        $form->hidebrowse = "0";
+        $form->hidebrowse = '0';
     }
     if (empty($form->hidetoc)) {
-        $form->hidetoc = "0";
+        $form->hidetoc = '0';
     }
     if (empty($form->hidenav)) {
-        $form->hidenav = "0";
+        $form->hidenav = '0';
     }
     if (empty($form->width)) {
         $form->width = $CFG->scorm_framewidth;
         $sessionkey = '&sesskey='.$form->sesskey;
     }
 
-    $strfilename = get_string("coursepacket", "scorm");
-    $strchooseafile = get_string("chooseapacket", "scorm");
-    $striframe = get_string("iframe", "scorm");
-    $striframedisplay = get_string("iframedisplay", "scorm");
-    $strnewwindow = get_string("popup", "scorm");
-    $strnewwindowopen = get_string("popupopen", "scorm");
-    $strheight = get_string("height", "scorm");
-    $strwidth = get_string("width", "scorm");
-    $strresizable = get_string("resizable", "scorm");
-    $strscrollbars = get_string("scrollbars", "scorm");
-    $strdirectories = get_string("directories", "scorm");
-    $strlocation = get_string("location", "scorm");
-    $strmenubar = get_string("menubar", "scorm");
-    $strtoolbar = get_string("toolbar", "scorm");
-    $strstatus = get_string("statusbar", "scorm");
+    $strfilename = get_string('coursepacket', 'scorm');
+    $strchooseafile = get_string('chooseapacket', 'scorm');
+    $striframe = get_string('iframe', 'scorm');
+    $striframedisplay = get_string('iframedisplay', 'scorm');
+    $strnewwindow = get_string('popup', 'scorm');
+    $strnewwindowopen = get_string('popupopen', 'scorm');
+    $strheight = get_string('height', 'scorm');
+    $strwidth = get_string('width', 'scorm');
+    $strresizable = get_string('resizable', 'scorm');
+    $strscrollbars = get_string('scrollbars', 'scorm');
+    $strdirectories = get_string('directories', 'scorm');
+    $strlocation = get_string('location', 'scorm');
+    $strmenubar = get_string('menubar', 'scorm');
+    $strtoolbar = get_string('toolbar', 'scorm');
+    $strstatus = get_string('statusbar', 'scorm');
 ?>
 
 <script type="text/javascript" src="<?php p($CFG->wwwroot) ?>/mod/scorm/request.js" ></script>
         if (set == true) {
             if (prefobj.value == '1') {
                 divobj.style.display = 'block';
-                butobj.value = '<?php print_string("hidesettings") ?>';
+                butobj.value = '<?php print_string('hidesettings') ?>';
             } else {
                 divobj.style.display = 'none';
-                butobj.value = '<?php print_string("showsettings") ?>...';
+                butobj.value = '<?php print_string('showsettings') ?>...';
             }
         } else {
             if (prefobj.value == '1') {
                 divobj.style.display = 'none';
-                butobj.value = '<?php print_string("showsettings") ?>...';
+                butobj.value = '<?php print_string('showsettings') ?>...';
                 prefobj.value = '0';
             } else {
                 divobj.style.display = 'block';
-                butobj.value = '<?php print_string("hidesettings") ?>';
+                butobj.value = '<?php print_string('hidesettings') ?>';
                 prefobj.value = '1';
             }
         }
 <form name="form" method="post" action="mod.php" onsubmit="return validate_scorm(document.form,document.form.reference.value);">
     <table cellpadding="5">
         <tr valign="top">
-            <td align="right"><b><?php print_string("name") ?>:</b></td>
+            <td align="right"><b><?php print_string('name') ?>:</b></td>
             <td>
-                <input type="text" name="name" size="50" value="<?php p($form->name) ?>" alt="<?php print_string("name") ?>" />
+                <input type="text" name="name" size="50" value="<?php p($form->name) ?>" alt="<?php print_string('name') ?>" />
             </td>
         </tr>
         <tr valign="top">
-            <td align="right"><b><?php print_string("summary") ?>:</b><br />
-                <?php helpbutton("summary", get_string("summary"), "scorm", true, true) ?>
+            <td align="right"><b><?php print_string('summary') ?>:</b><br />
+                <?php helpbutton('summary', get_string('summary'), 'scorm', true, true) ?>
             </td>
             <td>
-                <?php print_textarea($usehtmleditor, 10, 50, 680, 400, "summary", $form->summary); ?>
+                <?php print_textarea($usehtmleditor, 10, 50, 680, 400, 'summary', $form->summary); ?>
             </td>
         </tr>
         <tr valign="top">
             </td>
             <td>
                 <?php
-                    echo "<input name=\"reference\" size=\"50\" value=\"$form->reference\" alt=\"$strfilename\" />&nbsp;";
-                    button_to_popup_window ("/files/index.php?id=$course->id&amp;choose=form.reference",
-                                            "coursefiles", $strchooseafile, 500, 750, $strchooseafile);
-                    helpbutton("package", get_string("coursepacket", "scorm"), "scorm", true);
+                    echo '<input name="reference" size="50" value="'.$form->reference.'" alt="'.$strfilename.'" />&nbsp;';
+                    button_to_popup_window ('/files/index.php?id='.$course->id.'&amp;choose=form.reference',
+                                            'coursefiles', $strchooseafile, 500, 750, $strchooseafile);
+                    helpbutton('package', get_string('coursepacket', 'scorm'), 'scorm', true);
                 ?>
             </td>
         </tr>
         <tr valign="top">
-            <td align="right"><b><?php print_string("grademethod", "scorm") ?>:</b></td>
+            <td align="right"><b><?php print_string('grademethod', 'scorm') ?>:</b></td>
             <td>
             <?php
-                choose_from_menu($SCORM_GRADE_METHOD, 'grademethod', "$form->grademethod", '','checkmethod(this,document.form.maxgrade);');
-                helpbutton("grademethod", get_string("grademethod","scorm"), "scorm");
+                choose_from_menu($SCORM_GRADE_METHOD, 'grademethod', $form->grademethod, '','checkmethod(this,document.form.maxgrade);');
+                helpbutton('grademethod', get_string('grademethod','scorm'), 'scorm');
             ?>
             </td>
         </tr>
         <tr valign="top">
-            <td align="right"><b><?php print_string("maximumgrade") ?>:</b></td>
+            <td align="right"><b><?php print_string('maximumgrade') ?>:</b></td>
             <td>
             <?php
                 for ($i=100; $i>=1; $i--) {
                     $grades[$i] = $i;
                 }
                 $disabled = $form->grademethod=='0';
-                choose_from_menu($grades, 'maxgrade', "$form->maxgrade", '','','0',false,$disabled);
+                choose_from_menu($grades, 'maxgrade', $form->maxgrade, '','','0',false,$disabled);
                 helpbutton('maxgrade', get_string('maximumgrade'), 'scorm');
             ?>
             </td>
         <tr><td colspan="2"><hr /></td></tr>
 
         <tr>
-            <td align="right"><b><?php print_string("advanced", "scorm") ?>:</b></td>
+            <td align="right"><b><?php print_string('advanced', 'scorm') ?>:</b></td>
             <td>
-                <input type="button" value="<?php print_string("hidesettings") ?>" id="advancedsettingsbutton" onclick="javascrip: return showhide('advancedsettings');" />
+                <input type="button" value="<?php print_string('hidesettings') ?>" id="advancedsettingsbutton" onclick="javascrip: return showhide('advancedsettings');" />
                 <input type="hidden" name="advancedsettingspref" id="advancedsettingspref" 
                        value="<?php echo get_user_preferences('scorm_advancedsettingspref', $CFG->scorm_advancedsettings); ?>" />
-                <?php helpbutton("advanced", get_string("advanced", "scorm"), "scorm", true) ?>
+                <?php helpbutton('advanced', get_string('advanced', 'scorm'), 'scorm', true) ?>
             </td>
         </tr>
         <tr>
                 <div id="advancedsettings">
                     <table align="center">
                         <tr>
-                            <td align="right"><b><?php print_string("autocontinue","scorm") ?>:</b></td>
+                            <td align="right"><b><?php print_string('autocontinue','scorm') ?>:</b></td>
                             <td>
                             <?php
                                 $options = array();
-                                $options[0]=get_string("no");
-                                $options[1]=get_string("yes");
-                                choose_from_menu ($options, "auto", $form->auto,'');
+                                $options[0]=get_string('no');
+                                $options[1]=get_string('yes');
+                                choose_from_menu ($options, 'auto', $form->auto,'');
+                                helpbutton('autocontinue', get_string('autocontinue','scorm'), 'scorm', true);
                             ?>
                             </td>
                         </tr>
                         <tr>
-                            <td align="right"><b><?php print_string("hidebrowse","scorm") ?>:</b></td>
+                            <td align="right"><b><?php print_string('hidebrowse','scorm') ?>:</b></td>
                             <td>
                             <?php
                                 $options = array();
-                                $options[0]=get_string("no");
-                                $options[1]=get_string("yes");
-                                choose_from_menu ($options, "hidebrowse", $form->hidebrowse, '');
+                                $options[0]=get_string('no');
+                                $options[1]=get_string('yes');
+                                choose_from_menu ($options, 'hidebrowse', $form->hidebrowse, '');
+                                helpbutton('browsemode', get_string('hidebrowse','scorm'), 'scorm', true);
                             ?>
                             </td>
                         </tr>
                         <tr>
-                            <td align="right"><b><?php print_string("hidetoc","scorm") ?>:</b></td>
+                            <td align="right"><b><?php print_string('hidetoc','scorm') ?>:</b></td>
                             <td>
                             <?php
                                 $options = array();
-                                $options[0]=get_string("no");
-                                $options[1]=get_string("yes");
-                                choose_from_menu ($options, "hidetoc", $form->hidetoc, '');
+                                $options[0]=get_string('no');
+                                $options[1]=get_string('yes');
+                                choose_from_menu ($options, 'hidetoc', $form->hidetoc, '');
                             ?>
                             </td>
                         </tr>
                         <tr>
-                            <td align="right"><b><?php print_string("hidenav","scorm") ?>:</b></td>
+                            <td align="right"><b><?php print_string('hidenav','scorm') ?>:</b></td>
                             <td>
                             <?php
                                 $options = array();
-                                $options[0]=get_string("no");
-                                $options[1]=get_string("yes");
-                                choose_from_menu ($options, "hidenav", $form->hidenav, '');
+                                $options[0]=get_string('no');
+                                $options[1]=get_string('yes');
+                                choose_from_menu ($options, 'hidenav', $form->hidenav, '');
                             ?>
                             </td>
                         </tr>
             </td>
         </tr>
         <tr>
-            <td align="right"><b><?php print_string("window", "scorm") ?>:</b></td>
+            <td align="right"><b><?php print_string('window', 'scorm') ?>:</b></td>
             <td>
-                <input type="button" value="<?php print_string("hidesettings") ?>" id="windowsettingsbutton" onclick="javascrip: return showhide('windowsettings');" />
+                <input type="button" value="<?php print_string('hidesettings') ?>" id="windowsettingsbutton" onclick="javascrip: return showhide('windowsettings');" />
                 <input type="hidden" name="windowsettingspref" id="windowsettingspref" 
                        value="<?php echo get_user_preferences('scorm_windowsettingspref', $CFG->scorm_windowsettings); ?>" />
-                <?php helpbutton("window", get_string("window", "scorm"), "scorm", true) ?>
+                <?php helpbutton('window', get_string('window', 'scorm'), 'scorm', true) ?>
             </td>
         </tr>
         <tr>
                     <table align="center">
                         <tr valign="top">
                             <td>
-                                <b><?php print_string('stagesize','scorm'); ?></b><br />
+                                <b><?php print_string('stagesize','scorm'); ?></b>
+                                <?php helpbutton('size', get_string('size', 'scorm'), 'scorm', true) ?><br />
                                 <input name="width" type="text" size="4" value="<?php p($form->width) ?>" alt="<?php p($strwidth) ?>" />
                                 <label for="width"><?php p($strwidth) ?></label><br />
                                 <input name="height" type="text" size="4" value="<?php p($form->height) ?>" alt="<?php p($strheight) ?>" />
                                        type="radio" 
                                        value="1" 
                                        alt="<?php p($strnewwindow)?>" 
-                                       <?php echo ($form->popup == 1) ? "checked=\"checked\"" : "" ?>
+                                       <?php echo ($form->popup == 1) ? 'checked="checked"' : '' ?>
                                        onclick="return lockoptions('form', 'popup[1]', popupitems);"
                                 />
                                 <b title="<?php p($strnewwindowopen) ?>"><?php p($strnewwindow) ?></b>
                         </tr>
                     </table>
                 </div>
-<!--                <div id="windowsettings">
-                    <table align="center">
-                        <tr>
-                            <td align="right"><b><?php print_string("popup","scorm") ?>:</b></td>
-                            <td>
-                            <?php
-                                $options = array();
-                                $options[0]=get_string("no");
-                                $options[1]=get_string("yes");
-                                choose_from_menu ($options, "popup", $form->popup,'');
-                                helpbutton("popupwindow", get_string("popup", "scorm"), "scorm", true);
-                            ?>
-                            </td>
-                        </tr>
-                        <tr valign="top">
-                            <td align="right">
-                                <b><?php print_string("stagesize","scorm") ?></b>
-                                <?php helpbutton("size", get_string("stagesize", "scorm"), "scorm", true); ?>
-                            </td>
-                            <td>&nbsp;</td>
-                        </tr>
-                        <tr valign="top">
-                            <td align="right"><b><?php print_string("width","scorm") ?>:</b></td>
-                            <td>
-                               <input type="text" name="width" value="<?php echo $form->width ?>" size="4" />
-                            </td>
-                        </tr>
-                        <tr valign="top">
-                            <td align="right"><b><?php print_string("height","scorm") ?>:</b></td>
-                            <td>
-                               <input type="text" name="height" value="<?php echo $form->height ?>" size="4" />
-                            </td>
-                        </tr>
-                    </table>
-                </div> -->
                 <script language="javascript" type="text/javascript">
                     showhide('advancedsettings', true);
                     showhide('windowsettings', true);
     <input type="hidden" name="pkgtype" value="<?php p($form->pkgtype) ?>" />
     <input type="hidden" name="launch"  value="<?php p($form->launch) ?>" />
     <?php
-        $scorms = get_all_instances_in_course("scorm", $course);
+        $scorms = get_all_instances_in_course('scorm', $course);
         $coursescorm = current($scorms);
         if (($course->format == 'scorm') && ((count($scorms) == 0) || ($form->instance == $coursescorm->id))) {
     ?>
similarity index 59%
rename from mod/scorm/playscorm.php
rename to mod/scorm/player.php
index 7d9bd94..c90ba8b 100755 (executable)
@@ -1,9 +1,9 @@
 <?PHP  // $Id$
 
-/// This page prints a particular instance of scorm
+/// This page prints a particular instance of aicc/scorm package
 
     require_once('../../config.php');
-    require_once('lib.php');
+    require_once('locallib.php');
 
     //
     // Checkin' script parameters
     //
     $result = scorm_get_toc($scorm,'structurelist',$currentorg,$scoid,$mode,true);
     $sco = $result->sco;
+
+    if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
+       $mode = 'normal';
+    }
     if ($mode == 'normal') {
         if ($trackdata = scorm_get_tracks($USER->id,$sco->id)) {
             if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
             }
         }
     }
-    add_to_log($course->id, 'scorm', 'view', "playscorm.php?id=$cm->id&scoid=$sco->id", "$scorm->id");
+
+    add_to_log($course->id, 'scorm', 'view', "player.php?id=$cm->id&scoid=$sco->id", "$scorm->id");
+
     $scoidstr = '&amp;scoid='.$sco->id;
     $scoidpop = '&scoid='.$sco->id;
     $modestr = '&amp;mode='.$mode;
     $modepop = '&mode='.$mode;
-    if (!$result->incomplete) {
+    if ((!$result->incomplete) && ($result->attemptleft > 0)) {
         $attemptstr = '&amp;attempt=new';
         $attemptpop = '&attempt=new';
     }
     if ($scorm->popup == 1) {
         $bodyscript = 'onunload="main.close();"';
     }
-    $exitbutton = '<input name="exit" type="button" value="'.get_string('exit','scorm').'" onClick="document.location = \''.$CFG->wwwroot.'/course/view.php?id='.$cm->course.'\';" />';
+    $exitlink = '(<a href="'.$CFG->wwwroot.'/course/view.php?id='.$cm->course.'">'.get_string('exit','scorm').'</a>)&nbsp;';
     print_header($pagetitle, "$course->fullname",
                  "$navigation <a target='{$CFG->framename}' href='view.php?id=$cm->id'>".format_string($scorm->name,true)."</a>",
-                 '', '', true, $exitbutton.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript);
+                 '', '', true, $exitlink.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript);
+    if ($sco->scormtype == 'sco') {
 ?>
     <script language="JavaScript" type="text/javascript" src="request.js"></script>
     <script language="JavaScript" type="text/javascript" src="api.php?id=<?php echo $cm->id.$scoidstr.$modestr.$attemptstr ?>"></script>
-
+<?php
+    }
+?>
     <div id="scormpage">
 <?php  
     if ($scorm->hidetoc == 0) {
 ?>
         <div id="tocbox" class="generalbox">
             <div id="tochead" class="header"><?php print_string('coursestruct','scorm') ?></div>
-            <div id="toctree"><?php echo $result->toc; ?></div>
+            <div id="toctree">
+            <?php echo $result->toc; ?>
+            </div>
+            <noscript>
+                <div id="noscript">
+                <?php  
+                    print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-)
+                ?>
+                </div>
+            </noscript>
         </div>
 <?php
+        $class = ' class="toc"';
+    } else {
+        $class = ' class="no-toc"';
     }
 ?>
-        <div id="scormbox">
+        <div id="scormbox"<?php echo $class ?>>
+<?php
+    // This very big test check if is necessary the "scormtop" div
+    if (
+           ($mode != 'normal') ||  // We are not in normal mode so review or browse text will displayed
+           (
+               ($scorm->hidenav == 0) &&  // Teacher want to display navigation links
+               (
+                   (
+                       ($sco->previd != 0) &&  // This is not the first learning object of the package
+                       ($sco->previous == 0)   // Moodle must manage the previous link
+                   ) || 
+                   (
+                       ($sco->nextid != 0) &&  // This is not the last learning object of the package
+                       ($sco->next == 0)       // Moodle must manage the next link
+                   )
+               )
+            )
+        ) {
+?>
             <div id="scormtop">
-                <?php echo $mode == 'browse' ? '<div id="scormbrowse" class="left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>
-                <div id="scormnav" class="right">       
-                   <form name="navform" method="post" action="playscorm.php?id=<?php echo $cm->id ?>" target="_top">
-                        <input name="scoid" type="hidden" />
-                        <input name="currentorg" type="hidden" value="<?php echo $currentorg ?>" />
-                        <input name="mode" type="hidden" value="<?php echo $mode ?>" />
+                <?php echo $mode == 'browse' ? '<div id="scormmode" class="left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>
+                <?php echo $mode == 'review' ? '<div id="scormmode" class="left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>
 <?php
-    if ($scorm->hidenav == 0) {
+        if ($scorm->hidenav == 0) {
 ?>
-                        <input name="prev" type="<?php if (($sco->prev == 0) || ($sco->showprev == 1)) { echo 'hidden'; } else { echo 'button'; } ?>" value="<?php print_string('prev','scorm') ?>" onClick="prevSCO();" />
-                        <input name="next" type="<?php if (($sco->next == 0) || ($sco->shownext == 1)) { echo 'hidden'; } else { echo 'button'; } ?>" value="<?php print_string('next','scorm') ?>" onClick="nextSCO();" />
+                <div id="scormnav" class="right">
 <?php
-    }
+            $orgstr = '&amp;currentorg='.$currentorg;
+            if (($sco->previd != 0) && ($sco->previous == 0)) {
+                /// Print the prev LO link
+                $scostr = '&amp;scoid='.$sco->previd;
+                $prevlink = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
+                echo '<a href="'.$prevlink.'">&lt; '.get_string('prev','scorm').'</a>';
+            }
+            if (($sco->nextid != 0) && ($sco->next == 0)) {
+                /// Print the next LO link
+                $scostr = '&amp;scoid='.$sco->nextid;
+                $nextlink = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
+                echo '&nbsp;<a href="'.$nextlink.'">'.get_string('next','scorm').' &gt;</a>';
+            }
 ?>
-                    </form>
                 </div>
+<?php
+        } 
+?>
             </div>
+<?php
+    } // The end of the very test
+?>
             <div id="scormobject" class="right">
 <?php
     if ($result->prerequisites) {
         if ($scorm->popup == 0) {
+            if (strpos('MSIE',$_SERVER['HTTP_USER_AGENT']) === false) { 
+                /// Internet Explorer does not has full support to objects
+?>
+                    <iframe id="main"
+                            width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" 
+                            height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" 
+                            src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">
+                    </iframe>
+<?php
+            } else {
 ?>
                     <object id="main" 
                             class="scoframe" 
                             width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" 
                             height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" 
-                            data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr.$attemptstr ?>"
+                            data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>"
                             type="text/html">
-                         Add object support to your browser
+                         <?php print_string('noobjectsupport', 'scorm'); ?>
                     </object>
 <?php
+            }
         } else {
 ?>
                     <script lanuguage="javascript">
                             return windowobj;
                         }
 
-                        url = "loadSCO.php?id=<?php echo $cm->id.$scoidpop.$modepop.$attemptpop ?>";
+                        url = "loadSCO.php?id=<?php echo $cm->id.$scoidpop.$modepop ?>";
                         width = <?php p($scorm->width) ?>;
                         height = <?php p($scorm->height) ?>;
                         var main = openpopup(url, "<?php p($scorm->name) ?>", "<?php p($scorm->options) ?>", width, height);
                     </script>
+                    <noscript>
+<?php
+            if (strpos('MSIE',$_SERVER['HTTP_USER_AGENT']) === false) { 
+                /// Internet Explorer does not has full support to objects
+?>
+                    <iframe id="main"
+                            width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" 
+                            height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" 
+                            src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">
+                    </iframe>
+<?php
+            } else {
+?>
+                    <object id="main" 
+                            class="scoframe" 
+                            width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" 
+                            height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" 
+                            data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>"
+                            type="text/html">
+                         <?php print_string('noobjectsupport', 'scorm'); ?>
+                    </object>
+<?php
+            }
+?>
+                    </noscript>
 <?php            
         }
     } else {
             </div> <!-- SCORM object -->
         </div> <!-- SCORM box  -->
     </div> <!-- SCORM content -->
-
-    <script language="javascript" type="text/javascript">
-    <!--
-        function playSCO(scoid) {
-            document.navform.scoid.value=scoid;
-            document.navform.submit();
-        }
-
-        function prevSCO() {
-            playSCO(<?php echo $sco->prev ?>);
-        }
-
-        function nextSCO() {
-            playSCO(<?php echo $sco->next ?>);
-        }
-    -->
-    </script>
 <?php
     if ($scorm->hidetoc == 0) {
 ?>
index a423248..7529777 100755 (executable)
@@ -3,13 +3,14 @@
 // This script uses installed report plugins to print quiz reports
 
     require_once("../../config.php");
-    require_once("lib.php");
+    require_once('locallib.php');
 
-    optional_variable($id);    // Course Module ID, or
-    optional_variable($b);     // SCO ID
-    optional_variable($user);  // User ID
+    optional_param($id, 0, PARAM_NUM);    // Course Module ID, or
+    optional_param($a, 0, PARAM_NUM);     // SCORM ID
+    optional_param($b, 0, PARAM_NUM);     // SCO ID
+    optional_param($user, 0, PARAM_NUM);  // User ID
 
-    if ($id) {
+    if (!empty($id)) {
         if (! $cm = get_record("course_modules", "id", $id)) {
             error("Course Module ID was incorrect");
         }
         if (! $scorm = get_record("scorm", "id", $cm->instance)) {
             error("Course module is incorrect");
         }
-    } else if (isset($b)) {
-        if (! $sco = get_record("scorm_scoes", "id", $b)) {
-            error("Scorm activity is incorrect");
-        }
-        if (! $scorm = get_record("scorm", "id", $sco->scorm)) {
-            error("Course module is incorrect");
-        }
-        if (! $course = get_record("course", "id", $scorm->course)) {
-            error("Course is misconfigured");
+    } else {
+        if (!empty($b)) {
+            if (! $sco = get_record("scorm_scoes", "id", $b)) {
+                error("Scorm activity is incorrect");
+            }
+            $a = $sco->scorm;
         }
-        if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
-            error("Course Module ID was incorrect");
+        if (!empty($a)) {
+            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 (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
+                error("Course Module ID was incorrect");
+            }
         }
     }
 
@@ -54,7 +60,7 @@
         $strscorm  = get_string("modulename", "scorm");
         $strreport  = get_string("report", "scorm");
         $strname  = get_string('name');
-        if (!empty($id)) {
+        if (empty($b)) {
             print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",
                      "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>
                       -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a> -> $strreport",
@@ -68,7 +74,7 @@
         }
         print_heading(format_string($scorm->name));
     }
-    if (!empty($id)) {
+    if (empty($b) ) {
         if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) {
             if ($scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) {
                 $table = new stdClass();
index 033485d..409a519 100644 (file)
@@ -1,3 +1,12 @@
+.structlist  {
+  list-style-type: none;
+  white-space: nowrap;
+  font-size: small;
+}
+.orgtitle {
+  font-weight: bold;
+  font-size: small;
+}
 .mod-scorm .top {
   vertical-align: top;
 }
 .mod-scorm .scoframe {
 
 }
-.mod-scorm #scormpage {
+
+#mod-scorm-player #scormpage {
   position: relative;
   width: 100%;
 }
-.mod-scorm #tocbox {
+#mod-scorm-player #tocbox {
   position: absolute;
   left: 0px;
   top: 0px;
-  width: 30% 
+  width: 19%;
 }
-.mod-scorm #tochead {
+#mod-scorm-player #tochead {
   text-align: center;
   font-weight: bold;
 }
-.mod-scorm #scormbox {
+#mod-scorm-player #scormbox {
   position: absolute;
   right: 0px;
   top: 0px;
-  width: 70%;
-  margin-left: 30%; 
 }
-.mod-scorm #scormtop {
+#mod-scorm-player .toc {
+  width: 80%; 
+  margin-left: 20%; 
+}
+#mod-scorm-player .no-toc {
+  width: 100%;
+}
+#mod-scorm-player #scormobject {
+ /* border: 1px solid black; */
+}
+#mod-scorm-player #scormtop {
   position: relative;
   width: 100%;
   height: 30px;
 }
-.mod-scorm #scormbrowse {
+#mod-scorm-player #scormbrowse {
   position: absolute;
   left: 5px;
   top: 0px;
 }
-.mod-scorm #scormnav {
+#mod-scorm-player #scormnav {
   position: absolute;
   right: 5px;
   top: 0px;
 }
-.structlist  {
-  list-style-type: none;
-  white-space: nowrap;
-  font-size: small;
-}
-.orgtitle {
-  font-weight: bold;
-  font-size: small;
-}
-
-#mod-scorm-playscorm .structurehead {
-  float: left;
-}
-#mod-scorm-playscorm .structurelist {
+#mod-scorm-player .structurelist {
   list-style-type: none;
   text-indent:-4ex;
   font-size: small;
 }
+
 #mod-scorm-view .structurehead {
   font-weight: bold;
   text-align: center;
index 022e5b5..f1e2232 100755 (executable)
@@ -1,7 +1,7 @@
 <?php // $Id$
 
     require_once("../../config.php");
-    require_once("lib.php");
+    require_once('locallib.php');
 
     $courseid = required_param('id', '', PARAM_INT);             // Course Module ID, or
     $reference = required_param('reference', '', PARAM_PATH);    // Package path
index 12b3beb..e26b74d 100755 (executable)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2005092500;   // The (date) version of this module
+$module->version  = 2005092600;   // The (date) version of this module
 $module->requires = 2005060200;   // The version of Moodle that is required
 $module->cron     = 0;            // How often should cron check this module (seconds)?
 
index 934475a..753d880 100755 (executable)
@@ -4,7 +4,7 @@
 /// (Replace scorm with the name of your module)
 
     require_once("../../config.php");
-    require_once("lib.php");
+    require_once('locallib.php');
 
     $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or
     $a = optional_param('a', '', PARAM_INT);         // scorm ID
@@ -94,6 +94,9 @@
                        <?php print_string('organizations','scorm') ?>
                 <form name='changeorg' method='post' action='view.php?id=<?php echo $cm->id ?>'>
                     <?php choose_from_menu($orgs, 'organization', "$organization", '','submit()') ?>
+                    <noscript>
+                        <input type="submit" value="&gt;" />
+                    </noscript>
                 </form>
             </div>
 <?php
         print_simple_box_end();
  ?>
     <div class="center">
-        <form name="theform" method="post" action="playscorm.php?id=<?php echo $cm->id ?>">
+        <form name="theform" method="post" action="player.php?id=<?php echo $cm->id ?>">
 <?php
     if ($scorm->hidebrowse == 0) {
         print_string("mode","scorm");
diff --git a/mod/scorm/xml2array.class.php b/mod/scorm/xml2array.class.php
deleted file mode 100644 (file)
index 4b81f5f..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-/* Usage
- Grab some XML data, either from a file, URL, etc. however you want. Assume storage in $strYourXML;
-
- $objXML = new xml2Array();
- $arrOutput = $objXML->parse($strYourXML);
- print_r($arrOutput); //print it out, or do whatever!
-  
-*/
-class xml2Array {
-   
-   var $arrOutput = array();
-   var $resParser;
-   var $strXmlData;
-   
-   /**
-   * Convert a utf-8 string to html entities
-   *
-   * @param string $str The UTF-8 string
-   * @return string
-   */
-   function utf8_to_entities($str) {
-       $entities = '';
-       $values = array();
-       $lookingfor = 1;
-
-       for ($i = 0; $i < strlen($str); $i++) {
-           $thisvalue = ord($str[$i]);
-           if ($thisvalue < 128) {
-               $entities .= $str[$i]; // Leave ASCII chars unchanged 
-           } else {
-               if (count($values) == 0) {
-                   $lookingfor = ($thisvalue < 224) ? 2 : 3;
-               }
-               $values[] = $thisvalue;
-               if (count($values) == $lookingfor) {
-                   $number = ($lookingfor == 3) ?
-                       (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64):
-                       (($values[0] % 32) * 64) + ($values[1] % 64);
-                   $entities .= '&#' . $number . ';';
-                   $values = array();
-                   $lookingfor = 1;
-               }
-           }
-       }
-       return $entities;
-   }
-
-   /**
-   * Parse an XML text string and create an array tree that rapresent the XML structure
-   *
-   * @param string $strInputXML The XML string
-   * @return array
-   */
-   function parse($strInputXML) {
-           $this->resParser = xml_parser_create ('UTF-8');
-           xml_set_object($this->resParser,$this);
-           xml_set_element_handler($this->resParser, "tagOpen", "tagClosed");
-           
-           xml_set_character_data_handler($this->resParser, "tagData");
-       
-           $this->strXmlData = xml_parse($this->resParser,$strInputXML );
-           if(!$this->strXmlData) {
-               die(sprintf("XML error: %s at line %d",
-                           xml_error_string(xml_get_error_code($this->resParser)),
-                           xml_get_current_line_number($this->resParser)));
-           }
-                           
-           xml_parser_free($this->resParser);
-           
-           return $this->arrOutput;
-   }
-   
-   function tagOpen($parser, $name, $attrs) {
-       $tag=array("name"=>$name,"attrs"=>$attrs); 
-       array_push($this->arrOutput,$tag);
-   }
-   
-   function tagData($parser, $tagData) {
-       if(trim($tagData)) {
-           if(isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) {
-               $this->arrOutput[count($this->arrOutput)-1]['tagData'] .= $this->utf8_to_entities($tagData);
-           } else {
-               $this->arrOutput[count($this->arrOutput)-1]['tagData'] = $this->utf8_to_entities($tagData);
-           }
-       }
-   }
-   
-   function tagClosed($parser, $name) {
-       $this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1];
-       array_pop($this->arrOutput);
-   }
-}
-?>
\ No newline at end of file