MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / scorm / api.php
blob97b4c3817e8d58dadce470f828aa19124135fd50
1 <?php
3 require_once("../../config.php");
4 require_once('locallib.php');
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
12 if (!empty($id)) {
13 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
14 error("Course Module ID was incorrect");
16 if (! $course = get_record("course", "id", $cm->course)) {
17 error("Course is misconfigured");
19 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
20 error("Course module is incorrect");
22 } else if (!empty($a)) {
23 if (! $scorm = get_record("scorm", "id", $a)) {
24 error("Course module is incorrect");
26 if (! $course = get_record("course", "id", $scorm->course)) {
27 error("Course is misconfigured");
29 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
30 error("Course Module ID was incorrect");
32 } else {
33 error('A required parameter is missing');
36 require_login($course->id, false, $cm);
38 if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) {
39 if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || ($scorm->version != "SCORM_1.3")) {
40 $userdata = $usertrack;
41 } else {
42 $userdata->status = '';
43 $userdata->score_raw = '';
45 } else {
46 $userdata->status = '';
47 $userdata->score_raw = '';
49 $userdata->student_id = addslashes($USER->username);
50 $userdata->student_name = addslashes($USER->lastname .', '. $USER->firstname);
51 $userdata->mode = 'normal';
52 if (isset($mode)) {
53 $userdata->mode = $mode;
55 if ($userdata->mode == 'normal') {
56 $userdata->credit = 'credit';
57 } else {
58 $userdata->credit = 'no-credit';
60 if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
61 foreach ($scodatas as $key => $value) {
62 $userdata->$key = $value;
64 } else {
65 error('Sco not found');
67 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
68 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
69 include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
70 } else {
71 include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
75 var errorCode = "0";
76 function underscore(str) {
77 str = str.replace(/.N/g,".");
78 return str.replace(/\./g,"__");