Adding extra param fields to the user_info_field table to allow field type
[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)) {
14 error("Course Module ID was incorrect");
15 }
16 if (! $course = get_record("course", "id", $cm->course)) {
17 error("Course is misconfigured");
18 }
19 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
20 error("Course module is incorrect");
21 }
22 } else if (!empty($a)) {
23 if (! $scorm = get_record("scorm", "id", $a)) {
24 error("Course module is incorrect");
25 }
26 if (! $course = get_record("course", "id", $scorm->course)) {
27 error("Course is misconfigured");
28 }
29 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
30 error("Course Module ID was incorrect");
31 }
32 } else {
33 error('A required parameter is missing');
34 }
35
36 require_login($course->id, false, $cm);
37
38 if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) {
39 $userdata = $usertrack;
40 } else {
41 $userdata->status = '';
42 $userdata->score_raw = '';
43 }
44 $userdata->student_id = addslashes($USER->username);
45 $userdata->student_name = addslashes($USER->lastname .', '. $USER->firstname);
46 $userdata->mode = 'normal';
47 if (isset($mode)) {
48 $userdata->mode = $mode;
49 }
50 if ($userdata->mode == 'normal') {
51 $userdata->credit = 'credit';
52 } else {
53 $userdata->credit = 'no-credit';
54 }
55 if ($sco = get_record('scorm_scoes','id',$scoid)) {
56 $userdata->datafromlms = $sco->datafromlms;
57 $userdata->masteryscore = $sco->masteryscore;
58 $userdata->maxtimeallowed = $sco->maxtimeallowed;
59 $userdata->timelimitaction = $sco->timelimitaction;
60 } else {
61 error('Sco not found');
62 }
63 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
64 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
65 include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
66 } else {
67 include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
68 }
69?>
70
71var errorCode = "0";
72function underscore(str) {
73 return str.replace(/\./g,"__");
74}