Merge branch 'wip-mdl-30121-m22' of git://github.com/rajeshtaneja/moodle into MOODLE_...
[moodle.git] / mod / scorm / loaddatamodel.php
blobfb6e2eb329a1ff2478c7abc4285315a0886f6b36
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 require_once("../../config.php");
18 require_once('locallib.php');
20 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
21 $a = optional_param('a', '', PARAM_INT); // scorm ID
22 $scoid = required_param('scoid', PARAM_INT); // sco ID
23 $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
24 $attempt = required_param('attempt', PARAM_INT); // new attempt
26 //IE 6 Bug workaround
27 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && ini_get('zlib.output_compression') == 'On') {
28 ini_set('zlib.output_compression', 'Off');
31 if (!empty($id)) {
32 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
33 print_error('invalidcoursemodule');
35 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
36 print_error('coursemisconf');
38 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
39 print_error('invalidcoursemodule');
41 } else if (!empty($a)) {
42 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
43 print_error('invalidcoursemodule');
45 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
46 print_error('coursemisconf');
48 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
49 print_error('invalidcoursemodule');
51 } else {
52 print_error('missingparameter');
55 $url = new moodle_url('/mod/scorm/loaddatamodel.php', array('scoid'=>$scoid, 'id'=>$cm->id, 'attempt'=>$attempt));
56 if ($mode !== '') {
57 $url->param('mode', $mode);
59 $PAGE->set_url($url);
61 require_login($course, false, $cm);
63 if ($usertrack = scorm_get_tracks($scoid, $USER->id, $attempt)) {
64 if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || (!scorm_version_check($scorm->version, SCORM_13))) {
65 foreach ($usertrack as $key => $value) {
66 $userdata->$key = addslashes_js($value);
68 } else {
69 $userdata->status = '';
70 $userdata->score_raw = '';
72 } else {
73 $userdata->status = '';
74 $userdata->score_raw = '';
76 $userdata->student_id = addslashes_js($USER->username);
77 $userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname);
78 $userdata->mode = 'normal';
79 if (isset($mode)) {
80 $userdata->mode = $mode;
82 if ($userdata->mode == 'normal') {
83 $userdata->credit = 'credit';
84 } else {
85 $userdata->credit = 'no-credit';
87 if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
88 foreach ($scodatas as $key => $value) {
89 $userdata->$key = addslashes_js($value);
91 } else {
92 print_error('cannotfindsco', 'scorm');
94 if (!$sco = scorm_get_sco($scoid)) {
95 print_error('cannotfindsco', 'scorm');
97 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
98 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
99 include($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
100 } else {
101 include($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
103 // set the start time of this SCO
104 scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, 'x.start.time', time());
107 var errorCode = "0";
108 function underscore(str) {
109 str = String(str).replace(/.N/g,".");
110 return str.replace(/\./g,"__");