changed all the POST with option/required_param functions
[moodle.git] / mod / scorm / api.php
CommitLineData
2a0407b7 1<?php
2
3 require_once("../../config.php");
a5463b34 4 require_once("lib.php");
2a0407b7 5
7b873234 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
2a0407b7 10
7b873234 11 if (!empty($id)) {
2a0407b7 12 if (! $cm = get_record("course_modules", "id", $id)) {
13 error("Course Module ID was incorrect");
14 }
2a0407b7 15 if (! $course = get_record("course", "id", $cm->course)) {
16 error("Course is misconfigured");
17 }
2a0407b7 18 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
19 error("Course module is incorrect");
20 }
7b873234 21 } else if (!empty($a)) {
2a0407b7 22 if (! $scorm = get_record("scorm", "id", $a)) {
23 error("Course module is incorrect");
24 }
25 if (! $course = get_record("course", "id", $scorm->course)) {
26 error("Course is misconfigured");
27 }
28 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
29 error("Course Module ID was incorrect");
30 }
7b873234 31 } else {
32 error('A required parameter is missing');
2a0407b7 33 }
34
35 require_login($course->id, false, $cm);
4928a2f3 36
a5463b34 37 if ($usertrack=scorm_get_tracks($scoid,$USER->id)) {
5e5b6b7f 38 $userdata = $usertrack;
4928a2f3 39 } else {
5e5b6b7f 40 $userdata->status = '';
41 $userdata->scorre_raw = '';
a5463b34 42 }
43 $userdata->student_id = $USER->username;
44 $userdata->student_name = $USER->lastname .', '. $USER->firstname;
45 $userdata->mode = 'normal';
46 if (isset($mode)) {
5e5b6b7f 47 $userdata->mode = $mode;
a5463b34 48 }
d7006640 49 if ($userdata->mode == 'normal') {
9633a423 50 $userdata->credit = 'credit';
d7006640 51 } else {
9633a423 52 $userdata->credit = 'no-credit';
d7006640 53 }
a5463b34 54 if ($sco = get_record('scorm_scoes','id',$scoid)) {
5e5b6b7f 55 $userdata->datafromlms = $sco->datafromlms;
56 $userdata->masteryscore = $sco->masteryscore;
57 $userdata->maxtimeallowed = $sco->maxtimeallowed;
58 $userdata->timelimitaction = $sco->timelimitaction;
a5463b34 59 } else {
5e5b6b7f 60 error('Sco not found');
4928a2f3 61 }
2a0407b7 62
a5463b34 63 switch ($scorm->version) {
5e5b6b7f 64 case 'SCORM_1.2':
65 include_once ('datamodels/scorm1_2.js.php');
9633a423 66 break;
5e5b6b7f 67 case 'SCORM_1.3':
9633a423 68 include_once ('datamodels/scorm1_3.js.php');
69 break;
5e5b6b7f 70 case 'AICC':
9633a423 71 include_once ('datamodels/aicc.js.php');
72 break;
5e5b6b7f 73 default:
74 include_once ('datamodels/scorm1_2.js.php');
9633a423 75 break;
a5463b34 76 }
77?>
2a0407b7 78
2a0407b7 79var errorCode = "0";
80
a5463b34 81function underscore(str) {
82 return str.replace(/\./g,"__");
2a0407b7 83}