2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * This page loads the correct JS file based on package type
21 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once("../../config.php");
26 require_once('locallib.php');
28 $id = optional_param('id', 0, PARAM_INT
); // Course Module ID, or
29 $a = optional_param('a', 0, PARAM_INT
); // scorm ID.
30 $scoid = required_param('scoid', PARAM_INT
); // sco ID.
31 $mode = optional_param('mode', '', PARAM_ALPHA
); // navigation mode.
32 $currentorg = optional_param('currentorg', '', PARAM_RAW
); // Selected organization.
33 $attempt = required_param('attempt', PARAM_INT
); // new attempt.
36 $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST
);
37 $course = $DB->get_record('course', array('id'=>$cm->course
), '*', MUST_EXIST
);
38 $scorm = $DB->get_record('scorm', array('id'=>$cm->instance
), '*', MUST_EXIST
);
39 } else if (!empty($a)) {
40 $scorm = $DB->get_record('scorm', array('id'=>$a), '*', MUST_EXIST
);
41 $course = $DB->get_record('course', array('id'=>$scorm->course
), '*', MUST_EXIST
);
42 $cm = get_coursemodule_from_instance('scorm', $scorm->id
, $course->id
, false, MUST_EXIST
);
44 print_error('missingparameter');
47 $PAGE->set_url('/mod/scorm/loaddatamodel.php', array('scoid'=>$scoid, 'id'=>$cm->id
));
49 require_login($course, false, $cm);
51 $userdata = new stdClass();
52 if ($usertrack = scorm_get_tracks($scoid, $USER->id
, $attempt)) {
53 // According to SCORM 2004 spec(RTE V1, 4.2.8), only cmi.exit==suspend should allow previous datamodel elements on re-launch.
54 if (!scorm_version_check($scorm->version
, SCORM_13
) ||
55 (isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} == 'suspend'))) {
56 foreach ($usertrack as $key => $value) {
57 $userdata->$key = addslashes_js($value);
60 $userdata->status
= '';
61 $userdata->score_raw
= '';
64 $userdata->status
= '';
65 $userdata->score_raw
= '';
67 $userdata->student_id
= addslashes_js($USER->username
);
68 $userdata->student_name
= addslashes_js($USER->lastname
.', '. $USER->firstname
);
69 $userdata->mode
= 'normal';
71 $userdata->mode
= $mode;
73 if ($userdata->mode
== 'normal') {
74 $userdata->credit
= 'credit';
76 $userdata->credit
= 'no-credit';
78 if ($scodatas = scorm_get_sco($scoid, SCO_DATA
)) {
79 foreach ($scodatas as $key => $value) {
80 $userdata->$key = addslashes_js($value);
83 print_error('cannotfindsco', 'scorm');
85 if (!$sco = scorm_get_sco($scoid)) {
86 print_error('cannotfindsco', 'scorm');
88 if (scorm_version_check($scorm->version
, SCORM_13
)) {
89 $objectives = $DB->get_records('scorm_seq_objective', array('scoid' => $scoid));
91 foreach ($objectives as $objective) {
92 if (!empty($objective->minnormalizedmeasure
)) {
93 $userdata->{'cmi.scaled_passing_score'} = $objective->minnormalizedmeasure
;
95 if (!empty($objective->objectiveid
)) {
96 $userdata->{'cmi.objectives.N'.$index.'.id'} = $objective->objectiveid
;
102 header('Content-Type: text/javascript; charset=UTF-8');
104 $scorm->version
= strtolower(clean_param($scorm->version
, PARAM_SAFEDIR
)); // Just to be safe.
105 if (file_exists($CFG->dirroot
.'/mod/scorm/datamodels/'.$scorm->version
.'.js.php')) {
106 include_once($CFG->dirroot
.'/mod/scorm/datamodels/'.$scorm->version
.'.js.php');
108 include_once($CFG->dirroot
.'/mod/scorm/datamodels/scorm_12.js.php');
110 // Set the start time of this SCO.
111 scorm_insert_track($USER->id
, $scorm->id
, $scoid, $attempt, 'x.start.time', time());
116 function underscore(str
) {
117 str
= String(str
).replace(/.N
/g
,".");
118 return str
.replace(/\
./g
,"__");