Commit | Line | Data |
---|---|---|
5c2aa157 | 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/>. | |
5c2aa157 | 16 | |
f7b5c6aa DM |
17 | require_once("../../config.php"); |
18 | require_once('locallib.php'); | |
5c2aa157 | 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 | |
5c2aa157 | 25 | |
f7b5c6aa DM |
26 | //IE 6 Bug workaround |
27 | if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) { | |
28 | @ini_set('zlib.output_compression', 'Off'); | |
29 | @apache_setenv('no-gzip', 1); | |
30 | header( 'Content-Type: application/javascript' ); | |
31 | } | |
5c2aa157 | 32 | |
f7b5c6aa DM |
33 | if (!empty($id)) { |
34 | if (! $cm = get_coursemodule_from_id('scorm', $id)) { | |
35 | print_error('invalidcoursemodule'); | |
36 | } | |
37 | if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { | |
38 | print_error('coursemisconf'); | |
39 | } | |
40 | if (! $scorm = $DB->get_record('scorm', array('id'=>$cm->instance))) { | |
41 | print_error('invalidcoursemodule'); | |
42 | } | |
43 | } else if (!empty($a)) { | |
44 | if (! $scorm = $DB->get_record('scorm', array('id'=>$a))) { | |
45 | print_error('coursemisconf'); | |
5c2aa157 | 46 | } |
f7b5c6aa DM |
47 | if (! $course = $DB->get_record('course', array('id'=>$scorm->course))) { |
48 | print_error('coursemisconf'); | |
49 | } | |
50 | if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) { | |
51 | print_error('invalidcoursemodule'); | |
52 | } | |
53 | } else { | |
54 | print_error('missingparameter'); | |
55 | } | |
5c2aa157 | 56 | |
f7b5c6aa | 57 | $PAGE->set_url('/mod/scorm/api.php', array('scoid'=>$scoid, 'id'=>$cm->id)); |
5c2aa157 | 58 | |
f7b5c6aa | 59 | require_login($course->id, false, $cm); |
5c2aa157 | 60 | |
f7b5c6aa DM |
61 | if ($usertrack = scorm_get_tracks($scoid, $USER->id, $attempt)) { |
62 | //according to SCORM 2004 spec(RTE V1, 4.2.8), only cmi.exit==suspend should allow previous datamodel elements on re-launch | |
e6402b54 | 63 | if (!scorm_version_check($scorm->version, SCORM_13) || (isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} == 'suspend'))) { |
f7b5c6aa DM |
64 | foreach ($usertrack as $key => $value) { |
65 | $userdata->$key = addslashes_js($value); | |
5c2aa157 DM |
66 | } |
67 | } else { | |
68 | $userdata->status = ''; | |
69 | $userdata->score_raw = ''; | |
70 | } | |
f7b5c6aa DM |
71 | } else { |
72 | $userdata->status = ''; | |
73 | $userdata->score_raw = ''; | |
74 | } | |
75 | $userdata->student_id = addslashes_js($USER->username); | |
76 | $userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname); | |
77 | $userdata->mode = 'normal'; | |
ab94be6b | 78 | if (!empty($mode)) { |
f7b5c6aa DM |
79 | $userdata->mode = $mode; |
80 | } | |
81 | if ($userdata->mode == 'normal') { | |
82 | $userdata->credit = 'credit'; | |
83 | } else { | |
84 | $userdata->credit = 'no-credit'; | |
85 | } | |
86 | if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) { | |
87 | foreach ($scodatas as $key => $value) { | |
88 | $userdata->$key = addslashes_js($value); | |
5c2aa157 | 89 | } |
f7b5c6aa DM |
90 | } else { |
91 | print_error('cannotfindsco', 'scorm'); | |
92 | } | |
93 | if (!$sco = scorm_get_sco($scoid)) { | |
94 | print_error('cannotfindsco', 'scorm'); | |
95 | } | |
e6402b54 | 96 | if (scorm_version_check($scorm->version, SCORM_13)) { |
05c2b851 MG |
97 | $userdata->{'cmi.scaled_passing_score'} = $DB->get_field('scorm_seq_objective', 'minnormalizedmeasure', array('scoid'=>$scoid)); |
98 | } | |
f7b5c6aa DM |
99 | $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe |
100 | if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) { | |
101 | include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php'); | |
102 | } else { | |
103 | include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php'); | |
104 | } | |
105 | // set the start time of this SCO | |
106 | scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, 'x.start.time', time()); | |
5c2aa157 DM |
107 | ?> |
108 | ||
109 | ||
110 | var errorCode = "0"; | |
111 | function underscore(str) { | |
112 | str = String(str).replace(/.N/g,"."); | |
113 | return str.replace(/\./g,"__"); | |
114 | } |