Merge branch 'm20_MDL-26176_cleanup' of github.com:danmarsden/moodle
[moodle.git] / mod / scorm / api.php
... / ...
CommitLineData
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 //according to SCORM 2004 spec(RTE V1, 4.2.8), only cmi.exit==suspend should allow previous datamodel elements on re-launch
47 if ($scorm->version != "SCORM_1.3" || (isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} == 'suspend'))) {
48 foreach ($usertrack as $key => $value) {
49 $userdata->$key = addslashes_js($value);
50 }
51 } else {
52 $userdata->status = '';
53 $userdata->score_raw = '';
54 }
55 } else {
56 $userdata->status = '';
57 $userdata->score_raw = '';
58 }
59 $userdata->student_id = addslashes_js($USER->username);
60 $userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname);
61 $userdata->mode = 'normal';
62 if (isset($mode)) {
63 $userdata->mode = $mode;
64 }
65 if ($userdata->mode == 'normal') {
66 $userdata->credit = 'credit';
67 } else {
68 $userdata->credit = 'no-credit';
69 }
70 if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
71 foreach ($scodatas as $key => $value) {
72 $userdata->$key = addslashes_js($value);
73 }
74 } else {
75 print_error('cannotfindsco', 'scorm');
76 }
77 if (!$sco = scorm_get_sco($scoid)) {
78 print_error('cannotfindsco', 'scorm');
79 }
80 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
81 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
82 include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
83 } else {
84 include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
85 }
86 // set the start time of this SCO
87 scorm_insert_track($USER->id,$scorm->id,$scoid,$attempt,'x.start.time',time());
88?>
89
90
91var errorCode = "0";
92function underscore(str) {
93 str = String(str).replace(/.N/g,".");
94 return str.replace(/\./g,"__");
95}