"MDL-14129, add new lang string"
[moodle.git] / mod / scorm / api.php
CommitLineData
03f5a0f8 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 if (!empty($id)) {
13 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
5a2a5331 14 print_error("Course Module ID was incorrect");
03f5a0f8 15 }
bf347041 16 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
5a2a5331 17 print_error("Course is misconfigured");
03f5a0f8 18 }
bf347041 19 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
5a2a5331 20 print_error("Course module is incorrect");
03f5a0f8 21 }
22 } else if (!empty($a)) {
bf347041 23 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
5a2a5331 24 print_error("Course module is incorrect");
03f5a0f8 25 }
bf347041 26 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
5a2a5331 27 print_error("Course is misconfigured");
03f5a0f8 28 }
29 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
5a2a5331 30 print_error("Course Module ID was incorrect");
03f5a0f8 31 }
32 } else {
5a2a5331 33 print_error('A required parameter is missing');
03f5a0f8 34 }
35
36 require_login($course->id, false, $cm);
37
38 if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) {
2aaf134c 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 = '';
44 }
03f5a0f8 45 } else {
46 $userdata->status = '';
47 $userdata->score_raw = '';
48 }
bf347041 49 $userdata->student_id = $USER->username;
50 $userdata->student_name = $USER->lastname .', '. $USER->firstname;
03f5a0f8 51 $userdata->mode = 'normal';
52 if (isset($mode)) {
53 $userdata->mode = $mode;
54 }
55 if ($userdata->mode == 'normal') {
56 $userdata->credit = 'credit';
57 } else {
58 $userdata->credit = 'no-credit';
59 }
b3659259 60 if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
61 foreach ($scodatas as $key => $value) {
62 $userdata->$key = $value;
2aaf134c 63 }
03f5a0f8 64 } else {
5a2a5331 65 print_error('Sco not found');
03f5a0f8 66 }
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');
72 }
73?>
74
75var errorCode = "0";
76function underscore(str) {
2aaf134c 77 str = str.replace(/.N/g,".");
03f5a0f8 78 return str.replace(/\./g,"__");
79}