Language bug fix [#1542]
[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
fc1b2663 7 optional_variable($scoid); // sco ID
8 optional_variable($mode);
98ca59f6 9
10 if ($id) {
11 if (! $cm = get_record("course_modules", "id", $id)) {
12 error("Course Module ID was incorrect");
13 }
14
15 if (! $course = get_record("course", "id", $cm->course)) {
16 error("Course is misconfigured");
17 }
18
19 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
20 error("Course module is incorrect");
21 }
22
23 } else {
24 if (! $scorm = get_record("scorm", "id", $a)) {
25 error("Course module is incorrect");
26 }
27 if (! $course = get_record("course", "id", $scorm->course)) {
28 error("Course is misconfigured");
29 }
30 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
31 error("Course Module ID was incorrect");
32 }
33 }
34
35 require_login($course->id);
36
37 if ( $scoes_user = get_records_select("scorm_sco_users","userid = ".$USER->id." AND scormid = ".$scorm->id,"scoid ASC") ) {
fc1b2663 38 if ($scoid) {
39 $sco = get_record("scorm_scoes","id",$scoid);
98ca59f6 40 } else {
41 foreach ( $scoes_user as $sco_user ) {
42 if (($sco_user->cmi_core_lesson_status != "completed") && ($sco_user->cmi_core_lesson_status != "passed") && ($sco_user->cmi_core_lesson_status != "failed")) {
43 $sco = get_record("scorm_scoes","id",$sco_user->scoid);
44 break;
45 } else {
fc1b2663 46 if ($mode == "review") {
98ca59f6 47 $sco = get_record("scorm_scoes","id",$sco_user->scoid);
48 break;
49 }
50 }
51 }
52 }
53 if (!$sco)
54 $sco = get_record_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' order by id ASC");
55 } else {
56 if ($scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC")) {
57 foreach ($scoes as $sco) {
58 if ($sco->launch != "") {
59 if (!$first)
60 $first = $sco;
61 $sco_user->userid = $USER->id;
62 $sco_user->scoid = $sco->id;
63 $sco_user->scormid = $scorm->id;
64 $element = "cmi_core_lesson_status";
65 if ($sco->type == "sco")
66 $sco_user->$element = "not attempted";
67 else if ($sco->type == "sca")
68 $sco_user->$element = "completed";
69 $ident = insert_record("scorm_sco_users",$sco_user);
c5163bfd 70 }
98ca59f6 71 }
72 $sco = $first;
fc1b2663 73 if ($scoid) {
74 if ($sco = get_record("scorm_scoes","id",$scoid))
c5163bfd 75 unset($first);
76 }
98ca59f6 77 }
78 }
79 //
80 // Get first, last, prev and next scoes
81 //
82 $scoes = get_records("scorm_scoes","scorm",$scorm->id,"id ASC");
fc1b2663 83 $min = 0;
84 $max = 0;
85 $prevsco = 0;
86 $nextsco = 0;
98ca59f6 87 foreach ($scoes as $fsco) {
88 if ($fsco->launch != "") {
89 if (!$min || ($min > $fsco->id))
90 $min = $fsco->id;
91 if (!$max || ($max < $fsco->id))
92 $max = $fsco->id;
93 if ((!$prevsco) || ($sco->id > $fsco->id)) {
94 $prevsco = $fsco->id;
95 }
96 if ((!$nextsco) && ($sco->id < $fsco->id)) {
97 $nextsco = $fsco->id;
98 }
99 }
100 }
fc1b2663 101 $first = NULL;
102 $last = NULL;
98ca59f6 103 if ($sco->id == $min)
104 $first = $sco;
105 if ($sco->id == $max)
106 $last = $sco;
107
c5163bfd 108 // Get current sco User data
98ca59f6 109 $sco_user = get_record("scorm_sco_users","userid",$USER->id,"scoid",$sco->id);
c5163bfd 110
98ca59f6 111 if (scorm_external_link($sco->launch)) {
112 $result = $sco->launch;
113 } else {
114 if ($CFG->slasharguments) {
115 $result = "$CFG->wwwroot/file.php/$scorm->course/moddata/scorm$scorm->datadir/$sco->launch";
116 } else {
117 $result = "$CFG->wwwroot/file.php?file=/$scorm->course/moddata/scorm$scorm->datadir/$sco->launch";
118 }
119 }
120 include("api1_2.php");
c5163bfd 121
98ca59f6 122?>
c5163bfd 123
124function SCOInitialize() {
125<?php
126 if ( $sco->previous || $first) {
127 print "\ttop.nav.document.navform.prev.disabled = true;\n";
128 print "\ttop.nav.document.navform.prev.style.display = 'none';\n";
129 }
130 if ( $sco->next || $last) {
131 print "\ttop.nav.document.navform.next.disabled = true;\n";
132 print "\ttop.nav.document.navform.next.style.display = 'none';\n";
133 }
134?>
fc1b2663 135 top.main.location="<?php echo $result; ?>";
c5163bfd 136 for (i=0;i<top.nav.document.navform.courseStructure.options.length;i++) {
137 if ( top.nav.document.navform.courseStructure.options[i].value == <?php echo $sco->id; ?> )
138 top.nav.document.navform.courseStructure.options[i].selected = true;
139 }
140}
141
142function changeSco(direction) {
143 if (direction == "prev")
fc1b2663 144 top.nav.document.navform.scoid.value="<?php echo $prevsco; ?>";
c5163bfd 145 else
fc1b2663 146 top.nav.document.navform.scoid.value="<?php echo $nextsco; ?>";
c5163bfd 147
fc1b2663 148 //alert ("Prev: <?php echo $prevsco; ?>\nNext: <?php echo $nextsco; ?>\nNew SCO: "+top.nav.document.navform.scoid.value);
c5163bfd 149 top.nav.document.navform.submit();
150}