]> git.mjollnir.org Git - moodle.git/commitdiff
New version with SCORM 2004 sequencing done by Pham Minh Duc
authorbobopinna <bobopinna>
Thu, 25 May 2006 10:20:45 +0000 (10:20 +0000)
committerbobopinna <bobopinna>
Thu, 25 May 2006 10:20:45 +0000 (10:20 +0000)
21 files changed:
mod/scorm/aicc.php
mod/scorm/api.php
mod/scorm/backuplib.php
mod/scorm/coefficientconfirm.php [new file with mode: 0755]
mod/scorm/coefficientsetting.php [new file with mode: 0755]
mod/scorm/datamodel.php
mod/scorm/index.php
mod/scorm/lib.php
mod/scorm/loadSCO.php
mod/scorm/locallib.php
mod/scorm/mod.html
mod/scorm/player.php
mod/scorm/report.php
mod/scorm/restorelib.php
mod/scorm/sequencinglib.php [new file with mode: 0755]
mod/scorm/styles.php
mod/scorm/suspend.php [new file with mode: 0755]
mod/scorm/timePassReport.htm [new file with mode: 0755]
mod/scorm/validate.php
mod/scorm/version.php
mod/scorm/view.php

index dc107e8501f6d8d1537be41be7c55451fc4209bf..79b60e2ecac81cdcd608b78191893cab07c71531 100755 (executable)
-<?php
-    require_once('../../config.php');
-    require_once('locallib.php');
-
-    $command = required_param('command', PARAM_ALPHA);
-    $sessionid = required_param('session_id', PARAM_ALPHANUM);
-    $aiccdata = optional_param('aicc_data', '', PARAM_RAW);
-
-    require_login();
-    
-    if (!empty($command) && confirm_sesskey($sessionid)) {
-        $command = strtolower($command);
-       
-        if (isset($SESSION->scorm_scoid)) {
-            $scoid = $SESSION->scorm_scoid;
-        } else {
-            error('Invalid script call');
-        }
-        $mode = 'normal';
-        if (isset($SESSION->scorm_mode)) {
-            $mode = $SESSION->scorm_mode;
-        }
-        $status = 'Not Initialized';
-        if (isset($SESSION->scorm_status)) {
-            $status = $SESSION->scorm_status;
-        }
-        if (isset($SESSION->attempt)) {
-            $attempt = $SESSION->attempt;
-        } else {
-            $attempt = 1;
-        }
-
-        if ($sco = get_record('scorm_scoes','id',$scoid)) {
-            if (!$scorm = get_record('scorm','id',$sco->scorm)) {
-                error('Invalid script call');
-            }
-        } else {
-            error('Invalid script call');
-        }
-
-        if ($scorm = get_record('scorm','id',$sco->scorm)) {
-            switch ($command) {
-                case 'getparam':
-                    if ($status == 'Not Initialized') {
-                        $SESSION->scorm_status = 'Running';
-                        $status = 'Running';
-                    }
-                    if ($status != 'Running') {
-                        echo "error = 101\nerror_text = Terminated\n";
-                    } else {
-                        if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) {
-                            $userdata = $usertrack;
-                        } else {
-                            $userdata->status = '';
-                            $userdata->score_raw = '';
-                        }
-                        $userdata->student_id = $USER->username;
-                        $userdata->student_name = $USER->lastname .', '. $USER->firstname;
-                        $userdata->mode = $mode;
-                        if ($userdata->mode == 'normal') {
-                            $userdata->credit = 'credit';
-                        } else {
-                            $userdata->credit = 'no-credit';
-                        } 
-                
-                        if ($sco = get_record('scorm_scoes','id',$scoid)) {
-                            $userdata->course_id = $sco->identifier;
-                            $userdata->datafromlms = $sco->datafromlms;
-                            $userdata->masteryscore = $sco->masteryscore;
-                            $userdata->maxtimeallowed = $sco->maxtimeallowed;
-                            $userdata->timelimitaction = $sco->timelimitaction;
-                               
-                            echo "error = 0\nerror_text = Successful\naicc_data=\n";
-                            echo "[Core]\n";
-                            echo 'Student_ID = '.$userdata->student_id."\n";
-                            echo 'Student_Name = '.$userdata->student_name."\n";
-                            if (isset($userdata->{'cmi.core.lesson_location'})) {
-                                echo 'Lesson_Location = '.$userdata->{'cmi.core.lesson_location'}."\n";
-                            } else {
-                                echo 'Lesson_Location = '."\n";
-                            }
-                            echo 'Credit = '.$userdata->credit."\n";
-                            if (isset($userdata->status)) {
-                                if ($userdata->status == '') {
-                                    $userdata->entry = ', ab-initio';
-                                } else {
-                                    if (isset($userdata->{'cmi.core.exit'}) && ($userdata->{'cmi.core.exit'} == 'suspend')) {
-                                        $userdata->entry = ', resume';
-                                    } else {
-                                        $userdata->entry = '';
-                                    }
-                                }
-                            }
-                            if (isset($userdata->{'cmi.core.lesson_status'})) {
-                                echo 'Lesson_Status = '.$userdata->{'cmi.core.lesson_status'}.$userdata->entry."\n";
-                                $SESSION->scorm_lessonstatus = $userdata->{'cmi.core.lesson_status'};
-                            } else {
-                                echo 'Lesson_Status = not attempted'.$userdata->entry."\n";
-                                $SESSION->scorm_lessonstatus = 'not attempted';
-                            }
-                            if (isset($userdata->{'cmi.core.score.raw'})) {
-                                $max = '';
-                                $min = '';
-                                if (isset($userdata->{'cmi.core.score.max'}) && !empty($userdata->{'cmi.core.score.max'})) {
-                                    $max = ', '.$userdata->{'cmi.core.score.max'};
-                                    if (isset($userdata->{'cmi.core.score.min'}) && !empty($userdata->{'cmi.core.score.min'})) {
-                                        $min = ', '.$userdata->{'cmi.core.score.min'};
-                                    }
-                                }
-                                echo 'Score = '.$userdata->{'cmi.core.score.raw'}.$max.$min."\n";
-                            } else {
-                                echo 'Score = '."\n";
-                            }
-                            if (isset($userdata->{'cmi.core.total_time'})) {
-                                echo 'Time = '.$userdata->{'cmi.core.total_time'}."\n";
-                            } else {
-                                echo 'Time = '.'00:00:00'."\n";
-                            }
-                            echo 'Lesson_Mode = '.$userdata->mode."\n";
-                            if (isset($userdata->{'cmi.suspend_data'})) {
-                                echo "[Core_Lesson]\n".$userdata->{'cmi.suspend_data'}."\n";
-                            } else {
-                                echo "[Core_Lesson]\n"."\n";
-                            }
-                            echo "[Core_Vendor]\n".$userdata->datafromlms."\n";
-                            echo "[Evaluation]\nCourse_ID = {".$userdata->course_id."}\n";
-                            echo "[Student_Data]\n";
-                            echo 'Mastery_Score = '.$userdata->masteryscore."\n";
-                            echo 'Max_Time_Allowed = '.$userdata->maxtimeallowed."\n";
-                            echo 'Time_Limit_Action = '.$userdata->timelimitaction."\n";
-                        } else {
-                            error('Sco not found');
-                        }
-                    }
-                break;
-                case 'putparam':
-                    if ($status == 'Running') {
-                        if (!empty($aiccdata) && isstudent($scorm->course)) {
-                            $initlessonstatus = 'not attempted';
-                            $lessonstatus = 'not attempted';
-                            if (isset($SESSION->scorm_lessonstatus)) {
-                                $initlessonstatus = $SESSION->scorm_lessonstatus;
-                            }
-                            $score = '';
-                            $datamodel['lesson_location'] = 'cmi.core.lesson_location';
-                            $datamodel['lesson_status'] = 'cmi.core.lesson_status';
-                            $datamodel['score'] = 'cmi.core.score.raw';
-                            $datamodel['time'] = 'cmi.core.session_time';
-                            $datamodel['[core_lesson]'] = 'cmi.suspend_data';
-                            $datamodel['[comments]'] = 'cmi.comments';
-                            $datarows = explode("\n",$aiccdata);
-                            reset($datarows);
-                            while ((list(,$datarow) = each($datarows)) !== false) {
-                                if (($equal = strpos($datarow, '=')) !== false) {
-                                    $element = strtolower(trim(substr($datarow,0,$equal)));
-                                    $value = trim(substr($datarow,$equal+1));
-                                    if (isset($datamodel[$element])) {
-                                        $element = $datamodel[$element];
-                                        switch ($element) {
-                                            case 'cmi.core.lesson_location':
-                                                $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
-                                            break;
-                                            case 'cmi.core.lesson_status':
-                                                $statuses = array(
-                                                           'passed' => 'passed',
-                                                           'completed' => 'completed',
-                                                           'failed' => 'failed',
-                                                           'incomplete' => 'incomplete',
-                                                           'browsed' => 'browsed',
-                                                           'not attempted' => 'not attempted',
-                                                           'p' => 'passed',
-                                                           'c' => 'completed',
-                                                           'f' => 'failed',
-                                                           'i' => 'incomplete',
-                                                           'b' => 'browsed',
-                                                           'n' => 'not attempted'
-                                                           );
-                                                $exites = array(
-                                                           'logout' => 'logout',
-                                                           'time-out' => 'time-out',
-                                                           'suspend' => 'suspend',
-                                                           'l' => 'logout',
-                                                           't' => 'time-out',
-                                                           's' => 'suspend',
-                                                           );
-                                                $values = explode(',',$value);
-                                                $value = '';
-                                                if (count($values) > 1) {
-                                                    $value = trim(strtolower($values[1]));
-                                                    if (isset($exites[$value])) {
-                                                        $value = $exites[$value];
-                                                    }
-                                                }
-                                                if (empty($value) || isset($exites[$value])) {
-                                                    $subelement = 'cmi.core.exit';
-                                                    $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, $attempt, $element, $value);
-                                                }
-                                                $lessonstatus = $value;
-                                            break;
-                                            case 'cmi.core.score.raw':
-                                                 $values = explode(',',$value);
-                                                 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, $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, $attempt, $subelement, $value);
-                                                     }
-                                                 }
-                                              
-                                                 $value = '';
-                                                 if (is_numeric($values[0])) {
-                                                     $value = trim($values[0]);
-                                                     $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
-                                                 }
-                                                 $score = $value;
-                                            break;
-                                            case 'cmi.core.session_time':
-                                                 $SESSION->scorm_session_time = $value;
-                                            break;
-                                        }
-                                    }
-                                } else {
-                                    if (isset($datamodel[strtolower(trim($datarow))])) {
-                                        $element = $datamodel[strtolower(trim($datarow))];
-                                        $value = '';
-                                        while ((($datarow = current($datarows)) !== false) && (substr($datarow,0,1) != '[')) {
-                                            $value .= scorm_utf8_to_entities(datarow);
-                                            next($datarows);
-                                        }
-                                        $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, $attempt, 'cmi.core.lesson_status', 'browsed');
-                            }
-                            if ($mode == 'normal') {
-                                if ($lessonstatus == 'completed') {
-                                    if (!empty($sco->masteryscore) && !empty($score) && ($score >= $sco->masteryscore)) {
-                                        $lessonstatus = 'passed';
-                                    } else {
-                                        $lessonstatus = 'failed';
-                                    }
-                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', $lessonstatus);
-                                }
-                            }                  
-                        }
-                        echo "error = 0\nerror_text = Successful\n";
-                    } else if ($status == 'Terminated') {
-                        echo "error = 1\nerror_text = Terminated\n";
-                    } else {
-                        echo "error = 1\nerror_text = Not Initialized\n";
-                    }
-                break;
-                case 'putcomments':
-                    if ($status == 'Running') {
-                        echo "error = 0\nerror_text = Successful\n";
-                    } else if ($status == 'Terminated') {
-                        echo "error = 1\nerror_text = Terminated\n";
-                    } else {
-                        echo "error = 1\nerror_text = Not Initialized\n";
-                    }
-                break;
-                case 'putinteractions':
-                    if ($status == 'Running') {
-                        echo "error = 0\nerror_text = Successful\n";
-                    } else if ($status == 'Terminated') {
-                        echo "error = 1\nerror_text = Terminated\n";
-                    } else {
-                        echo "error = 1\nerror_text = Not Initialized\n";
-                    }
-                break;
-                case 'putobjectives':
-                    if ($status == 'Running') {
-                        echo "error = 0\nerror_text = Successful\n";
-                    } else if ($status == 'Terminated') {
-                        echo "error = 1\nerror_text = Terminated\n";
-                    } else {
-                        echo "error = 1\nerror_text = Not Initialized\n";
-                    }
-                break;
-                case 'putpath':
-                    if ($status == 'Running') {
-                        echo "error = 0\nerror_text = Successful\n";
-                    } else if ($status == 'Terminated') {
-                        echo "error = 1\nerror_text = Terminated\n";
-                    } else {
-                        echo "error = 1\nerror_text = Not Initialized\n";
-                    }
-                break;
-                case 'putperformance':
-                    if ($status == 'Running') {
-                        echo "error = 0\nerror_text = Successful\n";
-                    } else if ($status == 'Terminated') {
-                        echo "error = 1\nerror_text = Terminated\n";
-                    } else {
-                        echo "error = 1\nerror_text = Not Initialized\n";
-                    }
-                break;
-                case 'exitau':
-                    if ($status == 'Running') {
-                        if (isset($SESSION->scorm_session_time) && ($SESSION->scorm_session_time != '')) {
-                            if ($track = get_record_select('scorm_scoes_track',"userid='$USER->id' AND scormid='$scorm->id' AND scoid='$sco->id' AND element='cmi.core.total_time'")) {
-                                // Add session_time to total_time
-                                $value = scorm_add_time($track->value, $SESSION->scorm_session_time);
-                                $track->value = $value;
-                                $track->timemodified = time();
-                                $id = update_record('scorm_scoes_track',$track);
-                            } else {
-                                $track->userid = $USER->id;
-                                $track->scormid = $scorm->id;
-                                $track->scoid = $sco->id;
-                                $track->element = 'cmi.core.total_time';
-                                $track->value = $SESSION->scorm_session_time;
-                                $track->timemodified = time();
-                                $id = insert_record('scorm_scoes_track',$track);
-                            }
-                        }
-                        
-                        $SESSION->scorm_status = 'Terminated';
-                        $SESSION->scorm_session_time = '';
-                        echo "error = 0\nerror_text = Successful\n";
-                    } else if ($status == 'Terminated') {
-                        echo "error = 1\nerror_text = Terminated\n";
-                    } else {
-                        echo "error = 1\nerror_text = Not Initialized\n";
-                    }
-                break;
-                default:
-                    echo "error = 1\nerror_text = Invalid Command\n";
-                break;
-            }
-        }
-    } else {
-        if (empty($command)) {
-            echo "error = 1\nerror_text = Invalid Command\n";
-        } else {
-            echo "error = 3\nerror_text = Invalid Session ID\n";
-        }
-    }
-?>
+<?php\r
+    require_once('../../config.php');\r
+    require_once('locallib.php');\r
+       require_once('sequencinglib.php');\r
+       \r
+    $command = required_param('command', PARAM_ALPHA);\r
+    $sessionid = required_param('session_id', PARAM_ALPHANUM);\r
+    $aiccdata = optional_param('aicc_data', '', PARAM_RAW);\r
+\r
+    require_login();\r
+    \r
+    if (!empty($command) && confirm_sesskey($sessionid)) {\r
+        $command = strtolower($command);\r
+       \r
+        if (isset($SESSION->scorm_scoid)) {\r
+            $scoid = $SESSION->scorm_scoid;\r
+        } else {\r
+            error('Invalid script call');\r
+        }\r
+        $mode = 'normal';\r
+        if (isset($SESSION->scorm_mode)) {\r
+            $mode = $SESSION->scorm_mode;\r
+        }\r
+        $status = 'Not Initialized';\r
+        if (isset($SESSION->scorm_status)) {\r
+            $status = $SESSION->scorm_status;\r
+        }\r
+        if (isset($SESSION->attempt)) {\r
+            $attempt = $SESSION->attempt;\r
+        } else {\r
+            $attempt = 1;\r
+        }\r
+\r
+        if ($sco = get_record('scorm_scoes','id',$scoid)) {\r
+            if (!$scorm = get_record('scorm','id',$sco->scorm)) {\r
+                error('Invalid script call');\r
+            }\r
+        } else {\r
+            error('Invalid script call');\r
+        }\r
+\r
+        if ($scorm = get_record('scorm','id',$sco->scorm)) {\r
+            switch ($command) {\r
+                case 'getparam':\r
+                    if ($status == 'Not Initialized') {\r
+                        $SESSION->scorm_status = 'Running';\r
+                        $status = 'Running';\r
+                    }\r
+                    if ($status != 'Running') {\r
+                        echo "error = 101\nerror_text = Terminated\n";\r
+                    } else {\r
+                        if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) {\r
+                            $userdata = $usertrack;\r
+                        } else {\r
+                            $userdata->status = '';\r
+                            $userdata->score_raw = '';\r
+                        }\r
+                        $userdata->student_id = $USER->username;\r
+                        $userdata->student_name = $USER->lastname .', '. $USER->firstname;\r
+                        $userdata->mode = $mode;\r
+                        if ($userdata->mode == 'normal') {\r
+                            $userdata->credit = 'credit';\r
+                        } else {\r
+                            $userdata->credit = 'no-credit';\r
+                        } \r
+                \r
+                        if ($sco = get_record('scorm_scoes','id',$scoid)) {\r
+                            $userdata->course_id = $sco->identifier;\r
+                            $userdata->datafromlms = $sco->datafromlms;\r
+                            $userdata->masteryscore = $sco->masteryscore;\r
+                            $userdata->maxtimeallowed = $sco->maxtimeallowed;\r
+                            $userdata->timelimitaction = $sco->timelimitaction;\r
+                               \r
+                            echo "error = 0\nerror_text = Successful\naicc_data=\n";\r
+                            echo "[Core]\n";\r
+                            echo 'Student_ID = '.$userdata->student_id."\n";\r
+                            echo 'Student_Name = '.$userdata->student_name."\n";\r
+                            if (isset($userdata->{'cmi.core.lesson_location'})) {\r
+                                echo 'Lesson_Location = '.$userdata->{'cmi.core.lesson_location'}."\n";\r
+                            } else {\r
+                                echo 'Lesson_Location = '."\n";\r
+                            }\r
+                            echo 'Credit = '.$userdata->credit."\n";\r
+                            if (isset($userdata->status)) {\r
+                                if ($userdata->status == '') {\r
+                                    $userdata->entry = ', ab-initio';\r
+                                } else {\r
+                                    if (isset($userdata->{'cmi.core.exit'}) && ($userdata->{'cmi.core.exit'} == 'suspend')) {\r
+                                        $userdata->entry = ', resume';\r
+                                    } else {\r
+                                        $userdata->entry = '';\r
+                                    }\r
+                                }\r
+                            }\r
+                            if (isset($userdata->{'cmi.core.lesson_status'})) {\r
+                                echo 'Lesson_Status = '.$userdata->{'cmi.core.lesson_status'}.$userdata->entry."\n";\r
+                                $SESSION->scorm_lessonstatus = $userdata->{'cmi.core.lesson_status'};\r
+                            } else {\r
+                                echo 'Lesson_Status = not attempted'.$userdata->entry."\n";\r
+                                $SESSION->scorm_lessonstatus = 'not attempted';\r
+                            }\r
+                            if (isset($userdata->{'cmi.core.score.raw'})) {\r
+                                $max = '';\r
+                                $min = '';\r
+                                if (isset($userdata->{'cmi.core.score.max'}) && !empty($userdata->{'cmi.core.score.max'})) {\r
+                                    $max = ', '.$userdata->{'cmi.core.score.max'};\r
+                                    if (isset($userdata->{'cmi.core.score.min'}) && !empty($userdata->{'cmi.core.score.min'})) {\r
+                                        $min = ', '.$userdata->{'cmi.core.score.min'};\r
+                                    }\r
+                                }\r
+                                echo 'Score = '.$userdata->{'cmi.core.score.raw'}.$max.$min."\n";\r
+                            } else {\r
+                                echo 'Score = '."\n";\r
+                            }\r
+                            if (isset($userdata->{'cmi.core.total_time'})) {\r
+                                echo 'Time = '.$userdata->{'cmi.core.total_time'}."\n";\r
+                            } else {\r
+                                echo 'Time = '.'00:00:00'."\n";\r
+                            }\r
+                            echo 'Lesson_Mode = '.$userdata->mode."\n";\r
+                            if (isset($userdata->{'cmi.suspend_data'})) {\r
+                                echo "[Core_Lesson]\n".$userdata->{'cmi.suspend_data'}."\n";\r
+                            } else {\r
+                                echo "[Core_Lesson]\n"."\n";\r
+                            }\r
+                            echo "[Core_Vendor]\n".$userdata->datafromlms."\n";\r
+                            echo "[Evaluation]\nCourse_ID = {".$userdata->course_id."}\n";\r
+                            echo "[Student_Data]\n";\r
+                            echo 'Mastery_Score = '.$userdata->masteryscore."\n";\r
+                            echo 'Max_Time_Allowed = '.$userdata->maxtimeallowed."\n";\r
+                            echo 'Time_Limit_Action = '.$userdata->timelimitaction."\n";\r
+                        } else {\r
+                            error('Sco not found');\r
+                        }\r
+                    }\r
+                break;\r
+                case 'putparam':\r
+                    if ($status == 'Running') {\r
+                        if (!empty($aiccdata) && isstudent($scorm->course)) {\r
+                            $initlessonstatus = 'not attempted';\r
+                            $lessonstatus = 'not attempted';\r
+                            if (isset($SESSION->scorm_lessonstatus)) {\r
+                                $initlessonstatus = $SESSION->scorm_lessonstatus;\r
+                            }\r
+                            $score = '';\r
+                            $datamodel['lesson_location'] = 'cmi.core.lesson_location';\r
+                            $datamodel['lesson_status'] = 'cmi.core.lesson_status';\r
+                            $datamodel['score'] = 'cmi.core.score.raw';\r
+                            $datamodel['time'] = 'cmi.core.session_time';\r
+                            $datamodel['[core_lesson]'] = 'cmi.suspend_data';\r
+                            $datamodel['[comments]'] = 'cmi.comments';\r
+                            $datarows = explode("\n",$aiccdata);\r
+                            reset($datarows);\r
+                            while ((list(,$datarow) = each($datarows)) !== false) {\r
+                                if (($equal = strpos($datarow, '=')) !== false) {\r
+                                    $element = strtolower(trim(substr($datarow,0,$equal)));\r
+                                    $value = trim(substr($datarow,$equal+1));\r
+                                    if (isset($datamodel[$element])) {\r
+                                        $element = $datamodel[$element];\r
+                                        switch ($element) {\r
+                                            case 'cmi.core.lesson_location':\r
+                                                $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);\r
+                                            break;\r
+                                            case 'cmi.core.lesson_status':\r
+                                                $statuses = array(\r
+                                                           'passed' => 'passed',\r
+                                                           'completed' => 'completed',\r
+                                                           'failed' => 'failed',\r
+                                                           'incomplete' => 'incomplete',\r
+                                                           'browsed' => 'browsed',\r
+                                                           'not attempted' => 'not attempted',\r
+                                                           'p' => 'passed',\r
+                                                           'c' => 'completed',\r
+                                                           'f' => 'failed',\r
+                                                           'i' => 'incomplete',\r
+                                                           'b' => 'browsed',\r
+                                                           'n' => 'not attempted'\r
+                                                           );\r
+                                                $exites = array(\r
+                                                           'logout' => 'logout',\r
+                                                           'time-out' => 'time-out',\r
+                                                           'suspend' => 'suspend',\r
+                                                           'l' => 'logout',\r
+                                                           't' => 'time-out',\r
+                                                           's' => 'suspend',\r
+                                                           );\r
+                                                $values = explode(',',$value);\r
+                                                $value = '';\r
+                                                if (count($values) > 1) {\r
+                                                    $value = trim(strtolower($values[1]));\r
+                                                    if (isset($exites[$value])) {\r
+                                                        $value = $exites[$value];\r
+                                                    }\r
+                                                }\r
+                                                if (empty($value) || isset($exites[$value])) {\r
+                                                    $subelement = 'cmi.core.exit';\r
+                                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);\r
+                                                }\r
+                                                $value = trim(strtolower($values[0]));\r
+                                                if (isset($statuses[$value]) && ($mode == 'normal')) {\r
+                                                    $value = $statuses[$value];\r
+                                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);\r
+                                                }\r
+                                                $lessonstatus = $value;\r
+                                            break;\r
+                                            case 'cmi.core.score.raw':\r
+                                                 $values = explode(',',$value);\r
+                                                 if ((count($values) > 1) && ($values[1] >= $values[0]) && is_numeric($values[1])) {\r
+                                                     $subelement = 'cmi.core.score.max';\r
+                                                     $value = trim($values[1]);\r
+                                                     $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);\r
+                                                     if ((count($values) == 3) && ($values[2] <= $values[0]) && is_numeric($values[2])) {\r
+                                                         $subelement = 'cmi.core.score.min';\r
+                                                         $value = trim($values[2]);\r
+                                                         $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value);\r
+                                                     }\r
+                                                 }\r
+                                              \r
+                                                 $value = '';\r
+                                                 if (is_numeric($values[0])) {\r
+                                                     $value = trim($values[0]);\r
+                                                     $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);\r
+                                                 }\r
+                                                 $score = $value;\r
+                                            break;\r
+                                            case 'cmi.core.session_time':\r
+                                                 $SESSION->scorm_session_time = $value;\r
+                                            break;\r
+                                        }\r
+                                    }\r
+                                } else {\r
+                                    if (isset($datamodel[strtolower(trim($datarow))])) {\r
+                                        $element = $datamodel[strtolower(trim($datarow))];\r
+                                        $value = '';\r
+                                        while ((($datarow = current($datarows)) !== false) && (substr($datarow,0,1) != '[')) {\r
+                                            $value .= $datarow;\r
+                                            next($datarows);\r
+                                        }\r
+                                        $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);\r
+                                    }\r
+                                }                               \r
+                            }\r
+                            if (($mode == 'browse') && ($initlessonstatus == 'not attempted')){\r
+                                $lessonstatus = 'browsed';\r
+                                $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', 'browsed');\r
+                            }\r
+                            if ($mode == 'normal') {\r
+                                if ($lessonstatus == 'completed') {\r
+                                    if (!empty($sco->masteryscore) && !empty($score) && ($score >= $sco->masteryscore)) {\r
+                                        $lessonstatus = 'passed';\r
+                                    } else {\r
+                                        $lessonstatus = 'failed';\r
+                                    }\r
+                                    $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', $lessonstatus);\r
+                                }\r
+                            }                  \r
+                        }\r
+                        echo "error = 0\nerror_text = Successful\n";\r
+                    } else if ($status == 'Terminated') {\r
+                        echo "error = 1\nerror_text = Terminated\n";\r
+                    } else {\r
+                        echo "error = 1\nerror_text = Not Initialized\n";\r
+                    }\r
+                break;\r
+                case 'putcomments':\r
+                    if ($status == 'Running') {\r
+                        echo "error = 0\nerror_text = Successful\n";\r
+                    } else if ($status == 'Terminated') {\r
+                        echo "error = 1\nerror_text = Terminated\n";\r
+                    } else {\r
+                        echo "error = 1\nerror_text = Not Initialized\n";\r
+                    }\r
+                break;\r
+                case 'putinteractions':\r
+                    if ($status == 'Running') {\r
+                        echo "error = 0\nerror_text = Successful\n";\r
+                    } else if ($status == 'Terminated') {\r
+                        echo "error = 1\nerror_text = Terminated\n";\r
+                    } else {\r
+                        echo "error = 1\nerror_text = Not Initialized\n";\r
+                    }\r
+                break;\r
+                case 'putobjectives':\r
+                    if ($status == 'Running') {\r
+                        echo "error = 0\nerror_text = Successful\n";\r
+                    } else if ($status == 'Terminated') {\r
+                        echo "error = 1\nerror_text = Terminated\n";\r
+                    } else {\r
+                        echo "error = 1\nerror_text = Not Initialized\n";\r
+                    }\r
+                break;\r
+                case 'putpath':\r
+                    if ($status == 'Running') {\r
+                        echo "error = 0\nerror_text = Successful\n";\r
+                    } else if ($status == 'Terminated') {\r
+                        echo "error = 1\nerror_text = Terminated\n";\r
+                    } else {\r
+                        echo "error = 1\nerror_text = Not Initialized\n";\r
+                    }\r
+                break;\r
+                case 'putperformance':\r
+                    if ($status == 'Running') {\r
+                        echo "error = 0\nerror_text = Successful\n";\r
+                    } else if ($status == 'Terminated') {\r
+                        echo "error = 1\nerror_text = Terminated\n";\r
+                    } else {\r
+                        echo "error = 1\nerror_text = Not Initialized\n";\r
+                    }\r
+                break;\r
+                case 'exitau':\r
+                    if ($status == 'Running') {\r
+                        if (isset($SESSION->scorm_session_time) && ($SESSION->scorm_session_time != '')) {\r
+                            if ($track = get_record_select('scorm_scoes_track',"userid='$USER->id' AND scormid='$scorm->id' AND scoid='$sco->id' AND element='cmi.core.total_time'")) {\r
+                                // Add session_time to total_time\r
+                                $value = scorm_add_time($track->value, $SESSION->scorm_session_time);\r
+                                $track->value = $value;\r
+                                $track->timemodified = time();\r
+                                $id = update_record('scorm_scoes_track',$track);\r
+                            } else {\r
+                                $track->userid = $USER->id;\r
+                                $track->scormid = $scorm->id;\r
+                                $track->scoid = $sco->id;\r
+                                $track->element = 'cmi.core.total_time';\r
+                                $track->value = $SESSION->scorm_session_time;\r
+                                $track->timemodified = time();\r
+                                $id = insert_record('scorm_scoes_track',$track);\r
+                            }\r
+                        }\r
+                        \r
+                        $SESSION->scorm_status = 'Terminated';\r
+                        $SESSION->scorm_session_time = '';\r
+                        echo "error = 0\nerror_text = Successful\n";\r
+                    } else if ($status == 'Terminated') {\r
+                        echo "error = 1\nerror_text = Terminated\n";\r
+                    } else {\r
+                        echo "error = 1\nerror_text = Not Initialized\n";\r
+                    }\r
+                break;\r
+                default:\r
+                    echo "error = 1\nerror_text = Invalid Command\n";\r
+                break;\r
+            }\r
+        }\r
+    } else {\r
+        if (empty($command)) {\r
+            echo "error = 1\nerror_text = Invalid Command\n";\r
+        } else {\r
+            echo "error = 3\nerror_text = Invalid Session ID\n";\r
+        }\r
+    }\r
+?>\r
index 2d47e1bcb0e1db79016d7adca522335a009c4e5a..5223fe66e36c4272cd15186af1a3a8e5d052c1af 100644 (file)
@@ -1,83 +1,84 @@
-<?php
-
-    require_once("../../config.php");
-    require_once('locallib.php');
-
-    $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or
-    $a = optional_param('a', '', PARAM_INT);         // scorm ID
-    $scoid = required_param('scoid', PARAM_INT);  // sco ID
-    $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
-    $attempt = required_param('attempt', PARAM_INT); // new attempt
-
-    if (!empty($id)) {
-        if (! $cm = get_record("course_modules", "id", $id)) {
-            error("Course Module ID was incorrect");
-        }
-        if (! $course = get_record("course", "id", $cm->course)) {
-            error("Course is misconfigured");
-        }
-        if (! $scorm = get_record("scorm", "id", $cm->instance)) {
-            error("Course module is incorrect");
-        }
-    } else 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");
-        }
-    } else {
-        error('A required parameter is missing');
-    }
-
-    require_login($course->id, false, $cm);
-    
-    if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) {
-        $userdata = $usertrack;
-    } else {
-        $userdata->status = '';
-        $userdata->score_raw = '';
-    }
-    $userdata->student_id = addslashes($USER->username);
-    $userdata->student_name = addslashes($USER->lastname .', '. $USER->firstname);
-    $userdata->mode = 'normal';
-    if (isset($mode)) {
-        $userdata->mode = $mode;
-    }
-    if ($userdata->mode == 'normal') {
-        $userdata->credit = 'credit';
-    } else {
-        $userdata->credit = 'no-credit';
-    }    
-    if ($sco = get_record('scorm_scoes','id',$scoid)) {
-        $userdata->datafromlms = $sco->datafromlms;
-        $userdata->masteryscore = $sco->masteryscore;
-        $userdata->maxtimeallowed = $sco->maxtimeallowed;
-        $userdata->timelimitaction = $sco->timelimitaction;
-    } else {
-        error('Sco not found');
-    }
-
-    switch ($scorm->version) {
-        case 'SCORM_1.2':
-            include_once ('datamodels/scorm1_2.js.php');
-        break;
-        case 'SCORM_1.3':
-            include_once ('datamodels/scorm1_3.js.php');
-        break;
-        case 'AICC':
-            include_once ('datamodels/aicc.js.php');
-        break;
-        default:
-            include_once ('datamodels/scorm1_2.js.php');
-        break;
-    }
-?>
-
-var errorCode = "0";
-function underscore(str) {
-    return str.replace(/\./g,"__");
-}
+<?php\r
+\r
+    require_once("../../config.php");\r
+    require_once('locallib.php');\r
+       require_once('sequencinglib.php');\r
+       \r
+    $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or\r
+    $a = optional_param('a', '', PARAM_INT);         // scorm ID\r
+    $scoid = required_param('scoid', PARAM_INT);  // sco ID\r
+    $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode\r
+    $attempt = required_param('attempt', PARAM_INT); // new attempt\r
+\r
+    if (!empty($id)) {\r
+        if (! $cm = get_record("course_modules", "id", $id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $cm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
+            error("Course module is incorrect");\r
+        }\r
+    } else if (!empty($a)) {\r
+        if (! $scorm = get_record("scorm", "id", $a)) {\r
+            error("Course module is incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $scorm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+    } else {\r
+        error('A required parameter is missing');\r
+    }\r
+\r
+    require_login($course->id, false, $cm);\r
+    \r
+    if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) {\r
+        $userdata = $usertrack;\r
+    } else {\r
+        $userdata->status = '';\r
+        $userdata->score_raw = '';\r
+    }\r
+    $userdata->student_id = addslashes($USER->username);\r
+    $userdata->student_name = addslashes($USER->lastname .', '. $USER->firstname);\r
+    $userdata->mode = 'normal';\r
+    if (isset($mode)) {\r
+        $userdata->mode = $mode;\r
+    }\r
+    if ($userdata->mode == 'normal') {\r
+        $userdata->credit = 'credit';\r
+    } else {\r
+        $userdata->credit = 'no-credit';\r
+    }    \r
+    if ($sco = get_record('scorm_scoes','id',$scoid)) {\r
+        $userdata->datafromlms = $sco->datafromlms;\r
+        $userdata->masteryscore = $sco->masteryscore;\r
+        $userdata->maxtimeallowed = $sco->maxtimeallowed;\r
+        $userdata->timelimitaction = $sco->timelimitaction;\r
+    } else {\r
+        error('Sco not found');\r
+    }\r
+\r
+    switch ($scorm->version) {\r
+        case 'SCORM_1.2':\r
+            include_once ('datamodels/scorm1_2.js.php');\r
+        break;\r
+        case 'SCORM_1.3':\r
+            include_once ('datamodels/scorm1_3.js.php');\r
+        break;\r
+        case 'AICC':\r
+            include_once ('datamodels/aicc.js.php');\r
+        break;\r
+        default:\r
+            include_once ('datamodels/scorm1_2.js.php');\r
+        break;\r
+    }\r
+?>\r
+\r
+var errorCode = "0";\r
+function underscore(str) {\r
+    return str.replace(/\./g,"__");\r
+}\r
index 33294d7685c4a861fdce9b2d2a8e26abde72d0e3..ff049dc429558dfc3319eb25e5e0aedfc45c0a7a 100755 (executable)
@@ -61,7 +61,6 @@
         fwrite ($bf,full_tag("VERSION",4,false,$scorm->version));
         fwrite ($bf,full_tag("MAXGRADE",4,false,$scorm->maxgrade));
         fwrite ($bf,full_tag("GRADEMETHOD",4,false,$scorm->grademethod));
-        fwrite ($bf,full_tag("MAXATTEMPT",4,false,$scorm->maxattempt));
         fwrite ($bf,full_tag("LAUNCH",4,false,$scorm->launch));
         fwrite ($bf,full_tag("SUMMARY",4,false,$scorm->summary));
         fwrite ($bf,full_tag("HIDEBROWSE",4,false,$scorm->hidebrowse));
                 fwrite ($bf,full_tag("ID",6,false,$sco_track->id));
                 fwrite ($bf,full_tag("USERID",6,false,$sco_track->userid));
                 fwrite ($bf,full_tag("SCOID",6,false,$sco_track->scoid));
-                fwrite ($bf,full_tag("ATTEMPT",6,false,$sco_track->attempt));
                 fwrite ($bf,full_tag("ELEMENT",6,false,$sco_track->element));
                 fwrite ($bf,full_tag("VALUE",6,false,$sco_track->value));
                 //End sco track
diff --git a/mod/scorm/coefficientconfirm.php b/mod/scorm/coefficientconfirm.php
new file mode 100755 (executable)
index 0000000..bc41c38
--- /dev/null
@@ -0,0 +1,113 @@
+<?php  // $Id$\r
+\r
+// This script uses installed report plugins to print quiz reports\r
+\r
+    require_once("../../config.php");\r
+    require_once('locallib.php');\r
+       require_once('sequencinglib.php');\r
+       \r
+    $id = optional_param('id', '', PARAM_INT);    // Course Module ID, or\r
+    $a = optional_param('a', '', PARAM_INT);     // SCORM ID\r
+    $b = optional_param('b', '', PARAM_INT);     // SCO ID\r
+    $user = optional_param('user', '', PARAM_INT);  // User ID\r
+\r
+    if (!empty($id)) {\r
+        if (! $cm = get_record("course_modules", "id", $id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $cm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
+            error("Course module is incorrect");\r
+        }\r
+    } else {\r
+        if (!empty($b)) {\r
+            if (! $sco = get_record("scorm_scoes", "id", $b)) {\r
+                error("Scorm activity is incorrect");\r
+            }\r
+            $a = $sco->scorm;\r
+        }\r
+        if (!empty($a)) {\r
+            if (! $scorm = get_record("scorm", "id", $a)) {\r
+                error("Course module is incorrect");\r
+            }\r
+            if (! $course = get_record("course", "id", $scorm->course)) {\r
+                error("Course is misconfigured");\r
+            }\r
+            if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
+                error("Course Module ID was incorrect");\r
+            }\r
+        }\r
+    }\r
+\r
+    require_login($course->id, false, $cm);\r
+\r
+    if (!isteacher($course->id)) {\r
+        error("You are not allowed to use this script");\r
+    }\r
+\r
+    add_to_log($course->id, "scorm", "report", "cofficientsetting.php?id=$cm->id", "$scorm->id");\r
+\r
+/// Print the page header\r
+    if (empty($noheader)) {\r
+        if ($course->category) {\r
+            $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";\r
+        } else {\r
+            $navigation = '';\r
+        }\r
+\r
+        $strscorms = get_string("modulenameplural", "scorm");\r
+        $strscorm  = get_string("modulename", "scorm");\r
+        $strreport  = get_string("report", "scorm");\r
+        $strname  = get_string('name');\r
+               $strcoefficient = get_string('coefficient',"scorm");\r
+               $strcoefficient = "Thiet lap he so";\r
+        if (empty($b)) {\r
+            print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",\r
+                     "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>\r
+                      -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a> -> $strcoefficient",\r
+                     "", "", true);\r
+        } else {\r
+            print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",\r
+                     "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>\r
+                      -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a>\r
+              -> <a href=\"report.php?id=$cm->id\">$strreport</a> -> $sco->title",\r
+                     "", "", true);\r
+        }\r
+        print_heading(format_string($scorm->name));\r
+    }\r
+\r
+    $scormpixdir = $CFG->modpixpath.'/scorm/pix';\r
+\r
+       //Phan trinh bay chinh\r
+?>\r
+\r
+  <?php\r
+       $examScoes = get_records_select('scorm_scoes', 'scorm ='.($scorm->id).' and minnormalizedmeasure > -1');\r
+       foreach ($examScoes as $examSco){\r
+               $newcoefficient = optional_param($examSco->id,'',PARAM_INT);\r
+               $sco = get_record('scorm_scoes','scorm',$scorm->id,'id',$examSco->id,'','');\r
+               $sco->score_coefficient = $newcoefficient;\r
+               $ketqua = update_record('scorm_scoes',$sco);\r
+               //echo "Cap nhat $examSco->id voi he so diem ".$newcoefficient."<br>";\r
+       }\r
+\r
+       if ($ketqua)\r
+       {\r
+               echo "".get_string('updatesuccess','scorm');\r
+       }\r
+       else\r
+       {\r
+               echo "".get_string('updatefail','scorm');\r
+       }\r
+\r
+       echo "<br><br><a href=coefficientsetting.php?id=$id>".get_string('back','scorm')."</a>"\r
+?>\r
+<?php\r
+       //ket thuc phan trinh bay chinh\r
+\r
+    if (empty($noheader)) {\r
+        print_footer($course);\r
+    }\r
+?>\r
diff --git a/mod/scorm/coefficientsetting.php b/mod/scorm/coefficientsetting.php
new file mode 100755 (executable)
index 0000000..ba949f9
--- /dev/null
@@ -0,0 +1,120 @@
+<?php  // $Id$\r
+\r
+// This script uses installed report plugins to print quiz reports\r
+\r
+    require_once("../../config.php");\r
+    require_once('locallib.php');\r
+       require_once('sequencinglib.php');\r
+       \r
+    $id = optional_param('id', '', PARAM_INT);    // Course Module ID, or\r
+    $a = optional_param('a', '', PARAM_INT);     // SCORM ID\r
+    $b = optional_param('b', '', PARAM_INT);     // SCO ID\r
+    $user = optional_param('user', '', PARAM_INT);  // User ID\r
+\r
+    if (!empty($id)) {\r
+        if (! $cm = get_record("course_modules", "id", $id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $cm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
+            error("Course module is incorrect");\r
+        }\r
+    } else {\r
+        if (!empty($b)) {\r
+            if (! $sco = get_record("scorm_scoes", "id", $b)) {\r
+                error("Scorm activity is incorrect");\r
+            }\r
+            $a = $sco->scorm;\r
+        }\r
+        if (!empty($a)) {\r
+            if (! $scorm = get_record("scorm", "id", $a)) {\r
+                error("Course module is incorrect");\r
+            }\r
+            if (! $course = get_record("course", "id", $scorm->course)) {\r
+                error("Course is misconfigured");\r
+            }\r
+            if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
+                error("Course Module ID was incorrect");\r
+            }\r
+        }\r
+    }\r
+\r
+    require_login($course->id, false, $cm);\r
+\r
+    if (!isteacher($course->id)) {\r
+        error("You are not allowed to use this script");\r
+    }\r
+\r
+    add_to_log($course->id, "scorm", "report", "cofficientsetting.php?id=$cm->id", "$scorm->id");\r
+\r
+/// Print the page header\r
+    if (empty($noheader)) {\r
+        if ($course->category) {\r
+            $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";\r
+        } else {\r
+            $navigation = '';\r
+        }\r
+\r
+        $strscorms = get_string("modulenameplural", "scorm");\r
+        $strscorm  = get_string("modulename", "scorm");\r
+        $strreport  = get_string("report", "scorm");\r
+        $strname  = get_string('name');\r
+               $strcoefficient = get_string('coefficient','scorm');\r
+        if (empty($b)) {\r
+            print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",\r
+                     "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>\r
+                      -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a> -> $strcoefficient",\r
+                     "", "", true);\r
+        } else {\r
+            print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",\r
+                     "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>\r
+                      -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a>\r
+              -> <a href=\"report.php?id=$cm->id\">$strreport</a> -> $sco->title",\r
+                     "", "", true);\r
+        }\r
+        print_heading(format_string($scorm->name));\r
+    }\r
+\r
+    $scormpixdir = $CFG->modpixpath.'/scorm/pix';\r
+\r
+       //Phan trinh bay chinh\r
+?>\r
+<script type="text/javascript">\r
+function validate_form()\r
+{\r
+       return true;\r
+}\r
+</script>\r
+<form name="form" method="post" action="coefficientconfirm.php" onsubmit="return validate_form();" >\r
+  <table width="50%" border="0">\r
+    <tr>\r
+      <td class="scormtableheader"><?php echo(get_string('title','scorm')); ?></td>\r
+      <td class="scormtableheader"><?php echo(get_string('coefficient','scorm')); ?></td>\r
+    </tr>\r
\r
+  <?php\r
+       $examScoes = get_records_select('scorm_scoes', 'scorm ='.($scorm->id).' and minnormalizedmeasure > -1');\r
+       if(!empty($examScoes))\r
+       {\r
+       \r
+               foreach ($examScoes as $examSco){\r
+               echo "<tr><td>";        \r
+               echo "$examSco->identifier.</td><td><input type='text' name='$examSco->id' class='scormtextbox' value=$examSco->score_coefficient /></td></tr><br>";\r
+               }\r
+       }\r
+\r
+?>\r
+ </table>\r
+<br>\r
+<input type="hidden" name="id" value="<?php p($id) ?>" />\r
+<input type="submit" value="<?php print_string('savechanges') ?>" />\r
+</form>\r
+<?php\r
+       //ket thuc phan trinh bay chinh\r
+\r
+    if (empty($noheader)) {\r
+        print_footer($course);\r
+    }\r
+?>\r
index a253d98e8736105e38a50bf8e4cda8c74777119d..7adc6b7ccff87c900bb25d930d6feebe19dd5421 100755 (executable)
@@ -1,54 +1,67 @@
-<?php
-    require_once('../../config.php');
-    require_once('locallib.php');
-    
-    $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or
-    $a = optional_param('a', '', PARAM_INT);         // scorm ID
-    $scoid = required_param('scoid', PARAM_INT);  // sco ID
-    $attempt = required_param('attempt', PARAM_INT);  // attempt number
-
-    if (!empty($id)) {
-        if (! $cm = get_record("course_modules", "id", $id)) {
-            error("Course Module ID was incorrect");
-        }
-        if (! $course = get_record("course", "id", $cm->course)) {
-            error("Course is misconfigured");
-        }
-        if (! $scorm = get_record("scorm", "id", $cm->instance)) {
-            error("Course module is incorrect");
-        }
-    } else 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");
-        }
-    } else {
-        error('A required parameter is missing');
-    }
-
-    require_login($course->id, false, $cm);
-
-    if (confirm_sesskey() && (!empty($scoid))) {
-        $result = true;
-        if (isstudent($course->id) || (isteacher($course->id) && !isadmin())) {
-            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, $attempt, $element, $value) && $result;
-                }
-            }
-        }
-        if ($result) {
-            echo "true\n0";
-        } else {
-            echo "false\n101";
-        }
-    }
-?>
-
+<?php\r
+    require_once('../../config.php');\r
+    require_once('locallib.php');\r
+       require_once('sequencinglib.php');\r
+               \r
+       //$f = "D:\\test.txt";\r
+       //@$ft = fopen($f,"a");\r
+       //fwrite($ft,"Bat dau ghi tron datamodel.php \n");\r
+\r
+    $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or\r
+    $a = optional_param('a', '', PARAM_INT);         // scorm ID\r
+    $scoid = required_param('scoid', PARAM_INT);  // sco ID\r
+//    $attempt = required_param('attempt', PARAM_INT);  // attempt number\r
+       $attempt = $USER->attempt;\r
+       //fwrite($ft,"\n --------Gia tri attempt thu duoc tu datamodel.php-------- : ".$attempt);\r
+\r
+\r
+    if (!empty($id)) {\r
+        if (! $cm = get_record("course_modules", "id", $id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $cm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
+            error("Course module is incorrect");\r
+        }\r
+    } else if (!empty($a)) {\r
+        if (! $scorm = get_record("scorm", "id", $a)) {\r
+            error("Course module is incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $scorm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+    } else {\r
+        error('A required parameter is missing');\r
+    }\r
+\r
+    require_login($course->id, false, $cm);\r
+\r
+    if (confirm_sesskey() && (!empty($scoid))) {\r
+               //fwrite($ft," --Ghi du lieu--- \n");\r
+        $result = true;\r
+        if (isstudent($course->id) || (isteacher($course->id) && !isadmin())) {\r
+            foreach ($_POST as $element => $value) {\r
+                if (substr($element,0,3) == 'cmi') {\r
+                    $element = str_replace('__','.',$element);\r
+                    $element = preg_replace('/_(\d+)/',".\$1",$element);\r
+                    $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $element, $value) && $result;\r
+                                       //fwrite($ft,"\n Ghi xong mot phan tu tai Datamodel.php-- ".$scoid);\r
+\r
+                }\r
+            }\r
+        }\r
+        if ($result) {\r
+            echo "true\n0";\r
+                       //fwrite($ft,"Ghi thanh cong trong  Datamodel.php-");\r
+        } else {\r
+            echo "false\n101";\r
+                       //fwrite($ft,"Ghi that bai trong  Datamodel.php-");\r
+        }\r
+    }\r
+?>\r
+\r
index faffd41b8fc4f6cfedf5e9985318a23e6d9fcff4..34c1489412cf4f3120d98c26bbd2fe23b31d7d00 100755 (executable)
@@ -1,94 +1,96 @@
-<?php // $Id$
-
-    require_once("../../config.php");
-
-    $id = required_param('id', PARAM_INT);   // course id
-
-    if (!empty($id)) {
-        if (! $course = get_record("course", "id", $id)) {
-            error("Course ID is incorrect");
-        }
-    } else {
-        error('A required parameter is missing');
-    }
-
-    require_course_login($course);
-
-    add_to_log($course->id, "scorm", "view all", "index.php?id=$course->id", "");
-
-    $strscorm = get_string("modulename", "scorm");
-    $strscorms = get_string("modulenameplural", "scorm");
-    $strweek = get_string("week");
-    $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",
-                 "", "", true, "", navmenu($course));
-
-    if ($course->format == "weeks" or $course->format == "topics") {
-        $sortorder = "cw.section ASC";
-    } else {
-        $sortorder = "m.timemodified DESC";
-    }
-
-    if (! $scorms = get_all_instances_in_course("scorm", $course)) {
-        notice("There are no scorms", "../../course/view.php?id=$course->id");
-        exit;
-    }
-
-    if ($course->format == "weeks") {
-        $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, $strreport);
-        $table->align = array ("center", "left", "left", "left");
-    } else {
-        $table->head  = array ($strlastmodified, $strname, $strsummary, $strreport);
-        $table->align = array ("left", "left", "left", "left");
-    }
-
-    foreach ($scorms as $scorm) {
-
-        $tt = "";
-        if ($course->format == "weeks" or $course->format == "topics") {
-            if ($scorm->section) {
-                $tt = "$scorm->section";
-            }
-        } else {
-            $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), $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), $report);
-        }
-    }
-
-    echo "<br />";
-
-    print_table($table);
-
-    print_footer($course);
-
-
-?>
-
+<?php // $Id$\r
+\r
+    require_once("../../config.php");\r
+       require_once('sequencinglib.php');\r
+\r
+    $id = required_param('id', PARAM_INT);   // course id\r
+\r
+    if (!empty($id)) {\r
+        if (! $course = get_record("course", "id", $id)) {\r
+            error("Course ID is incorrect");\r
+        }\r
+    } else {\r
+        error('A required parameter is missing');\r
+    }\r
+\r
+    require_course_login($course);\r
+\r
+    add_to_log($course->id, "scorm", "view all", "index.php?id=$course->id", "");\r
+\r
+    $strscorm = get_string("modulename", "scorm");\r
+    $strscorms = get_string("modulenameplural", "scorm");\r
+    $strweek = get_string("week");\r
+    $strtopic = get_string("topic");\r
+    $strname = get_string("name");\r
+    $strsummary = get_string("summary");\r
+    $strreport = get_string("report",'scorm');\r
+    $strlastmodified = get_string("lastmodified");\r
+\r
+    print_header_simple("$strscorms", "", "$strscorms",\r
+                 "", "", true, "", navmenu($course));\r
+\r
+    if ($course->format == "weeks" or $course->format == "topics") {\r
+        $sortorder = "cw.section ASC";\r
+    } else {\r
+        $sortorder = "m.timemodified DESC";\r
+    }\r
+\r
+    if (! $scorms = get_all_instances_in_course("scorm", $course)) {\r
+        notice("There are no scorms", "../../course/view.php?id=$course->id");\r
+        exit;\r
+    }\r
+\r
+    if ($course->format == "weeks") {\r
+        $table->head  = array ($strweek, $strname, $strsummary, $strreport);\r
+        $table->align = array ("center", "left", "left", "left");\r
+    } else if ($course->format == "topics") {\r
+        $table->head  = array ($strtopic, $strname, $strsummary, $strreport);\r
+        $table->align = array ("center", "left", "left", "left");\r
+    } else {\r
+        $table->head  = array ($strlastmodified, $strname, $strsummary, $strreport);\r
+        $table->align = array ("left", "left", "left", "left");\r
+    }\r
+\r
+    foreach ($scorms as $scorm) {\r
+\r
+        $tt = "";\r
+        if ($course->format == "weeks" or $course->format == "topics") {\r
+            if ($scorm->section) {\r
+                $tt = "$scorm->section";\r
+            }\r
+        } else {\r
+            $tt = userdate($scorm->timemodified);\r
+        }\r
+        $report = '&nbsp;';\r
+        if (isteacher($course->id)) {\r
+            $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');\r
+            if ($trackedusers->c > 0) {\r
+                $reportshow = '<a href="report.php?a='.$scorm->id.'">'.get_string('viewallreports','scorm',$trackedusers->c).'</a></div>';\r
+            } else {\r
+                $reportshow = get_string('noreports','scorm');\r
+            }\r
+        } else if (isstudent($course->id)) {\r
+           require_once('locallib.php');\r
+           $report = scorm_grade_user_new(get_records('scorm_scoes','scorm',$scorm->id), $USER->id, $scorm->grademethod);\r
+                  $sco_count = scorm_get_user_sco_count($scorm->id,$USER->id);\r
+                       $reportshow = get_string('implement','scorm').$sco_count.get_string('lesson','scorm') ."<br><table width=".($report*100)."% bgcolor=#800000><tr><td height=15></td></tr></table>".get_string('scoreRate','scorm').": ".($report*100)."%";        }\r
+        if (!$scorm->visible) {\r
+           //Show dimmed if the mod is hidden\r
+           $table->data[] = array ($tt, "<a class=\"dimmed\" href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name,true)."</a>",\r
+                                   format_text($scorm->summary),$reportshow);\r
+        } else {\r
+           //Show normal if the mod is visible\r
+           $table->data[] = array ($tt, "<a href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name,true)."</a>",\r
+                                   format_text($scorm->summary), $reportshow);\r
+        }\r
+    }\r
+\r
+    echo "<br />";\r
+\r
+    print_table($table);\r
+\r
+    print_footer($course);\r
+\r
+\r
+?>\r
+\r
index 8fe635a23fefe7fafd62ebf4f2c5e80beb70e7d8..be729b8212d8f131556f9839e2a2df882d63f5bd 100755 (executable)
-<?php  // $Id$
-
-/// Library of functions and constants for module scorm
-
-define('GRADESCOES', '0');
-define('GRADEHIGHEST', '1');
-define('GRADEAVERAGE', '2');
-define('GRADESUM', '3');
-$SCORM_GRADE_METHOD = array (GRADESCOES => get_string('gradescoes', 'scorm'),
-                             GRADEHIGHEST => get_string('gradehighest', 'scorm'),
-                             GRADEAVERAGE => get_string('gradeaverage', 'scorm'),
-                             GRADESUM => get_string('gradesum', 'scorm'));
-
-define('VALUEHIGHEST', '0');
-define('VALUEAVERAGE', '1');
-define('VALUEFIRST', '2');
-define('VALUELAST', '3');
-$SCORM_WHAT_GRADE = array (VALUEHIGHEST => get_string('highestattempt', 'scorm'),
-                           VALUEAVERAGE => get_string('averageattempt', 'scorm'),
-                           VALUEFIRST => get_string('firstattempt', 'scorm'),
-                           VALUELAST => get_string('lastattempt', 'scorm'));
-
-$SCORM_POPUP_OPTIONS = array('resizable'=>1, 
-                             'scrollbars'=>1, 
-                             'directories'=>0, 
-                             'location'=>0,
-                             'menubar'=>0, 
-                             'toolbar'=>0, 
-                             'status'=>0);
-$stdoptions = '';
-foreach ($SCORM_POPUP_OPTIONS as $popupopt => $value) {
-    $stdoptions .= $popupopt.'='.$value;
-    if ($popupopt != 'status') {
-        $stdoptions .= ',';
-    }
-}
-
-if (!isset($CFG->scorm_maxattempts)) {
-    set_config('scorm_maxattempts','6');
-}
-
-if (!isset($CFG->scorm_frameheight)) {
-    set_config('scorm_frameheight','500');
-}
-
-if (!isset($CFG->scorm_framewidth)) {
-    set_config('scorm_framewidth','100%');
-}
-
-/**
-* Given an object containing all the necessary data,
-* (defined by the form in mod.html) this function
-* will create a new instance and return the id number
-* of the new instance.
-*
-* @param mixed $scorm Form data
-* @return int
-*/
-function scorm_add_instance($scorm) {
-
-    global $CFG;
-    $scorm->timemodified = time();
-
-    $scorm = scorm_option2text($scorm);
-    $scorm->width = str_replace('%','',$scorm->width);
-    $scorm->height = str_replace('%','',$scorm->height);
-
-    $id = insert_record('scorm', $scorm);
-
-    if (basename($scorm->reference) != 'imsmanifest.xml') {
-        // Rename temp scorm dir to scorm id
-        $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
-        rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id);
-    }
-
-    // Parse scorm manifest
-    if ($scorm->launch == 0) {
-        require_once('locallib.php');
-        $scorm->id = $id;
-        $scorm->launch = scorm_parse($scorm);
-        set_field('scorm','launch',$scorm->launch,'id',$scorm->id);
-    }
-
-    return $id;
-}
-
-/**
-* Given an object containing all the necessary data,
-* (defined by the form in mod.html) this function
-* will update an existing instance with new data.
-*
-* @param mixed $scorm Form data
-* @return int
-*/
-function scorm_update_instance($scorm) {
-
-    global $CFG;
-
-    $scorm->timemodified = time();
-    $scorm->id = $scorm->instance;
-
-    $scorm = scorm_option2text($scorm);
-    $scorm->width = str_replace('%','',$scorm->width);
-    $scorm->height = str_replace('%','',$scorm->height);
-
-    // Check if scorm manifest needs to be reparsed
-    if ($scorm->launch == 0) {
-        // Delete old related records
-        delete_records('scorm_scoes','scorm',$scorm->id);
-        delete_records('scorm_scoes_track','scormid',$scorm->id);
-        
-        $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
-        if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) && (basename($scorm->reference) != 'imsmanifest.xml')) {
-            scorm_delete_files($scorm->dir.'/'.$scorm->id);
-            rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id);
-        }
-        
-        require_once('locallib.php');
-        $scorm->launch = scorm_parse($scorm);
-    }
-
-    return update_record('scorm', $scorm);
-}
-
-/**
-* Given an ID of an instance of this module,
-* this function will permanently delete the instance
-* and any data that depends on it.
-*
-* @param int $id Scorm instance id
-* @return boolean
-*/
-function scorm_delete_instance($id) {
-
-    global $CFG;
-
-    if (! $scorm = get_record('scorm', 'id', $id)) {
-        return false;
-    }
-
-    $result = true;
-
-    // Delete any dependent files
-    scorm_delete_files($CFG->dataroot.'/'.$scorm->course.'/moddata/scorm/'.$scorm->id);
-
-    // Delete any dependent records
-    if (! delete_records('scorm_scoes_track', 'scormid', $scorm->id)) {
-        $result = false;
-    }
-    if (! delete_records('scorm_scoes', 'scorm', $scorm->id)) {
-        $result = false;
-    }
-    if (! delete_records('scorm', 'id', $scorm->id)) {
-        $result = false;
-    }
-
-    return $result;
-}
-
-/**
-* Return a small object with summary information about what a
-* user has done with a given particular instance of this module
-* Used for user activity reports.
-*
-* @param int $course Course id
-* @param int $user User id
-* @param int $mod  
-* @param int $scorm The scorm id
-* @return mixed
-*/
-function scorm_user_outline($course, $user, $mod, $scorm) { 
-
-    $return = NULL;
-    $scores->values = 0;
-    $scores->sum = 0;
-    $scores->max = 0;
-    $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++;
-               if ($userdata = scorm_get_tracks($sco->id, $user->id)) {
-                    if (!isset($scores->{$userdata->status})) {
-                        $scores->{$userdata->status} = 1;
-                    } else {    
-                        $scores->{$userdata->status}++;
-                    }
-                    if (!empty($userdata->score_raw)) {
-                        $scores->values++;
-                        $scores->sum += $userdata->score_raw;
-                        $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
-                    }
-                    if (isset($userdata->timemodified) && ($userdata->timemodified > $scores->lastmodify)) {
-                        $scores->lastmodify = $userdata->timemodified;
-                    }
-                }
-            }
-        }
-        switch ($scorm->grademethod) {
-            case VALUEHIGHEST:
-               if ($scores->values > 0) {
-                    $return->info = get_string('score','scorm').':&nbsp;'.$scores->max;
-                    $return->time = $scores->lastmodify;
-                }
-            break;
-            case VALUEAVERAGE:
-                if ($scores->values > 0) {
-                    $return->info = get_string('score','scorm').':&nbsp;'.$scores->sum/$scores->values;
-                    $return->time = $scores->lastmodify;
-                }
-            break;
-            case VALUESUM:
-                if ($scores->values > 0) {
-                    $return->info = get_string('score','scorm').':&nbsp;'.$scores->sum;
-                    $return->time = $scores->lastmodify;
-                }
-            break;
-            case VALUESCOES:
-                $return->info = '';
-                $scores->notattempted = $scores->count;
-                if (isset($scores->completed)) {
-                   $return->info .= get_string('completed','scorm').':&nbsp;'.$scores->completed.'<br />';
-                    $scores->notattempted -= $scores->completed;
-                }
-                if (isset($scores->passed)) {
-                   $return->info .= get_string('passed','scorm').':&nbsp;'.$scores->passed.'<br />';
-                    $scores->notattempted -= $scores->passed;
-                }
-                if (isset($scores->failed)) {
-                   $return->info .= get_string('failed','scorm').':&nbsp;'.$scores->failed.'<br />';
-                    $scores->notattempted -= $scores->failed;
-                }
-                if (isset($scores->incomplete)) {
-                   $return->info .= get_string('incomplete','scorm').':&nbsp;'.$scores->incomplete.'<br />';
-                    $scores->notattempted -= $scores->incomplete;
-                }
-                if (isset($scores->browsed)) {
-                   $return->info .= get_string('browsed','scorm').':&nbsp;'.$scores->browsed.'<br />';
-                    $scores->notattempted -= $scores->browsed;
-                }
-                $return->time = $scores->lastmodify;
-                if ($return->info == '') {
-                    $return = NULL;
-                } else {
-                   $return->info .= get_string('notattempted','scorm').':&nbsp;'.$scores->notattempted.'<br />';
-                }
-            break;
-        }
-    }
-    return $return;
-}
-
-/**
-* Print a detailed representation of what a user has done with
-* a given particular instance of this module, for user activity reports.
-*
-* @param int $course Course id
-* @param int $user User id
-* @param int $mod  
-* @param int $scorm The scorm id
-* @return boolean
-*/
-function scorm_user_complete($course, $user, $mod, $scorm) {
-    global $CFG;
-
-    $liststyle = 'structlist';
-    $scormpixdir = $CFG->modpixpath.'/scorm/pix';
-    $now = time();
-    $firstmodify = $now;
-    $lastmodify = 0;
-    $sometoreport = false;
-    $report = '';
-    
-    if ($orgs = get_records_select('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,identifier,title')) {
-        if (count($orgs) <= 1) {
-            unset($orgs);
-            $orgs[]->identifier = '';
-        }
-        $report .= '<div class="mod-scorm">'."\n";
-        foreach ($orgs as $org) {
-            $organizationsql = '';
-            $currentorg = '';
-            if (!empty($org->identifier)) {
-                $report .= '<div class="orgtitle">'.$org->title.'</div>';
-                $currentorg = $org->identifier;
-                $organizationsql = "AND organization='$currentorg'";
-            }
-            $report .= "<ul id='0' class='$liststyle'>";
-            if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
-                $level=0;
-                $sublist=1;
-                $parents[$level]='/';
-                foreach ($scoes as $sco) {
-                    if ($parents[$level]!=$sco->parent) {
-                        if ($level>0 && $parents[$level-1]==$sco->parent) {
-                            $report .= "\t\t</ul></li>\n";
-                            $level--;
-                        } else {
-                            $i = $level;
-                            $closelist = '';
-                            while (($i > 0) && ($parents[$level] != $sco->parent)) {
-                                $closelist .= "\t\t</ul></li>\n";
-                                $i--;
-                            }
-                            if (($i == 0) && ($sco->parent != $currentorg)) {
-                                $report .= "\t\t<li><ul id='$sublist' class='$liststyle'>\n";
-                                $level++;
-                            } else {
-                                $report .= $closelist;
-                                $level = $i;
-                            }
-                            $parents[$level]=$sco->parent;
-                        }
-                    }
-                    $report .= "\t\t<li>";
-                    $nextsco = next($scoes);
-                    if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
-                        $sublist++;
-                    } else {
-                        $report .= '<img src="'.$scormpixdir.'/spacer.gif" />';
-                    }
-
-                    if ($sco->launch) {
-                        require_once('locallib.php');
-                        $score = '';
-                        $totaltime = '';
-                        if ($usertrack=scorm_get_tracks($sco->id,$user->id)) {
-                            if ($usertrack->status == '') {
-                                $usertrack->status = 'notattempted';
-                            }
-                            $strstatus = get_string($usertrack->status,'scorm');
-                            $report .= "<img src='".$scormpixdir.'/'.$usertrack->status.".gif' alt='$strstatus' title='$strstatus' />";
-                            if ($usertrack->timemodified != 0) {
-                                if ($usertrack->timemodified > $lastmodify) {
-                                    $lastmodify = $usertrack->timemodified;
-                                }
-                                if ($usertrack->timemodified < $firstmodify) {
-                                    $firstmodify = $usertrack->timemodified;
-                                }
-                            }
-                        } else {
-                            if ($sco->scormtype == 'sco') {
-                                $report .= '<img src="'.$scormpixdir.'/'.'notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
-                            } else {
-                                $report .= '<img src="'.$scormpixdir.'/'.'asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
-                            }
-                        }
-                        $report .= "&nbsp;$sco->title $score$totaltime</li>\n";
-                        if ($usertrack !== false) {
-                            $sometoreport = true;
-                            $report .= "\t\t\t<li><ul class='$liststyle'>\n";
-                            foreach($usertrack as $element => $value) {
-                                if (substr($element,0,3) == 'cmi') {
-                                    $report .= '<li>'.$element.' => '.$value.'</li>';
-                                }
-                            }
-                            $report .= "\t\t\t</ul></li>\n";
-                        } 
-                    } else {
-                        $report .= "&nbsp;$sco->title</li>\n";
-                    }
-                }
-                for ($i=0;$i<$level;$i++) {
-                    $report .= "\t\t</ul></li>\n";
-                }
-            }
-            $report .= "\t</ul><br />\n";
-        }
-        $report .= "</div>\n";
-    }
-    if ($sometoreport) {
-        if ($firstmodify < $now) {
-            $timeago = format_time($now - $firstmodify);
-            echo get_string('firstaccess','scorm').': '.userdate($firstmodify).' ('.$timeago.")<br />\n";
-        }
-        if ($lastmodify > 0) {
-            $timeago = format_time($now - $lastmodify);
-            echo get_string('lastaccess','scorm').': '.userdate($lastmodify).' ('.$timeago.")<br />\n";
-        }
-        echo get_string('report','scorm').":<br />\n";
-        echo $report;
-    } else {
-       print_string('noactivity','scorm');
-    }
-
-    return true;
-}
-
-/**
-* Given a list of logs, assumed to be those since the last login
-* this function prints a short list of changes related to this module
-* If isteacher is true then perhaps additional information is printed.
-* This function is called from course/lib.php: print_recent_activity()
-*
-* @param reference $logs Logs reference
-* @param boolean $isteacher
-* @return boolean
-*/
-function scorm_print_recent_activity(&$logs, $isteacher=false) {
-    return false;  // True if anything was printed, otherwise false
-}
-
-/**
-* Function to be run periodically according to the moodle cron
-* This function searches for things that need to be done, such
-* as sending out mail, toggling flags etc ...
-*
-* @return boolean
-*/
-function scorm_cron () {
-
-    global $CFG;
-
-    return true;
-}
-
-/**
-* Given a scorm id return all the grades of that activity
-*
-* @param int $scormid Scorm instance id
-* @return mixed
-*/
-function scorm_grades($scormid) {
-
-    global $CFG;
-
-    if (!$scorm = get_record('scorm', 'id', $scormid)) {
-        return NULL;
-    }
-    if (!$scoes = get_records('scorm_scoes','scorm',$scormid)) {
-        return NULL;
-    }
-
-    if ($scorm->grademethod == GRADESCOES) {
-        if (!$return->maxgrade = count_records_select('scorm_scoes',"scorm='$scormid' AND launch<>''")) {
-            return NULL;
-        }
-    } else {
-        $return->maxgrade = $scorm->maxgrade;
-    }
-
-    $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) {
-            $return->grades[$scouser->userid] = scorm_grade_user($scoes, $scouser->userid, $scorm->grademethod);
-        }
-    }
-    return $return;
-}
-
-function scorm_get_view_actions() {
-    return array('pre-view','view','view all','report');
-}
-
-function scorm_get_post_actions() {
-    return array();
-}
-
-/**
-* This function will permanently delete the given
-* directory and all files and subdirectories.
-*
-* @param string $directory The directory to remove
-* @return boolean
-*/
-function scorm_delete_files($directory) {
-    if (is_dir($directory)) {
-        $files=scorm_scandir($directory);
-        foreach($files as $file) {
-            if (($file != '.') && ($file != '..')) {
-                if (!is_dir($directory.'/'.$file)) {
-                    unlink($directory.'/'.$file);
-                } else {
-                    scorm_delete_files($directory.'/'.$file);
-                }
-            }
-        }
-        rmdir($directory);
-        return true;
-    }
-    return false;
-}
-
-/**
-* Given a diretory path returns the file list
-*
-* @param string $directory
-* @return array
-*/
-function scorm_scandir($directory) {
-    if (version_compare(phpversion(),'5.0.0','>=')) {
-        return scandir($directory);
-    } else {
-        $files = array();
-        if ($dh = opendir($directory)) {
-            while (($file = readdir($dh)) !== false) {
-               $files[] = $file;
-            }
-            closedir($dh);
-        }
-        return $files;
-    }
-}
-
-function scorm_option2text($scorm) {
-    global $SCORM_POPUP_OPTIONS;
-
-    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 = '';
-    }
-    return $scorm;
-}
-
-?>
+<?php  // $Id$\r
+\r
+/// Library of functions and constants for module scorm\r
+\r
+define('GRADESCOES', '0');\r
+define('GRADEHIGHEST', '1');\r
+define('GRADEAVERAGE', '2');\r
+define('GRADESUM', '3');\r
+$SCORM_GRADE_METHOD = array (GRADESCOES => get_string('gradescoes', 'scorm'),\r
+                             GRADEHIGHEST => get_string('gradehighest', 'scorm'),\r
+                             GRADEAVERAGE => get_string('gradeaverage', 'scorm'),\r
+                             GRADESUM => get_string('gradesum', 'scorm'));\r
+\r
+define('VALUEHIGHEST', '0');\r
+define('VALUEAVERAGE', '1');\r
+define('VALUEFIRST', '2');\r
+define('VALUELAST', '3');\r
+$SCORM_WHAT_GRADE = array (VALUEHIGHEST => get_string('highestattempt', 'scorm'),\r
+                           VALUEAVERAGE => get_string('averageattempt', 'scorm'),\r
+                           VALUEFIRST => get_string('firstattempt', 'scorm'),\r
+                           VALUELAST => get_string('lastattempt', 'scorm'));\r
+\r
+$SCORM_POPUP_OPTIONS = array('resizable'=>1, \r
+                             'scrollbars'=>1, \r
+                             'directories'=>0, \r
+                             'location'=>0,\r
+                             'menubar'=>0, \r
+                             'toolbar'=>0, \r
+                             'status'=>0);\r
+$stdoptions = '';\r
+foreach ($SCORM_POPUP_OPTIONS as $popupopt => $value) {\r
+    $stdoptions .= $popupopt.'='.$value;\r
+    if ($popupopt != 'status') {\r
+        $stdoptions .= ',';\r
+    }\r
+}\r
+\r
+if (!isset($CFG->scorm_maxattempts)) {\r
+    set_config('scorm_maxattempts','6');\r
+}\r
+\r
+if (!isset($CFG->scorm_frameheight)) {\r
+    set_config('scorm_frameheight','500');\r
+}\r
+\r
+if (!isset($CFG->scorm_framewidth)) {\r
+    set_config('scorm_framewidth','100%');\r
+}\r
+\r
+/**\r
+* Given an object containing all the necessary data,\r
+* (defined by the form in mod.html) this function\r
+* will create a new instance and return the id number\r
+* of the new instance.\r
+*\r
+* @param mixed $scorm Form data\r
+* @return int\r
+*/\r
+function scorm_add_instance($scorm) {\r
+\r
+    global $CFG;\r
+    $scorm->timemodified = time();\r
+\r
+    $scorm = scorm_option2text($scorm);\r
+    $scorm->width = str_replace('%','',$scorm->width);\r
+    $scorm->height = str_replace('%','',$scorm->height);\r
+\r
+    $id = insert_record('scorm', $scorm);\r
+\r
+    if (basename($scorm->reference) != 'imsmanifest.xml') {\r
+        // Rename temp scorm dir to scorm id\r
+        $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';\r
+        rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id);\r
+    }\r
+\r
+    // Parse scorm manifest\r
+    if ($scorm->launch == 0) {\r
+        require_once('locallib.php');\r
+        $scorm->id = $id;\r
+        $scorm->launch = scorm_parse($scorm);\r
+        set_field('scorm','launch',$scorm->launch,'id',$scorm->id);\r
+    }\r
+\r
+    return $id;\r
+}\r
+\r
+/**\r
+* Given an object containing all the necessary data,\r
+* (defined by the form in mod.html) this function\r
+* will update an existing instance with new data.\r
+*\r
+* @param mixed $scorm Form data\r
+* @return int\r
+*/\r
+function scorm_update_instance($scorm) {\r
+\r
+    global $CFG;\r
+\r
+    $scorm->timemodified = time();\r
+    $scorm->id = $scorm->instance;\r
+\r
+    $scorm = scorm_option2text($scorm);\r
+    $scorm->width = str_replace('%','',$scorm->width);\r
+    $scorm->height = str_replace('%','',$scorm->height);\r
+\r
+    // Check if scorm manifest needs to be reparsed\r
+    if ($scorm->launch == 0) {\r
+               //$f = "D:\\test.txt";\r
+               //@$ft = fopen($f,"a");\r
+               //fwrite($ft,"\n Xu ly trong update trong lib.php \n");\r
+               //fwrite($ft,"\n Lauch co gia tri \n".($scorm->launch));\r
+\r
+        // Delete old related records\r
+        delete_records('scorm_scoes','scorm',$scorm->id);\r
+        delete_records('scorm_scoes_track','scormid',$scorm->id);\r
+        delete_records('scorm_sequencing_controlmode','scormid',$scorm->id);\r
+        delete_records('scorm_sequencing_rolluprules','scormid',$scorm->id);\r
+        delete_records('scorm_sequencing_rolluprule','scormid',$scorm->id);\r
+        delete_records('scorm_sequencing_rollupruleconditions','scormid',$scorm->id);\r
+        delete_records('scorm_sequencing_rolluprulecondition','scormid',$scorm->id);                           \r
+        delete_records('scorm_sequencing_ruleconditions','scormid',$scorm->id);\r
+        delete_records('scorm_sequencing_rulecondition','scormid',$scorm->id);                         \r
+\r
+        \r
+        $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';\r
+        if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) && (basename($scorm->reference) != 'imsmanifest.xml')) {\r
+            scorm_delete_files($scorm->dir.'/'.$scorm->id);\r
+            rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id);\r
+        }\r
+        \r
+        require_once('locallib.php');\r
+        $scorm->launch = scorm_parse($scorm);\r
+    }\r
+\r
+    return update_record('scorm', $scorm);\r
+}\r
+\r
+/**\r
+* Given an ID of an instance of this module,\r
+* this function will permanently delete the instance\r
+* and any data that depends on it.\r
+*\r
+* @param int $id Scorm instance id\r
+* @return boolean\r
+*/\r
+function scorm_delete_instance($id) {\r
+\r
+    global $CFG;\r
+\r
+    if (! $scorm = get_record('scorm', 'id', $id)) {\r
+        return false;\r
+    }\r
+\r
+    $result = true;\r
+\r
+    // Delete any dependent files\r
+    scorm_delete_files($CFG->dataroot.'/'.$scorm->course.'/moddata/scorm/'.$scorm->id);\r
+\r
+    // Delete any dependent records\r
+    if (! delete_records('scorm_scoes_track', 'scormid', $scorm->id)) {\r
+        $result = false;\r
+    }\r
+    if (! delete_records('scorm_scoes', 'scorm', $scorm->id)) {\r
+        $result = false;\r
+    }\r
+    if (! delete_records('scorm', 'id', $scorm->id)) {\r
+        $result = false;\r
+    }\r
+    if (! delete_records('scorm_sequencing_controlmode', 'scormid', $scorm->id)) {\r
+        $result = false;\r
+    }\r
+    if (! delete_records('scorm_sequencing_rolluprules', 'scormid', $scorm->id)) {\r
+        $result = false;\r
+    }\r
+    if (! delete_records('scorm_sequencing_rolluprule', 'scormid', $scorm->id)) {\r
+        $result = false;\r
+    }\r
+    if (! delete_records('scorm_sequencing_rollupruleconditions', 'scormid', $scorm->id)) {\r
+        $result = false;\r
+    }\r
+    if (! delete_records('scorm_sequencing_rolluprulecondition', 'scormid', $scorm->id)) {\r
+        $result = false;\r
+    }\r
+    if (! delete_records('scorm_sequencing_rulecondition', 'scormid', $scorm->id)) {\r
+        $result = false;\r
+    }\r
+    if (! delete_records('scorm_sequencing_ruleconditions', 'scormid', $scorm->id)) {\r
+        $result = false;\r
+    }          \r
+    return $result;\r
+}\r
+\r
+/**\r
+* Return a small object with summary information about what a\r
+* user has done with a given particular instance of this module\r
+* Used for user activity reports.\r
+*\r
+* @param int $course Course id\r
+* @param int $user User id\r
+* @param int $mod  \r
+* @param int $scorm The scorm id\r
+* @return mixed\r
+*/\r
+function scorm_user_outline($course, $user, $mod, $scorm) { \r
+\r
+    $return = NULL;\r
+    $scores->values = 0;\r
+    $scores->sum = 0;\r
+    $scores->max = 0;\r
+    $scores->lastmodify = 0;\r
+    $scores->count = 0;\r
+    if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) {\r
+        require_once('locallib.php');\r
+        foreach ($scoes as $sco) {\r
+            if ($sco->launch!='') {\r
+               $scores->count++;\r
+               if ($userdata = scorm_get_tracks($sco->id, $user->id)) {\r
+                    if (!isset($scores->{$userdata->status})) {\r
+                        $scores->{$userdata->status} = 1;\r
+                    } else {    \r
+                        $scores->{$userdata->status}++;\r
+                    }\r
+                    if (!empty($userdata->score_raw)) {\r
+                        $scores->values++;\r
+                        $scores->sum += $userdata->score_raw;\r
+                        $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;\r
+                    }\r
+                    if (isset($userdata->timemodified) && ($userdata->timemodified > $scores->lastmodify)) {\r
+                        $scores->lastmodify = $userdata->timemodified;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        switch ($scorm->grademethod) {\r
+            case VALUEHIGHEST:\r
+               if ($scores->values > 0) {\r
+                    $return->info = get_string('score','scorm').':&nbsp;'.$scores->max;\r
+                    $return->time = $scores->lastmodify;\r
+                }\r
+            break;\r
+            case VALUEAVERAGE:\r
+                if ($scores->values > 0) {\r
+                    $return->info = get_string('score','scorm').':&nbsp;'.$scores->sum/$scores->values;\r
+                    $return->time = $scores->lastmodify;\r
+                }\r
+            break;\r
+            case VALUESUM:\r
+                if ($scores->values > 0) {\r
+                    $return->info = get_string('score','scorm').':&nbsp;'.$scores->sum;\r
+                    $return->time = $scores->lastmodify;\r
+                }\r
+            break;\r
+            case VALUESCOES:\r
+                $return->info = '';\r
+                $scores->notattempted = $scores->count;\r
+                if (isset($scores->completed)) {\r
+                   $return->info .= get_string('completed','scorm').':&nbsp;'.$scores->completed.'<br />';\r
+                    $scores->notattempted -= $scores->completed;\r
+                }\r
+                if (isset($scores->passed)) {\r
+                   $return->info .= get_string('passed','scorm').':&nbsp;'.$scores->passed.'<br />';\r
+                    $scores->notattempted -= $scores->passed;\r
+                }\r
+                if (isset($scores->failed)) {\r
+                   $return->info .= get_string('failed','scorm').':&nbsp;'.$scores->failed.'<br />';\r
+                    $scores->notattempted -= $scores->failed;\r
+                }\r
+                if (isset($scores->incomplete)) {\r
+                   $return->info .= get_string('incomplete','scorm').':&nbsp;'.$scores->incomplete.'<br />';\r
+                    $scores->notattempted -= $scores->incomplete;\r
+                }\r
+                if (isset($scores->browsed)) {\r
+                   $return->info .= get_string('browsed','scorm').':&nbsp;'.$scores->browsed.'<br />';\r
+                    $scores->notattempted -= $scores->browsed;\r
+                }\r
+                $return->time = $scores->lastmodify;\r
+                if ($return->info == '') {\r
+                    $return = NULL;\r
+                } else {\r
+                   $return->info .= get_string('notattempted','scorm').':&nbsp;'.$scores->notattempted.'<br />';\r
+                }\r
+            break;\r
+        }\r
+    }\r
+    return $return;\r
+}\r
+\r
+/**\r
+* Print a detailed representation of what a user has done with\r
+* a given particular instance of this module, for user activity reports.\r
+*\r
+* @param int $course Course id\r
+* @param int $user User id\r
+* @param int $mod  \r
+* @param int $scorm The scorm id\r
+* @return boolean\r
+*/\r
+function scorm_user_complete($course, $user, $mod, $scorm) {\r
+    global $CFG;\r
+\r
+    $liststyle = 'structlist';\r
+    $scormpixdir = $CFG->modpixpath.'/scorm/pix';\r
+    $now = time();\r
+    $firstmodify = $now;\r
+    $lastmodify = 0;\r
+    $sometoreport = false;\r
+    $report = '';\r
+    \r
+    if ($orgs = get_records_select('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,identifier,title')) {\r
+        if (count($orgs) <= 1) {\r
+            unset($orgs);\r
+            $orgs[]->identifier = '';\r
+        }\r
+        $report .= '<div class="mod-scorm">'."\n";\r
+        foreach ($orgs as $org) {\r
+            $organizationsql = '';\r
+            $currentorg = '';\r
+            if (!empty($org->identifier)) {\r
+                $report .= '<div class="orgtitle">'.$org->title.'</div>';\r
+                $currentorg = $org->identifier;\r
+                $organizationsql = "AND organization='$currentorg'";\r
+            }\r
+            $report .= "<ul id='0' class='$liststyle'>";\r
+            if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){\r
+                $level=0;\r
+                $sublist=1;\r
+                $parents[$level]='/';\r
+                foreach ($scoes as $sco) {\r
+                    if ($parents[$level]!=$sco->parent) {\r
+                        if ($level>0 && $parents[$level-1]==$sco->parent) {\r
+                            $report .= "\t\t</ul></li>\n";\r
+                            $level--;\r
+                        } else {\r
+                            $i = $level;\r
+                            $closelist = '';\r
+                            while (($i > 0) && ($parents[$level] != $sco->parent)) {\r
+                                $closelist .= "\t\t</ul></li>\n";\r
+                                $i--;\r
+                            }\r
+                            if (($i == 0) && ($sco->parent != $currentorg)) {\r
+                                $report .= "\t\t<li><ul id='$sublist' class='$liststyle'>\n";\r
+                                $level++;\r
+                            } else {\r
+                                $report .= $closelist;\r
+                                $level = $i;\r
+                            }\r
+                            $parents[$level]=$sco->parent;\r
+                        }\r
+                    }\r
+                    $report .= "\t\t<li>";\r
+                    $nextsco = next($scoes);\r
+                    if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {\r
+                        $sublist++;\r
+                    } else {\r
+                        $report .= '<img src="'.$scormpixdir.'/spacer.gif" />';\r
+                    }\r
+\r
+                    if ($sco->launch) {\r
+                        require_once('locallib.php');\r
+                        $score = '';\r
+                        $totaltime = '';\r
+                        if ($usertrack=scorm_get_tracks($sco->id,$user->id)) {\r
+                            if ($usertrack->status == '') {\r
+                                $usertrack->status = 'notattempted';\r
+                            }\r
+                            $strstatus = get_string($usertrack->status,'scorm');\r
+                            $report .= "<img src='".$scormpixdir.'/'.$usertrack->status.".gif' alt='$strstatus' title='$strstatus' />";\r
+                            if ($usertrack->timemodified != 0) {\r
+                                if ($usertrack->timemodified > $lastmodify) {\r
+                                    $lastmodify = $usertrack->timemodified;\r
+                                }\r
+                                if ($usertrack->timemodified < $firstmodify) {\r
+                                    $firstmodify = $usertrack->timemodified;\r
+                                }\r
+                            }\r
+                        } else {\r
+                            if ($sco->scormtype == 'sco') {\r
+                                $report .= '<img src="'.$scormpixdir.'/'.'notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';\r
+                            } else {\r
+                                $report .= '<img src="'.$scormpixdir.'/'.'asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';\r
+                            }\r
+                        }\r
+                        $report .= "&nbsp;$sco->title $score$totaltime</li>\n";\r
+                        if ($usertrack !== false) {\r
+                            $sometoreport = true;\r
+                            $report .= "\t\t\t<li><ul class='$liststyle'>\n";\r
+                            foreach($usertrack as $element => $value) {\r
+                                if (substr($element,0,3) == 'cmi') {\r
+                                    $report .= '<li>'.$element.' => '.$value.'</li>';\r
+                                }\r
+                            }\r
+                            $report .= "\t\t\t</ul></li>\n";\r
+                        } \r
+                    } else {\r
+                        $report .= "&nbsp;$sco->title</li>\n";\r
+                    }\r
+                }\r
+                for ($i=0;$i<$level;$i++) {\r
+                    $report .= "\t\t</ul></li>\n";\r
+                }\r
+            }\r
+            $report .= "\t</ul><br />\n";\r
+        }\r
+        $report .= "</div>\n";\r
+    }\r
+    if ($sometoreport) {\r
+        if ($firstmodify < $now) {\r
+            $timeago = format_time($now - $firstmodify);\r
+            echo get_string('firstaccess','scorm').': '.userdate($firstmodify).' ('.$timeago.")<br />\n";\r
+        }\r
+        if ($lastmodify > 0) {\r
+            $timeago = format_time($now - $lastmodify);\r
+            echo get_string('lastaccess','scorm').': '.userdate($lastmodify).' ('.$timeago.")<br />\n";\r
+        }\r
+        echo get_string('report','scorm').":<br />\n";\r
+        echo $report;\r
+    } else {\r
+       print_string('noactivity','scorm');\r
+    }\r
+\r
+    return true;\r
+}\r
+\r
+/**\r
+* Given a list of logs, assumed to be those since the last login\r
+* this function prints a short list of changes related to this module\r
+* If isteacher is true then perhaps additional information is printed.\r
+* This function is called from course/lib.php: print_recent_activity()\r
+*\r
+* @param reference $logs Logs reference\r
+* @param boolean $isteacher\r
+* @return boolean\r
+*/\r
+function scorm_print_recent_activity(&$logs, $isteacher=false) {\r
+    return false;  // True if anything was printed, otherwise false\r
+}\r
+\r
+/**\r
+* Function to be run periodically according to the moodle cron\r
+* This function searches for things that need to be done, such\r
+* as sending out mail, toggling flags etc ...\r
+*\r
+* @return boolean\r
+*/\r
+function scorm_cron () {\r
+\r
+    global $CFG;\r
+\r
+    return true;\r
+}\r
+\r
+/**\r
+* Given a scorm id return all the grades of that activity\r
+*\r
+* @param int $scormid Scorm instance id\r
+* @return mixed\r
+*/\r
+function scorm_grades($scormid) {\r
+\r
+    global $CFG;\r
+\r
+    if (!$scorm = get_record('scorm', 'id', $scormid)) {\r
+        return NULL;\r
+    }\r
+    if (!$scoes = get_records('scorm_scoes','scorm',$scormid)) {\r
+        return NULL;\r
+    }\r
+\r
+    if ($scorm->grademethod == VALUESCOES) {\r
+        if (!$return->maxgrade = count_records_select('scorm_scoes',"scorm='$scormid' AND launch<>''")) {\r
+            return NULL;\r
+        }\r
+    } else {\r
+        $return->maxgrade = $scorm->maxgrade;\r
+    }\r
+\r
+    $return->grades = NULL;\r
+    if ($scousers=get_records_select('scorm_scoes_track', "scormid='$scormid' GROUP BY userid", "", "userid,null")) {\r
+        require_once('locallib.php');\r
+        foreach ($scousers as $scouser) {\r
+            $return->grades[$scouser->userid] = scorm_grade_user($scoes, $scouser->userid, $scorm->grademethod);\r
+        }\r
+    }\r
+    return $return;\r
+}\r
+\r
+function scorm_get_view_actions() {\r
+    return array('pre-view','view','view all','report');\r
+}\r
+\r
+function scorm_get_post_actions() {\r
+    return array();\r
+}\r
+\r
+/**\r
+* This function will permanently delete the given\r
+* directory and all files and subdirectories.\r
+*\r
+* @param string $directory The directory to remove\r
+* @return boolean\r
+*/\r
+function scorm_delete_files($directory) {\r
+    if (is_dir($directory)) {\r
+        $files=scorm_scandir($directory);\r
+        foreach($files as $file) {\r
+            if (($file != '.') && ($file != '..')) {\r
+                if (!is_dir($directory.'/'.$file)) {\r
+                    unlink($directory.'/'.$file);\r
+                } else {\r
+                    scorm_delete_files($directory.'/'.$file);\r
+                }\r
+            }\r
+        }\r
+        rmdir($directory);\r
+        return true;\r
+    }\r
+    return false;\r
+}\r
+\r
+/**\r
+* Given a diretory path returns the file list\r
+*\r
+* @param string $directory\r
+* @return array\r
+*/\r
+function scorm_scandir($directory) {\r
+    if (version_compare(phpversion(),'5.0.0','>=')) {\r
+        return scandir($directory);\r
+    } else {\r
+        $files = array();\r
+        if ($dh = opendir($directory)) {\r
+            while (($file = readdir($dh)) !== false) {\r
+               $files[] = $file;\r
+            }\r
+            closedir($dh);\r
+        }\r
+        return $files;\r
+    }\r
+}\r
+\r
+function scorm_option2text($scorm) {\r
+    global $SCORM_POPUP_OPTIONS;\r
+\r
+    if (isset($scorm->popup)) {\r
+        if ($scorm->popup) {\r
+            $optionlist = array();\r
+            foreach ($SCORM_POPUP_OPTIONS as $option) {\r
+                if (isset($scorm->$option)) {\r
+                    $optionlist[] = $option.'='.$scorm->$option;\r
+                } else {\r
+                    $optionlist[] = $option.'=0';\r
+                }\r
+            }       \r
+            $scorm->options = implode(',', $optionlist);\r
+        } else {\r
+            $scorm->options = '';\r
+        } \r
+    } else {\r
+        $scorm->popup = 0;\r
+        $scorm->options = '';\r
+    }\r
+    return $scorm;\r
+}\r
+\r
+?>\r
index 2b303b432c2b2af64ad75164349693e75fb55266..bce2b6f4fa0a52acc112bb991d225f0ef4df0c42 100755 (executable)
-<?php
-    require_once("../../config.php");
-    require_once('locallib.php');
-
-    $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or
-    $a = optional_param('a', '', PARAM_INT);         // scorm ID
-    $scoid = required_param('scoid', PARAM_INT); // sco ID
-
-    if (!empty($id)) {
-        if (! $cm = get_record("course_modules", "id", $id)) {
-            error("Course Module ID was incorrect");
-        }
-        if (! $course = get_record("course", "id", $cm->course)) {
-            error("Course is misconfigured");
-        }
-        if (! $scorm = get_record("scorm", "id", $cm->instance)) {
-            error("Course module is incorrect");
-        }
-    } else 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");
-        }
-    } else {
-        error('A required parameter is missing');
-    }
-
-    require_login($course->id, false, $cm);
-    if (!empty($scoid)) {
-    //
-    // Direct sco request
-    //
-        if ($sco = get_record("scorm_scoes","id",$scoid)) {
-            if ($sco->launch == '') {
-                // Search for the next launchable sco
-                if ($scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' AND id>".$sco->id,"id ASC")) {
-                    $sco = current($scoes);
-                }
-            }
-        }
-    }
-    //
-    // If no sco was found get the first of SCORM package
-    //
-    if (!isset($sco)) {
-        $scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>''","id ASC");
-        $sco = current($scoes);
-    }
-
-    //
-    // Forge SCO URL
-    //
-    $connector = '';
-    $version = substr($scorm->version,0,4);
-    if (!empty($sco->parameters) || ($version == 'AICC')) {
-        if (stripos($sco->launch,'?') !== false) {
-            $connector = '&';
-        } else {
-            $connector = '?';
-        }
-        if (!empty($sco->parameters) && ($sco->parameters[0] == '?')) {
-            $sco->parameters = substr($sco->parameters,1);
-        }
-    }
-    
-    if ($version == 'AICC') {
-        if (!empty($sco->parameters)) {
-            $sco->parameters = '&'. $sco->parameters;
-        }
-        $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters;
-    } else {
-        $launcher = $sco->launch.$connector.$sco->parameters;
-    }
-    
-    if (scorm_external_link($sco->launch)) {
-        $result = $launcher;
-    } else {
-        if (basename($scorm->reference) == 'imsmanifest.xml') {
-            $basedir = dirname($scorm->reference);
-        } else {
-            $basedir = 'moddata/scorm/'.$scorm->id;
-        }
-        if ($CFG->slasharguments) {
-            $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
-        } else {
-            $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;
-        }
-    }
-?>
-<html>
-    <head>
-        <title>LoadSCO</title>
-        <script language="javascript" type="text/javascript">
-        <!--
-            setTimeout('document.location = "<?php echo $result ?>";',1000);
-        -->
-        </script>
-        <noscript>
-            <meta http-equiv="refresh" content="1;url=<?php echo $result ?>" />
-        </noscript> 
-    </head>
-    <body>
-        &nbsp;
-    </body>
-</html>
+<?php\r
+    require_once("../../config.php");\r
+    require_once('locallib.php');\r
+       require_once('sequencinglib.php');\r
+       \r
+    $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or\r
+    $a = optional_param('a', '', PARAM_INT);         // scorm ID\r
+    $scoid = required_param('scoid', PARAM_INT); // sco ID\r
+\r
+    if (!empty($id)) {\r
+        if (! $cm = get_record("course_modules", "id", $id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $cm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
+            error("Course module is incorrect");\r
+        }\r
+    } else if (!empty($a)) {\r
+        if (! $scorm = get_record("scorm", "id", $a)) {\r
+            error("Course module is incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $scorm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+    } else {\r
+        error('A required parameter is missing');\r
+    }\r
+\r
+    require_login($course->id, false, $cm);\r
+    if (!empty($scoid)) {\r
+    //\r
+    // Dinh huong yeu cau cua SCO\r
+    //\r
+        if ($sco = get_record("scorm_scoes","id",$scoid)) {\r
+            if ($sco->launch == '') {\r
+                // Tim kiem SCO co the trien khai tiep theo\r
+                if ($scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' AND id>".$sco->id,"id ASC")) {\r
+                    $sco = current($scoes);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    //\r
+    // If no sco was found get the first of SCORM package\r
+    //\r
+    if (!isset($sco)) {\r
+        $scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>''","id ASC");\r
+        $sco = current($scoes);\r
+    }\r
+\r
+    //\r
+    // Forge SCO URL\r
+    //\r
+    $connector = '';\r
+    $version = substr($scorm->version,0,4);\r
+    if (!empty($sco->parameters) || ($version == 'AICC')) {\r
+        if (stripos($sco->launch,'?') !== false) {\r
+            $connector = '&';\r
+        } else {\r
+            $connector = '?';\r
+        }\r
+        if (!empty($sco->parameters) && ($sco->parameters[0] == '?')) {\r
+            $sco->parameters = substr($sco->parameters,1);\r
+        }\r
+    }\r
+    \r
+    if ($version == 'AICC') {\r
+        if (!empty($sco->parameters)) {\r
+            $sco->parameters = '&'. $sco->parameters;\r
+        }\r
+        $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters;\r
+    } else {\r
+        $launcher = $sco->launch.$connector.$sco->parameters;\r
+    }\r
+    \r
+    if (scorm_external_link($sco->launch)) {\r
+        $result = $launcher;\r
+    } else {\r
+        if (basename($scorm->reference) == 'imsmanifest.xml') {\r
+            $basedir = dirname($scorm->reference);\r
+        } else {\r
+            $basedir = 'moddata/scorm/'.$scorm->id;\r
+        }\r
+        if ($CFG->slasharguments) {\r
+            $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;\r
+        } else {\r
+            $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;\r
+        }\r
+    }\r
+?>\r
+<html>\r
+    <head>\r
+        <title>LoadSCO</title>\r
+        <script language="javascript" type="text/javascript">\r
+        <!--\r
+            setTimeout('document.location = "<?php echo $result ?>";',1000);\r
+        -->\r
+        </script>\r
+        <noscript>\r
+            <meta http-equiv="refresh" content="1;url=<?php echo $result ?>" />\r
+        </noscript> \r
+    </head>\r
+    <body>\r
+        &nbsp;\r
+    </body>\r
+</html>\r
index 6093981f24bc690ac43e060ec586a9f8815b62c7..720544316a4a6a574f51b73eaa9e373ae1b16bff 100755 (executable)
-<?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
-    $textlib = textlib_get_instance();
-    if ($textlib->strlen($stringa, current_charset()) > $len) {
-        $words = explode(' ', $stringa);
-        $newstring = '';
-        $substring = '';
-        foreach ($words as $word) {
-           if (($textlib->strlen($substring, current_charset())+$textlib->strlen($word, current_charset())+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,$attempt,$element,$value) {
-    $id = null;
-    if ($track = get_record_select('scorm_scoes_track',"userid='$userid' AND scormid='$scormid' AND scoid='$scoid' AND attempt='$attempt' 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->attempt = $attempt;
-        $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 '';
-    }
-
-    $current = current($scoes);
-    $attempt = scorm_get_last_attempt($current->scorm, $userid);
-    foreach ($scoes as $sco) { 
-        if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
-            if (($userdata->status == 'completed') || ($userdata->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($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {
-    global $CFG;
-
-    $strexpand = get_string('expcoll','scorm');
-    $modestr = '';
-    if ($mode == 'browse') {
-        $modestr = '&amp;mode='.$mode;
-    } 
-    $scormpixdir = $CFG->modpixpath.'/scorm/pix';
-    
-    $result = new stdClass();
-    $result->toc = "<ul id='0' class='$liststyle'>\n";
-    $tocmenus = array();
-    $result->prerequisites = true;
-    $incomplete = false;
-    
-    //
-    // Get the current organization infos
-    //
-    $organizationsql = '';
-    if (!empty($currentorg)) {
-        if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id,'identifier',$currentorg)) != '') {
-            $result->toc .= "\t<li>$organizationtitle</li>\n";
-            $tocmenus[] = $organizationtitle;
-        }
-        $organizationsql = "AND organization='$currentorg'";
-    }
-    //
-    // If not specified retrieve the last attempt number
-    //
-    if (empty($attempt)) {
-        $attempt = scorm_get_last_attempt($scorm->id, $user->id);
-    }
-    $result->attemptleft = $scorm->maxattempt - $attempt;
-    if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
-        //
-        // Retrieve user tracking data for each learning object
-        // 
-        $usertracks = array();
-        foreach ($scoes as $sco) {
-            if (!empty($sco->launch)) {
-                if ($usertrack=scorm_get_tracks($sco->id,$user->id,$attempt)) {
-                    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)) {
-                        $style = '';
-                        if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) {
-                            $style = ' style="display: none;"';
-                        }
-                        $result->toc .= "\t\t<li><ul id='$sublist' class='$liststyle'$style>\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++;
-                $icon = 'minus';
-                if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) {
-                    $icon = 'plus';
-                }
-                $result->toc .= '<a href="javascript:expandCollide(img'.$sublist.','.$sublist.','.$nextsco->id.');"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
-            } else {
-                $result->toc .= '<img src="'.$scormpixdir.'/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="'.$scormpixdir.'/'.$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="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
-                        $incomplete = true;
-                    } else {
-                        $result->toc .= '<img src="'.$scormpixdir.'/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;
-                    }
-                    $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
-                    $result->toc .= '&nbsp'.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
-                    $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
-                } 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";
-    if ($scorm->hidetoc == 0) {
-        $result->toc .= '
-          <script language="javascript" type="text/javascript">
-          <!--
-              function expandCollide(which,list,item) {
-                  var nn=document.ids?true:false
-                  var w3c=document.getElementById?true:false
-                  var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
-                  var mid=w3c?").style":".style";
-
-                  if (eval(beg+list+mid+".display") != "none") {
-                      which.src = "'.$scormpixdir.'/plus.gif";
-                      eval(beg+list+mid+".display=\'none\';");
-                      new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
-                  } else {
-                      which.src = "'.$scormpixdir.'/minus.gif";
-                      eval(beg+list+mid+".display=\'block\';");
-                      new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
-                  }
-              }
-          -->
-          </script>'."\n";
-    }
-    
-    $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid=';
-    $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true);
-
-    return $result;
-}
-
-function scorm_get_last_attempt($scormid, $userid) {
-/// Find the last attempt number for the given user id and scorm id
-    if ($lastattempt = get_record('scorm_scoes_track', 'userid', $userid, 'scormid', $scormid, '', '', 'max(attempt) as a')) {
-        if (empty($lastattempt->a)) {
-            return '1';
-        } else {
-            return $lastattempt->a;
-        }
-    }
-}
-
-function scorm_get_tracks($scoid,$userid,$attempt='') {
-/// Gets all tracks of specified sco and user
-    global $CFG;
-
-    if (empty($attempt)) {
-        if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) {
-            $attempt = scorm_get_last_attempt($scormid,$userid);
-        } else {
-            $attempt = 1;
-        }
-    }
-    $attemptsql = ' AND attempt=' . $attempt;
-    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;
-    }
-    if (substr($regexp,-1) == ',') {
-        $regexp = substr($regexp,0,-1);
-    }
-    $regexp .= '/';
-    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($matches)-1;$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($matches)-1;$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,'("[\w]+")?,?');
-            for ($i=1;$i<count($rows);$i++) {
-                if (preg_match($regexp,$rows[$i],$matches)) {
-                    for ($j=0;$j<count($matches)-1;$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 (isset($metadata['tagData']) && (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);
-                    if (!isset($block['tagData'])) {
-                        $block['tagData'] = '';
-                    }
-                    $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);
-                        if (!isset($block['tagData'])) {
-                            $block['tagData'] = '';
-                        }
-                        $scoes->elements[$manifest][$parent->organization][$parent->identifier]->prerequisites = addslashes($block['tagData']);
-                    }
-                break;
-                case 'ADLCP:MAXTIMEALLOWED':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    if (!isset($block['tagData'])) {
-                        $block['tagData'] = '';
-                    }
-                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->maxtimeallowed = addslashes($block['tagData']);
-                break;
-                case 'ADLCP:TIMELIMITACTION':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    if (!isset($block['tagData'])) {
-                        $block['tagData'] = '';
-                    }
-                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->timelimitaction = addslashes($block['tagData']);
-                break;
-                case 'ADLCP:DATAFROMLMS':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    if (!isset($block['tagData'])) {
-                        $block['tagData'] = '';
-                    }
-                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->datafromlms = addslashes($block['tagData']);
-                break;
-                case 'ADLCP:MASTERYSCORE':
-                    $parent = array_pop($parents);
-                    array_push($parents, $parent);
-                    if (!isset($block['tagData'])) {
-                        $block['tagData'] = '';
-                    }
-                    $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;
-}
-
-function scorm_course_format_display($user,$course) {
-    global $CFG;
-
-    $strupdate = get_string('update');
-    $strmodule = get_string('modulename','scorm');
-
-    echo '<div class="mod-scorm">';
-    if ($scorms = get_all_instances_in_course('scorm', $course)) {
-        // The module SCORM activity with the least id is the course  
-        $scorm = current($scorms);
-        if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
-            error("Course Module ID was incorrect");
-        }
-        $colspan = '';
-        $headertext = '<table width="100%"><tr><td class="title">'.get_string('name').': <b>'.format_string($scorm->name).'</b>';
-        if (isteacher($course->id, $user->id, true)) {
-            if (isediting($course->id)) {
-                // Display update icon
-                $path = $CFG->wwwroot.'/course';
-                $headertext .= '<span class="commands">'.
-                        '<a title="'.$strupdate.'" href="'.$path.'/mod.php?update='.$cm->id.'&amp;sesskey='.sesskey().'">'.
-                        '<img src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" alt="'.$strupdate.'" /></a></span>';
-            }
-            $headertext .= '</td>';
-            // Display report link
-            $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');
-            if ($trackedusers->c > 0) {
-                $headertext .= '<td class="reportlink">'.
-                              '<a target="'.$CFG->framename.'" href="'.$CFG->wwwroot.'/mod/scorm/report.php?id='.$cm->id.'">'.
-                               get_string('viewallreports','scorm',$trackedusers->c).'</a>';
-            } else {
-                $headertext .= '<td class="reportlink">'.get_string('noreports','scorm');
-            }
-            $colspan = ' colspan="2"';
-        } 
-        $headertext .= '</td></tr><tr><td'.$colspan.'>'.format_text(get_string('summary').':<br />'.$scorm->summary).'</td></tr></table>';
-        print_simple_box($headertext,'','100%');
-        scorm_view_display($user, $scorm, 'view.php?id='.$course->id, $cm, '100%');
-    } else {
-        if (isteacheredit($course->id, $user->id)) {
-            // Create a new activity
-               redirect('mod.php?id='.$course->id.'&amp;section=0&sesskey='.sesskey().'&amp;add=scorm');
-        } else {
-            notify('Could not find a scorm course here');
-        }
-    }
-    echo '</div>';
-}
-
-function scorm_view_display ($user, $scorm, $action, $cm, $blockwidth='') {
-    global $CFG;
-
-    $organization = optional_param('organization', '', PARAM_INT);
-
-    print_simple_box_start('center',$blockwidth);
-?>
-        <div class="structurehead"><?php print_string('coursestruct','scorm') ?></div>
-<?php
-    if (empty($organization)) {
-        $organization = $scorm->launch;
-    }
-    if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) {
-        if (count($orgs) > 1) {
- ?>
-            <div class='center'>
-                <?php print_string('organizations','scorm') ?>
-                <form name='changeorg' method='post' action='<?php echo $action ?>'>
-                    <?php choose_from_menu($orgs, 'organization', "$organization", '','submit()') ?>
-                </form>
-            </div>
-<?php
-        }
-    }
-    $orgidentifier = '';
-    if ($org = get_record('scorm_scoes','id',$organization)) {
-        if (($org->organization == '') && ($org->launch == '')) {
-            $orgidentifier = $org->identifier;
-        } else {
-            $orgidentifier = $org->organization;
-        }
-    }
-    $result = scorm_get_toc($user,$scorm,'structlist',$orgidentifier);
-    $incomplete = $result->incomplete;
-    echo $result->toc;
-    print_simple_box_end();
-?>
-            <div class="center">
-                <form name="theform" method="post" action="<?php echo $CFG->wwwroot ?>/mod/scorm/player.php?id=<?php echo $cm->id ?>"<?php echo $scorm->popup == 1?' target="newwin"':'' ?>>
-              <?php
-                  if ($scorm->hidebrowse == 0) {
-                      print_string("mode","scorm");
-                      echo ': <input type="radio" id="b" name="mode" value="browse" /><label for="b">'.get_string('browse','scorm').'</label>'."\n";
-                      if ($incomplete === true) {
-                          echo '<input type="radio" id="n" name="mode" value="normal" checked="checked" /><label for="n">'.get_string('normal','scorm')."</label>\n";
-                      } else {
-                          echo '<input type="radio" id="r" name="mode" value="review" checked="checked" /><label for="r">'.get_string('review','scorm')."</label>\n";
-                      }
-                  } else {
-                      if ($incomplete === true) {
-                          echo '<input type="hidden" name="mode" value="normal" />'."\n";
-                      } else {
-                          echo '<input type="hidden" name="mode" value="review" />'."\n";
-                      }
-                  }
-                  if (($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) {
-?>
-                  <br />
-                  <input type="checkbox" id="a" name="newattempt" />
-                  <label for="a"><?php print_string('newattempt','scorm') ?></label>
-<?php
-                  }
-              ?>
-              <br />
-              <input type="hidden" name="scoid" />
-              <input type="hidden" name="currentorg" value="<?php echo $orgidentifier ?>" />
-              <input type="submit" value="<?php print_string('entercourse','scorm') ?>" />
-              </form>
-          </div>
-<?php
-}
-
-
-function scorm_repeater($what, $times) {
-    if ($times <= 0) {
-        return null;
-    }
-    $return = '';
-    for ($i=0; $i<$times;$i++) {
-        $return .= $what;
-    }
-    return $return;
-}
-
-/**
-* Convert a utf-8 string to html entities
-*
-* @param string $str The UTF-8 string
-* @return string
-*/
-function scorm_utf8_to_entities($str) {
-    global $CFG;
-
-    $entities = '';
-    $values = array();
-    $lookingfor = 1;
-
-    if (empty($CFG->unicodedb)) {  // If Unicode DB support enable does not convert string
-        $textlib = textlib_get_instance();
-        for ($i = 0; $i < $textlib->strlen($str,'utf-8'); $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;
-    } else {
-        return $str;
-    }
-}
-
-/* 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;
-   
-   /**
-   * 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) {
-           /*if (($start = strpos($strInputXML,'encoding=')) !== false) {
-               $endchr = substr($strInputXML,$start+9,1);
-               if (($end = strpos($strInputXML,$endchr,$start+10)) !== false) {
-                   $charset = strtolower(substr($strInputXML,$start+10,$end-$start-10));
-                   if ($charset != 'utf-8') {
-                       $strInputXML = str_ireplace('encoding='.$endchr.$charset.$endchr,'encoding='.$endchr.'UTF-8'.$endchr,$strInputXML);
-                       $textlib = textlib_get_instance();
-                   }
-               }
-           }*/
-           $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'] .= scorm_utf8_to_entities($tagData);
-           } else {
-               $this->arrOutput[count($this->arrOutput)-1]['tagData'] = scorm_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);
-   }
-}
-?>
+\r
+<?php  // $Id$\r
+define("VALUESCOES",0);\r
+define("VALUEHIGHEST",1);\r
+define("VALUEAVERAGE",2);\r
+define("VALUESUM",3);\r
+\r
+/// Local Library of functions and constants for module scorm\r
+\r
+/**\r
+* Create a new temporary subdirectory with a random name in the given path\r
+*\r
+* @param string $strpath The scorm data directory\r
+* @return string/boolean\r
+*/\r
+function scorm_datadir($strPath)\r
+{\r
+    global $CFG;\r
+\r
+    if (is_dir($strPath)) {\r
+        do {\r
+            // Create a random string of 8 chars\r
+            $randstring = NULL;\r
+            $lchar = '';\r
+            $len = 8;\r
+            for ($i=0; $i<$len; $i++) {\r
+                $char = chr(rand(48,122));\r
+                while (!ereg('[a-zA-Z0-9]', $char)){\r
+                    if ($char == $lchar) continue;\r
+                        $char = chr(rand(48,90));\r
+                    }\r
+                    $randstring .= $char;\r
+                    $lchar = $char;\r
+            } \r
+            $datadir='/'.$randstring;\r
+        } while (file_exists($strPath.$datadir));\r
+        mkdir($strPath.$datadir, $CFG->directorypermissions);\r
+        @chmod($strPath.$datadir, $CFG->directorypermissions);  // Just in case mkdir didn't do it\r
+        return $strPath.$datadir;\r
+    } else {\r
+        return false;\r
+    }\r
+}\r
+\r
+/**\r
+* Given a package directory, this function will check if the package is valid\r
+*\r
+* @param string $packagedir The package directory\r
+* @return mixed\r
+*/\r
+function scorm_validate($packagedir) {\r
+\r
+    ////$f = "D:\\test.txt";\r
+    ////@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n Xu ly trong ham scorm_validate \n");    \r
+\r
+\r
+    $validation = new stdClass();\r
+    if (is_file($packagedir.'/imsmanifest.xml')) {\r
+        $validation->result = 'found';\r
+        $validation->pkgtype = 'SCORM';\r
+    } else {\r
+        if ($handle = opendir($packagedir)) {\r
+            while (($file = readdir($handle)) !== false) {\r
+                $ext = substr($file,strrpos($file,'.'));\r
+                if (strtolower($ext) == '.cst') {\r
+                    $validation->result = 'found';\r
+                    $validation->pkgtype = 'AICC';\r
+                    break;\r
+                }\r
+            }\r
+            closedir($handle);\r
+        }\r
+        if (!isset($validation)) {\r
+            $validation->result = 'nomanifest';\r
+            $validation->pkgtype = 'SCORM';\r
+        }\r
+    }\r
+    return $validation;\r
+}\r
+\r
+function scorm_get_user_data($userid) {\r
+/// Gets user info required to display the table of scorm results\r
+/// for report.php\r
+\r
+    return get_record('user','id',$userid,'','','','','firstname, lastname, picture');\r
+}\r
+\r
+function scorm_string_wrap($stringa, $len=15) {\r
+// Crop the given string into max $len characters lines\r
+    $textlib = textlib_get_instance();\r
+    if ($textlib->strlen($stringa, current_charset()) > $len) {\r
+        $words = explode(' ', $stringa);\r
+        $newstring = '';\r
+        $substring = '';\r
+        foreach ($words as $word) {\r
+           if (($textlib->strlen($substring, current_charset())+$textlib->strlen($word, current_charset())+1) < $len) {\r
+               $substring .= ' '.$word;\r
+           } else {\r
+               $newstring .= ' '.$substring.'<br />';\r
+               $substring = $word;\r
+           }\r
+        }\r
+        if (!empty($substring)) {\r
+            $newstring .= ' '.$substring;\r
+        }\r
+        return $newstring;\r
+    } else {\r
+        return $stringa;\r
+    }\r
+}\r
+\r
+function scorm_eval_prerequisites($prerequisites,$usertracks) {\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n Xu ly trong ham scorm_eval_prerequisites \n");    \r
+\r
+\r
+    $element = '';\r
+    $stack = array();\r
+    $statuses = array(\r
+                'passed' => 'passed',\r
+                'completed' => 'completed',\r
+                'failed' => 'failed',\r
+                'incomplete' => 'incomplete',\r
+                'browsed' => 'browsed',\r
+                'not attempted' => 'notattempted',\r
+                'p' => 'passed',\r
+                'c' => 'completed',\r
+                'f' => 'failed',\r
+                'i' => 'incomplete',\r
+                'b' => 'browsed',\r
+                'n' => 'notattempted'\r
+                );\r
+    $i=0;  \r
+    while ($i<strlen($prerequisites)) {\r
+        $symbol = $prerequisites[$i];\r
+        switch ($symbol) {\r
+            case '&':\r
+            case '|':\r
+                $symbol .= $symbol;\r
+            case '~':\r
+            case '(':\r
+            case ')':\r
+            case '*':\r
+            //case '{':\r
+            //case '}':\r
+            //case ',':\r
+                $element = trim($element);\r
+                \r
+                if (!empty($element)) {\r
+                    $element = trim($element);\r
+                    if (isset($usertracks[$element])) {\r
+                        $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '.\r
+                                  '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; \r
+                    } else if (($operator = strpos($element,'=')) !== false) {\r
+                        $item = trim(substr($element,0,$operator));\r
+                        if (!isset($usertracks[$item])) {\r
+                            return false;\r
+                        }\r
+                        \r
+                        $value = trim(trim(substr($element,$operator+1)),'"');\r
+                        if (isset($statuses[$value])) {\r
+                            $status = $statuses[$value];\r
+                        } else {\r
+                            return false;\r
+                        }\r
+                                              \r
+                        $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')';\r
+                    } else if (($operator = strpos($element,'<>')) !== false) {\r
+                        $item = trim(substr($element,0,$operator));\r
+                        if (!isset($usertracks[$item])) {\r
+                            return false;\r
+                        }\r
+                        \r
+                        $value = trim(trim(substr($element,$operator+2)),'"');\r
+                        if (isset($statuses[$value])) {\r
+                            $status = $statuses[$value];\r
+                        } else {\r
+                            return false;\r
+                        }\r
+                        \r
+                        $element = '(\''.$usertracks[$item]->status.'\' != \''.$status.'\')';\r
+                    } else if (is_numeric($element)) {\r
+                        if ($symbol == '*') {\r
+                            $symbol = '';\r
+                            $open = strpos($prerequisites,'{',$i);\r
+                            $opened = 1;\r
+                            $closed = 0;\r
+                            for ($close=$open+1; (($opened > $closed) && ($close<strlen($prerequisites))); $close++) { \r
+                                 if ($prerequisites[$close] == '}') {\r
+                                     $closed++;\r
+                                 } else if ($prerequisites[$close] == '{') {\r
+                                     $opened++;\r
+                                 }\r
+                            } \r
+                            $i = $close;\r
+                            \r
+                            $setelements = explode(',', substr($prerequisites, $open+1, $close-($open+1)-1));\r
+                            $settrue = 0;\r
+                            foreach ($setelements as $setelement) {\r
+                                if (scorm_eval_prerequisites($setelement,$usertracks)) {\r
+                                    $settrue++;\r
+                                }\r
+                            }\r
+                            \r
+                            if ($settrue >= $element) {\r
+                                $element = 'true'; \r
+                            } else {\r
+                                $element = 'false';\r
+                            }\r
+                        }\r
+                    } else {\r
+                        return false;\r
+                    }\r
+                    \r
+                    array_push($stack,$element);\r
+                    $element = '';\r
+                }\r
+                if ($symbol == '~') {\r
+                    $symbol = '!';\r
+                }\r
+                if (!empty($symbol)) {\r
+                    array_push($stack,$symbol);\r
+                }\r
+            break;\r
+            default:\r
+                $element .= $symbol;\r
+            break;\r
+        }\r
+        $i++;\r
+    }\r
+    if (!empty($element)) {\r
+        $element = trim($element);\r
+        if (isset($usertracks[$element])) {\r
+            $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '.\r
+                       '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; \r
+        } else if (($operator = strpos($element,'=')) !== false) {\r
+            $item = trim(substr($element,0,$operator));\r
+            if (!isset($usertracks[$item])) {\r
+                return false;\r
+            }\r
+            \r
+            $value = trim(trim(substr($element,$operator+1)),'"');\r
+            if (isset($statuses[$value])) {\r
+                $status = $statuses[$value];\r
+            } else {\r
+                return false;\r
+            }\r
+            \r
+            $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')';\r
+        } else if (($operator = strpos($element,'<>')) !== false) {\r
+            $item = trim(substr($element,0,$operator));\r
+            if (!isset($usertracks[$item])) {\r
+                return false;\r
+            }\r
+            \r
+            $value = trim(trim(substr($element,$operator+1)),'"');\r
+            if (isset($statuses[$value])) {\r
+                $status = $statuses[$value];\r
+            } else {\r
+                return false;\r
+            }\r
+            \r
+            $element = '(\''.$usertracks[$item]->status.'\' != \''.trim($status).'\')';\r
+        } else {\r
+            return false;\r
+        }\r
+        \r
+        array_push($stack,$element);\r
+    }\r
+    return eval('return '.implode($stack).';');\r
+}\r
+\r
+function scorm_insert_statistic($statisticInput){\r
+\r
+    $id = null;\r
+    if ($statistic = get_record_select('scorm_statistic',"userid='$statisticInput->userid' AND scormid='$statisticInput->scormid'")) {\r
+\r
+        $statistic->durationtime = $statisticInput->duration;\r
+        $statistic->accesstime = $statisticInput->accesstime;        \r
+        $statistic->status = $statisticInput->status;        \r
+        $statistic->attemptnumber = $statisticInput->attemptnumber;        \r
+        $id = update_record('scorm_statistic',$statistic);\r
+    } else {\r
+        ////fwrite($ft,"Insert trong ham scorm_insert_track \n");    \r
+        $id = insert_record('scorm_statistic',$statisticInput);\r
+    }\r
+    return $id;\r
+\r
+}\r
+function scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value) {\r
+\r
+//    //$f = "D:\\test.txt";\r
+//    //@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n Xu ly trong ham scorm_insert_track \n");    \r
+\r
+    $id = null;\r
+    if ($track = get_record_select('scorm_scoes_track',"userid='$userid' AND scormid='$scormid' AND scoid='$scoid' AND attempt='$attempt' AND element='$element'")) {\r
+        $track->value = $value;\r
+        $track->timemodified = time();\r
+        ////fwrite($ft,$userid."Update trong ham scorm_insert_track voi cac gia tri userid = ");    \r
+        $id = update_record('scorm_scoes_track',$track);\r
+    } else {\r
+        $track->userid = $userid;\r
+        $track->scormid = $scormid;\r
+        $track->scoid = $scoid;\r
+        $track->attempt = $attempt;\r
+        $track->element = $element;\r
+        $track->value = addslashes($value);\r
+        $track->timemodified = time();\r
+        ////fwrite($ft,"Insert trong ham scorm_insert_track \n");    \r
+        $id = insert_record('scorm_scoes_track',$track);\r
+    }\r
+    return $id;\r
+}\r
+\r
+function scorm_insert_trackmodel($userid,$scormid,$scoid,$attempt) {\r
+\r
+//    //$f = "D:\\test.txt";\r
+//    //@$ft = fopen($f,"a");\r
+\r
+    $id = null;\r
+    if ($suspendtrack = get_record_select('scorm_suspendtrack',"userid='$userid' AND scormid='$scormid'")) {\r
+        $suspendtrack->suspendscoid = $scoid;\r
+        $suspendtrack->attempt = $attempt;\r
+\r
+        $id = update_record('scorm_suspendtrack',$suspendtrack);\r
+    } else {\r
+        $suspendtrack->scormid = $scormid;\r
+        $suspendtrack->suspendscoid = $scoid;\r
+        $suspendtrack->userid = $userid;\r
+        $suspendtrack->attempt = $attempt;\r
+        $id = insert_record('scorm_suspendtrack',$suspendtrack);\r
+    }\r
+    return $id;\r
+}\r
+\r
+function scorm_get_suspendscoid($scormid,$userid)\r
+{\r
+        $sco = get_record("scorm_suspendtrack","scormid",$scormid,"userid",$userid);\r
+        $suspendscoid = $sco->suspendscoid;\r
+        return $suspendscoid;\r
+}\r
+function scorm_add_time($a, $b) {\r
+    $aes = explode(':',$a);\r
+    $bes = explode(':',$b);\r
+    $aseconds = explode('.',$aes[2]);\r
+    $bseconds = explode('.',$bes[2]);\r
+    $change = 0;\r
+\r
+    $acents = 0;  //Cents\r
+    if (count($aseconds) > 1) {\r
+        $acents = $aseconds[1];\r
+    }\r
+    $bcents = 0;\r
+    if (count($bseconds) > 1) {\r
+        $bcents = $bseconds[1];\r
+    }\r
+    $cents = $acents + $bcents;\r
+    $change = floor($cents / 100);\r
+    $cents = $cents - ($change * 100);\r
+    if (floor($cents) < 10) {\r
+        $cents = '0'. $cents;\r
+    }\r
+\r
+    $secs = $aseconds[0] + $bseconds[0] + $change;  //Seconds\r
+    $change = floor($secs / 60);\r
+    $secs = $secs - ($change * 60);\r
+    if (floor($secs) < 10) {\r
+        $secs = '0'. $secs;\r
+    }\r
+\r
+    $mins = $aes[1] + $bes[1] + $change;   //Minutes\r
+    $change = floor($mins / 60);\r
+    $mins = $mins - ($change * 60);\r
+    if ($mins < 10) {\r
+        $mins = '0' .  $mins;\r
+    }\r
+\r
+    $hours = $aes[0] + $bes[0] + $change;  //Hours\r
+    if ($hours < 10) {\r
+        $hours = '0' . $hours;\r
+    }\r
+\r
+    if ($cents != '0') {\r
+        return $hours . ":" . $mins . ":" . $secs . '.' . $cents;\r
+    } else {\r
+        return $hours . ":" . $mins . ":" . $secs;\r
+    }\r
+}\r
+\r
+function scorm_external_link($link) {\r
+// check if a link is external\r
+    $result = false;\r
+    $link = strtolower($link);\r
+    if (substr($link,0,7) == 'http://') {\r
+        $result = true;\r
+    } else if (substr($link,0,8) == 'https://') {\r
+        $result = true;\r
+    } else if (substr($link,0,4) == 'www.') {\r
+        $result = true;\r
+    }\r
+    return $result;\r
+}\r
+\r
+function scorm_grade_user($scoes, $userid, $grademethod=VALUESCOES) {\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    //fwrite($ft,"\n Xu ly trong ham scorm_grade_user \n");    \r
+\r
+    $scores = NULL; \r
+    $scores->scoes = 0;\r
+    $scores->values = 0;\r
+    $scores->max = 0;\r
+    $scores->sum = 0;\r
+\r
+    if (!$scoes) {\r
+        return '';\r
+    }\r
+\r
+    $current = current($scoes);\r
+    $attempt = scorm_get_last_attempt($current->scorm, $userid);\r
+    foreach ($scoes as $sco) { \r
+        if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {\r
+            if (($userdata->status == 'completed') || ($userdata->status == 'passed')) {\r
+                $scores->scoes++;\r
+            }       \r
+            if (!empty($userdata->score_raw)) {\r
+                $scores->values++;\r
+                $scores->sum += $userdata->score_raw;\r
+                $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;\r
+            }       \r
+        }       \r
+    }\r
+    switch ($grademethod) {\r
+        case VALUEHIGHEST:\r
+            return $scores->max;\r
+        break;  \r
+        case VALUEAVERAGE:\r
+            if ($scores->values > 0) {\r
+                return $scores->sum/$scores->values;\r
+            } else {\r
+                return 0;\r
+            }       \r
+        break;  \r
+        case VALUESUM:\r
+            return $scores->sum;\r
+        break;  \r
+        case VALUESCOES:\r
+            return $scores->scoes;\r
+        break;  \r
+    }\r
+}\r
+\r
+//Lay diem theo Sco cha.. Thuc chat la theo bai kiem tra\r
+function scorm_get_score_from_parent($sco,$userid,$grademethod=VALUESCOES)\r
+{\r
+    \r
+    $scores = NULL; \r
+    $scores->scoes = 0;\r
+    $scores->values = 0;\r
+    $scores->scaled = 0;\r
+    $scores->max = 0;\r
+    $scores->sum = 0;\r
+\r
+    $scoes_total = 0;\r
+    $scoes_count = 0;\r
+    $attempt = scorm_get_last_attempt($sco->scorm, $userid);\r
+    $scoes = get_records('scorm_scoes', 'parent', $sco->identifier);\r
+    foreach ($scoes as $sco)\r
+    {\r
+           $scoes_total++;\r
+           if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {\r
+               if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {\r
+                    $scoes_count++;\r
+               }\r
+\r
+\r
+            $scoreraw = $userdata->score_raw; \r
+\r
+            if (!empty($userdata->score_raw)) {\r
+                $scores->values++;\r
+                $scores->sum += $userdata->score_raw;\r
+                $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;\r
+            }   \r
+            if (!empty($userdata->score_scaled)) {\r
+                $scores->scaled = $scores->scaled + $userdata->score_scaled;\r
+            }       \r
+            \r
+        }       \r
+    }\r
+    if ($scoes_count > 0)\r
+    {\r
+        $scores->scaled = ($scores->scaled)/($scoes_count);\r
+    }\r
+    switch ($grademethod) {\r
+        case VALUEHIGHEST:\r
+            return $scores->max;\r
+        break;  \r
+        case VALUEAVERAGE:\r
+            if ($scores->values > 0) {\r
+                return $scores->sum/$scores->values;\r
+            } else {\r
+                return 0;\r
+            }       \r
+        break;  \r
+        case VALUESUM:\r
+            return $scores->sum;\r
+        break;  \r
+        case VALUESCOES:\r
+            return $scores->scaled;\r
+        break;  \r
+    }\r
+\r
+}\r
+\r
+// Lay ra so luong cac scoes duoc user thuc hien xong\r
+function scorm_get_user_sco_count($scormid, $userid)\r
+{\r
+    $scoes_count = 0;\r
+    $attempt = scorm_get_last_attempt($current->scorm, $userid);\r
+    $scoes = get_records('scorm_scoes', 'scorm', $scormid);\r
+\r
+\r
+\r
+    foreach ($scoes as $sco)\r
+    {\r
+           if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {\r
+\r
+               if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {\r
+                    $scoes_count++;\r
+               }\r
+           }\r
+\r
+    }\r
+    return $scoes_count;\r
+    \r
+}\r
+\r
+function scorm_grade_user_new($scoes, $userid, $grademethod=VALUESCOES) {\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    //fwrite($ft,"\n Xu ly trong ham scorm_grade_user \n");    \r
+\r
+    $scores = NULL; \r
+    $scores->scoes = 0;\r
+    $scores->values = 0;\r
+    $scores->scaled = 0;\r
+    $scores->max = 0;\r
+    $scores->sum = 0;\r
+\r
+    if (!$scoes) {\r
+        //fwrite($ft,"\n Khong xuat hien mot SCO duoc tinh diem \n");    \r
+        return '';\r
+    }\r
+\r
+    $current = current($scoes);\r
+    $attempt = scorm_get_last_attempt($current->scorm, $userid);\r
+    //fwrite($ft,"\n ---------------------------------------\n");    \r
+    foreach ($scoes as $sco) { \r
+        if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {\r
+            if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {\r
+                $scores->scoes++;\r
+                //fwrite($ft,"\n Them mot khoa hoan thanh co id la ".$sco->id." co gia tri scaled la ".$userdata->score_scaled." \n");    \r
+        \r
+            }  \r
+            $scaled = $userdata->score_scaled;\r
+            $scoreraw = $userdata->score_raw; \r
+            if ($scaled ==0){\r
+                $scores->scaled = $scores->scaled / $scores->scoes;\r
+                //fwrite($ft,"\n Ti le chinh xac ".($scores->scaled*100)." phan tram");    \r
+\r
+            }\r
+\r
+            if (!empty($userdata->score_raw)) {\r
+                $scores->values++;\r
+                $scores->sum += $userdata->score_raw;\r
+                $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;\r
+            }  \r
+                        \r
+            if (!empty($scaled)) {\r
+                //fwrite($ft,"\n go ---->>> \n");    \r
+                $scores->scaled = (($scores->scaled) * ($scores->scoes-1) + $scaled)/($scores->scoes);\r
+                //fwrite($ft,"\n Ti le chinh xac ".($scores->scaled*100)." phan tram");    \r
+\r
+            }       \r
+            \r
+        }       \r
+    }\r
+    //fwrite($ft,"\n ----+++++++++++------\n");    \r
+    //fwrite($ft,"\n Kieu gia tri tra ve la  ".$grademethod);    \r
+    switch ($grademethod) {\r
+        case VALUEHIGHEST:\r
+            //fwrite($ft,"\n Gia tri tra ve thouoc loai cao nhat");    \r
+            return $scores->max;\r
+        break;  \r
+        case VALUEAVERAGE:\r
+            //fwrite($ft,"\n Gia tri tra ve thouoc loai trung binh");    \r
+            if ($scores->values > 0) {\r
+                return $scores->sum/$scores->values;\r
+            } else {\r
+                return 0;\r
+            }       \r
+        break;  \r
+        case VALUESUM:\r
+            //fwrite($ft,"\n Gia tri tra ve thouoc loai tong cong");    \r
+            return $scores->sum;\r
+        break;  \r
+        case VALUESCOES:\r
+            //fwrite($ft,"\n Gia tri tra ve thouoc loai scoes co gia tri".$scores->scaled);    \r
+            return $scores->scaled;\r
+        break;  \r
+    }\r
+}\r
+\r
+function scorm_count_launchable($scormid,$organization) {\r
+    return count_records_select('scorm_scoes',"scorm=$scormid AND organization='$organization' AND launch<>''");\r
+}\r
+\r
+function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {\r
+    global $CFG;\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    //fwrite($ft,"\n Xu ly trong ham scorm_get_toc \n");    \r
+\r
+    //\r
+    $suspendscoid = scorm_get_suspendscoid($scorm->id,$user->id);\r
+    //\r
+\r
+    $strexpand = get_string('expcoll','scorm');\r
+    $modestr = '';\r
+    if ($mode == 'browse') {\r
+        $modestr = '&amp;mode='.$mode;\r
+    } \r
+    $scormpixdir = $CFG->modpixpath.'/scorm/pix';\r
+    \r
+    $result = new stdClass();\r
+    $result->toc = "<ul id='0' class='$liststyle'>\n";\r
+    $tocmenus = array();\r
+    $result->prerequisites = true;\r
+    $incomplete = false;\r
+    \r
+    //\r
+    // Get the current organization infos\r
+    //\r
+    $organizationsql = '';\r
+    if (!empty($currentorg)) {\r
+        if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id,'identifier',$currentorg)) != '') {\r
+            $result->toc .= "\t<li>$organizationtitle</li>\n";\r
+            $tocmenus[] = $organizationtitle;\r
+        }\r
+        $organizationsql = "AND organization='$currentorg'";\r
+    }\r
+    //\r
+    // If not specified retrieve the last attempt number\r
+    //\r
+    if (empty($attempt)) {\r
+        $attempt = scorm_get_last_attempt($scorm->id, $user->id);\r
+    }\r
+    $result->attemptleft = $scorm->maxattempt - $attempt;\r
+\r
+    //fwrite($ft,"\n So lan attempt con lai la \n".$result->attemptleft);    \r
+    \r
+    if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){\r
+        //\r
+        // Lay du lieu da duoc tracking cho moi doi tuong hoc tap\r
+        // \r
+        $usertracks = array();\r
+        foreach ($scoes as $sco) {\r
+            //Kiem tra xem $sco co phai la phan muc khong. Neu la trang Asset hoac SCO thi xu ly tiep\r
+            if (!empty($sco->launch)) {\r
+                if ($usertrack=scorm_get_tracks($sco->id,$user->id,$attempt)) {\r
+                    if ($usertrack->status == '') {\r
+                        $usertrack->status = 'notattempted';\r
+                    }\r
+                    // Ghi lai thong tin $usertracks theo tung doi tuong sco\r
+                    $usertracks[$sco->identifier] = $usertrack;\r
+                }\r
+            }\r
+        }\r
+\r
+        $level=0;\r
+        $sublist=1;\r
+        $previd = 0;\r
+        $nextid = 0;\r
+        $findnext = false;\r
+        $parents[$level]='/';\r
+        \r
+        foreach ($scoes as $sco) {\r
+            if ($parents[$level]!=$sco->parent) {\r
+                if ($newlevel = array_search($sco->parent,$parents)) {\r
+                    for ($i=0; $i<($level-$newlevel); $i++) {\r
+                        $result->toc .= "\t\t</ul></li>\n";\r
+                    }\r
+                    $level = $newlevel;\r
+                } else {\r
+                    $i = $level;\r
+                    $closelist = '';\r
+                    while (($i > 0) && ($parents[$level] != $sco->parent)) {\r
+                        $closelist .= "\t\t</ul></li>\n";\r
+                        $i--;\r
+                    }\r
+                    if (($i == 0) && ($sco->parent != $currentorg)) {\r
+                        $style = '';\r
+                        if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) {\r
+                            $style = ' style="display: none;"';\r
+                        }\r
+                        $result->toc .= "\t\t<li><ul id='$sublist' class='$liststyle'$style>\n";\r
+                        $level++;\r
+                    } else {\r
+                        $result->toc .= $closelist;\r
+                        $level = $i;\r
+                    }\r
+                    $parents[$level]=$sco->parent;\r
+                }\r
+            }\r
+            $result->toc .= "\t\t<li>";\r
+            $nextsco = next($scoes);\r
+            if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {\r
+                $sublist++;\r
+                $icon = 'minus';\r
+                if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) {\r
+                    $icon = 'plus';\r
+                }\r
+                $result->toc .= '<a href="javascript:expandCollide(img'.$sublist.','.$sublist.','.$nextsco->id.');"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';\r
+            } else {\r
+                $result->toc .= '<img src="'.$scormpixdir.'/spacer.gif" />';\r
+            }\r
+            if (empty($sco->title)) {\r
+                $sco->title = $sco->identifier;\r
+            }\r
+            if (!empty($sco->launch)) {\r
+                $startbold = '';\r
+                $endbold = '';\r
+                $score = '';\r
+                if (empty($scoid) && ($mode != 'normal')) {\r
+                    $scoid = $sco->id;\r
+                }\r
+                //Neu la sco suspend thi hien thi anh khac\r
+                if ($suspendscoid == $sco->id){\r
+                    $result->toc .= '<img src="'.$scormpixdir.'/suspend.gif" alt="Dang tam dung o day" title="Dang dung o day" />';                \r
+                }\r
+                else{\r
+                //-----------------------\r
+                    if (isset($usertracks[$sco->identifier])) {\r
+                        $usertrack = $usertracks[$sco->identifier];\r
+                        $strstatus = get_string($usertrack->status,'scorm');\r
+                        $result->toc .= '<img src="'.$scormpixdir.'/'.$usertrack->status.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';\r
+                        \r
+                        if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {\r
+                            //Neu khoa hoc chua duoc attempted hoac chua hoan thanh hoac la chi browsed\r
+                            $incomplete = true;\r
+                            if ($play && empty($scoid)) {\r
+                                $scoid = $sco->id;\r
+                            }\r
+                        }\r
+                        if ($usertrack->score_raw != '') {\r
+                            $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';\r
+                        }\r
+                    } else {\r
+                        if ($play && empty($scoid)) {\r
+                            $scoid = $sco->id;\r
+                        }\r
+                        if ($sco->scormtype == 'sco') {\r
+                            $result->toc .= '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';\r
+                            $incomplete = true;\r
+                        } else {\r
+                            $result->toc .= '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';\r
+                        }\r
+                    }\r
+                }\r
+                if ($sco->id == $scoid) {\r
+                    $startbold = '<b>';\r
+                    $endbold = '</b>';\r
+                    $findnext = true;\r
+                    $shownext = $sco->next;\r
+                    $showprev = $sco->previous;\r
+                }\r
+                \r
+                if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {\r
+                    if (!empty($sco->launch)) {\r
+                        $previd = $sco->id;\r
+                    }\r
+                }\r
+                if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) {\r
+                    if ($sco->id == $scoid) {\r
+                        $result->prerequisites = true;\r
+                    }\r
+                    if (scorm_isChoice($scorm->id,$sco->id) == 1)\r
+                    {\r
+                    $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;\r
+                    $result->toc .= '&nbsp;'.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";\r
+                    $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);\r
+                    }\r
+                    else\r
+                    {\r
+                    $result->toc .= '&nbsp;'.$startbold.format_string($sco->title).$score.$endbold."</li>\n";\r
+                    $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);                    \r
+                    }\r
+                } else {\r
+                    if ($sco->id == $scoid) {\r
+                        $result->prerequisites = false;\r
+                    }\r
+                    $result->toc .= '&nbsp;'.$sco->title."</li>\n";\r
+                }\r
+            } else {\r
+                $result->toc .= '&nbsp;'.$sco->title."</li>\n";\r
+            }\r
+            if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {\r
+                if (!empty($nextsco->launch)) {\r
+                    $nextid = $nextsco->id;\r
+                }\r
+            }\r
+        }\r
+        for ($i=0;$i<$level;$i++) {\r
+            $result->toc .= "\t\t</ul></li>\n";\r
+        }\r
+        \r
+        if ($play) {\r
+            $sco = get_record('scorm_scoes','id',$scoid);\r
+            $sco->previd = $previd;\r
+            $sco->nextid = $nextid;\r
+            $result->sco = $sco;\r
+            $result->incomplete = $incomplete;\r
+        } else {\r
+            $result->incomplete = $incomplete;\r
+        }\r
+    }\r
+    $result->toc .= "\t</ul>\n";\r
+    if ($scorm->hidetoc == 0) {\r
+        $result->toc .= '\r
+          <script language="javascript" type="text/javascript">\r
+          <!--\r
+              function expandCollide(which,list,item) {\r
+                  var nn=document.ids?true:false\r
+                  var w3c=document.getElementById?true:false\r
+                  var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";\r
+                  var mid=w3c?").style":".style";\r
+\r
+                  if (eval(beg+list+mid+".display") != "none") {\r
+                      which.src = "'.$scormpixdir.'/plus.gif";\r
+                      eval(beg+list+mid+".display=\'none\';");\r
+                      new cookie("hide:SCORMitem" + item, 1, 356, "/").set();\r
+                  } else {\r
+                      which.src = "'.$scormpixdir.'/minus.gif";\r
+                      eval(beg+list+mid+".display=\'block\';");\r
+                      new cookie("hide:SCORMitem" + item, 1, -1, "/").set();\r
+                  }\r
+              }\r
+          -->\r
+          </script>'."\n";\r
+    }\r
+    \r
+    $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid=';\r
+    $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true);\r
+\r
+    return $result;\r
+}\r
+\r
+function scorm_get_last_attempt($scormid, $userid) {\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n Xu ly trong ham scorm_get_last_attempt \n");    \r
+\r
+/// Find the last attempt number for the given user id and scorm id\r
+    if ($lastattempt = get_record('scorm_scoes_track', 'userid', $userid, 'scormid', $scormid, '', '', 'max(attempt) as a')) {\r
+        if (empty($lastattempt->a)) {\r
+            return '1';\r
+        } else {\r
+            return $lastattempt->a;\r
+        }\r
+    }\r
+}\r
+\r
+// Khi mot nguoi truy nhap vao mot SCO thi se thiet lap\r
+// nguoi do da no luc thuc hien no\r
+function scorm_set_attempt($scoid,$userid)\r
+{\r
+    //Lay gia tri last attempt\r
+    if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) {\r
+        $attempt = scorm_get_last_attempt($scormid,$userid);\r
+    } else {\r
+        $attempt = 1;\r
+    }\r
+    //Chi set attempt cho cac SCO\r
+    $scormtype = get_field('scorm_scoes','scormtype','id',$scoid) ;\r
+    if ($scormtype == 'sco'){\r
+        $element = 'cmi.attempt_status';\r
+        $value = 'attempted';\r
+        scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value);\r
+    }\r
+}\r
+function scorm_get_tracks($scoid,$userid,$attempt='') {\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n Xu ly trong ham scorm_get_tracks \n");    \r
+\r
+/// Gets all tracks of specified sco and user\r
+    global $CFG;\r
+\r
+    if (empty($attempt)) {\r
+        if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) {\r
+            $attempt = scorm_get_last_attempt($scormid,$userid);\r
+        } else {\r
+            $attempt = 1;\r
+        }\r
+    }\r
+    $attemptsql = ' AND attempt=' . $attempt;\r
+    if ($tracks = get_records_select('scorm_scoes_track',"userid=$userid AND scoid=$scoid".$attemptsql,'element ASC')) {\r
+        $usertrack->userid = $userid;\r
+        $usertrack->scoid = $scoid; \r
+        $usertrack->score_raw = '';\r
+        $usertrack->score_scaled = '';\r
+        $usertrack->status = '';\r
+        $usertrack->success_status = '';\r
+        $usertrack->attempt_status = '';\r
+        $usertrack->satisfied_status = '';\r
+        $usertrack->total_time = '00:00:00';\r
+        $usertrack->session_time = '00:00:00';\r
+        $usertrack->timemodified = 0;\r
+        foreach ($tracks as $track) {\r
+            $element = $track->element;\r
+            $usertrack->{$element} = $track->value;\r
+            switch ($element) {\r
+                case 'cmi.core.lesson_status':\r
+                case 'cmi.attempt_status':\r
+                    $usertrack->status = $track->value;\r
+                    $usertrack->attempt_status = $track->value;                    \r
+                break;                \r
+                case 'cmi.completion_status':\r
+                    if ($track->value == 'not attempted') {\r
+                        $track->value = 'notattempted';\r
+                        $usertrack->attempt_status = $track->value;\r
+                    }       \r
+                    $usertrack->status = $track->value;\r
+                break;  \r
+                case 'cmi.success_status':\r
+                    $usertrack->success_status = $track->value;\r
+                    if ($track->value=='passed'){\r
+                        $usertrack->satisfied_status = 'satisfied';                    \r
+                    }\r
+                    if ($track->value=='failed'){\r
+                        $usertrack->satisfied_status = 'notSatisfied';                    \r
+                    }                    \r
+                break;\r
+                case 'cmi.core.score.raw':\r
+                case 'cmi.score.raw':\r
+                    $usertrack->score_raw = $track->value;\r
+                break;  \r
+                case 'cmi.score.scaled':\r
+                    $usertrack->score_scaled = $track->value;\r
+                break;  \r
+                case 'cmi.core.session_time':\r
+                case 'cmi.session_time':\r
+                    $usertrack->session_time = $track->value;\r
+                break;  \r
+                case 'cmi.core.total_time':\r
+                case 'cmi.total_time':\r
+                    $usertrack->total_time = $track->value;\r
+                break;  \r
+            }       \r
+            if (isset($track->timemodified) && ($track->timemodified > $usertrack->timemodified)) {\r
+                $usertrack->timemodified = $track->timemodified;\r
+            }       \r
+        }       \r
+        return $usertrack;\r
+    } else {\r
+        return false;\r
+    }\r
+}\r
+\r
+\r
+function scorm_get_AbsoluteTimeLimit($scoid){\r
+    $sco = get_record("scorm_scoes","id",$scoid);\r
+    if (!empty($sco)){\r
+        return $sco->attemptAbsoluteDurationLimit;\r
+    }\r
+    return 0;\r
+}\r
+//-----------------------------------------------------\r
+/// Library of functions and constants for parsing packages\r
+\r
+function scorm_parse($scorm) {\r
+    global $CFG;\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_parse \n");\r
+\r
+    // Parse scorm manifest\r
+    if ($scorm->pkgtype == 'AICC') {\r
+        $scorm->launch = scorm_parse_aicc($scorm->dir.'/'.$scorm->id,$scorm->id);\r
+    } else {\r
+        if (basename($scorm->reference) != 'imsmanifest.xml') {\r
+            $scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id);\r
+        } else {\r
+            $scorm->launch = scorm_parse_scorm($CFG->dataroot.'/'.$scorm->course.'/'.dirname($scorm->reference),$scorm->id);\r
+        }\r
+    }\r
+\r
+    return $scorm->launch;\r
+}\r
+\r
+/**\r
+* Take the header row of an AICC definition file\r
+* and returns sequence of columns and a pointer to\r
+* the sco identifier column.\r
+*\r
+* @param string $row AICC header row\r
+* @param string $mastername AICC sco identifier column\r
+* @return mixed\r
+*/\r
+function scorm_get_aicc_columns($row,$mastername='system_id') {\r
+    $tok = strtok(strtolower($row),"\",\n\r");\r
+    $result->columns = array();\r
+    $i=0;\r
+    while ($tok) {\r
+        if ($tok !='') {\r
+            $result->columns[] = $tok;\r
+            if ($tok == $mastername) {\r
+                $result->mastercol = $i;\r
+            }\r
+            $i++;\r
+        }\r
+        $tok = strtok("\",\n\r");\r
+    }\r
+    return $result;\r
+}\r
+\r
+/**\r
+* Given a colums array return a string containing the regular\r
+* expression to match the columns in a text row.\r
+*\r
+* @param array $column The header columns\r
+* @param string $remodule The regular expression module for a single column\r
+* @return string\r
+*/\r
+function scorm_forge_cols_regexp($columns,$remodule='(".*")?,') {\r
+    $regexp = '/^';\r
+    foreach ($columns as $column) {\r
+        $regexp .= $remodule;\r
+    }\r
+    $regexp = substr($regexp,0,-1) . '/';\r
+    return $regexp;\r
+}\r
+\r
+function scorm_parse_aicc($pkgdir,$scormid){\r
+    \r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_parse_aicc \n");    \r
+    \r
+    $version = 'AICC';\r
+    $ids = array();\r
+    $courses = array();\r
+    if ($handle = opendir($pkgdir)) {\r
+        while (($file = readdir($handle)) !== false) {\r
+            $ext = substr($file,strrpos($file,'.'));\r
+            $extension = strtolower(substr($ext,1));\r
+            $id = strtolower(basename($file,$ext));\r
+            $ids[$id]->$extension = $file;\r
+        }\r
+        closedir($handle);\r
+    }\r
+    foreach ($ids as $courseid => $id) {\r
+        if (isset($id->crs)) {\r
+            if (is_file($pkgdir.'/'.$id->crs)) {\r
+                $rows = file($pkgdir.'/'.$id->crs);\r
+                foreach ($rows as $row) {\r
+                    if (preg_match("/^(.+)=(.+)$/",$row,$matches)) {\r
+                        switch (strtolower(trim($matches[1]))) {\r
+                            case 'course_id':\r
+                                $courses[$courseid]->id = trim($matches[2]);\r
+                            break;\r
+                            case 'course_title':\r
+                                $courses[$courseid]->title = trim($matches[2]);\r
+                            break;\r
+                            case 'version':\r
+                                $courses[$courseid]->version = 'AICC_'.trim($matches[2]);\r
+                            break;\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        if (isset($id->des)) {\r
+            $rows = file($pkgdir.'/'.$id->des);\r
+            $columns = scorm_get_aicc_columns($rows[0]);\r
+            $regexp = scorm_forge_cols_regexp($columns->columns);\r
+            for ($i=1;$i<count($rows);$i++) {\r
+                if (preg_match($regexp,$rows[$i],$matches)) {\r
+                    for ($j=0;$j<count($columns->columns);$j++) {\r
+                        $column = $columns->columns[$j];\r
+                        $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        if (isset($id->au)) {\r
+            $rows = file($pkgdir.'/'.$id->au);\r
+            $columns = scorm_get_aicc_columns($rows[0]);\r
+            $regexp = scorm_forge_cols_regexp($columns->columns);\r
+            for ($i=1;$i<count($rows);$i++) {\r
+                if (preg_match($regexp,$rows[$i],$matches)) {\r
+                    for ($j=0;$j<count($columns->columns);$j++) {\r
+                        $column = $columns->columns[$j];\r
+                        $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        if (isset($id->cst)) {\r
+            $rows = file($pkgdir.'/'.$id->cst);\r
+            $columns = scorm_get_aicc_columns($rows[0],'block');\r
+            $regexp = scorm_forge_cols_regexp($columns->columns,'(.+)?,');\r
+            for ($i=1;$i<count($rows);$i++) {\r
+                if (preg_match($regexp,$rows[$i],$matches)) {\r
+                    for ($j=0;$j<count($columns->columns);$j++) {\r
+                        if ($j != $columns->mastercol) {\r
+                            $courses[$courseid]->elements[substr(trim($matches[$j+1]),1,-1)]->parent = substr(trim($matches[$columns->mastercol+1]),1,-1);\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        if (isset($id->ort)) {\r
+            $rows = file($pkgdir.'/'.$id->ort);\r
+        }\r
+        if (isset($id->pre)) {\r
+            $rows = file($pkgdir.'/'.$id->pre);\r
+            $columns = scorm_get_aicc_columns($rows[0],'structure_element');\r
+            $regexp = scorm_forge_cols_regexp($columns->columns,'(.+),');\r
+            for ($i=1;$i<count($rows);$i++) {\r
+                if (preg_match($regexp,$rows[$i],$matches)) {\r
+                    $courses[$courseid]->elements[$columns->mastercol+1]->prerequisites = substr(trim($matches[1-$columns->mastercol+1]),1,-1);\r
+                }\r
+            }\r
+        }\r
+        if (isset($id->cmp)) {\r
+            $rows = file($pkgdir.'/'.$id->cmp);\r
+        }\r
+    }\r
+    //print_r($courses);\r
+    $launch = 0;\r
+    if (isset($courses)) {\r
+        foreach ($courses as $course) {\r
+            unset($sco);\r
+            $sco->identifier = $course->id;\r
+            $sco->scorm = $scormid;\r
+            $sco->organization = '';\r
+            $sco->title = $course->title;\r
+            $sco->parent = '/';\r
+            $sco->launch = '';\r
+            $sco->scormtype = '';\r
+            //print_r($sco);\r
+            $id = insert_record('scorm_scoes',$sco);\r
+            if ($launch == 0) {\r
+                $launch = $id;\r
+            }\r
+            if (isset($course->elements)) {\r
+                foreach($course->elements as $element) {\r
+                    unset($sco);\r
+                    $sco->identifier = $element->system_id;\r
+                    $sco->scorm = $scormid;\r
+                    $sco->organization = $course->id;\r
+                    $sco->title = $element->title;\r
+                    if (strtolower($element->parent) == 'root') {\r
+                        $sco->parent = '/';\r
+                    } else {\r
+                        $sco->parent = $element->parent;\r
+                    }\r
+                    if (isset($element->file_name)) {\r
+                        $sco->launch = $element->file_name;\r
+                        $sco->scormtype = 'sco';\r
+                    } else {\r
+                        $element->file_name = '';\r
+                        $sco->scormtype = '';\r
+                    }\r
+                    if (!isset($element->prerequisites)) {\r
+                        $element->prerequisites = '';\r
+                    }\r
+                    $sco->prerequisites = $element->prerequisites;\r
+                    if (!isset($element->max_time_allowed)) {\r
+                        $element->max_time_allowed = '';\r
+                    }\r
+                    $sco->maxtimeallowed = $element->max_time_allowed;\r
+                    if (!isset($element->time_limit_action)) {\r
+                        $element->time_limit_action = '';\r
+                    }\r
+                    $sco->timelimitaction = $element->time_limit_action;\r
+                    if (!isset($element->mastery_score)) {\r
+                        $element->mastery_score = '';\r
+                    }\r
+                    $sco->masteryscore = $element->mastery_score;\r
+                    $sco->previous = 0;\r
+                    $sco->next = 0;\r
+                    $id = insert_record('scorm_scoes',$sco);\r
+                    if ($launch==0) {\r
+                        $launch = $id;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+    set_field('scorm','version','AICC','id',$scormid);\r
+    return $launch;\r
+}\r
+\r
+function scorm_get_resources($blocks) {\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n Xu ly trong ham scorm_get_resources \n");    \r
+\r
+    foreach ($blocks as $block) {\r
+        if ($block['name'] == 'RESOURCES') {\r
+            foreach ($block['children'] as $resource) {\r
+                if ($resource['name'] == 'RESOURCE') {\r
+                    $resources[addslashes($resource['attrs']['IDENTIFIER'])] = $resource['attrs'];\r
+                }\r
+            }\r
+        }\r
+    }\r
+    return $resources;\r
+}\r
+\r
+function scorm_get_manifest($blocks,$scoes) {\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_get_manifest.  \n");    \r
+    ////////fwrite($ft,$blocks." la  gia tri block la  \n");    \r
+\r
+    static $parents = array();\r
+    static $resources;\r
+\r
+    static $manifest;\r
+    static $organization;\r
+\r
+    if (count($blocks) > 0) {\r
+        foreach ($blocks as $block) {\r
+            switch ($block['name']) {\r
+                case 'METADATA':\r
+                    if (isset($block['children'])) {\r
+                        foreach ($block['children'] as $metadata) {\r
+                            if ($metadata['name'] == 'SCHEMAVERSION') {\r
+                                if (empty($scoes->version)) {\r
+                                    if (isset($metadata['tagData']) && (preg_match("/^(1\.2)$|^(CAM )?(1\.3)$/",$metadata['tagData'],$matches))) {\r
+                                        $scoes->version = 'SCORM_'.$matches[count($matches)-1];\r
+                                    } else {\r
+                                        $scoes->version = 'SCORM_1.2';\r
+                                    }\r
+                                }\r
+                            }\r
+                        }\r
+                    }\r
+                break;\r
+                case 'MANIFEST':\r
+                    $manifest = addslashes($block['attrs']['IDENTIFIER']); //Lay thuoc tinh IDENTFIER cua MANIFEST\r
+                    $organization = '';\r
+                    $resources = array();\r
+                    $resources = scorm_get_resources($block['children']);\r
+                    $scoes = scorm_get_manifest($block['children'],$scoes);\r
+                    if (count($scoes->elements) <= 0) {\r
+                        foreach ($resources as $item => $resource) {\r
+                            if (!empty($resource['HREF'])) {\r
+                                $sco = new stdClass();\r
+                                $sco->identifier = $item;\r
+                                $sco->title = $item;\r
+                                $sco->parent = '/';\r
+                                $sco->launch = addslashes($resource['HREF']);\r
+                                $sco->scormtype = addslashes($resource['ADLCP:SCORMTYPE']);\r
+                                $scoes->elements[$manifest][$organization][$item] = $sco;\r
+                            }\r
+                        }\r
+                    }\r
+                break;\r
+                case 'ORGANIZATIONS':\r
+                    if (!isset($scoes->defaultorg)) {\r
+                        $scoes->defaultorg = addslashes($block['attrs']['DEFAULT']);\r
+                    }\r
+                    $scoes = scorm_get_manifest($block['children'],$scoes);\r
+                break;\r
+                case 'ORGANIZATION':\r
+                    $identifier = addslashes($block['attrs']['IDENTIFIER']);\r
+                    $organization = '';\r
+                    $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier;\r
+                    $scoes->elements[$manifest][$organization][$identifier]->parent = '/';\r
+                    $scoes->elements[$manifest][$organization][$identifier]->launch = '';\r
+                    $scoes->elements[$manifest][$organization][$identifier]->scormtype = '';\r
+\r
+                    $parents = array();\r
+                    $parent = new stdClass();\r
+                    $parent->identifier = $identifier;\r
+                    $parent->organization = $organization;\r
+                    array_push($parents, $parent);\r
+                    $organization = $identifier;\r
+\r
+                    $scoes = scorm_get_manifest($block['children'],$scoes);\r
+                    \r
+                    array_pop($parents);\r
+                break;\r
+                case 'ITEM':\r
+                    $parent = array_pop($parents);\r
+                    array_push($parents, $parent);\r
+\r
+                    $identifier = addslashes($block['attrs']['IDENTIFIER']);\r
+                    $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier;\r
+                    $scoes->elements[$manifest][$organization][$identifier]->parent = $parent->identifier;\r
+                    if (!isset($block['attrs']['ISVISIBLE'])) {\r
+                        $block['attrs']['ISVISIBLE'] = 'true';\r
+                    }\r
+                    $scoes->elements[$manifest][$organization][$identifier]->isvisible = addslashes($block['attrs']['ISVISIBLE']);\r
+                    if (!isset($block['attrs']['PARAMETERS'])) {\r
+                        $block['attrs']['PARAMETERS'] = '';\r
+                    }\r
+                    $scoes->elements[$manifest][$organization][$identifier]->parameters = addslashes($block['attrs']['PARAMETERS']);\r
+                    if (!isset($block['attrs']['IDENTIFIERREF'])) {\r
+                        $scoes->elements[$manifest][$organization][$identifier]->launch = '';\r
+                        $scoes->elements[$manifest][$organization][$identifier]->scormtype = 'asset';\r
+                    } else {\r
+                        $idref = addslashes($block['attrs']['IDENTIFIERREF']);\r
+                        $base = '';\r
+                        if (isset($resources[$idref]['XML:BASE'])) {\r
+                            $base = $resources[$idref]['XML:BASE'];\r
+                        }\r
+                        $scoes->elements[$manifest][$organization][$identifier]->launch = addslashes($base.$resources[$idref]['HREF']);\r
+                        if (empty($resources[$idref]['ADLCP:SCORMTYPE'])) {\r
+                            $resources[$idref]['ADLCP:SCORMTYPE'] = 'asset';\r
+                        }\r
+                        $scoes->elements[$manifest][$organization][$identifier]->scormtype = addslashes($resources[$idref]['ADLCP:SCORMTYPE']);\r
+                    }\r
+                    \r
+                    //////fwrite($ft,"---Dang lam viec voi ITEM co Identifier = ".$identifier);\r
+                    $parent = new stdClass();\r
+                    $parent->identifier = $identifier;\r
+                    $parent->organization = $organization;\r
+                    array_push($parents, $parent);\r
+\r
+                    $scoes = scorm_get_manifest($block['children'],$scoes);\r
+                    \r
+                    array_pop($parents);\r
+                break;\r
+                case 'TITLE':\r
+                    $parent = array_pop($parents);\r
+                    array_push($parents, $parent);\r
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->title = addslashes($block['tagData']);\r
+                break;\r
+                case 'ADLCP:PREREQUISITES':\r
+                    if ($block['attrs']['TYPE'] == 'aicc_script') {\r
+                        $parent = array_pop($parents);\r
+                        array_push($parents, $parent);\r
+                        $scoes->elements[$manifest][$parent->organization][$parent->identifier]->prerequisites = addslashes($block['tagData']);\r
+                    }\r
+                break;\r
+                case 'ADLCP:MAXTIMEALLOWED':\r
+                    $parent = array_pop($parents);\r
+                    array_push($parents, $parent);\r
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->maxtimeallowed = addslashes($block['tagData']);\r
+                break;\r
+                case 'ADLCP:TIMELIMITACTION':\r
+                    $parent = array_pop($parents);\r
+                    array_push($parents, $parent);\r
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->timelimitaction = addslashes($block['tagData']);\r
+                break;\r
+                case 'ADLCP:DATAFROMLMS':\r
+                    $parent = array_pop($parents);\r
+                    array_push($parents, $parent);\r
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->datafromlms = addslashes($block['tagData']);\r
+                break;\r
+                case 'ADLCP:MASTERYSCORE':\r
+                    $parent = array_pop($parents);\r
+                    array_push($parents, $parent);\r
+                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->masteryscore = addslashes($block['tagData']);\r
+                break;\r
+                case 'ADLNAV:PRESENTATION':\r
+                    $parent = array_pop($parents);\r
+                    array_push($parents, $parent);\r
+                    foreach ($block['children'] as $adlnav) {\r
+                        if ($adlnav['name'] == 'ADLNAV:NAVIGATIONINTERFACE') {                                    //////fwrite($ft,$scoes->elements[$manifest][$parent->organization][$parent->identifier]->title."  Xuat hien dieu khien NAV \n");\r
+                            foreach ($adlnav['children'] as $adlnavInterface){\r
+                                if ($adlnavInterface['name'] == 'ADLNAV:HIDELMSUI'){\r
+                                //////fwrite($ft,$scoes->elements[$manifest][$parent->organization][$parent->identifier]->title."  Xuat hien dieu khien NAV HIDELMSUI\n");\r
+                                //////fwrite($ft," Gia tri thuoc tinh an la ".$adlnavInterface['tagData']);\r
+                                    if ($adlnavInterface['tagData'] == 'continue')    {\r
+                                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->next = 1; \r
+//                                    //////fwrite($ft," Thiet lap thuoc tinh an OK ");\r
+                                    }\r
+                                    if ($adlnavInterface['tagData'] == 'previous')    {\r
+                                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->previous = 1; \r
+//                                    //////fwrite($ft," Thiet lap thuoc tinh an OK ");\r
+                                    }\r
+                                }\r
+\r
+                            }\r
+\r
+                        }\r
+                    }\r
+                break;\r
+\r
+                case 'IMSSS:SEQUENCING':\r
+                    $parent = array_pop($parents);\r
+                    array_push($parents, $parent);\r
+                    foreach ($block['children'] as $sequencing) {\r
+                        //////fwrite($ft,"\n Xuat hien IMSSS:SEQUENCING cua ".$parent->identifier);\r
+                        if ($sequencing['name']=='IMSSS:CONTROLMODE'){\r
+                            //Xu ly cac Control Mode voi mot Item trong SCO\r
+                            if ($sequencing['attrs']['CHOICE'] == 'false'){\r
+                            $scoes->elements[$manifest][$parent->organization][$parent->identifier]->choice = 0;\r
+                            //////fwrite($ft,"\n Xuat hien lua chon choice  \n");\r
+                            }\r
+                            if ($sequencing['attrs']['CHOICEEXIT'] == 'false'){\r
+                            $scoes->elements[$manifest][$parent->organization][$parent->identifier]->choiceexit = 0;\r
+                            }\r
+                            if ($sequencing['attrs']['FLOW'] == 'true'){\r
+                            $scoes->elements[$manifest][$parent->organization][$parent->identifier]->flow = 1;\r
+                            }\r
+                            if ($sequencing['attrs']['FORWARDONLY'] == 'true'){\r
+                            $scoes->elements[$manifest][$parent->organization][$parent->identifier]->forwardonly = 1;\r
+                            }\r
+                            if ($sequencing['attrs']['USECURRENTATTEMPTOBJECTINFO'] == 'true'){\r
+                            $scoes->elements[$manifest][$parent->organization][$parent->identifier]->usecurrentattemptobjectinfo = 1;\r
+                            }\r
+                            if ($sequencing['attrs']['USECURRENTATTEMPTPROGRESSINFO'] == 'true'){\r
+                            $scoes->elements[$manifest][$parent->organization][$parent->identifier]->usecurrentattemptprogressinfo = 1;\r
+                            }\r
+                        }\r
+                        if ($sequencing['name']=='ADLSEQ:CONSTRAINEDCHOICECONSIDERATIONS'){\r
+                            //Xu ly cac dieu kien rang buoc thu tu \r
+                            if ($sequencing['attrs']['CONSTRAINCHOICE'] == 'true'){\r
+                            $scoes->elements[$manifest][$parent->organization][$parent->identifier]->constrainChoice = 1;\r
+                            }\r
+                            if ($sequencing['attrs']['PREVENTACTIVATION'] == 'true'){\r
+                            $scoes->elements[$manifest][$parent->organization][$parent->identifier]->preventactivation = 1;\r
+                            }\r
+\r
+                        }\r
+                        if ($sequencing['name']=='IMSSS:OBJECTIVES'){\r
+                            //Xu ly cac cac gia tri muc tieu\r
+                            foreach ($sequencing['children'] as $objective){\r
+                                if($objective['name']=='IMSSS:PRIMARYOBJECTIVE'){\r
+                                    //Xac dinh primary objective de lay thong so\r
+                                    foreach ($objective['children'] as $primaryobjective){\r
+                                        if($primaryobjective['name']=='IMSSS:MINNORMALIZEDMEASURE'){    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->minnormalizedmeasure = $primaryobjective['tagData'];\r
+                                        }\r
+                                    }\r
+                                }\r
+                            }\r
+                        }\r
+                        if ($sequencing['name']=='IMSSS:LIMITCONDITIONS'){\r
+                            //Xu ly cac cac gia tri cac dieu kien gioi han\r
+                            if (!empty($sequencing['attrs']['ATTEMPTLIMIT'])){\r
+                                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->attemptLimit = $sequencing['attrs']['ATTEMPTLIMIT'];                                \r
+                            }\r
+                            if (!empty($sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT'])){\r
+                                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->attemptAbsoluteDurationLimit = $sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT'];                                \r
+                            }                            \r
+                        }                        \r
+                        if ($sequencing['name']=='IMSSS:ROLLUPRULES'){\r
+                            $rolluprules = array();\r
+                            //Phan danh cho RollupRule\r
+                            if (!empty($sequencing['attrs']['ROLLUPOBJECTIVESATISFIED'])){\r
+                                if ($sequencing['attrs']['ROLLUPOBJECTIVESATISFIED']== 'false'){\r
+                                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rollupobjectivesatisfied = 0;                                \r
+                                }\r
+                            }\r
+                            if (!empty($sequencing['attrs']['ROLLUPPROGRESSCOMPLETION'])){\r
+                                if ($sequencing['attrs']['ROLLUPPROGRESSCOMPLETION']== 'false'){\r
+                                    $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rollupprogresscompletion = 0;                                \r
+                                }\r
+                            }\r
+                            if (!empty($sequencing['attrs']['OBJECTIVEMEASUREWEIGHT'])){\r
+                                $scoes->elements[$manifest][$parent->organization][$parent->identifier]->objectivemeasureweight = $sequencing['attrs']['OBJECTIVEMEASUREWEIGHT'];                    \r
+                            }\r
+\r
+                            if (!empty($sequencing['children'])){\r
+                                foreach ($sequencing['children'] as $sequencingrolluprule){\r
+                                    if ($sequencingrolluprule['name']=='IMSSS:ROLLUPRULE' ){\r
+                                        $rolluprule = new stdClass();\r
+                                        if ($sequencingrolluprule['attrs']['CHILDACTIVITYSET'] !=' '){\r
+                                            $rolluprule->childactivityset = $sequencingrolluprule['attrs']['CHILDACTIVITYSET'];\r
+                                            ////fwrite($ft,"\n Thiet lap them 1 childActivitySet la ".$rolluprule->childactivityset);\r
+\r
+                                            //Phan xu ly danh sach condition\r
+                                            if (!empty($sequencingrolluprule['children'])){\r
+                                                foreach ($sequencingrolluprule['children'] as $rolluproleconditions)\r
+                                                {\r
+                                                    if ($rolluproleconditions['name']=='IMSSS:ROLLUPCONDITIONS'){\r
+                                                        $conditions = array();\r
+                                                        if (!empty($rolluproleconditions['attrs']['conditionCombination'])){\r
+                                                        $rolluprule->conditionCombination = $rolluproleconditions['attrs']['conditionCombination'];\r
+                                                        }\r
+                                                        foreach ($rolluproleconditions['children'] as $rolluprulecondition){\r
+                                                            if ($rolluprulecondition['name']=='IMSSS:ROLLUPCONDITION'){\r
+                                                                $condition = new stdClass();\r
+                                                                if (!empty($rolluprulecondition['attrs']['OPERATOR'])){\r
+                                                                    $condition->operator = $rolluprulecondition['attrs']['OPERATOR'];\r
+                                                                }\r
+                                                                if (!empty($rolluprulecondition['attrs']['CONDITION'])){\r
+                                                                    $condition->condition = $rolluprulecondition['attrs']['CONDITION'];\r
+                                                                }\r
+                                                            array_push($conditions,$condition);    \r
+                                                            ////fwrite($ft,"Da them mot rolluprulecondition");\r
+                                                            }\r
+\r
+                                                        }\r
+                                                    $rolluprule->conditions = $conditions;\r
+                                                    }\r
+                                                    if ($rolluproleconditions['name']=='IMSSS:ROLLUPACTION'){\r
+                                                    $rolluprule->rollupruleaction = $rolluproleconditions['attrs']['ACTION'];\r
+                                                    }\r
+                                                }\r
+                                            }\r
+                                            //Ket thuc xu ly danh sach condition\r
+\r
+                                        }\r
+                                        ////fwrite($ft,"\n Dua them 1 rule vao \n");\r
+                                        array_push($rolluprules, $rolluprule);\r
+                                        ////fwrite($ft,"\n Dua them 1 rule vao mang \n");\r
+                                    }\r
+\r
+                                }\r
+                            }\r
+                            $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rolluprules = $rolluprules;\r
+\r
+//                            ////fwrite($ft,"\n >>>>NOW TEST ");\r
+//                            foreach ($scoes->elements[$manifest][$parent->organization][$parent->identifier]->rolluprules as $rolluptest){\r
+//                            ////fwrite($ft,"\n >>>> Gia tri Test thu duoc la:".$rolluptest->childactivityset);\r
+    \r
+                        }\r
+\r
+\r
+                        \r
+                        if ($sequencing['name']=='IMSSS:SEQUENCINGRULES'){\r
+                            //Xu ly cac dieu kien Rules cua Sequencing\r
+                            //////fwrite($ft,"\n Xuat hien SEQUENCINGRULES >>>>>>>>>>");                            \r
+                            $sequencingrules = array();\r
+                            foreach ($sequencing['children'] as $conditionrules){\r
+                                if($conditionrules['name']=='IMSSS:EXITCONDITIONRULE'){\r
+                                        $sequencingrule = new stdClass();\r
+                                        //Phan xu ly danh sach condition\r
+                                        //////fwrite($ft,"\n Xuat hien exitrule >>>>>>>>>>");\r
+                                        if (!empty($conditionrules['children'])){\r
+                                            foreach ($conditionrules['children'] as $conditionrule)\r
+                                            {\r
+                                                if ($conditionrule['name']=='IMSSS:RULECONDITIONS'){\r
+                                                    $ruleconditions = array();\r
+                                                    if (!empty($conditionrule['attrs']['conditionCombination'])){\r
+                                                    $sequencingrule->conditionCombination = $conditionrule['attrs']['conditionCombination'];\r
+                                                    }\r
+                                                    foreach ($conditionrule['children'] as $rulecondition){\r
+                                                        if ($rulecondition['name']=='IMSSS:RULECONDITION'){\r
+                                                            $condition = new stdClass();\r
+                                                            if (!empty($rulecondition['attrs']['OPERATOR'])){\r
+                                                                $condition->operator = $rulecondition['attrs']['OPERATOR'];\r
+                                                            }\r
+                                                            if (!empty($rulecondition['attrs']['CONDITION'])){\r
+                                                                $condition->condition = $rulecondition['attrs']['CONDITION'];\r
+                                                            }\r
+                                                            if (!empty($rulecondition['attrs']['MEASURETHRESHOLD'])){\r
+                                                                $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD'];\r
+                                                            }\r
+                                                            if (!empty($rulecondition['attrs']['REFERENCEDOBJECTIVE'])){\r
+                                                                $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE'];\r
+                                                            }                                                                                                                        \r
+                                                        array_push($ruleconditions,$condition);    \r
+                                                        ////fwrite($ft,"\n Da them mot rulecondition trong exitrule");\r
+                                                        }\r
+\r
+                                                    }\r
+                                                $sequencingrule->ruleconditions = $ruleconditions;\r
+                                                }\r
+                                                if ($conditionrule['name']=='IMSSS:RULEACTION'){\r
+                                                $sequencingrule->exitconditionruleaction = $conditionrule['attrs']['ACTION'];\r
+                                                }\r
+                                            }\r
+                                        }\r
+                                        //Ket thuc xu ly danh sach condition\r
+                                array_push($sequencingrules,$sequencingrule);                                        \r
+                                }\r
+                                if ($conditionrules['name']=='IMSSS:PRECONDITIONRULE'){\r
+                                    $sequencingrule = new stdClass();\r
+                                    //Phan xu ly danh sach condition\r
+                                    if (!empty($conditionrules['children'])){\r
+                                        foreach ($conditionrules['children'] as $conditionrule)\r
+                                        {\r
+                                            if ($conditionrule['name']=='IMSSS:RULECONDITIONS'){\r
+                                                $ruleconditions = array();\r
+                                                if (!empty($conditionrule['attrs']['conditionCombination'])){\r
+                                                    $sequencingrule->conditionCombination = $conditionrule['attrs']['conditionCombination'];\r
+                                                }\r
+                                                foreach ($conditionrule['children'] as $rulecondition){\r
+                                                    if ($rulecondition['name']=='IMSSS:RULECONDITION'){\r
+                                                        $condition = new stdClass();\r
+                                                        if (!empty($rulecondition['attrs']['OPERATOR'])){\r
+                                                            $condition->operator = $rulecondition['attrs']['OPERATOR'];\r
+                                                        }\r
+                                                        if (!empty($rulecondition['attrs']['CONDITION'])){\r
+                                                            $condition->condition = $rulecondition['attrs']['CONDITION'];\r
+                                                        }\r
+                                                        if (!empty($rulecondition['attrs']['MEASURETHRESHOLD'])){\r
+                                                            $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD'];\r
+                                                        }\r
+                                                        if (!empty($rulecondition['attrs']['REFERENCEDOBJECTIVE'])){\r
+                                                            $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE'];\r
+                                                        }                                                                                                                        \r
+                                                    array_push($ruleconditions,$condition);    \r
+                                                    ////fwrite($ft,"\n Da them mot rulecondition trong prerule");\r
+                                                    }\r
+\r
+                                                }\r
+                                            $sequencingrule->ruleconditions = $ruleconditions;\r
+                                            }\r
+                                            if ($conditionrule['name']=='IMSSS:RULEACTION'){\r
+                                            $sequencingrule->preconditionruleaction = $conditionrule['attrs']['ACTION'];\r
+                                            }\r
+                                        }\r
+                                    }\r
+                                    //Ket thuc xu ly danh sach condition\r
+                                array_push($sequencingrules,$sequencingrule);                                \r
+                                }\r
+                                if($conditionrules['name']=='IMSSS:POSTCONDITIONRULE'){\r
+                                        $sequencingrule = new stdClass();\r
+                                        //Phan xu ly danh sach condition\r
+                                        if (!empty($conditionrules['children'])){\r
+                                            foreach ($conditionrules['children'] as $conditionrule)\r
+                                            {\r
+                                                if ($conditionrule['name']=='IMSSS:RULECONDITIONS'){\r
+                                                    $ruleconditions = array();\r
+                                                    if (!empty($conditionrule['attrs']['conditionCombination'])){\r
+                                                    $sequencingrule->conditionCombination = $conditionrule['attrs']['conditionCombination'];\r
+                                                    }\r
+                                                    foreach ($conditionrule['children'] as $rulecondition){\r
+                                                        if ($rulecondition['name']=='IMSSS:RULECONDITION'){\r
+                                                            $condition = new stdClass();\r
+                                                            if (!empty($rulecondition['attrs']['OPERATOR'])){\r
+                                                                $condition->operator = $rulecondition['attrs']['OPERATOR'];\r
+                                                            }\r
+                                                            if (!empty($rulecondition['attrs']['CONDITION'])){\r
+                                                                $condition->condition = $rulecondition['attrs']['CONDITION'];\r
+                                                            }\r
+                                                            if (!empty($rulecondition['attrs']['MEASURETHRESHOLD'])){\r
+                                                                $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD'];\r
+                                                            }\r
+                                                            if (!empty($rulecondition['attrs']['REFERENCEDOBJECTIVE'])){\r
+                                                                $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE'];\r
+                                                            }                                                                                                                        \r
+                                                        array_push($ruleconditions,$condition);    \r
+                                                        ////fwrite($ft,"\n Da them mot rulecondition trong postrule");\r
+                                                        }\r
+\r
+                                                    }\r
+                                                $sequencingrule->ruleconditions = $ruleconditions;\r
+                                                }\r
+                                                if ($conditionrule['name']=='IMSSS:RULEACTION'){\r
+                                                $sequencingrule->postconditionruleaction = $conditionrule['attrs']['ACTION'];\r
+                                                }\r
+                                            }\r
+                                        }\r
+                                        //Ket thuc xu ly danh sach condition\r
+                                array_push($sequencingrules,$sequencingrule);                                \r
+                                }\r
+                                $scoes->elements[$manifest][$parent->organization][$parent->identifier]->sequencingrules = $sequencingrules;                                \r
+                            }\r
+                        }\r
+                    }\r
+\r
+                break;\r
+\r
+            }\r
+        }\r
+    }\r
+\r
+    return $scoes;\r
+}\r
+\r
+function scorm_parse_scorm($pkgdir,$scormid) {\r
+    global $CFG;\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    //////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_parse_scorm \n");\r
+    \r
+    $launch = 0;\r
+    $manifestfile = $pkgdir.'/imsmanifest.xml';\r
+\r
+    if (is_file($manifestfile)) {\r
+    \r
+        $xmlstring = file_get_contents($manifestfile);\r
+        $objXML = new xml2Array();\r
+        $manifests = $objXML->parse($xmlstring);\r
+            \r
+        $scoes = new stdClass();\r
+        $scoes->version = '';\r
+        $scoes = scorm_get_manifest($manifests,$scoes);\r
+\r
+        if (count($scoes->elements) > 0) {\r
+            foreach ($scoes->elements as $manifest => $organizations) {\r
+                foreach ($organizations as $organization => $items) {\r
+                    foreach ($items as $identifier => $item) {\r
+                        $item->scorm = $scormid;\r
+                        $item->manifest = $manifest;\r
+                        $item->organization = $organization;\r
+                        //////fwrite($ft,"\n ---- Item chuan bi dua vao la ".$item->identifier);\r
+                        $id = insert_record('scorm_scoes',$item);\r
+                        //////fwrite($ft,"\n Lay duoc ScoID la ".$id);\r
+                        $item->scormid = $scormid;\r
+                        $item->scoid = $id;\r
+                        $idControlMode = insert_record('scorm_sequencing_controlmode',$item);\r
+\r
+                        if (!empty($item->sequencingrules)){\r
+                            ////fwrite($ft,"\n ++++++++Them SequencingRules cho SCO: ".$item->scoid) ;\r
+                            foreach($item->sequencingrules as $sequencingrule){\r
+                                ////fwrite($ft,"\n ----Chuan bi them 1 sequencingrule vao CSDL: ");\r
+                                $sequencingrule->scormid = $scormid;\r
+                                $sequencingrule->scoid = $item->scoid;\r
+                                ////fwrite($ft,"\n ----Thong tin Scormid: ".$sequencingrule->scormid);                                                                                            \r
+                                ////fwrite($ft,"\n ----Thong tin Scoid: ".$sequencingrule->scoid);                                                                                                                            \r
+                                $idruleconditions = insert_record('scorm_sequencing_ruleconditions',$sequencingrule);\r
+                                foreach($sequencingrule->ruleconditions as $rulecondition){\r
+                                    $rulecondition->scormid = $sequencingrule->scormid;\r
+                                    $rulecondition->scoid = $sequencingrule->scoid;\r
+                                    $rulecondition->ruleconditionsid = $idruleconditions;\r
+                                    $idrulecondition = insert_record('scorm_sequencing_rulecondition',$rulecondition);\r
+                                    ////fwrite($ft,"\n ----Da them 1 sequencingrulecondition vao CSDL: ");                                    \r
+                                }\r
+                            \r
+                            }                        \r
+                        }\r
+                        \r
+                        if (!empty($item->rolluprules)){\r
+                            ////fwrite($ft,"\n ++++++++Them RollupRules cho SCO: ".$item->scoid) ;\r
+                            $idControlMode = insert_record('scorm_sequencing_rolluprules',$item);\r
+                            ////fwrite($ft,"\n ----Gia tri idRollupRules \n");\r
+                            foreach($item->rolluprules as $rollup)\r
+                            {\r
+                                ////fwrite($ft,"\n ----Chuan bi them 1 rule vao CSDL ");\r
+                                $rollup->rolluprulesid =$idControlMode;\r
+                                $rollup->scormid = $scormid;\r
+                                $rollup->scoid =  $item->scoid;\r
+\r
+                                ////fwrite($ft,"\n ----Cac thong tin cua Rule: \n ");\r
+                                ////fwrite($ft,"\n ----rolluprulesid:  ".$rollup->rolluprulesid);\r
+                                ////fwrite($ft,"\n ----scormid:  ".$rollup->scormid );\r
+                                ////fwrite($ft,"\n ----scoid:  ".$rollup->scoid);\r
+                                ////fwrite($ft,"\n ----activichild:  ".$rollup->childactivityset);\r
+                                ////fwrite($ft,"\n ----rollupaction:  ".$rollup->rollupruleaction);\r
+                                $idRollupRule = insert_record('scorm_sequencing_rolluprule',$rollup);\r
+                                ////fwrite($ft,"\n ----Dua them 1 rule vao CSDL -- Chuan bi them condition vao rule".$idRollupRule);\r
+                                $rollup->rollupruleid = $idRollupRule;\r
+                                $idconditions = insert_record('scorm_sequencing_rollupruleconditions',$rollup);\r
+                                ////fwrite($ft,"\n --Dua cac condition con vao CSDL");\r
+                                foreach($rollup->conditions as $condition){\r
+                                    $condition->ruleconditionsid = $idconditions;\r
+                                    $condition->scormid = $rollup->scormid;\r
+                                    $condition->scoid = $rollup->scoid;\r
+                                    $idcondition = insert_record('scorm_sequencing_rolluprulecondition',$condition);\r
+                                    ////fwrite($ft,"\n --Da dua them 1 condition vao CSDL");\r
+                                }\r
+                                                                \r
+                                \r
+                            }\r
+                        }\r
+                        if (($launch == 0) && ((empty($scoes->defaultorg)) || ($scoes->defaultorg == $identifier))) {\r
+                            $launch = $id;\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+            set_field('scorm','version',$scoes->version,'id',$scormid);\r
+        }\r
+    } \r
+    \r
+    return $launch;\r
+}\r
+\r
+function scorm_course_format_display($user,$course) {\r
+    global $CFG;\r
+\r
+    $strupdate = get_string('update');\r
+    $strmodule = get_string('modulename','scorm');\r
+\r
+    echo '<div class="mod-scorm">';\r
+    if ($scorms = get_all_instances_in_course('scorm', $course)) {\r
+        // The module SCORM activity with the least id is the course  \r
+        $scorm = current($scorms);\r
+        if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+        $colspan = '';\r
+        $headertext = '<table width="100%"><tr><td class="title">'.get_string('name').': <b>'.format_string($scorm->name).'</b>';\r
+        if (isteacher($course->id, $user->id, true)) {\r
+            if (isediting($course->id)) {\r
+                // Display update icon\r
+                $path = $CFG->wwwroot.'/course';\r
+                $headertext .= '<span class="commands">'.\r
+                        '<a title="'.$strupdate.'" href="'.$path.'/mod.php?update='.$cm->id.'&amp;sesskey='.sesskey().'">'.\r
+                        '<img src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" alt="'.$strupdate.'" /></a></span>';\r
+            }\r
+            $headertext .= '</td>';\r
+            // Display report link\r
+            $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');\r
+            if ($trackedusers->c > 0) {\r
+                $headertext .= '<td class="reportlink">'.\r
+                              '<a target="'.$CFG->framename.'" href="'.$CFG->wwwroot.'/mod/scorm/report.php?id='.$cm->id.'">'.\r
+                               get_string('viewallreports','scorm',$trackedusers->c).'</a>';\r
+            } else {\r
+                $headertext .= '<td class="reportlink">'.get_string('noreports','scorm');\r
+            }\r
+            $colspan = ' colspan="2"';\r
+        } \r
+        $headertext .= '</td></tr><tr><td'.$colspan.'>'.format_text(get_string('summary').':<br />'.$scorm->summary).'</td></tr></table>';\r
+        print_simple_box($headertext,'','100%');\r
+        scorm_view_display($user, $scorm, 'view.php?id='.$course->id, $cm, '100%');\r
+    } else {\r
+        if (isteacheredit($course->id, $user->id)) {\r
+            // Create a new activity\r
+            redirect('mod.php?id='.$course->id.'&amp;section=0&sesskey='.sesskey().'&amp;add=scorm');\r
+        } else {\r
+            notify('Could not find a scorm course here');\r
+        }\r
+    }\r
+    echo '</div>';\r
+}\r
+\r
+function scorm_view_display ($user, $scorm, $action, $cm, $blockwidth='') {\r
+    global $CFG;\r
+    $organization = optional_param('organization', '', PARAM_INT);\r
+\r
+    print_simple_box_start('center',$blockwidth);\r
+?>\r
+        <div class="structurehead"><?php print_string('coursestruct','scorm') ?></div>\r
+<?php\r
+    if (empty($organization)) {\r
+        $organization = $scorm->launch;\r
+    }\r
+    if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) {\r
+        if (count($orgs) > 1) {\r
+ ?>\r
+            <div class='center'>\r
+                <?php print_string('organizations','scorm') ?>\r
+                <form name='changeorg' method='post' action='<?php echo $action ?>'>\r
+                    <?php choose_from_menu($orgs, 'organization', "$organization", '','submit()') ?>\r
+                </form>\r
+            </div>\r
+<?php\r
+        }\r
+    }\r
+    $orgidentifier = '';\r
+    if ($org = get_record('scorm_scoes','id',$organization)) {\r
+        if (($org->organization == '') && ($org->launch == '')) {\r
+            $orgidentifier = $org->identifier;\r
+        } else {\r
+            $orgidentifier = $org->organization;\r
+        }\r
+    }\r
+    $result = scorm_get_toc($user,$scorm,'structlist',$orgidentifier);\r
+    $incomplete = $result->incomplete;\r
+//    echo ("Toc ---");\r
+    echo $result->toc;\r
+//    echo ("Ket thuc");\r
+    print_simple_box_end();\r
+?>\r
+            <div class="center">\r
+                <form name="theform" method="post" action="<?php echo $CFG->wwwroot ?>/mod/scorm/player.php?id=<?php echo $cm->id ?>"<?php echo $scorm->popup == 1?' target="newwin"':'' ?>>\r
+              <?php\r
+\r
+// Thiet lap suspend\r
+            $suspend = get_record("scorm_suspendtrack","scormid",$scorm->id,"userid",$user->id);\r
+\r
+//------------------\r
+                  if ($scorm->hidebrowse == 0) {\r
+                      print_string("mode","scorm");\r
+                      echo ': <input type="radio" id="b" name="mode" value="browse" /><label for="b">'.get_string('browse','scorm').'</label>'."\n";\r
+                      if ($incomplete === true) {\r
+                          echo '<input type="radio" id="n" name="mode" value="normal" checked="checked" /><label for="n">'.get_string('normal','scorm')."</label>\n";\r
+                            \r
+                            //Neu co luu tru thi co the chon continue de tiep tu\r
+                          if (!empty($suspend))\r
+                          {\r
+                              echo '<input type="radio" id="n" name="mode" value="continue" checked="checked" /><label for="n">'.get_string('continue','scorm')."</label>\n";\r
+                          }\r
+\r
+                      } else {\r
+                          echo '<input type="radio" id="r" name="mode" value="review" checked="checked" /><label for="r">'.get_string('review','scorm')."</label>\n";\r
+                      }\r
+                  } else {\r
+                      if ($incomplete === true) {\r
+                          echo '<input type="hidden" name="mode" value="normal" />'."\n";\r
+                      } else {\r
+                          echo '<input type="hidden" name="mode" value="review" />'."\n";\r
+                      }\r
+                  }\r
+                  if (($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) {\r
+?>\r
+                  <br />\r
+                  <input type="checkbox" id="a" name="newattempt" />\r
+                  <label for="a"><?php print_string('newattempt','scorm') ?></label>\r
+<?php\r
+                  }\r
+              ?>\r
+              <br />\r
+              <input type="hidden" name="scoid" />\r
+              <input type="hidden" name="currentorg" value="<?php echo $orgidentifier ?>" />\r
+              <input type="submit" value="<?php print_string('entercourse','scorm') ?>" />\r
+              </form>\r
+          </div>\r
+<?php\r
+}\r
+\r
+function scorm_update_status($scormid,$scoid)\r
+{\r
+    \r
+}\r
+\r
+\r
+function scorm_repeater($what, $times) {\r
+    if ($times <= 0) {\r
+        return null;\r
+    }\r
+    $return = '';\r
+    for ($i=0; $i<$times;$i++) {\r
+        $return .= $what;\r
+    }\r
+    return $return;\r
+}\r
+\r
+//chuyen toi SCO duoc thuc hien tiep theo\r
+function scorm_get_nextsco($scormid,$scoid)\r
+{\r
+\r
+\r
+\r
+}\r
+//Chuyen toi SCO duoc thuc hien truoc\r
+function scorm_get_presco($scormid,$scoid)\r
+{\r
+\r
+\r
+\r
+}\r
+//Xac dinh xem doi tuong do co cho phep lua chon khong\r
+function scorm_isChoice($scormid,$scoid)\r
+{\r
+//    //$f = "D:\\test.txt";\r
+//    //@$ft = fopen($f,"a");\r
+    $sco = get_record("scorm_sequencing_controlmode","scormid",$scormid,"scoid",$scoid);\r
+//    ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_isChoice scormid la ".$scormid." scoid la: ".$scoid);\r
+    $scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);\r
+//    ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_isChoice scoparent scormid la ".$scormid." scoid la: ".$scoparent->scoid);\r
+\r
+\r
+//    ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_isChoice gia tri la: ".$scoparent->choice);\r
+    return $scoparent->choice;\r
+}\r
+\r
+//Xac dinh xem doi tuong do co cho phep lua chon thoat khong\r
+function scorm_isChoiceexit($scormid,$scoid)\r
+{\r
+    $sco = get_record("scorm_sequencing_controlmode","scormid",$scormid,"scoid",$scoid);\r
+    $scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);\r
+\r
+    return $scoparent->choiceexit;\r
+}\r
+/* Usage\r
+ Grab some XML data, either from a file, URL, etc. however you want. Assume storage in $strYourXML;\r
+\r
+ $objXML = new xml2Array();\r
+ $arrOutput = $objXML->parse($strYourXML);\r
+ print_r($arrOutput); //print it out, or do whatever!\r
+  \r
+*/\r
+class xml2Array {\r
+   \r
+   var $arrOutput = array();\r
+   var $resParser;\r
+   var $strXmlData;\r
+   \r
+   /**\r
+   * Convert a utf-8 string to html entities\r
+   *\r
+   * @param string $str The UTF-8 string\r
+   * @return string\r
+   */\r
+   function utf8_to_entities($str) {\r
+       $entities = '';\r
+       $values = array();\r
+       $lookingfor = 1;\r
+\r
+       for ($i = 0; $i < strlen($str); $i++) {\r
+           $thisvalue = ord($str[$i]);\r
+           if ($thisvalue < 128) {\r
+               $entities .= $str[$i]; // Leave ASCII chars unchanged \r
+           } else {\r
+               if (count($values) == 0) {\r
+                   $lookingfor = ($thisvalue < 224) ? 2 : 3;\r
+               }\r
+               $values[] = $thisvalue;\r
+               if (count($values) == $lookingfor) {\r
+                   $number = ($lookingfor == 3) ?\r
+                       (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64):\r
+                       (($values[0] % 32) * 64) + ($values[1] % 64);\r
+                   $entities .= '&#' . $number . ';';\r
+                   $values = array();\r
+                   $lookingfor = 1;\r
+               }\r
+           }\r
+       }\r
+       return $entities;\r
+   }\r
+\r
+   /**\r
+   * Parse an XML text string and create an array tree that rapresent the XML structure\r
+   *\r
+   * @param string $strInputXML The XML string\r
+   * @return array\r
+   */\r
+   function parse($strInputXML) {\r
+           $this->resParser = xml_parser_create ('UTF-8');\r
+           xml_set_object($this->resParser,$this);\r
+           xml_set_element_handler($this->resParser, "tagOpen", "tagClosed");\r
+           \r
+           xml_set_character_data_handler($this->resParser, "tagData");\r
+       \r
+           $this->strXmlData = xml_parse($this->resParser,$strInputXML );\r
+           if(!$this->strXmlData) {\r
+               die(sprintf("XML error: %s at line %d",\r
+                           xml_error_string(xml_get_error_code($this->resParser)),\r
+                           xml_get_current_line_number($this->resParser)));\r
+           }\r
+                           \r
+           xml_parser_free($this->resParser);\r
+           \r
+           return $this->arrOutput;\r
+   }\r
+   \r
+   function tagOpen($parser, $name, $attrs) {\r
+       $tag=array("name"=>$name,"attrs"=>$attrs); \r
+       array_push($this->arrOutput,$tag);\r
+   }\r
+   \r
+   function tagData($parser, $tagData) {\r
+       if(trim($tagData)) {\r
+           if(isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) {\r
+               $this->arrOutput[count($this->arrOutput)-1]['tagData'] .= $this->utf8_to_entities($tagData);\r
+           } else {\r
+               $this->arrOutput[count($this->arrOutput)-1]['tagData'] = $this->utf8_to_entities($tagData);\r
+           }\r
+       }\r
+   }\r
+   \r
+   function tagClosed($parser, $name) {\r
+       $this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1];\r
+       array_pop($this->arrOutput);\r
+   }\r
+\r
+}\r
+?>\r
index 1baeb7b2fb6313739bf327c540e8b80395ec6c31..8c5b7724491b9485a4be76f12e9b0f80951d1bee 100755 (executable)
-<?php
-    require_once($CFG->dirroot.'/mod/scorm/lib.php');
-    if (!isset($form->name)) {
-        $form->name = '';
-    }
-    if (!isset($form->reference)) {
-        $form->reference = '';
-    }
-    if (!isset($form->summary)) {
-        $form->summary = '';
-    }
-    if (!isset($form->launch)) {
-        $form->launch = '';
-    }
-    if (!isset($form->auto)) {
-        $form->auto = '';
-    }
-    if (!isset($form->popup)) {
-        $form->popup = 0;
-    }
-    if (!isset($form->datadir)) {
-        $form->datadir = '';
-    }
-    if (!isset($form->maxgrade)) {
-        $form->maxgrade = '';
-    }
-    if (!isset($form->grademethod)) {
-        $form->grademethod = 0;
-    }
-    if (!isset($form->maxattempt)) {
-        $form->maxattempt = 1;
-    }
-    if (!isset($form->whatgrade)) {
-        $form->whatgrade = 0;
-    }
-    if (!isset($form->hidebrowse)) {
-        $form->hidebrowse = 0;
-    }
-    if (!isset($form->hidetoc)) {
-        $form->hidetoc = 0;
-    }
-    if (!isset($form->hidenav)) {
-        $form->hidenav = 0;
-    }
-    if (!isset($form->width)) {
-        $form->width = $CFG->scorm_framewidth;
-    }
-    if ((strpos($form->width,'%') === false) && ($form->width <= 100)) {
-        $form->width .= '%';
-    }
-    if (!isset($form->height)) {
-        $form->height = $CFG->scorm_frameheight;
-    }
-    if ((strpos($form->height,'%') === false) && ($form->height <= 100)) {
-        $form->height .= '%';
-    }
-    if (!isset($form->options) || empty($form->options)) {
-        $form->options = $stdoptions;
-    }
-    $options = explode(',',$form->options);
-    $window = new stdClass();
-    foreach ($options as $option) {
-        list($element,$value) = explode('=',$option);
-        $element = trim($element);
-        $window->$element = trim($value)==1?'checked':''; 
-    }
-    $scormid = '';
-    if (!empty($form->instance)) {
-        $scormid = '&instance='.$form->instance;
-    }
-    $datadir = '';
-    if (!empty($form->datadir)) {
-        $datadir = '&datadir='.$form->datadir;
-    }
-    $sessionkey = '';
-    if (!empty($form->sesskey)) {
-        $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');
-?>
-
-<script type="text/javascript" src="<?php p($CFG->wwwroot) ?>/mod/scorm/request.js" ></script>
-<script type="text/javascript">
-    function validate_scorm(theform,filename) {
-        var myRequest = NewHttpReq();
-        result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php","id=<?php p($form->course) ?>&reference="+filename+"<?php echo $sessionkey.$scormid.$datadir ?>");
-        //alert(result);
-        results = result.split('\n');
-        result = '';
-        errorlogs = '';
-        datadir = '';
-        for (i=0;i<results.length;i++) {
-            element = results[i].split('=');
-            switch(element[0]) {
-               case 'result':
-                  result = element[1];
-               break;
-               case 'launch':
-                  launch = element[1];
-               break;
-               case 'datadir':
-                  datadir = element[1];
-               break;
-               case 'pkgtype':
-                  pkgtype = element[1];
-               break;
-               case 'errorlogs':
-                   i++;
-                   do {
-                      errorlogs.concat(results[i]+'\n');
-                      i++;
-                   } while (i<results.lenght());
-
-               break;
-            }
-        }
-        if ((result == "found") || (result == "regular")) {
-            theform.datadir.value = datadir;
-            theform.pkgtype.value = pkgtype;
-            theform.launch.value = launch;
-            if (launch == 0) {
-                if ('<?php echo $scormid ?>' != '') {
-                    return confirm('<?php print_string('trackingloose','scorm') ?>');
-                }
-            }
-            return true;
-        } else {
-            result = '<?php print_string('validation','scorm') ?>: '+ result + '\n';
-            if (errorlogs != '') {
-               result.concat('<?php print_string('errorlogs','scorm') ?>:\n'+errorlogs);
-            }
-            alert(result);
-            return false;
-        }
-    }
-
-    function checkscormform (whatcheck,checkvalue,whatset) {
-        if (whatcheck.options[whatcheck.selectedIndex].value == checkvalue) {
-            whatset.disabled = true;
-        } else {
-            whatset.disabled = false;
-        }
-    }
-    
-    function showhide (id, set) {
-        divobj = document.getElementById(id);
-        butobj = document.getElementById(id+'button');
-        prefobj = document.getElementById(id+'pref');
-        if (set == true) {
-            if (prefobj.value == '1') {
-                divobj.style.display = 'block';
-                butobj.value = '<?php print_string('hidesettings') ?>';
-            } else {
-                divobj.style.display = 'none';
-                butobj.value = '<?php print_string('showsettings') ?>...';
-            }
-        } else {
-            if (prefobj.value == '1') {
-                divobj.style.display = 'none';
-                butobj.value = '<?php print_string('showsettings') ?>...';
-                prefobj.value = '0';
-            } else {
-                divobj.style.display = 'block';
-                butobj.value = '<?php print_string('hidesettings') ?>';
-                prefobj.value = '1';
-            }
-        }
-    }
-</script>
-
-<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>
-                <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>
-            <td>
-                <?php print_textarea($usehtmleditor, 10, 50, 680, 400, 'summary', $form->summary); ?>
-            </td>
-        </tr>
-        <tr valign="top">
-            <td align="right" nowrap="nowrap">
-                <b><?php echo $strfilename?>:</b>
-            </td>
-            <td>
-                <input name="reference" size="50" value="<?php echo $form->reference ?>" alt="<?php echo $strfilename ?>" />&nbsp;
-                <?php
-                    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>
-            <?php
-                choose_from_menu($SCORM_GRADE_METHOD, 'grademethod', (int) $form->grademethod, '','checkscormform(this,0,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>
-            <?php
-                for ($i=100; $i>=1; $i--) {
-                    $grades[$i] = $i;
-                }
-                $disabled = $form->grademethod=='0';
-                choose_from_menu($grades, 'maxgrade', (int) $form->maxgrade, '','','0',false,$disabled);
-                helpbutton('maxgrade', get_string('maximumgrade'), 'scorm');
-            ?>
-            </td>
-        </tr>
-        <tr valign="top">
-            <td align="right"><b><?php print_string('maximumattempts','scorm') ?>:</b></td>
-            <td>
-            <?php
-                for ($i=1; $i<=$CFG->scorm_maxattempts; $i++) {
-                    if ($i == 1) {
-                        $attempts[$i] = $i . ' ' . get_string('attempt','scorm');
-                    } else {
-                        $attempts[$i] = $i . ' ' . get_string('attempts','scorm');
-                    }
-                }
-                choose_from_menu($attempts, 'maxattempt', (int) $form->maxattempt, get_string('nolimit','scorm'),'checkscormform(this,1,document.form.whatgrade);');
-                helpbutton('maxattempt', get_string('maximumattempts','scorm'), 'scorm');
-            ?>
-            </td>
-        </tr>
-        <tr valign="top">
-            <td align="right"><b><?php print_string('whatgrade','scorm') ?>:</b></td>
-            <td>
-            <?php
-                $disabled = (int) $form->maxattempt === 1;
-                choose_from_menu($SCORM_WHAT_GRADE, 'whatgrade', (int) $form->whatgrade, '','','0',false,$disabled);
-                helpbutton('whatgrade', get_string('whatgrade','scorm'), 'scorm');
-            ?>
-            </td>
-        </tr>
-        <tr><td colspan="2"><hr /></td></tr>
-
-        <tr>
-            <td align="right"><b><?php print_string('advanced', 'scorm') ?>:</b></td>
-            <td>
-                <input type="button" value="<?php print_string('hidesettings') ?>" id="advancedsettingsbutton" onclick="javascript: 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) ?>
-            </td>
-        </tr>
-        <tr>
-            <td colspan="2">
-                <div id="advancedsettings">
-                    <table align="center">
-                        <tr>
-                            <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', (int) $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>
-                            <?php
-                                $options = array();
-                                $options[0]=get_string('no');
-                                $options[1]=get_string('yes');
-                                choose_from_menu ($options, 'hidebrowse', (int) $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>
-                            <?php
-                                $options = array();
-                                $options[1]=get_string('hidden','scorm');
-                                $options[0]=get_string('sided','scorm');
-                                $options[2]=get_string('popupmenu','scorm');
-                                choose_from_menu ($options, 'hidetoc', (int) $form->hidetoc, '');
-                            ?>
-                            </td>
-                        </tr>
-                        <tr>
-                            <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', (int) $form->hidenav, '');
-                            ?>
-                            </td>
-                        </tr>
-                    </table>
-                </div>
-            </td>
-        </tr>
-        <tr>
-            <td align="right"><b><?php print_string('window', 'scorm') ?>:</b></td>
-            <td>
-                <input type="button" value="<?php print_string('hidesettings') ?>" id="windowsettingsbutton" onclick="javascript: 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) ?>
-            </td>
-        </tr>
-        <tr>
-            <td colspan="2">
-                <div id="windowsettings">
-                    <table align="center">
-                        <tr valign="top">
-                            <td>
-                                <b><?php print_string('stagesize','scorm'); ?></b>
-                                <?php helpbutton('size', get_string('stagesize', '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) ?>" />
-                                <label for="height"><?php p($strheight) ?></label>
-                            </td>
-                        </tr>
-                        <tr valign="top">
-                            <td>
-                                <script type="text/javascript">
-                                    var popupitems = ["<?php echo implode('","',array_keys($SCORM_POPUP_OPTIONS)); ?>"];
-                                </script>
-                                <br /><b><?php print_string('display','scorm'); ?>:</b><br />
-                                <input type="radio" 
-                                       name="popup"
-                                       value="0" alt="<?php p($striframe) ?>" 
-                                       <?php echo ($form->popup == 0) ? "checked=\"checked\"" : "" ?> 
-                                       onclick="return lockoptions('form', 'popup[1]', popupitems);"
-                                />
-                                <b title="<?php p($striframedisplay) ?>"><?php p($striframe) ?></b>
-                            </td>
-                        </tr>
-                        <tr valign="top">
-                            <td>
-                                <input name="popup" 
-                                       type="radio" 
-                                       value="1" 
-                                       alt="<?php p($strnewwindow)?>" 
-                                       <?php echo ($form->popup == 1) ? 'checked="checked"' : '' ?>
-                                       onclick="return lockoptions('form', 'popup[1]', popupitems);"
-                                />
-                                <b title="<?php p($strnewwindowopen) ?>"><?php p($strnewwindow) ?></b>
-                                <blockquote>
-                                    <?php
-                                        foreach ($window as $name => $value) {
-                                            echo "<input name=\"h$name\" type=\"hidden\" value=\"0\"/>\n";
-                                            echo "<input name=\"$name\" type=\"checkbox\" value=\"1\" ".$window->$name." alt=\"$name\" />\n";
-                                            $stringname = "str$name";
-                                            echo $$stringname."<br />\n";
-                                        }
-                                    ?>
-                                    <script type="text/javascript">
-                                        lockoptions('form','popup[1]', popupitems);
-                                    </script>
-                                </blockquote>
-                            </td>
-                        </tr>
-                    </table>
-                </div>
-                <script language="javascript" type="text/javascript">
-                    showhide('advancedsettings', true);
-                    showhide('windowsettings', true);
-                </script>
-            </td>
-        </tr>
-    </table>
-    <input type="hidden" name="datadir" value="<?php p($form->datadir) ?>" />
-    <input type="hidden" name="pkgtype" value="<?php p($form->pkgtype) ?>" />
-    <input type="hidden" name="launch"  value="<?php p($form->launch) ?>" />
-    <?php
-        $scorms = get_all_instances_in_course('scorm', $course);
-        $coursescorm = current($scorms);
-        if (($course->format == 'scorm') && ((count($scorms) == 0) || ($form->instance == $coursescorm->id))) {
-    ?>
-    <input type="hidden" name="redirect"       value="yes" />
-    <input type="hidden" name="redirecturl"    value="../course/view.php?id=<?php p($form->course) ?>" />    
-    <?php
-        } 
-    ?>
-    <input type="hidden" name="course"  value="<?php p($form->course) ?>" />
-    <input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
-    <input type="hidden" name="section" value="<?php p($form->section) ?>" />
-    <input type="hidden" name="module"  value="<?php p($form->module) ?>" />
-    <input type="hidden" name="mode"    value="<?php p($form->mode) ?>" />
-    <input type="hidden" name="coursemodule"    value="<?php p($form->coursemodule) ?>" />
-    <input type="hidden" name="modulename"      value="<?php p($form->modulename) ?>" />
-    <input type="hidden" name="instance"        value="<?php p($form->instance) ?>" />
-    <center>
-        <input type="submit" value="<?php print_string('savechanges') ?>" />
-        <input type="button" name="cancel" value="<?php print_string('cancel') ?>" onclick="document.location='view.php?id=<?php echo $form->course ?>'" />
-    </center>
-</form>
+<?php\r
+    require_once($CFG->dirroot.'/mod/scorm/lib.php');\r
+    if (!isset($form->name)) {\r
+        $form->name = '';\r
+    }\r
+    if (!isset($form->reference)) {\r
+        $form->reference = '';\r
+    }\r
+    if (!isset($form->summary)) {\r
+        $form->summary = '';\r
+    }\r
+    if (!isset($form->launch)) {\r
+        $form->launch = '';\r
+    }\r
+    if (!isset($form->auto)) {\r
+        $form->auto = '';\r
+    }\r
+    if (!isset($form->popup)) {\r
+        $form->popup = 0;\r
+    }\r
+    if (!isset($form->datadir)) {\r
+        $form->datadir = '';\r
+    }\r
+    if (!isset($form->maxgrade)) {\r
+        $form->maxgrade = '';\r
+    }\r
+    if (!isset($form->grademethod)) {\r
+        $form->grademethod = 0;\r
+    }\r
+    if (!isset($form->maxattempt)) {\r
+        $form->maxattempt = 1;\r
+    }\r
+    if (!isset($form->whatgrade)) {\r
+        $form->whatgrade = 0;\r
+    }\r
+    if (!isset($form->hidebrowse)) {\r
+        $form->hidebrowse = 0;\r
+    }\r
+    if (!isset($form->hidetoc)) {\r
+        $form->hidetoc = 0;\r
+    }\r
+    if (!isset($form->hidenav)) {\r
+        $form->hidenav = 0;\r
+    }\r
+    if (!isset($form->width)) {\r
+        $form->width = $CFG->scorm_framewidth;\r
+    }\r
+    if ((strpos($form->width,'%') === false) && ($form->width <= 100)) {\r
+        $form->width .= '%';\r
+    }\r
+    if (!isset($form->height)) {\r
+        $form->height = $CFG->scorm_frameheight;\r
+    }\r
+    if ((strpos($form->height,'%') === false) && ($form->height <= 100)) {\r
+        $form->height .= '%';\r
+    }\r
+    if (!isset($form->options) || empty($form->options)) {\r
+        $form->options = $stdoptions;\r
+    }\r
+    $options = explode(',',$form->options);\r
+    $window = new stdClass();\r
+    foreach ($options as $option) {\r
+        list($element,$value) = explode('=',$option);\r
+        $element = trim($element);\r
+        $window->$element = trim($value)==1?'checked':''; \r
+    }\r
+    $scormid = '';\r
+    if (!empty($form->instance)) {\r
+        $scormid = '&instance='.$form->instance;\r
+    }\r
+    $datadir = '';\r
+    if (!empty($form->datadir)) {\r
+        $datadir = '&datadir='.$form->datadir;\r
+    }\r
+    $sessionkey = '';\r
+    if (!empty($form->sesskey)) {\r
+        $sessionkey = '&sesskey='.$form->sesskey;\r
+    }\r
+\r
+    $strfilename = get_string('coursepacket', 'scorm');\r
+    $strchooseafile = get_string('chooseapacket', 'scorm');\r
+    $striframe = get_string('iframe', 'scorm');\r
+    $striframedisplay = get_string('iframedisplay', 'scorm');\r
+    $strnewwindow = get_string('popup', 'scorm');\r
+    $strnewwindowopen = get_string('popupopen', 'scorm');\r
+    $strheight = get_string('height', 'scorm');\r
+    $strwidth = get_string('width', 'scorm');\r
+    $strresizable = get_string('resizable', 'scorm');\r
+    $strscrollbars = get_string('scrollbars', 'scorm');\r
+    $strdirectories = get_string('directories', 'scorm');\r
+    $strlocation = get_string('location', 'scorm');\r
+    $strmenubar = get_string('menubar', 'scorm');\r
+    $strtoolbar = get_string('toolbar', 'scorm');\r
+    $strstatus = get_string('statusbar', 'scorm');\r
+?>\r
+\r
+<script type="text/javascript" src="<?php p($CFG->wwwroot) ?>/mod/scorm/request.js" ></script>\r
+<script type="text/javascript">\r
+    function validate_scorm(theform,filename) {\r
+        var myRequest = NewHttpReq();\r
+        result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php","id=<?php p($form->course) ?>&reference="+filename+"<?php echo $sessionkey.$scormid.$datadir ?>");\r
+        alert("Scorm validating....");\r
+        results = result.split('\n');\r
+        result = '';\r
+        errorlogs = '';\r
+        datadir = '';\r
+        for (i=0;i<results.length;i++) {\r
+            element = results[i].split('=');\r
+            switch(element[0]) {\r
+               case 'result':\r
+                  result = element[1];\r
+               break;\r
+               case 'launch':\r
+                  launch = element[1];\r
+               break;\r
+               case 'datadir':\r
+                  datadir = element[1];\r
+               break;\r
+               case 'pkgtype':\r
+                  pkgtype = element[1];\r
+               break;\r
+               case 'errorlogs':\r
+                   i++;\r
+                   do {\r
+                      errorlogs.concat(results[i]+'\n');\r
+                      i++;\r
+                   } while (i<results.lenght());\r
+\r
+               break;\r
+            }\r
+        }\r
+        if ((result == "found") || (result == "regular")) {\r
+            theform.datadir.value = datadir;\r
+            theform.pkgtype.value = pkgtype;\r
+            theform.launch.value = launch;\r
+            if (launch == 0) {\r
+                if ('<?php echo $scormid ?>' != '') {\r
+                    return confirm('<?php print_string('trackingloose','scorm') ?>');\r
+                }\r
+            }\r
+            return true;\r
+        } else {\r
+            result = '<?php print_string('validation','scorm') ?>: '+ result + '\n';\r
+            if (errorlogs != '') {\r
+               result.concat('<?php print_string('errorlogs','scorm') ?>:\n'+errorlogs);\r
+            }\r
+            alert(result);\r
+                       alert("Khong tuan chuan Scorm");\r
+                       document.form.name.focus();\r
+\r
+            return false;\r
+        }\r
+    }\r
+\r
+    function checkscormform (whatcheck,checkvalue,whatset) {\r
+        if (whatcheck.options[whatcheck.selectedIndex].value == checkvalue) {\r
+            whatset.disabled = true;\r
+        } else {\r
+            whatset.disabled = false;\r
+        }\r
+    }\r
+    \r
+    function showhide (id, set) {\r
+        divobj = document.getElementById(id);\r
+        butobj = document.getElementById(id+'button');\r
+        prefobj = document.getElementById(id+'pref');\r
+        if (set == true) {\r
+            if (prefobj.value == '1') {\r
+                divobj.style.display = 'block';\r
+                butobj.value = '<?php print_string('hidesettings') ?>';\r
+            } else {\r
+                divobj.style.display = 'none';\r
+                butobj.value = '<?php print_string('showsettings') ?>...';\r
+            }\r
+        } else {\r
+            if (prefobj.value == '1') {\r
+                divobj.style.display = 'none';\r
+                butobj.value = '<?php print_string('showsettings') ?>...';\r
+                prefobj.value = '0';\r
+            } else {\r
+                divobj.style.display = 'block';\r
+                butobj.value = '<?php print_string('hidesettings') ?>';\r
+                prefobj.value = '1';\r
+            }\r
+        }\r
+    }\r
+</script>\r
+\r
+<form name="form" method="post" action="mod.php?goto=" onsubmit="return validate_scorm(document.form,document.form.reference.value);">\r
+\r
+\r
+    <table cellpadding="5">\r
+        <tr valign="top">\r
+            <td align="right"><b><?php print_string('name') ?>:</b></td>\r
+            <td>\r
+                <input type="text" name="name" size="50" value="<?php p($form->name) ?>" alt="<?php print_string('name') ?>" />\r
+            </td>\r
+        </tr>\r
+        <tr valign="top">\r
+            <td align="right"><b><?php print_string('summary') ?>:</b><br />\r
+                <?php helpbutton('summary', get_string('summary'), 'scorm', true, true) ?>\r
+            </td>\r
+            <td>\r
+                <?php print_textarea($usehtmleditor, 10, 50, 680, 400, 'summary', $form->summary); ?>\r
+            </td>\r
+        </tr>\r
+        <tr valign="top">\r
+            <td align="right" nowrap="nowrap">\r
+                <b><?php echo $strfilename?>:</b>\r
+            </td>\r
+            <td>\r
+                <input name="reference" size="50" value="<?php echo $form->reference ?>" alt="<?php echo $strfilename ?>" />&nbsp;\r
+                <?php\r
+                    button_to_popup_window ('/files/index.php?id='.$course->id.'&amp;choose=form.reference',\r
+                                            'coursefiles', $strchooseafile, 500, 750, $strchooseafile);\r
+                    helpbutton('package', get_string('coursepacket', 'scorm'), 'scorm', true);\r
+                ?>\r
+            </td>\r
+        </tr>\r
+        <tr valign="top">\r
+            <td align="right"><b><?php print_string('grademethod', 'scorm') ?>:</b></td>\r
+            <td>\r
+            <?php\r
+                choose_from_menu($SCORM_GRADE_METHOD, 'grademethod', (int) $form->grademethod, '','checkscormform(this,0,document.form.maxgrade);');\r
+                helpbutton('grademethod', get_string('grademethod','scorm'), 'scorm');\r
+            ?>\r
+            </td>\r
+        </tr>\r
+        <tr valign="top">\r
+            <td align="right"><b><?php print_string('maximumgrade') ?>:</b></td>\r
+            <td>\r
+            <?php\r
+                for ($i=100; $i>=1; $i--) {\r
+                    $grades[$i] = $i;\r
+                }\r
+                $disabled = $form->grademethod=='0';\r
+                choose_from_menu($grades, 'maxgrade', (int) $form->maxgrade, '','','0',false,$disabled);\r
+                helpbutton('maxgrade', get_string('maximumgrade'), 'scorm');\r
+            ?>\r
+            </td>\r
+        </tr>\r
+        <tr valign="top">\r
+            <td align="right"><b><?php print_string('maximumattempts','scorm') ?>:</b></td>\r
+            <td>\r
+            <?php\r
+                for ($i=1; $i<=$CFG->scorm_maxattempts; $i++) {\r
+                    if ($i == 1) {\r
+                        $attempts[$i] = $i . ' ' . get_string('attempt','scorm');\r
+                    } else {\r
+                        $attempts[$i] = $i . ' ' . get_string('attempts','scorm');\r
+                    }\r
+                }\r
+                choose_from_menu($attempts, 'maxattempt', (int) $form->maxattempt, get_string('nolimit','scorm'),'checkscormform(this,1,document.form.whatgrade);');\r
+                helpbutton('maxattempt', get_string('maximumattempts','scorm'), 'scorm');\r
+            ?>\r
+            </td>\r
+        </tr>\r
+        <tr valign="top">\r
+            <td align="right"><b><?php print_string('whatgrade','scorm') ?>:</b></td>\r
+            <td>\r
+            <?php\r
+                $disabled = (int) $form->maxattempt === 1;\r
+                choose_from_menu($SCORM_WHAT_GRADE, 'whatgrade', (int) $form->whatgrade, '','','0',false,$disabled);\r
+                helpbutton('whatgrade', get_string('whatgrade','scorm'), 'scorm');\r
+            ?>\r
+            </td>\r
+        </tr>\r
+        <tr><td colspan="2"><hr /></td></tr>\r
+\r
+        <tr>\r
+            <td align="right"><b><?php print_string('advanced', 'scorm') ?>:</b></td>\r
+            <td>\r
+                <input type="button" value="<?php print_string('hidesettings') ?>" id="advancedsettingsbutton" onclick="javascript: return showhide('advancedsettings');" />\r
+                <input type="hidden" name="advancedsettingspref" id="advancedsettingspref" \r
+                       value="<?php echo get_user_preferences('scorm_advancedsettingspref', $CFG->scorm_advancedsettings); ?>" />\r
+                <?php helpbutton('advanced', get_string('advanced', 'scorm'), 'scorm', true) ?>\r
+            </td>\r
+        </tr>\r
+        <tr>\r
+            <td colspan="2">\r
+                <div id="advancedsettings">\r
+                    <table align="center">\r
+                        <tr>\r
+                            <td align="right"><b><?php print_string('autocontinue','scorm') ?>:</b></td>\r
+                            <td>\r
+                            <?php\r
+                                $options = array();\r
+                                $options[0]=get_string('no');\r
+                                $options[1]=get_string('yes');\r
+                                choose_from_menu ($options, 'auto', (int) $form->auto,'');\r
+                                helpbutton('autocontinue', get_string('autocontinue','scorm'), 'scorm', true);\r
+                            ?>\r
+                            </td>\r
+                        </tr>\r
+                        <tr>\r
+                            <td align="right"><b><?php print_string('hidebrowse','scorm') ?>:</b></td>\r
+                            <td>\r
+                            <?php\r
+                                $options = array();\r
+                                $options[0]=get_string('no');\r
+                                $options[1]=get_string('yes');\r
+                                choose_from_menu ($options, 'hidebrowse', (int) $form->hidebrowse, '');\r
+                                helpbutton('browsemode', get_string('hidebrowse','scorm'), 'scorm', true);\r
+                            ?>\r
+                            </td>\r
+                        </tr>\r
+                        <tr>\r
+                            <td align="right"><b><?php print_string('hidetoc','scorm') ?>:</b></td>\r
+                            <td>\r
+                            <?php\r
+                                $options = array();\r
+                                $options[1]=get_string('hidden','scorm');\r
+                                $options[0]=get_string('sided','scorm');\r
+                                $options[2]=get_string('popupmenu','scorm');\r
+                                choose_from_menu ($options, 'hidetoc', (int) $form->hidetoc, '');\r
+                            ?>\r
+                            </td>\r
+                        </tr>\r
+                        <tr>\r
+                            <td align="right"><b><?php print_string('hidenav','scorm') ?>:</b></td>\r
+                            <td>\r
+                            <?php\r
+                                $options = array();\r
+                                $options[0]=get_string('no');\r
+                                $options[1]=get_string('yes');\r
+                                choose_from_menu ($options, 'hidenav', (int) $form->hidenav, '');\r
+                            ?>\r
+                            </td>\r
+                        </tr>\r
+                    </table>\r
+                </div>\r
+            </td>\r
+        </tr>\r
+        <tr>\r
+            <td align="right"><b><?php print_string('window', 'scorm') ?>:</b></td>\r
+            <td>\r
+                <input type="button" value="<?php print_string('hidesettings') ?>" id="windowsettingsbutton" onclick="javascript: return showhide('windowsettings');" />\r
+                <input type="hidden" name="windowsettingspref" id="windowsettingspref" \r
+                       value="<?php echo get_user_preferences('scorm_windowsettingspref', $CFG->scorm_windowsettings); ?>" />\r
+                <?php helpbutton('window', get_string('window', 'scorm'), 'scorm', true) ?>\r
+            </td>\r
+        </tr>\r
+        <tr>\r
+            <td colspan="2">\r
+                <div id="windowsettings">\r
+                    <table align="center">\r
+                        <tr valign="top">\r
+                            <td>\r
+                                <b><?php print_string('stagesize','scorm'); ?></b>\r
+                                <?php helpbutton('size', get_string('stagesize', 'scorm'), 'scorm', true) ?><br />\r
+                                <input name="width" type="text" size="4" value="<?php p($form->width) ?>" alt="<?php p($strwidth) ?>" />\r
+                                <label for="width"><?php p($strwidth) ?></label><br />\r
+                                <input name="height" type="text" size="4" value="<?php p($form->height) ?>" alt="<?php p($strheight) ?>" />\r
+                                <label for="height"><?php p($strheight) ?></label>\r
+                            </td>\r
+                        </tr>\r
+                        <tr valign="top">\r
+                            <td>\r
+                                <script type="text/javascript">\r
+                                    var popupitems = ["<?php echo implode('","',array_keys($SCORM_POPUP_OPTIONS)); ?>"];\r
+                                </script>\r
+                                <br /><b><?php print_string('display','scorm'); ?>:</b><br />\r
+                                <input type="radio" \r
+                                       name="popup"\r
+                                       value="0" alt="<?php p($striframe) ?>" \r
+                                       <?php echo ($form->popup == 0) ? "checked=\"checked\"" : "" ?> \r
+                                       onclick="return lockoptions('form', 'popup[1]', popupitems);"\r
+                                />\r
+                                <b title="<?php p($striframedisplay) ?>"><?php p($striframe) ?></b>\r
+                            </td>\r
+                        </tr>\r
+                        <tr valign="top">\r
+                            <td>\r
+                                <input name="popup" \r
+                                       type="radio" \r
+                                       value="1" \r
+                                       alt="<?php p($strnewwindow)?>" \r
+                                       <?php echo ($form->popup == 1) ? 'checked="checked"' : '' ?>\r
+                                       onclick="return lockoptions('form', 'popup[1]', popupitems);"\r
+                                />\r
+                                <b title="<?php p($strnewwindowopen) ?>"><?php p($strnewwindow) ?></b>\r
+                                <blockquote>\r
+                                    <?php\r
+                                        foreach ($window as $name => $value) {\r
+                                            echo "<input name=\"h$name\" type=\"hidden\" value=\"0\"/>\n";\r
+                                            echo "<input name=\"$name\" type=\"checkbox\" value=\"1\" ".$window->$name." alt=\"$name\" />\n";\r
+                                            $stringname = "str$name";\r
+                                            echo $$stringname."<br />\n";\r
+                                        }\r
+                                    ?>\r
+                                    <script type="text/javascript">\r
+                                        lockoptions('form','popup[1]', popupitems);\r
+                                    </script>\r
+                                </blockquote>\r
+                            </td>\r
+                        </tr>\r
+                    </table>\r
+                </div>\r
+                <script language="javascript" type="text/javascript">\r
+                    showhide('advancedsettings', true);\r
+                    showhide('windowsettings', true);\r
+                </script>\r
+            </td>\r
+        </tr>\r
+    </table>\r
+    <input type="hidden" name="datadir" value="<?php p($form->datadir) ?>" />\r
+    <input type="hidden" name="pkgtype" value="<?php p($form->pkgtype) ?>" />\r
+    <input type="hidden" name="launch"  value="<?php p($form->launch) ?>" />\r
+    <?php\r
+        $scorms = get_all_instances_in_course('scorm', $course);\r
+        $coursescorm = current($scorms);\r
+        if (($course->format == 'scorm') && ((count($scorms) == 0) || ($form->instance == $coursescorm->id))) {\r
+    ?>\r
+    <input type="hidden" name="redirect"       value="yes" />\r
+    <input type="hidden" name="redirecturl"    value="../course/view.php?id=<?php p($form->course) ?>" />    \r
+    <?php\r
+        } \r
+    ?>\r
+    <input type="hidden" name="course"  value="<?php p($form->course) ?>" />\r
+    <input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />\r
+    <input type="hidden" name="section" value="<?php p($form->section) ?>" />\r
+    <input type="hidden" name="module"  value="<?php p($form->module) ?>" />\r
+    <input type="hidden" name="mode"    value="<?php p($form->mode) ?>" />\r
+    <input type="hidden" name="coursemodule"    value="<?php p($form->coursemodule) ?>" />\r
+    <input type="hidden" name="modulename"      value="<?php p($form->modulename) ?>" />\r
+    <input type="hidden" name="instance"        value="<?php p($form->instance) ?>" />\r
+    <center>\r
+        <input type="submit" value="<?php print_string('savechanges') ?>"/>\r
+        <input type="button" name="cancel" value="<?php print_string('cancel') ?>" onclick="document.location='view.php?id=<?php echo $form->course ?>'" />\r
+    </center>\r
+</form>\r
index 2a4b7d55d512671c0f0a9b30b9e2e5e56dad1fc1..17dc67327e0f8d8190f8df29ab7fc9933121d929 100755 (executable)
-<?PHP  // $Id$
-
-/// This page prints a particular instance of aicc/scorm package
-
-    require_once('../../config.php');
-    require_once('locallib.php');
-
-    //
-    // Checkin' script parameters
-    //
-    $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', 'normal', PARAM_ALPHA); // navigation mode
-    $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
-    $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
-
-    if (!empty($id)) {
-        if (! $cm = get_record("course_modules", "id", $id)) {
-            error("Course Module ID was incorrect");
-        }
-        if (! $course = get_record("course", "id", $cm->course)) {
-            error("Course is misconfigured");
-        }
-        if (! $scorm = get_record("scorm", "id", $cm->instance)) {
-            error("Course module is incorrect");
-        }
-    } else 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");
-        }
-    } else {
-        error('A required parameter is missing');
-    }
-
-    require_login($course->id, false, $cm);
-
-    $strscorms = get_string('modulenameplural', 'scorm');
-    $strscorm  = get_string('modulename', 'scorm');
-    $strpopup = get_string('popup','scorm');
-
-    if ($course->category != 0) {
-        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
-        if ($scorms = get_all_instances_in_course('scorm', $course)) {
-            // The module SCORM activity with the least id is the course  
-            $firstscorm = current($scorms);
-            if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) {
-                $navigation .= "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
-            }
-        }
-    } else {
-        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
-    }
-
-    $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
-
-    if (!$cm->visible and !isteacher($course->id)) {
-        print_header($pagetitle, "$course->fullname",
-                 "$navigation <a target='{$CFG->framename}' href='view.php?id=$cm->id'>".format_string($scorm->name,true)."</a>",
-                 '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);
-        notice(get_string("activityiscurrentlyhidden"));
-    }
-
-    //
-    // TOC processing
-    //
-    $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
-    if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
-        $attempt++;
-    }
-    $attemptstr = '&amp;attempt=' . $attempt;
-
-    $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true);
-    $sco = $result->sco;
-
-    if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
-       $mode = 'normal';
-    }
-    if ($mode != 'browse') {
-        if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) {
-            if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
-                $mode = 'review';
-            } else {
-                $mode = 'normal';
-            }
-        }
-    }
-
-    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;
-    if ($mode == 'browse') {
-        $modepop = '&mode='.$mode;
-    } else {
-        $modepop = '';
-    }
-    $orgstr = '&currentorg='.$currentorg;
-
-    $SESSION->scorm_scoid = $sco->id;
-    $SESSION->scorm_status = 'Not Initialized';
-    $SESSION->scorm_mode = $mode;
-    $SESSION->attempt = $attempt;
-
-    //
-    // Print the page header
-    //
-    $bodyscript = '';
-    if ($scorm->popup == 1) {
-        $bodyscript = 'onunload="main.close();"';
-    }
-    $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, $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
-    }
-    if (($sco->previd != 0) && ($sco->previous == 0)) {
-        $scostr = '&scoid='.$sco->previd;
-        echo '    <script language="javascript">var prev="'.$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."\";</script>\n";
-    } else {
-        echo '    <script language="javascript">var prev="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";</script>\n";
-    }
-    if (($sco->nextid != 0) && ($sco->next == 0)) {
-        $scostr = '&scoid='.$sco->nextid;
-        echo '    <script language="javascript">var next="'.$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."\";</script>\n";
-    } else {
-        echo '    <script language="javascript">var next="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";</script>\n";
-    }
-?>
-    <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>
-<?php
-        $class = ' class="toc"';
-    } else {
-        $class = ' class="no-toc"';
-    }
-?>
-        <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
-                   ) 
-               )
-           ) || ($scorm->hidetoc == 2)      // Teacher want to display toc in a small popup menu 
-       ) {
-?>
-            <div id="scormtop">
-        <?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) || ($scorm->hidetoc == 2)) {
-?>
-                <div id="scormnav" class="right">
-        <?php
-            $orgstr = '&amp;currentorg='.$currentorg;
-            if (($scorm->hidenav == 0) && ($sco->previd != 0) && ($sco->previous == 0)) {
-                /// Print the prev LO link
-                $scostr = '&amp;scoid='.$sco->previd;
-                $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
-                echo '<a href="'.$url.'">&lt; '.get_string('prev','scorm').'</a>';
-            }
-            if ($scorm->hidetoc == 2) {
-               echo $result->tocmenu;
-            }
-            if (($scorm->hidenav == 0) && ($sco->nextid != 0) && ($sco->next == 0)) {
-                /// Print the next LO link
-                $scostr = '&amp;scoid='.$sco->nextid;
-                $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
-                echo '            &nbsp;<a href="'.$url.'">'.get_string('next','scorm').' &gt;</a>';
-            }
-        ?>
-
-                </div>
-<?php
-        } 
-?>
-            </div>
-<?php
-    } // The end of the very big test
-?>
-            <div id="scormobject" class="right">
-                <noscript>
-                    <div id="noscript">
-                        <?php print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>
-
-                    </div>
-                </noscript>
-<?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 ?>"
-                        type="text/html">
-                     <?php print_string('noobjectsupport', 'scorm'); ?>
-                </object>
-<?php
-            }
-        } else {
-?>
-                    <script lanuguage="javascript">
-                        function openpopup(url,name,options,width,height) {
-                            fullurl = "<?php echo $CFG->wwwroot.'/mod/scorm/' ?>" + url;
-                            windowobj = window.open(fullurl,name,options);
-                            if ((width==100) && (height==100)) {
-                                // Fullscreen
-                                windowobj.moveTo(0,0);
-                            } 
-                            if (width<=100) {
-                                width = Math.round(screen.availWidth * width / 100);
-                            }
-                            if (height<=100) {
-                                height = Math.round(screen.availHeight * height / 100);
-                            }
-                            windowobj.resizeTo(width,height);
-                            windowobj.focus();
-                            return windowobj;
-                        }
-
-                        url = "loadSCO.php?id=<?php echo $cm->id.$scoidpop ?>";
-                        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 {
-        print_simple_box(get_string('noprerequisites','scorm'),'center');
-    }
-?>
-            </div> <!-- SCORM object -->
-        </div> <!-- SCORM box  -->
-    </div> <!-- SCORM content -->
-    </div> <!-- Content -->
-    </div> <!-- Page -->
-</body>
-</html>
-
+<?PHP  // $Id$\r
+\r
+/// This page prints a particular instance of aicc/scorm package\r
+\r
+    require_once('../../config.php');\r
+    require_once('locallib.php');\r
+    require_once('sequencinglib.php');\r
+    \r
+    //\r
+    // Checkin' script parameters\r
+    //\r
+    $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or\r
+    $a = optional_param('a', '', PARAM_INT);         // scorm ID\r
+    $scoid = required_param('scoid', PARAM_INT);  // sco ID\r
+    $mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode\r
+    $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization\r
+    $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt\r
+\r
+    if (!empty($id)) {\r
+        if (! $cm = get_record("course_modules", "id", $id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $cm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
+            error("Course module is incorrect");\r
+        }\r
+    } else if (!empty($a)) {\r
+        if (! $scorm = get_record("scorm", "id", $a)) {\r
+            error("Course module is incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $scorm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+    } else {\r
+        error('A required parameter is missing');\r
+    }\r
+\r
+    require_login($course->id, false, $cm);\r
+\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    //fwrite($ft,"\n ++ Thong tin quyen set attempt ".$USER->setAttempt);\r
+    $strscorms = get_string('modulenameplural', 'scorm');\r
+    $strscorm  = get_string('modulename', 'scorm');\r
+    $strpopup = get_string('popup','scorm');\r
+\r
+\r
+    $attempt = scorm_get_last_attempt($scorm->id,$USER->id);    \r
+    \r
+    //Kiem tra xem co phai la tiep tuc khong \r
+    if ($mode=='continue')\r
+    {\r
+        $scoid = scorm_get_suspendscoid($scorm->id,$USER->id);\r
+        $USER->setAttempt = 'set';\r
+        $mode = 'normal';\r
+    }\r
+    if (($mode == 'normal') && ($USER->setAttempt == 'notset')){\r
+        $attempt++;\r
+        $USER->setAttempt = 'set';\r
+    }\r
+    //Thuc hien Sequencing\r
+\r
+    if ($mode!='review')\r
+    {\r
+    $sequencingResult = scorm_sequecingrule_implement($scorm->id,$scoid,$USER->id);\r
+    //echo "<script language='JavaScript'>";\r
+    //    echo "alert('Sequencing');";\r
+    //echo "<script>";\r
+        if (($sequencingResult->rule == 'pre') && ($sequencingResult->action == 'disabled')){\r
+            echo "<script language='JavaScript'>";\r
+            echo "alert('Disabling');";\r
+            echo "</script>";        \r
+        }\r
+        if (($sequencingResult->rule == 'exit') && ($sequencingResult->action == 'exit')){\r
+            $exitscoid = get_sco_after_exit($scoid,$scorm->id);\r
+            //fwrite($ft,"\n ++ Thong tin exit sco la ".$exitscoid);\r
+            $orgstr = '&currentorg='.$currentorg;\r
+            $modepop = '&mode='.$mode;\r
+            $scostr = '&scoid='.$exitscoid;\r
+            echo "<script language='JavaScript'>";\r
+            echo "alert('Exiting');";\r
+            echo "location.href='".$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."';";\r
+            echo "</script>";                \r
+            \r
+        }        \r
+    }    \r
+\r
+    //Thiet lap attempt_status cho scoid\r
+    scorm_set_attempt($scoid,$USER->id);\r
+    //Ket thuc thiet lap attemp_status\r
+    if ($mode!='review')\r
+    {\r
+    //Update trang thai\r
+    scorm_rollup_updatestatus($scorm->id,$scoid,$USER->id);\r
+    //------------------------------\r
+    }    \r
+    //Thiet lap thong tin lien quan truy xuat Scorm\r
+    $statistic = get_record('scorm_statistic',"scormid",$scorm->id,"userid",$USER->id);\r
+    if (empty($statistic)){\r
+        $statisticInput->accesstime = time();\r
+        $statisticInput->durationtime = 0;\r
+        $statisticInput->status = 'during';\r
+        $statisticInput->attemptnumber = $attempt;\r
+        $statisticInput->scormid = $scorm->id;\r
+        $statisticInput->userid = $USER->id;\r
+        $statisticid = scorm_insert_statistic($statisticInput);\r
+    }\r
+    else{\r
+        if ($statistic->status=='suspend'){\r
+        $statisticInput->accesstime = time();\r
+        $statisticInput->durationtime = $statistic->durationtime;\r
+        $statisticInput->status = 'during';\r
+        $statisticInput->attemptnumber = $attempt;\r
+        $statisticInput->scormid = $scorm->id;\r
+        $statisticInput->userid = $USER->id;\r
+        }\r
+    }    \r
+\r
+    //---------------------Ket thuc thiet lap thoi gian ---------------\r
+\r
+    //Lay thoi gian toi da cho phep\r
+    $absoluteTimeLimit = scorm_get_AbsoluteTimeLimit($scoid);\r
+    if ($absoluteTimeLimit > 0)\r
+    {    \r
+        echo "<script type='text/javascript'>"; \r
+        echo "alert('Bai nay co thoi gian lam la: ".$absoluteTimeLimit."');";\r
+        echo "function remind(msg1) {"; \r
+        echo "var msg = 'Da het gio lam bai ' + msg1 +' Secs.Lua chon bai khac de tiep tuc';";\r
+        echo "alert(msg);"; \r
+        echo "window.location.href = 'view.php?id=".$scorm->id."';";\r
+        echo "}";\r
+        echo "setTimeout('remind(".$absoluteTimeLimit.")',".$absoluteTimeLimit.");";\r
+        echo "</script>";\r
+    }\r
+    //--------------------------------\r
+\r
+    \r
+    if ($course->category != 0) {\r
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";\r
+        if ($scorms = get_all_instances_in_course('scorm', $course)) {\r
+            // The module SCORM activity with the least id is the course  \r
+            $firstscorm = current($scorms);\r
+            if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) {\r
+                $navigation .= "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";\r
+            }\r
+        }\r
+    } else {\r
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";\r
+    }\r
+\r
+    $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));\r
+\r
+    if (!$cm->visible and !isteacher($course->id)) {\r
+        print_header($pagetitle, "$course->fullname",\r
+                 "$navigation <a target='{$CFG->framename}' href='view.php?id=$cm->id'>".format_string($scorm->name,true)."</a>",\r
+                 '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);\r
+        notice(get_string("activityiscurrentlyhidden"));\r
+    }\r
+\r
+    //\r
+    // TOC processing\r
+    //\r
+    //$attempt = scorm_get_last_attempt($scorm->id, $USER->id);\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    ////fwrite($ft,"\n ++ ++ + ++ Gia tri $attempt lay duoc la ".$attempt);\r
+\r
+    //if ($mode=='normal'){\r
+    //    $newattempt = 'on';\r
+    //}\r
+    if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {\r
+        $attempt++;\r
+        $f = "D:\\test.txt";\r
+        @$ft = fopen($f,"a");\r
+        //fwrite($ft,"\n ----New attempt------- ".$attempt);\r
+\r
+    }\r
+    $attemptstr = '&amp;attempt=' . $attempt;\r
+\r
+    //fwrite($ft,"\n ----Gia tri attempt bay gio la------- ".$attempt);\r
+    $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true);\r
+    $sco = $result->sco;\r
+\r
+    if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {\r
+       $mode = 'normal';\r
+    }\r
+    if ($mode != 'browse') {\r
+        ////fwrite($ft,"\n ++ ++ + ++ Gia tri $mode khac browser ".$mode);\r
+        if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) {\r
+            if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {\r
+                $mode = 'review';\r
+                ////fwrite($ft,"\n ++ ++ + ++ Gia tri $mode ".$mode);\r
+            } else {\r
+                $mode = 'normal';\r
+                ////fwrite($ft,"\n ++ ++ + ++ Gia tri $mode ".$mode);\r
+\r
+            }\r
+        }\r
+    }\r
+\r
+    add_to_log($course->id, 'scorm', 'view', "player.php?id=$cm->id&scoid=$sco->id", "$scorm->id");\r
+\r
+    $scoidstr = '&amp;scoid='.$sco->id;\r
+    $scoidpop = '&scoid='.$sco->id;\r
+    $modestr = '&amp;mode='.$mode;\r
+    if ($mode == 'browse') {\r
+        $modepop = '&mode='.$mode;\r
+    } else {\r
+        $modepop = '';\r
+    }\r
+    $orgstr = '&currentorg='.$currentorg;\r
+\r
+    $SESSION->scorm_scoid = $sco->id;\r
+    $SESSION->scorm_status = 'Not Initialized';\r
+    $SESSION->scorm_mode = $mode;\r
+    $SESSION->attempt = $attempt;\r
+\r
+    //    Doan code them\r
+    ////fwrite($ft,"\n ++ ++ + ++ Gia tri attempt duoc gan cho user la ".$attempt);\r
+    $USER->attempt = $attempt;\r
+    //------------Ket thuc doan them\r
+\r
+    //\r
+    // Print the page header\r
+    //\r
+    $bodyscript = '';\r
+    if ($scorm->popup == 1) {\r
+        $bodyscript = 'onunload="main.close();"';\r
+    }\r
+\r
+    // Kiem tra xem co duoc exit khong\r
+    if (scorm_isChoiceexit($sco->scorm,$sco->id)){\r
+    $exitlink = '(<a href="'.$CFG->wwwroot.'/course/view.php?id='.$cm->course.'">'.get_string('exit','scorm').'</a>)&nbsp;';\r
+    }\r
+    else\r
+    {\r
+    $exitlink = get_string('exitisnotallowed','scorm');\r
+    }\r
+\r
+    //Luu giu khoa hoc thoat ra\r
+    $suspend = '(<a href="suspend.php?scorm='.$sco->scorm.'&sco='.$sco->id.'&userid='.$USER->id.'&id='.$cm->course.'">'.get_string('suspend','scorm').'</a>)&nbsp;';\r
+\r
+    print_header($pagetitle, "$course->fullname",\r
+                 "$navigation <a target='{$CFG->framename}' href='view.php?id=$cm->id'>".format_string($scorm->name,true)."</a>",\r
+                 '', '', true, $exitlink.$suspend.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript);\r
+    if ($sco->scormtype == 'sco') {\r
+?>\r
+    <script language="JavaScript" type="text/javascript" src="request.js"></script>\r
+    <script language="JavaScript" type="text/javascript" src="api.php?id=<?php echo $cm->id.$scoidstr.$modestr.$attemptstr ?>"></script>\r
+<?php\r
+    }\r
+    if (($sco->previd != 0) && ($sco->previous == 0)) {\r
+        $scostr = '&scoid='.$sco->previd;\r
+        echo '    <script language="javascript">var prev="'.$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."\";</script>\n";\r
+    } else {\r
+        echo '    <script language="javascript">var prev="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";</script>\n";\r
+    }\r
+    if (($sco->nextid != 0) && ($sco->next == 0)) {\r
+        $scostr = '&scoid='.$sco->nextid;\r
+        echo '    <script language="javascript">var next="'.$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."\";</script>\n";\r
+    } else {\r
+        echo '    <script language="javascript">var next="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";</script>\n";\r
+    }\r
+?>\r
+    <div id="scormpage">\r
+<?php  \r
+    if ($scorm->hidetoc == 0) {\r
+?>\r
+        <div id="tocbox" class="generalbox">\r
+            <div id="tochead" class="header"><?php print_string('coursestruct','scorm') ?></div>\r
+            <div id="toctree">\r
+            <?php echo $result->toc; ?>\r
+            </div>\r
+        </div>\r
+<?php\r
+        $class = ' class="toc"';\r
+    } else {\r
+        $class = ' class="no-toc"';\r
+    }\r
+?>\r
+        <div id="scormbox"<?php echo $class ?>>\r
+<?php\r
+    // This very big test check if is necessary the "scormtop" div\r
+    if (\r
+           ($mode != 'normal') ||  // We are not in normal mode so review or browse text will displayed\r
+           (\r
+               ($scorm->hidenav == 0) &&  // Teacher want to display navigation links\r
+               (\r
+                   (\r
+                       ($sco->previd != 0) &&  // This is not the first learning object of the package\r
+                       ($sco->previous == 0)   // Moodle must manage the previous link\r
+                   ) || \r
+                   (\r
+                       ($sco->nextid != 0) &&  // This is not the last learning object of the package\r
+                       ($sco->next == 0)       // Moodle must manage the next link\r
+                   ) \r
+               )\r
+           ) || ($scorm->hidetoc == 2)      // Teacher want to display toc in a small dropdown menu \r
+       ) {\r
+?>\r
+            <div id="scormtop">\r
+        <?php echo $mode == 'browse' ? '<div id="scormmode" class="left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>\r
+        <?php echo $mode == 'review' ? '<div id="scormmode" class="left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>\r
+<?php\r
+        if (($scorm->hidenav == 0) || ($scorm->hidetoc == 2)) {\r
+?>\r
+                <div id="scormnav" class="right">\r
+        <?php\r
+            $orgstr = '&amp;currentorg='.$currentorg;\r
+            if (($scorm->hidenav == 0) && ($sco->previd != 0) && ($sco->previous == 0)) {\r
+                /// Print the prev LO link\r
+                $scostr = '&amp;scoid='.$sco->previd;\r
+                $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;\r
+                echo '<a href="'.$url.'">&lt; '.get_string('prev','scorm').'</a>';\r
+            }\r
+            if ($scorm->hidetoc == 2) {\r
+                echo $result->tocmenu;\r
+            }\r
+            if (($scorm->hidenav == 0) && ($sco->nextid != 0) && ($sco->next == 0)) {\r
+                /// Print the next LO link\r
+                $scostr = '&amp;scoid='.$sco->nextid;\r
+                $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;\r
+                echo '            &nbsp;<a href="'.$url.'">'.get_string('next','scorm').' &gt;</a>';\r
+            }\r
+        ?>\r
+\r
+                </div>\r
+<?php\r
+        } \r
+?>\r
+            </div>\r
+<?php\r
+    } // The end of the very big test\r
+?>\r
+            <div id="scormobject" class="right">\r
+                <noscript>\r
+                    <div id="noscript">\r
+                        <?php print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>\r
+\r
+                    </div>\r
+                </noscript>\r
+<?php\r
+    if ($result->prerequisites) {\r
+        if ($scorm->popup == 0) {\r
+            if (strpos('MSIE',$_SERVER['HTTP_USER_AGENT']) === false) { \r
+                /// Internet Explorer does not has full support to objects\r
+?>\r
+                <iframe id="main"\r
+                        width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" \r
+                        height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" \r
+                        src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">\r
+                </iframe>\r
+<?php\r
+            } else {\r
+?>\r
+                <object id="main" \r
+                        class="scoframe" \r
+                        width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" \r
+                        height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" \r
+                        data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>"\r
+                        type="text/html">\r
+                     <?php print_string('noobjectsupport', 'scorm'); ?>\r
+                </object>\r
+<?php\r
+            }\r
+        } else {\r
+?>\r
+                    <script lanuguage="javascript">\r
+                        function openpopup(url,name,options,width,height) {\r
+                            fullurl = "<?php echo $CFG->wwwroot.'/mod/scorm/' ?>" + url;\r
+                            windowobj = window.open(fullurl,name,options);\r
+                            if ((width==100) && (height==100)) {\r
+                                // Fullscreen\r
+                                windowobj.moveTo(0,0);\r
+                            } \r
+                            if (width<=100) {\r
+                                width = Math.round(screen.availWidth * width / 100);\r
+                            }\r
+                            if (height<=100) {\r
+                                height = Math.round(screen.availHeight * height / 100);\r
+                            }\r
+                            windowobj.resizeTo(width,height);\r
+                            windowobj.focus();\r
+                            return windowobj;\r
+                        }\r
+\r
+                        url = "loadSCO.php?id=<?php echo $cm->id.$scoidpop ?>";\r
+                        width = <?php p($scorm->width) ?>;\r
+                        height = <?php p($scorm->height) ?>;\r
+                        var main = openpopup(url, "<?php p($scorm->name) ?>", "<?php p($scorm->options) ?>", width, height);\r
+                    </script>\r
+                    <noscript>\r
+<?php\r
+            if (strpos('MSIE',$_SERVER['HTTP_USER_AGENT']) === false) { \r
+                /// Internet Explorer does not has full support to objects\r
+?>\r
+                    <iframe id="main"\r
+                            width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" \r
+                            height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" \r
+                            src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">\r
+                    </iframe>\r
+<?php\r
+            } else {\r
+?>\r
+                    <object id="main" \r
+                            class="scoframe" \r
+                            width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" \r
+                            height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" \r
+                            data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>"\r
+                            type="text/html">\r
+                         <?php print_string('noobjectsupport', 'scorm'); ?>\r
+                    </object>\r
+<?php\r
+            }\r
+?>\r
+                    </noscript>\r
+<?php            \r
+        }\r
+    } else {\r
+        print_simple_box(get_string('noprerequisites','scorm'),'center');\r
+    }\r
+?>\r
+            </div> <!-- SCORM object -->\r
+        </div> <!-- SCORM box  -->\r
+    </div> <!-- SCORM content -->\r
+    </div> <!-- Content -->\r
+    </div> <!-- Page -->\r
+\r
+</body>\r
+</html>\r
+\r
index 59f56688aede139fe99cab56f390d2a4116fe8b8..6145e401543650681eb94bc165336fa1516db759 100755 (executable)
-<?php  // $Id$
-
-// This script uses installed report plugins to print quiz reports
-
-    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
-    $b = optional_param('b', '', PARAM_INT);     // SCO ID
-    $user = optional_param('user', '', PARAM_INT);  // User ID
-
-    if (!empty($id)) {
-        if (! $cm = get_record("course_modules", "id", $id)) {
-            error("Course Module ID was incorrect");
-        }
-        if (! $course = get_record("course", "id", $cm->course)) {
-            error("Course is misconfigured");
-        }
-        if (! $scorm = get_record("scorm", "id", $cm->instance)) {
-            error("Course module is incorrect");
-        }
-    } else {
-        if (!empty($b)) {
-            if (! $sco = get_record("scorm_scoes", "id", $b)) {
-                error("Scorm activity is incorrect");
-            }
-            $a = $sco->scorm;
-        }
-        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");
-            }
-        }
-    }
-
-    require_login($course->id, false, $cm);
-
-    if (!isteacher($course->id)) {
-        error("You are not allowed to use this script");
-    }
-
-    add_to_log($course->id, "scorm", "report", "report.php?id=$cm->id", "$scorm->id");
-
-/// Print the page header
-    if (empty($noheader)) {
-        if ($course->category) {
-            $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
-        } else {
-            $navigation = '';
-        }
-
-        $strscorms = get_string("modulenameplural", "scorm");
-        $strscorm  = get_string("modulename", "scorm");
-        $strreport  = get_string("report", "scorm");
-        $strname  = get_string('name');
-        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",
-                     "", "", true);
-        } else {
-            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>
-              -> <a href=\"report.php?id=$cm->id\">$strreport</a> -> $sco->title",
-                     "", "", true);
-        }
-        print_heading(format_string($scorm->name));
-    }
-
-    $scormpixdir = $CFG->modpixpath.'/scorm/pix';
-
-    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();
-                $table->head = array('&nbsp;', $strname);
-                $table->align = array('center', 'left');
-                $table->wrap = array('nowrap', 'nowrap');
-                $table->width = '100%';
-                $table->size = array(10, '*');
-                foreach ($scoes as $sco) {
-                    if ($sco->launch!='') {
-                        $table->head[]=scorm_string_wrap($sco->title);
-                        //$table->head[]=$sco->title;
-                        $table->align[] = 'center';
-                        $table->wrap[] = 'nowrap';
-                        $table->size[] = '*';
-                    }
-                }
-
-                foreach ($scousers as $scouser) {
-                    if ($userdata = scorm_get_user_data($scouser->userid)) {
-                        $row = array();
-                        $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true);
-                        $row[] = "<a href=\"$CFG->wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">".
-                                 "$userdata->firstname $userdata->lastname</a>";
-                        foreach ($scoes as $sco) {
-                            if ($sco->launch!='') {
-                                $anchorstart = '';
-                                $anchorend = '';
-                                $scoreview = '';
-                                if ($trackdata = scorm_get_tracks($sco->id,$scouser->userid)) {
-                                    if ($trackdata->score_raw != '') {
-                                        $scoreview = '<br />'.get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;
-                                    }
-                                    if ($trackdata->status == '') {
-                                        $trackdata->status = 'notattempted';
-                                    } else {
-                                        $anchorstart = '<a href="report.php?b='.$sco->id.'&user='.$scouser->userid.'" title="'.
-                                                       get_string('details','scorm').'">';
-                                        $anchorend = '</a>';
-                                    }
-                                } else {
-                                    $trackdata->status = 'notattempted';
-                                    $trackdata->total_time = '';
-                                }
-                                $strstatus = get_string($trackdata->status,'scorm');
-                                $row[] = $anchorstart.'<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
-                                         $strstatus.'">&nbsp;'.$trackdata->total_time.$scoreview.$anchorend;
-                            }
-                        }
-                        $table->data[] = $row;
-                    }
-                }
-                print_table($table);
-            } else {
-                notice('No users to report');
-            }
-        }
-    } else {
-        if (!empty($user)) {
-            if ($userdata = scorm_get_user_data($user)) {
-                print_simple_box_start('center');
-                print_heading(format_string($sco->title));
-                echo '<div align="center">'."\n";
-                print_user_picture($user, $course->id, $userdata->picture, false, false);
-                echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">".
-                     "$userdata->firstname $userdata->lastname</a><br />";
-                $scoreview = '';
-                if ($trackdata = scorm_get_tracks($sco->id,$user)) {
-                    if ($trackdata->score_raw != '') {
-                        $scoreview = get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;
-                    }
-                    if ($trackdata->status == '') {
-                        $trackdata->status = 'notattempted';
-                    }
-                } else {
-                    $trackdata->status = 'notattempted';
-                    $trackdata->total_time = '';
-                }
-                $strstatus = get_string($trackdata->status,'scorm');
-                echo '<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
-                $strstatus.'">&nbsp;'.$trackdata->total_time.'<br />'.$scoreview.'<br />';
-                echo '</div>'."\n";
-                echo '<hr /><h2>'.get_string('details','scorm').'</h2>';
-                
-                // Print general score data
-                $table = new stdClass();
-                $table->head = array(get_string('element','scorm'), get_string('value','scorm'));
-                $table->align = array('left', 'left');
-                $table->wrap = array('nowrap', 'nowrap');
-                $table->width = '100%';
-                $table->size = array('*', '*');
-                
-                $existelements = false;
-                if ($scorm->version == 'SCORM_1.3') {
-                    $elements = array('raw' => 'cmi.score.raw',
-                                      'min' => 'cmi.score.min',
-                                      'max' => 'cmi.score.max',
-                                      'status' => 'cmi.completition_status',
-                                      'time' => 'cmi.total_time');
-                } else {
-                    $elements = array('raw' => 'cmi.core.score.raw',
-                                      'min' => 'cmi.core.score.min',
-                                      'max' => 'cmi.core.score.max',
-                                      'status' => 'cmi.core.lesson_status',
-                                      'time' => 'cmi.core.total_time');
-                }
-                foreach ($elements as $key => $element) {
-                    if (isset($trackdata->$element)) {
-                        $existelements = true;
-                        $printedelements[]=$element;
-                        $row = array();
-                        $row[] = get_string($key,'scorm');
-                        $row[] = $trackdata->$element;
-                        $table->data[] = $row;
-                    }
-                }
-                if ($existelements) {
-                    echo '<h3>'.get_string('general','scorm').'</h3>';
-                    print_table($table);
-                }                
-                
-                // Print Interactions data
-                $table = new stdClass();
-                $table->head = array(get_string('identifier','scorm'),
-                                     get_string('type','scorm'),
-                                     get_string('result','scorm'),
-                                     get_string('student_response','scorm'));
-                $table->align = array('center', 'center', 'center', 'center');
-                $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap');
-                $table->width = '100%';
-                $table->size = array('*', '*', '*', '*', '*');
-                
-                $existinteraction = false;
-                
-                $i = 0;
-                $interactionid = 'cmi.interactions.'.$i.'.id';
-                
-                while (isset($trackdata->$interactionid)) {
-                    $existinteraction = true;
-                    $printedelements[]=$interactionid;
-                    $elements = array($interactionid,
-                                      'cmi.interactions.'.$i.'.type',
-                                      'cmi.interactions.'.$i.'.result',
-                                      'cmi.interactions.'.$i.'.student_response');
-                    $row = array();
-                    foreach ($elements as $element) {
-                        if (isset($trackdata->$element)) {
-                            $row[] = $trackdata->$element;
-                            $printedelements[]=$element;
-                        } else {
-                            $row[] = '&nbsp;';
-                        }
-                    }
-                    $table->data[] = $row;
-                    
-                    $i++;
-                    $interactionid = 'cmi.interactions.'.$i.'.id';
-                }
-                if ($existinteraction) {
-                    echo '<h3>'.get_string('interactions','scorm').'</h3>';
-                    print_table($table);
-                }
-                
-                // Print Objectives data
-                $table = new stdClass();
-                $table->head = array(get_string('identifier','scorm'),
-                                     get_string('status','scorm'),
-                                     get_string('raw','scorm'),
-                                     get_string('min','scorm'),
-                                     get_string('max','scorm'));
-                $table->align = array('center', 'center', 'center', 'center', 'center');
-                $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
-                $table->width = '100%';
-                $table->size = array('*', '*', '*', '*', '*');
-                
-                $existobjective = false;
-                
-                $i = 0;
-                $objectiveid = 'cmi.objectives.'.$i.'.id';
-                
-                while (isset($trackdata->$objectiveid)) {
-                    $existobjective = true;
-                    $printedelements[]=$objectiveid;
-                    $elements = array($objectiveid,
-                                      'cmi.objectives.'.$i.'.status',
-                                      'cmi.objectives.'.$i.'.score.raw',
-                                      'cmi.objectives.'.$i.'.score.min',
-                                      'cmi.objectives.'.$i.'.score.max');
-                    $row = array();
-                    foreach ($elements as $element) {
-                        if (isset($trackdata->$element)) {
-                            $row[] = $trackdata->$element;
-                            $printedelements[]=$element;
-                        } else {
-                            $row[] = '&nbsp;';
-                        }
-                    }
-                    $table->data[] = $row;
-                    
-                    $i++;
-                    $objectiveid = 'cmi.objectives.'.$i.'.id';
-                }
-                if ($existobjective) {
-                    echo '<h3>'.get_string('objectives','scorm').'</h3>';
-                    print_table($table);
-                }
-                $table = new stdClass();
-                $table->head = array(get_string('element','scorm'), get_string('value','scorm'));
-                $table->align = array('left', 'left');
-                $table->wrap = array('nowrap', 'wrap');
-                $table->width = '100%';
-                $table->size = array('*', '*');
-                
-                $existelements = false;
-                
-                foreach($trackdata as $element => $value) {
-                    if (substr($element,0,3) == 'cmi') { 
-                        if (!(in_array ($element, $printedelements))) {
-                            $existelements = true;
-                            $row = array();
-                            $row[] = get_string($element,'scorm') != '[['.$element.']]' ? get_string($element,'scorm') : $element;
-                            $row[] = $value;
-                            $table->data[] = $row;
-                        }
-                    }
-                }
-                if ($existelements) {
-                    echo '<h3>'.get_string('othertracks','scorm').'</h3>';
-                    print_table($table);
-                }                
-                print_simple_box_end();
-            }
-        } else {
-            error('Missing script parameter');
-        }
-    }
-    if (empty($noheader)) {
-        print_footer($course);
-    }
-?>
+<?php  // $Id$\r
+\r
+// This script uses installed report plugins to print quiz reports\r
+\r
+    require_once("../../config.php");\r
+    require_once('locallib.php');\r
+       require_once('sequencinglib.php');\r
+       \r
+    $id = optional_param('id', '', PARAM_INT);    // Course Module ID, or\r
+    $a = optional_param('a', '', PARAM_INT);     // SCORM ID\r
+    $b = optional_param('b', '', PARAM_INT);     // SCO ID\r
+    $user = optional_param('user', '', PARAM_INT);  // User ID\r
+\r
+    if (!empty($id)) {\r
+        if (! $cm = get_record("course_modules", "id", $id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $cm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
+            error("Course module is incorrect");\r
+        }\r
+    } else {\r
+        if (!empty($b)) {\r
+            if (! $sco = get_record("scorm_scoes", "id", $b)) {\r
+                error("Scorm activity is incorrect");\r
+            }\r
+            $a = $sco->scorm;\r
+        }\r
+        if (!empty($a)) {\r
+            if (! $scorm = get_record("scorm", "id", $a)) {\r
+                error("Course module is incorrect");\r
+            }\r
+            if (! $course = get_record("course", "id", $scorm->course)) {\r
+                error("Course is misconfigured");\r
+            }\r
+            if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
+                error("Course Module ID was incorrect");\r
+            }\r
+        }\r
+    }\r
+\r
+    require_login($course->id, false, $cm);\r
+\r
+    if (!isteacher($course->id)) {\r
+        error("You are not allowed to use this script");\r
+    }\r
+\r
+    add_to_log($course->id, "scorm", "report", "report.php?id=$cm->id", "$scorm->id");\r
+\r
+/// Print the page header\r
+    if (empty($noheader)) {\r
+        if ($course->category) {\r
+            $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";\r
+        } else {\r
+            $navigation = '';\r
+        }\r
+\r
+        $strscorms = get_string("modulenameplural", "scorm");\r
+        $strscorm  = get_string("modulename", "scorm");\r
+        $strreport  = get_string("report", "scorm");\r
+        $strname  = get_string('name');\r
+        if (empty($b)) {\r
+            print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",\r
+                     "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>\r
+                      -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a> -> $strreport",\r
+                     "", "", true);\r
+        } else {\r
+            print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",\r
+                     "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>\r
+                      -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a>\r
+              -> <a href=\"report.php?id=$cm->id\">$strreport</a> -> $sco->title",\r
+                     "", "", true);\r
+        }\r
+        print_heading(format_string($scorm->name));\r
+    }\r
+\r
+    $scormpixdir = $CFG->modpixpath.'/scorm/pix';\r
+\r
+    if (empty($b) ) {\r
+        if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) {\r
+            if ($scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) {\r
+                $table = new stdClass();\r
+                $table->head = array('&nbsp;', $strname);\r
+                $table->align = array('center', 'left');\r
+                $table->wrap = array('nowrap', 'nowrap');\r
+                $table->width = '100%';\r
+                $table->size = array(10, '*');\r
+                foreach ($scoes as $sco) {\r
+                    if ($sco->launch!='') {\r
+                        $table->head[]=scorm_string_wrap($sco->title);\r
+                        //$table->head[]=$sco->title;\r
+                        $table->align[] = 'center';\r
+                        $table->wrap[] = 'nowrap';\r
+                        $table->size[] = '*';\r
+                    }\r
+                }\r
+\r
+                foreach ($scousers as $scouser) {\r
+                    if ($userdata = scorm_get_user_data($scouser->userid)) {\r
+                        $row = array();\r
+                        $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true);\r
+                        $row[] = "<a href=\"$CFG->wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">".\r
+                                 "$userdata->firstname $userdata->lastname</a>";\r
+                        foreach ($scoes as $sco) {\r
+                            if ($sco->launch!='') {\r
+                                $anchorstart = '';\r
+                                $anchorend = '';\r
+                                $scoreview = '';\r
+                                if ($trackdata = scorm_get_tracks($sco->id,$scouser->userid)) {\r
+                                    if ($trackdata->score_raw != '') {\r
+                                        $scoreview = '<br />'.get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;\r
+                                    }\r
+                                    if ($trackdata->status == '') {\r
+                                        $trackdata->status = 'notattempted';\r
+                                    } else {\r
+                                        $anchorstart = '<a href="report.php?b='.$sco->id.'&user='.$scouser->userid.'" title="'.\r
+                                                       get_string('details','scorm').'">';\r
+                                        $anchorend = '</a>';\r
+                                    }\r
+                                } else {\r
+                                    $trackdata->status = 'notattempted';\r
+                                    $trackdata->total_time = '';\r
+                                }\r
+                                $strstatus = get_string($trackdata->status,'scorm');\r
+                                $row[] = $anchorstart.'<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.\r
+                                         $strstatus.'">&nbsp;'.$trackdata->total_time.$scoreview.$anchorend;\r
+                            }\r
+                        }\r
+                        $table->data[] = $row;\r
+                    }\r
+                }\r
+                print_table($table);\r
+            } else {\r
+                notice('No users to report');\r
+            }\r
+        }\r
+    } else {\r
+        if (!empty($user)) {\r
+            if ($userdata = scorm_get_user_data($user)) {\r
+                print_simple_box_start('center');\r
+                print_heading(format_string($sco->title));\r
+                echo '<div align="center">'."\n";\r
+                print_user_picture($user, $course->id, $userdata->picture, false, false);\r
+                echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">".\r
+                     "$userdata->firstname $userdata->lastname</a><br />";\r
+                $scoreview = '';\r
+                if ($trackdata = scorm_get_tracks($sco->id,$user)) {\r
+                    if ($trackdata->score_raw != '') {\r
+                        $scoreview = get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;\r
+                    }\r
+                    if ($trackdata->status == '') {\r
+                        $trackdata->status = 'notattempted';\r
+                    }\r
+                } else {\r
+                    $trackdata->status = 'notattempted';\r
+                    $trackdata->total_time = '';\r
+                }\r
+                $strstatus = get_string($trackdata->status,'scorm');\r
+                echo '<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.\r
+                $strstatus.'">&nbsp;'.$trackdata->total_time.'<br />'.$scoreview.'<br />';\r
+                echo '</div>'."\n";\r
+                echo '<hr /><h2>'.get_string('details','scorm').'</h2>';\r
+                \r
+                // Print general score data\r
+                $table = new stdClass();\r
+                $table->head = array(get_string('element','scorm'), get_string('value','scorm'));\r
+                $table->align = array('left', 'left');\r
+                $table->wrap = array('nowrap', 'nowrap');\r
+                $table->width = '100%';\r
+                $table->size = array('*', '*');\r
+                \r
+                $existelements = false;\r
+                if ($scorm->version == 'SCORM_1.3') {\r
+                    $elements = array('raw' => 'cmi.score.raw',\r
+                                      'min' => 'cmi.score.min',\r
+                                      'max' => 'cmi.score.max',\r
+                                      'status' => 'cmi.completition_status',\r
+                                      'time' => 'cmi.total_time');\r
+                } else {\r
+                    $elements = array('raw' => 'cmi.core.score.raw',\r
+                                      'min' => 'cmi.core.score.min',\r
+                                      'max' => 'cmi.core.score.max',\r
+                                      'status' => 'cmi.core.lesson_status',\r
+                                      'time' => 'cmi.core.total_time');\r
+                }\r
+                foreach ($elements as $key => $element) {\r
+                    if (isset($trackdata->$element)) {\r
+                        $existelements = true;\r
+                        $printedelements[]=$element;\r
+                        $row = array();\r
+                        $row[] = get_string($key,'scorm');\r
+                        $row[] = $trackdata->$element;\r
+                        $table->data[] = $row;\r
+                    }\r
+                }\r
+                if ($existelements) {\r
+                    echo '<h3>'.get_string('general','scorm').'</h3>';\r
+                    print_table($table);\r
+                }                \r
+                \r
+                // Print Interactions data\r
+                $table = new stdClass();\r
+                $table->head = array(get_string('identifier','scorm'),\r
+                                     get_string('type','scorm'),\r
+                                     get_string('result','scorm'),\r
+                                     get_string('student_response','scorm'));\r
+                $table->align = array('center', 'center', 'center', 'center');\r
+                $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap');\r
+                $table->width = '100%';\r
+                $table->size = array('*', '*', '*', '*', '*');\r
+                \r
+                $existinteraction = false;\r
+                \r
+                $i = 0;\r
+                $interactionid = 'cmi.interactions.'.$i.'.id';\r
+                \r
+                while (isset($trackdata->$interactionid)) {\r
+                    $existinteraction = true;\r
+                    $printedelements[]=$interactionid;\r
+                    $elements = array($interactionid,\r
+                                      'cmi.interactions.'.$i.'.type',\r
+                                      'cmi.interactions.'.$i.'.result',\r
+                                      'cmi.interactions.'.$i.'.student_response');\r
+                    $row = array();\r
+                    foreach ($elements as $element) {\r
+                        if (isset($trackdata->$element)) {\r
+                            $row[] = $trackdata->$element;\r
+                            $printedelements[]=$element;\r
+                        } else {\r
+                            $row[] = '&nbsp;';\r
+                        }\r
+                    }\r
+                    $table->data[] = $row;\r
+                    \r
+                    $i++;\r
+                    $interactionid = 'cmi.interactions.'.$i.'.id';\r
+                }\r
+                if ($existinteraction) {\r
+                    echo '<h3>'.get_string('interactions','scorm').'</h3>';\r
+                    print_table($table);\r
+                }\r
+                \r
+                // Print Objectives data\r
+                $table = new stdClass();\r
+                $table->head = array(get_string('identifier','scorm'),\r
+                                     get_string('status','scorm'),\r
+                                     get_string('raw','scorm'),\r
+                                     get_string('min','scorm'),\r
+                                     get_string('max','scorm'));\r
+                $table->align = array('center', 'center', 'center', 'center', 'center');\r
+                $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');\r
+                $table->width = '100%';\r
+                $table->size = array('*', '*', '*', '*', '*');\r
+                \r
+                $existobjective = false;\r
+                \r
+                $i = 0;\r
+                $objectiveid = 'cmi.objectives.'.$i.'.id';\r
+                \r
+                while (isset($trackdata->$objectiveid)) {\r
+                    $existobjective = true;\r
+                    $printedelements[]=$objectiveid;\r
+                    $elements = array($objectiveid,\r
+                                      'cmi.objectives.'.$i.'.status',\r
+                                      'cmi.objectives.'.$i.'.score.raw',\r
+                                      'cmi.objectives.'.$i.'.score.min',\r
+                                      'cmi.objectives.'.$i.'.score.max');\r
+                    $row = array();\r
+                    foreach ($elements as $element) {\r
+                        if (isset($trackdata->$element)) {\r
+                            $row[] = $trackdata->$element;\r
+                            $printedelements[]=$element;\r
+                        } else {\r
+                            $row[] = '&nbsp;';\r
+                        }\r
+                    }\r
+                    $table->data[] = $row;\r
+                    \r
+                    $i++;\r
+                    $objectiveid = 'cmi.objectives.'.$i.'.id';\r
+                }\r
+                if ($existobjective) {\r
+                    echo '<h3>'.get_string('objectives','scorm').'</h3>';\r
+                    print_table($table);\r
+                }\r
+                $table = new stdClass();\r
+                $table->head = array(get_string('element','scorm'), get_string('value','scorm'));\r
+                $table->align = array('left', 'left');\r
+                $table->wrap = array('nowrap', 'wrap');\r
+                $table->width = '100%';\r
+                $table->size = array('*', '*');\r
+                \r
+                $existelements = false;\r
+                \r
+                foreach($trackdata as $element => $value) {\r
+                    if (substr($element,0,3) == 'cmi') { \r
+                        if (!(in_array ($element, $printedelements))) {\r
+                            $existelements = true;\r
+                            $row = array();\r
+                            $row[] = get_string($element,'scorm') != '[['.$element.']]' ? get_string($element,'scorm') : $element;\r
+                            $row[] = $value;\r
+                            $table->data[] = $row;\r
+                        }\r
+                    }\r
+                }\r
+                if ($existelements) {\r
+                    echo '<h3>'.get_string('othertracks','scorm').'</h3>';\r
+                    print_table($table);\r
+                }                \r
+                print_simple_box_end();\r
+            }\r
+        } else {\r
+            error('Missing script parameter');\r
+        }\r
+    }\r
+       \r
+    print_heading(format_string(get_string('timestatistic','scorm')));\r
+       $scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid");        \r
+    $attempt = scorm_get_last_attempt($scorm->id,$USER->id);   \r
+       \r
+       foreach($scousers as $scouser){\r
+               $str = 'scormid ='.($scorm->id).' and userid = '.$scouser->userid.' and attempt = '.$attempt.' ORDER BY timemodified asc';\r
+               $endtrack       = get_record_select("scorm_scoes_track", $str,'max(timemodified) as maxtimemodified');\r
+\r
+       }\r
+\r
+//Phan trinh bay thong ke theo thoi gian\r
+               $table = new stdClass();\r
+               $table->head = array('&nbsp;', get_string('name','scorm'));\r
+               $table->align = array('center', 'left');\r
+               $table->wrap = array('nowrap', 'nowrap');\r
+               $table->width = '100%';\r
+               $table->size = array(10, '*');\r
+\r
+               $table->head[]=scorm_string_wrap(get_string('beginTime','scorm'));\r
+               $table->align[] = 'center';\r
+               $table->wrap[] = 'nowrap';\r
+               $table->size[] = '*';\r
+\r
+               $table->head[]=scorm_string_wrap(get_string('endTime','scorm'));\r
+               $table->align[] = 'center';\r
+               $table->wrap[] = 'nowrap';\r
+               $table->size[] = '*';\r
+\r
+               $row = array();\r
+               $row[] = "";\r
+               $row[] = "(".get_string('coefficient','scorm').")";\r
+       foreach($scousers as $scouser){\r
+               $userdata = scorm_get_user_data($scouser->userid);\r
+               $row = array();\r
+               $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true);\r
+               $row[] = "<a href=\"$CFG->wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">".\r
+                                                "$userdata->firstname $userdata->lastname</a>";        \r
+               $str = 'scormid ='.($scorm->id).' and userid = '.$scouser->userid.' and attempt = '.$attempt.' ORDER BY timemodified asc';\r
+               $begintrack     = get_record_select("scorm_scoes_track", $str,'min(timemodified) as mintimemodified');          \r
+               $row[] = strftime( "%H h -%M ' - %S s - %d -%m-%Y", $begintrack->mintimemodified);              \r
+               $endtrack       = get_record_select("scorm_scoes_track", $str,'max(timemodified) as maxtimemodified');\r
+               $row[] = strftime( "%H h -%M ' - %S s - %d -%m-%Y", $endtrack->maxtimemodified);\r
+        $table->data[] = $row;\r
+               }\r
+               print_table($table);\r
+       \r
+       echo "<br><a href='viewScore.php?a=$scorm->id'>".format_string(get_string('viewscore','scorm'))."</a>";\r
+    if (empty($noheader)) {\r
+        print_footer($course);\r
+    }\r
+?>\r
index 9a2e7e29a3a668f52ef921b01bb97ef35d71f2e3..748d64856973d4f20e74d2718550b97e53ce1f01 100755 (executable)
             if (!is_int($scorm->grademethod)) {
                 $scorm->grademethod = 0;
             }
-            $scorm->maxattempt = backup_todb($info['MOD']['#']['MAXATTEMPT']['0']['#']);
-            if (!is_int($scorm->maxattempt)) {
-                $scorm->maxattempt = 1;
-            }
             if ($restore->backup_version < 2005041500) {
                 $scorm->datadir = substr(backup_todb($info['MOD']['#']['DATADIR']['0']['#']),1);
             } else {
             $scotrack->scormid = $scorm_id;
             $scotrack->userid = backup_todb($sub_info['#']['USERID']['0']['#']);
             $scotrack->scoid = backup_todb($sub_info['#']['SCOID']['0']['#']);
-            $scotrack->attempt = backup_todb($sub_info['#']['ATTEMPT']['0']['#']);
-            if (!is_int($scotrack->attempt)) {
-                $scotrack->attempt = 1;
-            }
             $scotrack->element = backup_todb($sub_info['#']['ELEMENT']['0']['#']);
             $scotrack->value = backup_todb($sub_info['#']['VALUE']['0']['#']);
 
                     $status = update_record("scorm",$scorm);
                     if ($CFG->debug>7) {
                         if (!defined('RESTORE_SILENTLY')) {
-                            echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
+                            echo '<br /><hr />'.htmlentities($content).'<br />changed to<br />'.htmlentities($result).'<hr /><br />';
                         }
                     }
                 }
diff --git a/mod/scorm/sequencinglib.php b/mod/scorm/sequencinglib.php
new file mode 100755 (executable)
index 0000000..bd0c321
--- /dev/null
@@ -0,0 +1,513 @@
+<?php \r
+\r
+// Cac ham danh cho viec thuc thi Sequencing\r
+// --------Ket thuc cac ham danh cho viec thuc thi Sequencing ------------\r
+\r
+// Cac ham danh cho viec thuc thi Rollup\r
+\r
+//-----------------------------------------------------\r
+function scorm_rollup_updatestatus($scormid,$scoidchild, $userid)\r
+{\r
+    //$f = "D:\\test.txt";\r
+    //@$ft = fopen($f,"a");\r
+    //fwrite($ft,"\n >>>>> SCO goi Rollup la ".$scoidchild);\r
+    $scochild = get_record("scorm_scoes","id",$scoidchild);\r
+    $scoparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$scochild->parent);\r
+    //Danh sach cac con cua cha\r
+    $scochildren = get_records_select("scorm_scoes","scorm =".$scormid." and parent ='".$scoparent->identifier."'");\r
+    //Lay gia tri last attempt\r
+    //fwrite($ft,"\n >>>>> Bat dau xu ly Rollup SCO cha ".$scoparent->id);\r
+    $attempt = scorm_get_last_attempt($scormid,$userid);\r
+    \r
+    if(!empty($scoparent)){\r
+        $scoid = $scoparent->id;\r
+        $rolluprules = get_record("scorm_sequencing_rolluprules","scormid",$scormid,"scoid",$scoid);\r
+        if (!empty($rolluprules)){\r
+            $idrolluprules = $rolluprules->id;\r
+            $rules = get_records_select('scorm_sequencing_rolluprule','scoid ='.$scoid.'  and rolluprulesid ='. $idrolluprules);\r
+    \r
+            foreach ($rules as $rule){\r
+                $ruleid = $rule->id;\r
+                $ruleConditions = get_record("scorm_sequencing_rollupruleconditions","scoid",$scoid,"rollupruleid",$ruleid);            \r
+                $idruleConditions = $ruleConditions->id;\r
+                $conditions = get_records_select('scorm_sequencing_rolluprulecondition','scoid ='.$scoid.'  and ruleconditionsid ='.$idruleConditions);    \r
+    \r
+                //Truong hop 1: childactivitySet = all\r
+                //                conditioncombination = any\r
+                if (($rule->childactivityset == 'all') && ($ruleConditions->conditioncombination=='any')){\r
+                    foreach($conditions as $condition){\r
+                        $conditionOK = false;   \r
+                        //Condition 1:    condition = attempted         operator = 'noOp'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'attempted') && ($condition->operator=='noOp')){\r
+                        $conditionOK = true; \r
+                            foreach ($scochildren as $sco){\r
+                                //fwrite($ft,"\n >>>>> Xu ly Rollup voi dieu kien attempt  \n");\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->attempt_status != 'attempted'){\r
+                                    //fwrite($ft,"\n >>>>> Co SCO con chua attempted  \n");\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                        }\r
+                        //Condition 2:    condition = attempted         operator = 'not'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'attempted') && ($condition->operator=='not')){\r
+                        $conditionOK = true; \r
+                            foreach ($scochildren as $sco){\r
+                                //fwrite($ft,"\n >>>>> Xu ly Rollup voi dieu kien not attempt  \n");\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->attempt_status != 'notattempted'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                        }                    \r
+                        //Condition 3:    condition = satisfied         operator = 'noOp'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'satisfied') && ($condition->operator=='noOp')){\r
+                        $conditionOK = true; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->satisfied_status != 'satisfied'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                        }\r
+                        //Condition 4:    condition = satisfied         operator = 'not'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'satisfied') && ($condition->operator=='not')){\r
+                        $conditionOK = true; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->satisfied_status != 'notSatisfied'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                        }                    \r
+                        //Condition 5:    condition = completed         operator = 'noOp'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'completed') && ($condition->operator=='noOp')){\r
+                        $conditionOK = true; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->attempt_status != 'completed'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                        }    \r
+                        //Condition 6:    condition = completed         operator = 'not'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'completed') && ($condition->operator=='not')){\r
+                        $conditionOK = true; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->attempt_status != 'notcompleted'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                        }                                    \r
+                        //Neu dieu kien van dung sau khi xem xet thi thuc hien action\r
+                        if ($conditionOK == true){\r
+                            if ($ruleConditions->rollupruleaction == 'completed')\r
+                            {\r
+                            scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.completion_status','completed');\r
+                            //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong voi completed cho SCO ".$scoid);\r
+                            }\r
+                            if ($ruleConditions->rollupruleaction == 'satisfied')\r
+                            {\r
+                            scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','passed');\r
+                            //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong  voi satisfied\n");\r
+                            }\r
+                            if ($ruleConditions->rollupruleaction == 'notSatisfied')\r
+                            {\r
+                            scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','failed');\r
+                            //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong  voi notSatisfied\n");\r
+                            }                                                        \r
+                            //echo "<script language='JavaScript'>";\r
+                            //echo "alert('Thuc hien rollup. Trang thai ".$scoparent->identifier." la hoan thanh voi userid".$userid."');";\r
+                            //echo "<script>";\r
+                            \r
+                        }\r
+                    }\r
+                }\r
+                //Ket thuc truong hop 1\r
+                //Truong hop 2: childactivitySet = any\r
+                //                conditioncombination = any\r
+                if (($rule->childactivityset == 'any') && ($ruleConditions->conditioncombination=='any')){\r
+                    $conditionOK = false;  \r
+                    foreach($conditions as $condition){\r
+                        //$conditionOK = false;   \r
+                        //Condition 1:    condition = attempted         operator = 'noOp'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'attempted') && ($condition->operator=='noOp')){\r
+                        $conditionOK = false; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->attempt_status = 'attempted'){\r
+                                    $conditionOK = true;\r
+                                }\r
+                            }\r
+                        }\r
+                        //Condition 2:    condition = attempted         operator = 'not'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'attempted') && ($condition->operator=='not')){\r
+                        $conditionOK = false; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->attempt_status = 'notattempted'){\r
+                                    $conditionOK = true;\r
+                                }\r
+                            }\r
+                        }                    \r
+                        //Condition 3:    condition = satisfied         operator = 'noOp'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'satisfied') && ($condition->operator=='noOp')){\r
+                        $conditionOK = false; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->satisfied_status = 'satisfied'){\r
+                                    $conditionOK = true;\r
+                                }\r
+                            }\r
+                        }\r
+                        //Condition 4:    condition = satisfied         operator = 'not'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'satisfied') && ($condition->operator=='not')){\r
+                        $conditionOK = false; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->satisfied_status = 'notSatisfied'){\r
+                                    //fwrite($ft,"\n >>>>> Xu ly Rollup voi notSatisfied\n");\r
+                                    $conditionOK = true;\r
+                                }\r
+                            }\r
+                        }                    \r
+                        //Condition 5:    condition = completed         operator = 'noOp'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'completed') && ($condition->operator=='noOp')){\r
+                        $conditionOK = false; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->attempt_status = 'completed'){\r
+                                    $conditionOK = true;\r
+                                }\r
+                            }\r
+                        }    \r
+                        //Condition 6:    condition = completed         operator = 'not'\r
+                        //                Thuc hien rollupaction \r
+                        if (($condition->condition == 'completed') && ($condition->operator=='not')){\r
+                        $conditionOK = false; \r
+                            foreach ($scochildren as $sco){\r
+                                $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                                if ($usertrack->attempt_status = 'notcompleted'){\r
+                                    $conditionOK = true;\r
+                                }\r
+                            }\r
+                        }                                    \r
+                        //Neu dieu kien van dung sau khi xem xet thi thuc hien action\r
+                        if ($conditionOK == true){\r
+                            if ($ruleConditions->rollupruleaction == 'completed')\r
+                            {\r
+                            scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.completion_status','completed');\r
+                            //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong voi completed\n");\r
+                            }\r
+                            if ($ruleConditions->rollupruleaction == 'satisfied')\r
+                            {\r
+                            scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','passed');\r
+                            //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong  voi satisfied\n");\r
+                            }\r
+                            if ($ruleConditions->rollupruleaction == 'notSatisfied')\r
+                            {\r
+                            scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','failed');\r
+                            //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong  voi notSatisfied\n");\r
+                            }                                                        \r
+                            //echo "<script language='JavaScript'>";\r
+                            //echo "alert('Thuc hien rollup. Trang thai ".$scoparent->identifier." la hoan thanh voi userid".$userid."');";\r
+                            //echo "<script>";\r
+                            \r
+                        }\r
+                    }\r
+                }\r
+                //Ket thuc truong hop 2\r
+                //Truong hop 3: childactivitySet = any\r
+                //                conditioncombination = all\r
+                if (($rule->childactivityset == 'any') && ($ruleConditions->conditioncombination=='all')){\r
+                    foreach ($scochildren as $sco){\r
+                    $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                    $conditionOK = true;  \r
+                        foreach($conditions as $condition){\r
+                            //Condition 1:    condition = attempted         operator = 'noOp'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'attempted') && ($condition->operator=='noOp')){\r
+                                if ($usertrack->attempt_status != 'attempted'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                            //Condition 2:    condition = attempted         operator = 'not'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'attempted') && ($condition->operator=='not')){\r
+                                if ($usertrack->attempt_status != 'notattempted'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }                    \r
+                            //Condition 3:    condition = satisfied         operator = 'noOp'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'satisfied') && ($condition->operator=='noOp')){\r
+                                if ($usertrack->attempt_status != 'satisfied'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                            //Condition 4:    condition = satisfied         operator = 'not'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'satisfied') && ($condition->operator=='not')){\r
+                                if ($usertrack->attempt_status != 'notSatisfied'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }                    \r
+                            //Condition 5:    condition = completed         operator = 'noOp'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'completed') && ($condition->operator=='noOp')){\r
+                                if ($usertrack->attempt_status != 'completed'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }    \r
+                            //Condition 6:    condition = completed         operator = 'not'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'completed') && ($condition->operator=='not')){\r
+                                if ($usertrack->attempt_status != 'notcompleted'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }                                    \r
+                            //Neu dieu kien van dung sau khi xem xet thi thuc hien action\r
+                        }\r
+                    }\r
+                    if ($conditionOK == true){\r
+                        if ($ruleConditions->rollupruleaction == 'completed')\r
+                        {\r
+                        scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.completion_status','completed');\r
+                        //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong voi completed\n");\r
+                        }\r
+                        if ($ruleConditions->rollupruleaction == 'satisfied')\r
+                        {\r
+                        scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','passed');\r
+                        //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong  voi satisfied\n");\r
+                        }\r
+                        if ($ruleConditions->rollupruleaction == 'notSatisfied')\r
+                        {\r
+                        scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','failed');\r
+                        //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong  voi notSatisfied\n");\r
+                        }                                                        \r
+                        //echo "<script language='JavaScript'>";\r
+                        //echo "alert('Thuc hien rollup. Trang thai ".$scoparent->identifier." la hoan thanh voi userid".$userid."');";\r
+                        //echo "<script>";\r
+                        \r
+                    }                    \r
+                }\r
+                //Ket thuc truong hop 3\r
+                //Truong hop 4: childactivitySet = all\r
+                //                conditioncombination = all\r
+                if (($rule->childactivityset == 'all') && ($ruleConditions->conditioncombination=='all')){\r
+                    $conditionOK = true;                \r
+                    foreach ($scochildren as $sco){\r
+                    $usertrack = scorm_get_tracks($sco->id,$userid);\r
+                        foreach($conditions as $condition){\r
+                            //Condition 1:    condition = attempted         operator = 'noOp'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'attempted') && ($condition->operator=='noOp')){\r
+                                if ($usertrack->attempt_status != 'attempted'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                            //Condition 2:    condition = attempted         operator = 'not'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'attempted') && ($condition->operator=='not')){\r
+                                if ($usertrack->attempt_status != 'notattempted'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }                    \r
+                            //Condition 3:    condition = satisfied         operator = 'noOp'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'satisfied') && ($condition->operator=='noOp')){\r
+                                if ($usertrack->attempt_status != 'satisfied'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }\r
+                            //Condition 4:    condition = satisfied         operator = 'not'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'satisfied') && ($condition->operator=='not')){\r
+                                if ($usertrack->attempt_status != 'notSatisfied'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }                    \r
+                            //Condition 5:    condition = completed         operator = 'noOp'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'completed') && ($condition->operator=='noOp')){\r
+                                if ($usertrack->attempt_status != 'completed'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }    \r
+                            //Condition 6:    condition = completed         operator = 'not'\r
+                            //                Thuc hien rollupaction \r
+                            if (($condition->condition == 'completed') && ($condition->operator=='not')){\r
+                                if ($usertrack->attempt_status != 'notcompleted'){\r
+                                    $conditionOK = false;\r
+                                }\r
+                            }                                    \r
+                            //Neu dieu kien van dung sau khi xem xet thi thuc hien action\r
+                        }\r
+                    }\r
+                    if ($conditionOK == true){\r
+                        if ($ruleConditions->rollupruleaction == 'completed')\r
+                        {\r
+                        scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.completion_status','completed');\r
+                        //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong voi completed\n");\r
+                        }\r
+                        if ($ruleConditions->rollupruleaction == 'satisfied')\r
+                        {\r
+                        scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','passed');\r
+                        //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong  voi satisfied\n");\r
+                        }\r
+                        if ($ruleConditions->rollupruleaction == 'notSatisfied')\r
+                        {\r
+                        scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','failed');\r
+                        //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong  voi notSatisfied\n");\r
+                        }                                                        \r
+                        //echo "<script language='JavaScript'>";\r
+                        //echo "alert('Thuc hien rollup. Trang thai ".$scoparent->identifier." la hoan thanh voi userid".$userid."');";\r
+                        //echo "<script>";\r
+                        \r
+                    }                    \r
+                }\r
+                //Ket thuc truong hop 4                                                \r
+            }    \r
+        }\r
+    \r
+        //Thuc hien de qui cho Rollup voi cac muc cha\r
+        $scograndparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$scoparent->parent);\r
+        if (!empty($scograndparent)){\r
+            //fwrite($ft,"\n >>>>> Quay lui Rollup SCO ".$scoparent->id);\r
+            scorm_rollup_updatestatus($scormid,$scoparent->id, $userid);\r
+        }\r
+    }\r
+}\r
+\r
+// --------Ket thuc cac ham danh cho viec thuc thi Rollup -------\r
+\r
+//---------Thuc hien sequencing rule -----------------\r
+function scorm_sequecingrule_implement($scormid,$scoidchild, $userid)\r
+{\r
+    $sequencingResult->rule = '';   //Rule co 3 truong hop exit, pre va post\r
+    $sequencingResult->action = '';\r
+    \r
+    \r
+    $f = "D:\\test.txt";\r
+    @$ft = fopen($f,"a");\r
+    //fwrite($ft,"\n >>>>> Kiem tra Sequencing \n");\r
+\r
+    $scochild = get_record("scorm_scoes","id",$scoidchild);\r
+    $scoparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$scochild->parent);\r
+    //Danh sach cac con cua cha\r
+    $scochildren = get_records_select("scorm_scoes","scorm =".$scormid." and parent ='".$scoparent->identifier."'");\r
+    //Lay gia tri last attempt\r
+    \r
+    $attempt = scorm_get_last_attempt($scormid,$userid);\r
+    \r
+    if(!empty($scoparent)){\r
+        //fwrite($ft,"\n >>>>> Kiem tra Sequencing : Co Parent\n");\r
+    \r
+        $scoid = $scoparent->id;\r
+        //Lay trang thai cua SCO cha\r
+        $usertrack = scorm_get_tracks($scoid,$userid);\r
+        //fwrite($ft,"\n >>>>> Kiem tra Sequencing : id Parent ".$scoid);                \r
+        //fwrite($ft,"\n >>>>> Kiem tra Sequencing : usertrack ".$usertrack->status);                        \r
+        $sequencingrules = get_records_select("scorm_sequencing_ruleconditions","scormid=".$scormid." and scoid=".$scoid);\r
+        if (!empty($sequencingrules)){\r
+            foreach($sequencingrules as $sequencingrule){\r
+                //fwrite($ft,"\n >>>>> Kiem tra Sequencing : Co Sequencing o SCO".$sequencingrule->scoid);        \r
+                \r
+                $idsequencingrule = $sequencingrule->id;\r
+                $ruleconditions = get_records_select('scorm_sequencing_rulecondition','scoid ='.$scoid.'  and ruleconditionsid ='. $idsequencingrule);\r
+        \r
+                $conditionOK = true;\r
+                //Truong hop 1: conditioncombination = all            \r
+                if ($sequencingrule->conditioncombination =='all'){\r
+                    //fwrite($ft,"\n >>>>> Kiem tra Sequencing :conditioncombination la all \n");        \r
+                    $conditionOK = true;\r
+                    //fwrite($ft,"\n >>>>> Usertrack->status la: ".$usertrack->status);\r
+                    foreach ($ruleconditions as $rulecondition){\r
+                        //Neu co mot dieu kien khong thoa man thi se khong dung\r
+                        if (($rulecondition->condition != $usertrack->status)&&($rulecondition->condition != $usertrack->success_status)&&($rulecondition->condition != $usertrack->satisfied_status)){\r
+                            $conditionOK = false;                \r
+                        }\r
+                    }    \r
+                }\r
+                //Truong hop 2: conditioncombination = any                        \r
+                if ($sequencingrule->conditioncombination =='any'){\r
+                    $conditionOK = false;            \r
+                    foreach ($ruleconditions as $rulecondition){\r
+                        //Neu co mot dieu kien thoa man thi se dung\r
+                        if (($rulecondition->condition == $usertrack->status) || ($rulecondition->condition == $usertrack->success_status) || ($rulecondition->condition == $usertrack->satisfied_status) ){\r
+                            $conditionOK = true;                \r
+                        }\r
+                    }    \r
+                }\r
+    \r
+                //fwrite($ft,"\n >>>>> Gia tri conditionOK sau khi kiem tra dk la: ".$conditionOK);\r
+                //Neu dieu kien van dung thi thuc hien Action            \r
+                if ($conditionOK == true){\r
+                    //fwrite($ft,"\n >>>>> Dieu kien Sequencing OK..Thuc hien Action \n");                \r
+                    //Truong hop 1: ExitAction la Exit\r
+                    if ($sequencingrule->exitconditionruleaction=='exit')\r
+                    {\r
+                    //fwrite($ft,"\n >>>>> Xu ly Sequencing thanh cong -- Thuc hien su kien exit \n");\r
+                    echo "<script language='JavaScript'>";\r
+                    echo "alert('Thuc hien sequen. Do Trang thai ".$scoparent->identifier." la hoan thanh. Tien hanh EXIT');";\r
+                    echo "</script>";\r
+                    $sequencingResult->rule = 'exit';\r
+                    $sequencingResult->action = 'exit';                                        \r
+                    }\r
+                    if ($sequencingrule->preconditionruleaction=='disabled')\r
+                    {\r
+                    //fwrite($ft,"\n >>>>> Xu ly Sequencing thanh cong -- Thuc hien su kien disable \n");\r
+                    echo "<script language='JavaScript'>";\r
+                    echo "alert('Thuc hien sequen. Do Trang thai ".$scoparent->identifier." la hoan thanh. Tien hanh Disable');";\r
+                    echo "</script>";                    \r
+                    $sequencingResult->rule = 'pre';\r
+                    $sequencingResult->action = 'disable';                                        \r
+                    \r
+                    }                    \r
+                    \r
+                }\r
+            }\r
+        }\r
+    }\r
+    return $sequencingResult;\r
+}\r
+function get_sco_after_exit($scoid,$scormid){\r
+    $scochild = get_record("scorm_scoes","id",$scoid);\r
+    $scoparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$scochild->parent);\r
+    $exitscoid = $scoid++;\r
+    $exitscochild = get_record("scorm_scoes","id",$exitscoid,"scorm",$scormid);\r
+    if (empty($exitscochild)){\r
+    //Da ra ngoai vung scoid. Hay day chinh la sco cuoi cung\r
+        return 0;\r
+    }\r
+    else{\r
+        $exitscoparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$exitscochild->parent);\r
+        //Neu chua ra khoi activity do thi tiep tuc\r
+        while ($exitscoparent->id == $scoparent->id){\r
+            $exitscoid++;\r
+            $exitscochild = get_record("scorm_scoes","id",$exitscoid);\r
+                if (empty($exitscochild)){\r
+                //Da ra ngoai vung scoid. Hay day chinh la sco cuoi cung\r
+                return 0;\r
+                }\r
+                else{\r
+                $exitscoparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$exitscochild->parent);\r
+                }\r
+        }\r
+    }\r
+    return $exitscoid;    \r
+}\r
+\r
+?>\r
index 409a5196bc03e8313268f44fd7f9c9e37bab7251..6950c457ad68ae8b629fa5642e82f920f7ac4149 100644 (file)
@@ -1,83 +1,93 @@
-.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 .left {
-  text-align: left;
-}
-.mod-scorm .center {
-  text-align: center;
-}
-.mod-scorm .right {
-  text-align: right;
-}
-.mod-scorm .scoframe {
-
-}
-
-#mod-scorm-player #scormpage {
-  position: relative;
-  width: 100%;
-}
-#mod-scorm-player #tocbox {
-  position: absolute;
-  left: 0px;
-  top: 0px;
-  width: 19%;
-}
-#mod-scorm-player #tochead {
-  text-align: center;
-  font-weight: bold;
-}
-#mod-scorm-player #scormbox {
-  position: absolute;
-  right: 0px;
-  top: 0px;
-}
-#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-player #scormbrowse {
-  position: absolute;
-  left: 5px;
-  top: 0px;
-}
-#mod-scorm-player #scormnav {
-  position: absolute;
-  right: 5px;
-  top: 0px;
-}
-#mod-scorm-player .structurelist {
-  list-style-type: none;
-  text-indent:-4ex;
-  font-size: small;
-}
-
-#mod-scorm-view .structurehead {
-  font-weight: bold;
-  text-align: center;
-}
-#mod-scorm-view .structurelist  {
-  list-style-type: none;
-  white-space: nowrap;
-}
+.structlist  {\r
+  list-style-type: none;\r
+  white-space: nowrap;\r
+  font-size: small;\r
+}\r
+.orgtitle {\r
+  font-weight: bold;\r
+  font-size: small;\r
+}\r
+.mod-scorm .top {\r
+  vertical-align: top;\r
+}\r
+.mod-scorm .left {\r
+  text-align: left;\r
+}\r
+.mod-scorm .center {\r
+  text-align: center;\r
+}\r
+.mod-scorm .right {\r
+  text-align: right;\r
+}\r
+.mod-scorm .scoframe {\r
+\r
+}\r
+\r
+#mod-scorm-player #scormpage {\r
+  position: relative;\r
+  width: 100%;\r
+}\r
+#mod-scorm-player #tocbox {\r
+  position: absolute;\r
+  left: 0px;\r
+  top: 0px;\r
+  width: 19%;\r
+}\r
+#mod-scorm-player #tochead {\r
+  text-align: center;\r
+  font-weight: bold;\r
+}\r
+#mod-scorm-player #scormbox {\r
+  position: absolute;\r
+  right: 0px;\r
+  top: 0px;\r
+}\r
+#mod-scorm-player .toc {\r
+  width: 80%; \r
+  margin-left: 20%; \r
+}\r
+#mod-scorm-player .no-toc {\r
+  width: 100%;\r
+}\r
+#mod-scorm-player #scormobject {\r
+ /* border: 1px solid black; */\r
+}\r
+#mod-scorm-player #scormtop {\r
+  position: relative;\r
+  width: 100%;\r
+  height: 30px;\r
+}\r
+#mod-scorm-player #scormbrowse {\r
+  position: absolute;\r
+  left: 5px;\r
+  top: 0px;\r
+}\r
+#mod-scorm-player #scormnav {\r
+  position: absolute;\r
+  right: 5px;\r
+  top: 0px;\r
+}\r
+#mod-scorm-player .structurelist {\r
+  list-style-type: none;\r
+  text-indent:-4ex;\r
+  font-size: small;\r
+}\r
+\r
+#mod-scorm-view .structurehead {\r
+  font-weight: bold;\r
+  text-align: center;\r
+}\r
+#mod-scorm-view .structurelist  {\r
+  list-style-type: none;\r
+  white-space: nowrap;\r
+}\r
+.scormtextbox {\r
+border-style: solid;\r
+border-width: 1;\r
+padding-left: 5;\r
+}\r
+.scormtableheader{\r
+font-face: Arial;\r
+color: #000066;\r
+font-weight: bold;\r
+}\r
diff --git a/mod/scorm/suspend.php b/mod/scorm/suspend.php
new file mode 100755 (executable)
index 0000000..e32dbeb
--- /dev/null
@@ -0,0 +1,36 @@
+<?php\r
+    require_once('../../config.php');\r
+    require_once('locallib.php');\r
+       require_once('sequencinglib.php');\r
+               \r
+//     $f = "D:\\test.txt";\r
+//     @$ft = fopen($f,"a");\r
+//     fwrite($ft,"Bat dau ghi tron datamodel.php \n");\r
+\r
+    $id = required_param('id', PARAM_INT);         // course ID\r
+    $scormid = required_param('scorm', PARAM_INT);         // scorm ID\r
+    $scoid = required_param('sco', PARAM_INT);  // suspend sco ID\r
+    $userid = required_param('userid', PARAM_INT);  // user ID\r
+\r
+       $attempt = scorm_get_last_attempt($scormid,$userid);\r
+       $statistic = get_record('scorm_statistic',"scormid",$scormid,"userid",$userid);\r
+       $statisticInput->accesstime = $statistic->accesstime;\r
+       $statisticInput->durationtime = $statistic->durationtime + time()- $statistic->accesstime;\r
+       $statisticInput->status = 'suspend';\r
+       $statisticInput->attemptnumber = $attempt;\r
+       $statisticInput->scormid = $statistic->scormid;\r
+       $statisticInput->userid = $statistic->userid;   \r
+       $statisticid = scorm_insert_statistic($statisticInput);\r
+\r
+    $result = scorm_insert_trackmodel($userid, $scormid, $scoid,$attempt);\r
+        if ($result) {\r
+                       echo "<script language='Javascript' type='text/javascript'>";\r
+                       echo "location.href='".$CFG->wwwroot." /course/view.php?id=".$id."';";      \r
+                       echo "</script>";\r
+        } \r
+               else {\r
+                       echo "Suspend failed";\r
+        }\r
+\r
+?>\r
+\r
diff --git a/mod/scorm/timePassReport.htm b/mod/scorm/timePassReport.htm
new file mode 100755 (executable)
index 0000000..8c0e3a0
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\r
+<html>\r
+<head>\r
+<title></title>\r
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\r
+</head>\r
+<body>\r
+Thời gian làm bài đã hết... Mời bạn chọn bài khác.\r
+</body>\r
+</html>\r
index d1a6988d75c4830823a6b94a8bd17a55828fddb5..ab06ff7d04a220b3ff3d9bc050a4dc326fdce0cb 100755 (executable)
-<?php // $Id$
-
-    require_once("../../config.php");
-    require_once('locallib.php');
-
-    $courseid = required_param('id', PARAM_INT);             // Course Module ID, or
-    $reference = required_param('reference', PARAM_PATH);    // Package path
-    $scormid = optional_param('instance', '', PARAM_INT);       // scorm ID
-
-    require_login($courseid, false);
-
-if (confirm_sesskey() && !empty($courseid)) {
-    $launch = 0;
-    $validation = new stdClass();
-    if (empty($reference)) {
-        $launch = -1;
-        $validation->result = "packagefile";
-    }
-    if (!empty($scormid)) {  
-        //
-        // SCORM Update
-        //
-        if (is_file($CFG->dataroot.'/'.$courseid.'/'.$reference)) {
-            $fp = fopen($CFG->dataroot.'/'.$courseid.'/'.$reference,"r");
-            $fstat = fstat($fp);
-            fclose($fp);
-            if ($scorm = get_record("scorm","id",$scormid)) {
-                $launch = $scorm->launch;
-                if ((($scorm->timemodified < $fstat["mtime"]) && ($scorm->reference == $reference)) || ($scorm->reference != $reference)) {
-                    // This is a new package
-                    $launch = 0;
-                } else {
-                    // Old package already validated
-                    $validation->result = 'found';
-                    if (strpos($scorm->version,'AICC') !== false) {
-                        $validation->pkgtype = 'AICC';
-                    } else {
-                        $validation->pkgtype = 'SCORM';
-                    }
-                }
-            } else {
-                $validation->result = 'badinstance';
-                $launch = -1;
-            }
-        } else {
-            $validation->result = 'badreference';
-            $launch = -1;
-        }
-    }
-    //$launch = 0;
-    if ($launch == 0) {
-        //
-        // Package must be validated
-        //
-
-        $ext = strtolower(substr(basename($reference),strrpos(basename($reference),'.')));
-        switch ($ext) {
-            case '.pif':
-            case '.zip':
-                // Create a temporary directory to unzip package and validate package
-                $tempdir = '';
-                $scormdir = '';
-                if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
-                    if ($tempdir = scorm_datadir($scormdir)) {
-                        copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference));
-                        unzip_file($tempdir."/".basename($reference), $tempdir, false);
-                        unlink ($tempdir."/".basename($reference));
-                        $validation = scorm_validate($tempdir);
-                    } else {
-                        $validation->result = "packagedir";
-                    }
-                } else {
-                    $validation->result = "datadir";
-                }
-            break;
-            case '.xml':
-                if (basename($reference) == 'imsmanifest.xml') {
-                    $validation = scorm_validate("$CFG->dataroot/$courseid/".dirname($reference));
-                } else {
-                    $validation->result = "manifestfile";
-                }
-            break;
-            default: 
-                $validation->result = "packagefile";
-            break;
-        }
-        if (($validation->result != "regular") && ($validation->result != "found")) {
-            $validation->result = get_string($validation->result,'scorm');
-            if (is_dir($tempdir)) {
-                // Delete files and temporary directory
-                scorm_delete_files($tempdir);
-            }
-        } else {
-            if ($ext == '.xml') {
-                $datadir = dirname($reference);
-            } else {
-                $datadir = substr($tempdir,strlen($scormdir));
-            }
-        }
-    }
-    //
-    // Print validation result
-    //
-    echo 'result=' . $validation->result . "\n";
-    echo 'launch=' . $launch . "\n";
-    if (isset($validation->pkgtype)) {
-        echo 'pkgtype=' . $validation->pkgtype . "\n";
-    }
-    if (isset($datadir)) {
-        echo 'datadir=' . $datadir . "\n";
-    }
-    if (isset($validation->errors[1])) {
-        echo 'errorlogs='."\n";
-        foreach($validation->errors as $error) {
-            echo get_string($error->type,"scorm",$error->data) . "\n";
-        }
-    }
-} else {
-    echo 'result=' . get_string('badrequest','scorm') . "\n";
-}
-?>
+<?php // $Id$\r
+\r
+    require_once("../../config.php");\r
+    require_once('locallib.php');\r
+       require_once('sequencinglib.php');\r
+       \r
+    $courseid = required_param('id', PARAM_INT);             // Course Module ID, or\r
+    $reference = required_param('reference', PARAM_PATH);    // Package path\r
+    $scormid = optional_param('instance', '', PARAM_INT);       // scorm ID\r
+\r
+    require_login($courseid, false);\r
+\r
+if (confirm_sesskey() && !empty($courseid)) {\r
+    $launch = 0;\r
+    $validation = new stdClass();\r
+    if (empty($reference)) {\r
+        $launch = -1;\r
+        $validation->result = "packagefile";\r
+    }\r
+    if (!empty($scormid)) {  \r
+        //\r
+        // SCORM Update\r
+        //\r
+        if (is_file($CFG->dataroot.'/'.$courseid.'/'.$reference)) {\r
+            $fp = fopen($CFG->dataroot.'/'.$courseid.'/'.$reference,"r");\r
+            $fstat = fstat($fp);\r
+            fclose($fp);\r
+            if ($scorm = get_record("scorm","id",$scormid)) {\r
+                $launch = $scorm->launch;\r
+                if ((($scorm->timemodified < $fstat["mtime"]) && ($scorm->reference == $reference)) || ($scorm->reference != $reference)) {\r
+                    // This is a new package\r
+                    $launch = 0;\r
+                } else {\r
+                    // Old package already validated\r
+                    $validation->result = 'found';\r
+                    if (strpos($scorm->version,'AICC') !== false) {\r
+                        $validation->pkgtype = 'AICC';\r
+                    } else {\r
+                        $validation->pkgtype = 'SCORM';\r
+                    }\r
+                }\r
+            } else {\r
+                $validation->result = 'badinstance';\r
+                $launch = -1;\r
+            }\r
+        } else {\r
+            $validation->result = 'badreference';\r
+            $launch = -1;\r
+        }\r
+    }\r
+    //$launch = 0;\r
+    if ($launch == 0) {\r
+        //\r
+        // Package must be validated\r
+        //\r
+\r
+        $ext = strtolower(substr(basename($reference),strrpos(basename($reference),'.')));\r
+        switch ($ext) {\r
+            case '.pif':\r
+            case '.zip':\r
+                // Create a temporary directory to unzip package and validate package\r
+                $tempdir = '';\r
+                $scormdir = '';\r
+                if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {\r
+                    if ($tempdir = scorm_datadir($scormdir)) {\r
+                        copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference));\r
+                        unzip_file($tempdir."/".basename($reference), $tempdir, false);\r
+                        unlink ($tempdir."/".basename($reference));\r
+                        $validation = scorm_validate($tempdir);\r
+                    } else {\r
+                        $validation->result = "packagedir";\r
+                    }\r
+                } else {\r
+                    $validation->result = "datadir";\r
+                }\r
+            break;\r
+            case '.xml':\r
+                if (basename($reference) == 'imsmanifest.xml') {\r
+                    $validation = scorm_validate("$CFG->dataroot/$courseid/".dirname($reference));\r
+                } else {\r
+                    $validation->result = "manifestfile";\r
+                }\r
+            break;\r
+            default: \r
+                $validation->result = "packagefile";\r
+            break;\r
+        }\r
+        if (($validation->result != "regular") && ($validation->result != "found")) {\r
+            $validation->result = get_string($validation->result,'scorm');\r
+            if (is_dir($tempdir)) {\r
+                // Delete files and temporary directory\r
+                scorm_delete_files($tempdir);\r
+            }\r
+        } else {\r
+            if ($ext == '.xml') {\r
+                $datadir = dirname($reference);\r
+            } else {\r
+                $datadir = substr($tempdir,strlen($scormdir));\r
+            }\r
+        }\r
+    }\r
+    //\r
+    // Print validation result\r
+    //\r
+    echo 'result=' . $validation->result . "\n";\r
+    echo 'launch=' . $launch . "\n";\r
+    if (isset($validation->pkgtype)) {\r
+        echo 'pkgtype=' . $validation->pkgtype . "\n";\r
+    }\r
+    if (isset($datadir)) {\r
+        echo 'datadir=' . $datadir . "\n";\r
+    }\r
+    if (isset($validation->errors[1])) {\r
+        echo 'errorlogs='."\n";\r
+        foreach($validation->errors as $error) {\r
+            echo get_string($error->type,"scorm",$error->data) . "\n";\r
+        }\r
+    }\r
+} else {\r
+    echo 'result=' . get_string('badrequest','scorm') . "\n";\r
+}\r
+?>\r
index 863842fd2f661779f3f53fc6f1dd335de46e3286..bd600fcb8b63404522a73b13fc8129700667ffb7 100755 (executable)
@@ -1,12 +1,12 @@
-<?php // $Id$
-
-/////////////////////////////////////////////////////////////////////////////////
-///  Code fragment to define the version of scorm
-///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
-/////////////////////////////////////////////////////////////////////////////////
-
-$module->version  = 2006021401;   // 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)?
-
-?>
+<?php // $Id$\r
+\r
+/////////////////////////////////////////////////////////////////////////////////\r
+///  Code fragment to define the version of scorm\r
+///  This fragment is called by moodle_needs_upgrading() and /admin/index.php\r
+/////////////////////////////////////////////////////////////////////////////////\r
+\r
+$module->version  = 2006050502;   // The (date) version of this module\r
+$module->requires = 2005060200;   // The version of Moodle that is required\r
+$module->cron     = 0;            // How often should cron check this module (seconds)?\r
+\r
+?>\r
index 64dd861fa7858615327658853d9f64e81e70bb95..ea17ce03e7e93bde3daa37ccd45676cbb7719fa5 100755 (executable)
-<?php  // $Id$
-
-/// This page prints a particular instance of scorm
-/// (Replace scorm with the name of your module)
-
-    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
-    //$organization = optional_param('organization', '', PARAM_INT); // organization ID
-
-    if (!empty($id)) {
-        if (! $cm = get_record("course_modules", "id", $id)) {
-            error("Course Module ID was incorrect");
-        }
-        if (! $course = get_record("course", "id", $cm->course)) {
-            error("Course is misconfigured");
-        }
-        if (! $scorm = get_record("scorm", "id", $cm->instance)) {
-            error("Course module is incorrect");
-        }
-    } else 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");
-        }
-    } else {
-        error('A required parameter is missing');
-    }
-
-    require_login($course->id, false, $cm);
-
-    if (isset($SESSION->scorm_scoid)) {
-        unset($SESSION->scorm_scoid);
-    }
-
-    $strscorms = get_string("modulenameplural", "scorm");
-    $strscorm  = get_string("modulename", "scorm");
-
-    if ($course->category != 0) { 
-        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
-        if ($scorms = get_all_instances_in_course('scorm', $course)) {
-            // The module SCORM activity with the least id is the course  
-            $firstscorm = current($scorms);
-            if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) {
-                $navigation .= "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
-            }       
-        }
-    } else {
-        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
-    }
-
-    $pagetitle = strip_tags($course->shortname.': '.format_string($scorm->name));
-
-    add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id");
-
-    //
-    // Print the page header
-    //
-    if (!$cm->visible and !isteacher($course->id)) {
-        print_header($pagetitle, "$course->fullname", "$navigation ".format_string($scorm->name), '', '', true,
-                     update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
-        notice(get_string('activityiscurrentlyhidden'));
-    } else {
-        print_header($pagetitle, "$course->fullname",
-                     "$navigation <a target=\"{$CFG->framename}\" href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a>",
-                     '', '', true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
-
-        if (isteacher($course->id)) {
-            $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');
-            if ($trackedusers->c > 0) {
-                echo "<div class=\"reportlink\"><a target=\"{$CFG->framename}\" href=\"report.php?id=$cm->id\">".get_string('viewallreports','scorm',$trackedusers->c).'</a></div>';
-            } else {
-                echo '<div class="reportlink">'.get_string('noreports','scorm').'</div>';
-            }
-        }
-        // Print the main part of the page
-
-        print_heading(format_string($scorm->name));
-
-        print_simple_box(format_text($scorm->summary), 'center', '70%', '', 5, 'generalbox', 'intro');
-        scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
-        print_footer($course);
-    }
-?>
+<?php  // $Id$\r
+\r
+/// This page prints a particular instance of scorm\r
+/// (Replace scorm with the name of your module)\r
+\r
+    require_once("../../config.php");\r
+    require_once('locallib.php');\r
+    require_once('sequencinglib.php');\r
+    \r
+    $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or\r
+    $a = optional_param('a', '', PARAM_INT);         // scorm ID\r
+    //$organization = optional_param('organization', '', PARAM_INT); // organization ID\r
+\r
+    if (!empty($id)) {\r
+        if (! $cm = get_record("course_modules", "id", $id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $cm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
+            error("Course module is incorrect");\r
+        }\r
+    } else if (!empty($a)) {\r
+        if (! $scorm = get_record("scorm", "id", $a)) {\r
+            error("Course module is incorrect");\r
+        }\r
+        if (! $course = get_record("course", "id", $scorm->course)) {\r
+            error("Course is misconfigured");\r
+        }\r
+        if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
+            error("Course Module ID was incorrect");\r
+        }\r
+    } else {\r
+        error('A required parameter is missing');\r
+    }\r
+\r
+    require_login($course->id, false, $cm);\r
+\r
+    if (isset($SESSION->scorm_scoid)) {\r
+        unset($SESSION->scorm_scoid);\r
+    }\r
+\r
+    $strscorms = get_string("modulenameplural", "scorm");\r
+    $strscorm  = get_string("modulename", "scorm");\r
+\r
+    if ($course->category != 0) { \r
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";\r
+        if ($scorms = get_all_instances_in_course('scorm', $course)) {\r
+            // The module SCORM activity with the least id is the course  \r
+            $firstscorm = current($scorms);\r
+            if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) {\r
+                $navigation .= "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";\r
+            }       \r
+        }\r
+    } else {\r
+        $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";\r
+    }\r
+\r
+    $pagetitle = strip_tags($course->shortname.': '.format_string($scorm->name));\r
+\r
+    add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id");\r
+\r
+    //\r
+    // Print the page header\r
+    //\r
+    if (!$cm->visible and !isteacher($course->id)) {\r
+        print_header($pagetitle, "$course->fullname", "$navigation ".format_string($scorm->name), '', '', true,\r
+                     update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));\r
+        notice(get_string('activityiscurrentlyhidden'));\r
+    } else {\r
+        print_header($pagetitle, "$course->fullname",\r
+                     "$navigation <a target=\"{$CFG->framename}\" href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a>",\r
+                     '', '', true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));\r
+\r
+        if (isteacher($course->id)) {\r
+\r
+        //Phan thiet lap he so diem\r
+            $examNumber = get_record_select('scorm_scoes', 'scorm ='.($scorm->id).' and minnormalizedmeasure > -1','count(id) as examCount');\r
+            //fwrite($ft,"\n So bai kiem tra la ".($examNumber->examCount));    \r
+            if ($examNumber->examCount > 0){\r
+                echo "<div class=\"reportlink\"><img src='pix\SuaHeSoDiem.png' /><a target=\"{$CFG->framename}\" href=\"coefficientSetting.php?id=$cm->id\"> ".get_string('scorecoefficientsetting','scorm',$examNumber->examCount).'</a></div>';\r
+            }\r
+\r
+        //-----------------------\r
+            $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');\r
+            if ($trackedusers->c > 0) {\r
+                echo "<div class=\"reportlink\"><img src='pix\ThongKe.png' /><a target=\"{$CFG->framename}\" href=\"report.php?id=$cm->id\"> ".get_string('viewallreports','scorm',$trackedusers->c).'</a></div>';\r
+            } else {\r
+                echo '<div class="reportlink">'.get_string('noreports','scorm').'</div>';\r
+            }\r
+        }\r
+\r
+        $USER->setAttempt = 'notset';\r
+        // Print the main part of the page\r
+        print_heading(format_string($scorm->name));\r
+        print_simple_box(format_text($scorm->summary), 'center', '70%', '', 5, 'generalbox', 'intro');\r
+        scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);\r
+        print_footer($course);\r
+    }\r
+?>\r