Putting SCORM into maintree CVS, to make it easier to test.
[moodle.git] / mod / scorm / scormAPI.php
CommitLineData
98ca59f6 1<?php
2 require_once("../../config.php");
3 require_once("lib.php");
4
5 optional_variable($id); // Course Module ID, or
6 optional_variable($a); // scorm ID
7
8 if ($id) {
9 if (! $cm = get_record("course_modules", "id", $id)) {
10 error("Course Module ID was incorrect");
11 }
12
13 if (! $course = get_record("course", "id", $cm->course)) {
14 error("Course is misconfigured");
15 }
16
17 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
18 error("Course module is incorrect");
19 }
20
21 } else {
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 }
31 }
32
33 require_login($course->id);
34
35 if ( $scoes_user = get_records_select("scorm_sco_users","userid = ".$USER->id." AND scormid = ".$scorm->id,"scoid ASC") ) {
36 if ($_GET["scoid"]) {
37 $sco = get_record("scorm_scoes","id",$_GET["scoid"]);
38 } else {
39 foreach ( $scoes_user as $sco_user ) {
40 if (($sco_user->cmi_core_lesson_status != "completed") && ($sco_user->cmi_core_lesson_status != "passed") && ($sco_user->cmi_core_lesson_status != "failed")) {
41 $sco = get_record("scorm_scoes","id",$sco_user->scoid);
42 break;
43 } else {
44 if ($_GET["mode"] == "review") {
45 $sco = get_record("scorm_scoes","id",$sco_user->scoid);
46 break;
47 }
48 }
49 }
50 }
51 if (!$sco)
52 $sco = get_record_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' order by id ASC");
53 } else {
54 if ($scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC")) {
55 foreach ($scoes as $sco) {
56 if ($sco->launch != "") {
57 if (!$first)
58 $first = $sco;
59 $sco_user->userid = $USER->id;
60 $sco_user->scoid = $sco->id;
61 $sco_user->scormid = $scorm->id;
62 $element = "cmi_core_lesson_status";
63 if ($sco->type == "sco")
64 $sco_user->$element = "not attempted";
65 else if ($sco->type == "sca")
66 $sco_user->$element = "completed";
67 $ident = insert_record("scorm_sco_users",$sco_user);
68 }
69 }
70 $sco = $first;
71 if ($_GET["scoid"])
72 $sco = get_record("scorm_scoes","id",$_GET["scoid"]);
73 }
74 }
75 //
76 // Get first, last, prev and next scoes
77 //
78 $scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC");
79 foreach ($scoes as $fsco) {
80 if ($fsco->launch != "") {
81 if (!$min || ($min > $fsco->id))
82 $min = $fsco->id;
83 if (!$max || ($max < $fsco->id))
84 $max = $fsco->id;
85 if ((!$prevsco) || ($sco->id > $fsco->id)) {
86 $prevsco = $fsco->id;
87 }
88 if ((!$nextsco) && ($sco->id < $fsco->id)) {
89 $nextsco = $fsco->id;
90 }
91 }
92 }
93 if ($sco->id == $min)
94 $first = $sco;
95 if ($sco->id == $max)
96 $last = $sco;
97
98 // Get User data
99 $sco_user = get_record("scorm_sco_users","userid",$USER->id,"scoid",$sco->id);
100 if (scorm_external_link($sco->launch)) {
101 $result = $sco->launch;
102 } else {
103 if ($CFG->slasharguments) {
104 $result = "$CFG->wwwroot/file.php/$scorm->course/moddata/scorm$scorm->datadir/$sco->launch";
105 } else {
106 $result = "$CFG->wwwroot/file.php?file=/$scorm->course/moddata/scorm$scorm->datadir/$sco->launch";
107 }
108 }
109 include("api1_2.php");
110?>