MDL-28933 SCORM use a global function to check SCORM version to make sure all methods...
[moodle.git] / mod / scorm / loaddatamodel.php
CommitLineData
03f5a0f8 1<?php
f7b5c6aa
DM
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.
13//
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/>.
03f5a0f8 16
f7b5c6aa
DM
17require_once("../../config.php");
18require_once('locallib.php');
9528568b 19
f7b5c6aa
DM
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
03f5a0f8 25
f7b5c6aa
DM
26//IE 6 Bug workaround
27if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && ini_get('zlib.output_compression') == 'On') {
28 ini_set('zlib.output_compression', 'Off');
29}
30
31if (!empty($id)) {
32 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
33 print_error('invalidcoursemodule');
15d0fae4 34 }
f7b5c6aa
DM
35 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
36 print_error('coursemisconf');
03f5a0f8 37 }
f7b5c6aa
DM
38 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
39 print_error('invalidcoursemodule');
5c508e3f 40 }
f7b5c6aa
DM
41} else if (!empty($a)) {
42 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
43 print_error('invalidcoursemodule');
03f5a0f8 44 }
f7b5c6aa
DM
45 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
46 print_error('coursemisconf');
03f5a0f8 47 }
f7b5c6aa
DM
48 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
49 print_error('invalidcoursemodule');
9528568b 50 }
f7b5c6aa
DM
51} else {
52 print_error('missingparameter');
53}
54
55$url = new moodle_url('/mod/scorm/loaddatamodel.php', array('scoid'=>$scoid, 'id'=>$cm->id, 'attempt'=>$attempt));
56if ($mode !== '') {
57 $url->param('mode', $mode);
58}
59$PAGE->set_url($url);
60
61require_login($course, false, $cm);
62
63if ($usertrack = scorm_get_tracks($scoid, $USER->id, $attempt)) {
e6402b54 64 if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || (!scorm_version_check($scorm->version, SCORM_13))) {
f7b5c6aa 65 foreach ($usertrack as $key => $value) {
dac958fc 66 $userdata->$key = addslashes_js($value);
2aaf134c 67 }
03f5a0f8 68 } else {
f7b5c6aa
DM
69 $userdata->status = '';
70 $userdata->score_raw = '';
2aa9a35e 71 }
f7b5c6aa
DM
72} else {
73 $userdata->status = '';
74 $userdata->score_raw = '';
75}
76$userdata->student_id = addslashes_js($USER->username);
77$userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname);
78$userdata->mode = 'normal';
79if (isset($mode)) {
80 $userdata->mode = $mode;
81}
82if ($userdata->mode == 'normal') {
83 $userdata->credit = 'credit';
84} else {
85 $userdata->credit = 'no-credit';
86}
87if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
88 foreach ($scodatas as $key => $value) {
89 $userdata->$key = addslashes_js($value);
03f5a0f8 90 }
f7b5c6aa
DM
91} else {
92 print_error('cannotfindsco', 'scorm');
93}
94if (!$sco = scorm_get_sco($scoid)) {
95 print_error('cannotfindsco', 'scorm');
96}
97$scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
98if (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');
102}
103// set the start time of this SCO
104scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, 'x.start.time', time());
03f5a0f8 105?>
106
107var errorCode = "0";
108function underscore(str) {
d5f3bdc9 109 str = String(str).replace(/.N/g,".");
03f5a0f8 110 return str.replace(/\./g,"__");
111}