Index: mod/scorm/locallib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/locallib.php,v
retrieving revision 1.46.2.26
diff -u -r1.46.2.26 locallib.php
--- mod/scorm/locallib.php	12 Dec 2008 19:39:32 -0000	1.46.2.26
+++ mod/scorm/locallib.php	28 Dec 2008 17:40:02 -0000
@@ -369,6 +369,9 @@
             $element = $track->element;
             $usertrack->{$element} = $track->value;
             switch ($element) {
+                case 'x.start.time':
+                    $usertrack->x_start_time = $track->value;
+                    break;
                 case 'cmi.core.lesson_status':
                 case 'cmi.completion_status':
                     if ($track->value == 'not attempted') {
@@ -402,6 +405,45 @@
     }
 }
 
+/* Find the start and finsh time for a a given SCO attempt
+ *
+ * @param int $scormid SCORM Id
+ * @param int $scoid SCO Id
+ * @param int $userid User Id
+ * @param int $attemt Attempt Id
+ *
+ * @return object start and finsh time EPOC secods
+ *
+ */
+function scorm_get_sco_runtime($scormid, $scoid, $userid, $attempt=1) {
+
+    $timedata = new object();
+    $sql = !empty($scoid) ? "userid=$userid AND scormid=$scormid AND scoid=$scoid AND attempt=$attempt" : "userid=$userid AND scormid=$scormid AND attempt=$attempt";
+    $tracks = get_records_select('scorm_scoes_track',"$sql ORDER BY timemodified ASC");
+    if ($tracks) {
+        $tracks = array_values($tracks);
+    }
+
+    if ($start_track = get_records_select('scorm_scoes_track',"$sql AND element='x.start.time' ORDER BY scoid ASC")) {
+        $start_track = array_values($start_track);
+        $timedata->start = $start_track[0]->value;
+    }
+    else if ($tracks) {
+        $timedata->start = $tracks[0]->timemodified;
+    }
+    else {
+        $timedata->start = false;
+    }
+    if ($tracks && $track = array_pop($tracks)) {
+        $timedata->finish = $track->timemodified;
+    }
+    else {
+        $timedata->finish = $timedata->start;
+    }
+    return $timedata;
+}
+
+
 function scorm_get_user_data($userid) {
 /// Gets user info required to display the table of scorm results
 /// for report.php
@@ -707,7 +749,7 @@
 }
 function scorm_simple_play($scorm,$user) {
     $result = false;
-    
+
     if ($scorm->updatefreq == UPDATE_EVERYTIME) {
         scorm_parse($scorm);
     }
Index: mod/scorm/report.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/report.php,v
retrieving revision 1.46.2.8
diff -u -r1.46.2.8 report.php
--- mod/scorm/report.php	10 Dec 2008 06:30:24 -0000	1.46.2.8
+++ mod/scorm/report.php	28 Dec 2008 17:40:02 -0000
@@ -177,14 +177,17 @@
                                  fullname($userdata).'</a>';
                         $row[] = '<a href="report.php?a='.$scorm->id.'&amp;user='.$scouser->userid.'&amp;attempt='.$a.'">'.$a.'</a>';
                         $select = 'scormid = '.$scorm->id.' and userid = '.$scouser->userid.' and attempt = '.$a;
-                        $timetracks = get_record_select('scorm_scoes_track', $select,'min(timemodified) as started, max(timemodified) as last');
+//                        $timetracks = get_record_select('scorm_scoes_track', $select,'min(timemodified) as started, max(timemodified) as last');
+                        $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $a);
                         // jump out here if this attempt doesnt exist
-                        if (!$timetracks->started) {
+//                        if (!$timetracks->started) {
+                        if (!$timetracks->start) {
                             continue;
                         }
-                        $row[] = userdate($timetracks->started, get_string('strftimedaydatetime'));
-                        $row[] = userdate($timetracks->last, get_string('strftimedaydatetime'));
-
+//                        $row[] = userdate($timetracks->started, get_string('strftimedaydatetime'));
+//                        $row[] = userdate($timetracks->last, get_string('strftimedaydatetime'));
+                        $row[] = userdate($timetracks->start, get_string('strftimedaydatetime'));
+                        $row[] = userdate($timetracks->finish, get_string('strftimedaydatetime'));
                         $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $a);
                         $table->data[] = $row;
                     }
Index: mod/scorm/api.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/Attic/api.php,v
retrieving revision 1.24.6.2
diff -u -r1.24.6.2 api.php
--- mod/scorm/api.php	22 Aug 2008 01:38:37 -0000	1.24.6.2
+++ mod/scorm/api.php	28 Dec 2008 17:40:02 -0000
@@ -2,7 +2,7 @@
 
     require_once("../../config.php");
     require_once('locallib.php');
-    
+
     $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or
     $a = optional_param('a', '', PARAM_INT);         // scorm ID
     $scoid = required_param('scoid', PARAM_INT);     // sco ID
@@ -34,7 +34,7 @@
     }
 
     require_login($course->id, false, $cm);
-    
+
     if ($usertrack = scorm_get_tracks($scoid,$USER->id,$attempt)) {
         if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || ($scorm->version != "SCORM_1.3")) {
             foreach ($usertrack as $key => $value) {
@@ -58,7 +58,7 @@
         $userdata->credit = 'credit';
     } else {
         $userdata->credit = 'no-credit';
-    }    
+    }
     if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
         foreach ($scodatas as $key => $value) {
             $userdata->$key = addslashes_js($value);
@@ -75,6 +75,10 @@
     } else {
         include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
     }
+
+    // set the start time of this SCO
+    scorm_insert_track($USER->id,$scorm->id,$scoid,$attempt,'x.start.time',time());
+
 ?>
 
 var errorCode = "0";
