SCORM MDL-22951 New player for SCORM fixes major regression that prevents some SCORM...
[moodle.git] / mod / scorm / api.php
CommitLineData
5c2aa157
DM
1<?php
2
3 require_once("../../config.php");
4 require_once('locallib.php');
5
6 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
7 $a = optional_param('a', '', PARAM_INT); // scorm ID
8 $scoid = required_param('scoid', PARAM_INT); // sco ID
9 $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
10 $attempt = required_param('attempt', PARAM_INT); // new attempt
11
12 //IE 6 Bug workaround
13 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && ini_get('zlib.output_compression') == 'On') {
14 ini_set('zlib.output_compression', 'Off');
15 }
16
17 if (!empty($id)) {
18 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
19 print_error('invalidcoursemodule');
20 }
21 if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
22 print_error('coursemisconf');
23 }
24 if (! $scorm = $DB->get_record('scorm', array('id'=>$cm->instance))) {
25 print_error('invalidcoursemodule');
26 }
27 } else if (!empty($a)) {
28 if (! $scorm = $DB->get_record('scorm', array('id'=>$a))) {
29 print_error('coursemisconf');
30 }
31 if (! $course = $DB->get_record('course', array('id'=>$scorm->course))) {
32 print_error('coursemisconf');
33 }
34 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
35 print_error('invalidcoursemodule');
36 }
37 } else {
38 print_error('missingparameter');
39 }
40
41 $PAGE->set_url('/mod/scorm/api.php', array('scoid'=>$scoid, 'id'=>$cm->id));
42
43 require_login($course->id, false, $cm);
44
45 if ($usertrack = scorm_get_tracks($scoid,$USER->id,$attempt)) {
46 if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || ($scorm->version != "SCORM_1.3")) {
47 foreach ($usertrack as $key => $value) {
48 $userdata->$key = addslashes_js($value);
49 }
50 } else {
51 $userdata->status = '';
52 $userdata->score_raw = '';
53 }
54 } else {
55 $userdata->status = '';
56 $userdata->score_raw = '';
57 }
58 $userdata->student_id = addslashes_js($USER->username);
59 $userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname);
60 $userdata->mode = 'normal';
61 if (isset($mode)) {
62 $userdata->mode = $mode;
63 }
64 if ($userdata->mode == 'normal') {
65 $userdata->credit = 'credit';
66 } else {
67 $userdata->credit = 'no-credit';
68 }
69 if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
70 foreach ($scodatas as $key => $value) {
71 $userdata->$key = addslashes_js($value);
72 }
73 } else {
74 error('Sco not found');
75 }
76 if (!$sco = scorm_get_sco($scoid)) {
77 error('Sco not found');
78 }
79 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
80 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
81 include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
82 } else {
83 include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
84 }
85 // set the start time of this SCO
86 scorm_insert_track($USER->id,$scorm->id,$scoid,$attempt,'x.start.time',time());
87?>
88
89
90var errorCode = "0";
91function underscore(str) {
92 str = String(str).replace(/.N/g,".");
93 return str.replace(/\./g,"__");
94}