test commit for lineending cleanup
[moodle.git] / mod / scorm / api.php
CommitLineData
1a50a1f9 1<?php\r
2\r
3 require_once("../../config.php");\r
4 require_once('locallib.php');\r
dabfd0ed 5 \r
1a50a1f9 6 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or\r
7 $a = optional_param('a', '', PARAM_INT); // scorm ID\r
2b3447c3 8 $scoid = required_param('scoid', PARAM_INT); // sco ID\r
1a50a1f9 9 $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode\r
10 $attempt = required_param('attempt', PARAM_INT); // new attempt\r
11\r
12 if (!empty($id)) {\r
f9d5371b 13 if (! $cm = get_coursemodule_from_id('scorm', $id)) {\r
1a50a1f9 14 error("Course Module ID was incorrect");\r
15 }\r
16 if (! $course = get_record("course", "id", $cm->course)) {\r
17 error("Course is misconfigured");\r
18 }\r
19 if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
20 error("Course module is incorrect");\r
21 }\r
22 } else if (!empty($a)) {\r
23 if (! $scorm = get_record("scorm", "id", $a)) {\r
24 error("Course module is incorrect");\r
25 }\r
26 if (! $course = get_record("course", "id", $scorm->course)) {\r
27 error("Course is misconfigured");\r
28 }\r
29 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
30 error("Course Module ID was incorrect");\r
31 }\r
32 } else {\r
33 error('A required parameter is missing');\r
34 }\r
35\r
36 require_login($course->id, false, $cm);\r
37 \r
38 if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) {\r
39 $userdata = $usertrack;\r
40 } else {\r
41 $userdata->status = '';\r
42 $userdata->score_raw = '';\r
43 }\r
44 $userdata->student_id = addslashes($USER->username);\r
45 $userdata->student_name = addslashes($USER->lastname .', '. $USER->firstname);\r
46 $userdata->mode = 'normal';\r
47 if (isset($mode)) {\r
48 $userdata->mode = $mode;\r
49 }\r
50 if ($userdata->mode == 'normal') {\r
51 $userdata->credit = 'credit';\r
52 } else {\r
53 $userdata->credit = 'no-credit';\r
54 } \r
55 if ($sco = get_record('scorm_scoes','id',$scoid)) {\r
56 $userdata->datafromlms = $sco->datafromlms;\r
57 $userdata->masteryscore = $sco->masteryscore;\r
58 $userdata->maxtimeallowed = $sco->maxtimeallowed;\r
59 $userdata->timelimitaction = $sco->timelimitaction;\r
60 } else {\r
61 error('Sco not found');\r
62 }\r
2b3447c3 63 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe\r
64 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {\r
65 include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');\r
66 } else {\r
67 include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');\r
1a50a1f9 68 }\r
69?>\r
70\r
71var errorCode = "0";\r
72function underscore(str) {\r
73 return str.replace(/\./g,"__");\r
74}\r