Fixed last Explorer popup bug and added user score view
[moodle.git] / mod / scorm / playscorm.php
CommitLineData
98ca59f6 1<?PHP // $Id$
2
3/// This page prints a particular instance of scorm
4/// (Replace scorm with the name of your module)
5
6 require_once("../../config.php");
7 require_once("lib.php");
8
9 optional_variable($id); // Course Module ID, or
10 optional_variable($a); // scorm ID
fc1b2663 11 optional_variable($frameset, "");
98ca59f6 12
13 if ($id) {
14 if (! $cm = get_record("course_modules", "id", $id)) {
15 error("Course Module ID was incorrect");
16 }
17
18 if (! $course = get_record("course", "id", $cm->course)) {
19 error("Course is misconfigured");
20 }
21
22 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
23 error("Course module is incorrect");
24 }
25
26 } else {
27 if (! $scorm = get_record("scorm", "id", $a)) {
28 error("Course module is incorrect");
29 }
30 if (! $course = get_record("course", "id", $scorm->course)) {
31 error("Course is misconfigured");
32 }
33 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
34 error("Course Module ID was incorrect");
35 }
36 }
37
38 require_login($course->id);
39
40
41 $strscorms = get_string("modulenameplural", "scorm");
42 $strscorm = get_string("modulename", "scorm");
43
44 if ($course->category) {
45 $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
46 <a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
47 } else {
48 $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
49 }
50
51 $pagetitle = strip_tags("$course->shortname: $scorm->name");
52
53 if (!$cm->visible and !isteacher($course->id)) {
54 print_header($pagetitle, "$course->fullname", "$navigation $scorm->name", "", "", true,
55 update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
56 notice(get_string("activityiscurrentlyhidden"));
57 }
b98eebbf 58
59 if (!empty($_POST["scoid"]))
60 $scoid = "&scoid=".$_POST["scoid"];
61 if (($scorm->popup != "") && (!empty($_POST["mode"])))
62 $mode = $_POST["mode"];
63 if (($scorm->popup == "") && (!empty($_GET["mode"])))
64 $mode = $_GET["mode"];
65
66 if (($frameset == "top") || ($scorm->popup != "")) {
c5163bfd 67 add_to_log($course->id, "scorm", "view", "playscorm.php?id=$cm->id", "$scorm->id");
68 //
69 // Print the page header
70 //
71 print_header($pagetitle, "$course->fullname",
98ca59f6 72 "$navigation <a target=\"{$CFG->framename}\" href=\"view.php?id=$cm->id\" title=\"$scorm->summary\">$scorm->name</a>",
c5163bfd 73 "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top'));
98ca59f6 74
76d35423 75 echo "<table width=\"100%\">\n <tr><td align=\"center\">".text_to_html($scorm->summary, true, false)."</td>\n";
b98eebbf 76 if ($mode == "browse")
76d35423 77 echo "<td align=\"right\" width=\"10%\" nowrap>".get_string("browsemode","scorm")."</td>\n";
78 echo " </tr>\n</table>\n";
79
b98eebbf 80 if ($scorm->popup != "") {
81 echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&mode=".$mode.$scoid."\"></script>\n";
76d35423 82 $currentSCO = "";
b98eebbf 83 if (!empty($_POST['scoid']))
84 $currentSCO = $_POST['scoid'];
76d35423 85 ?>
86 <br />
87 <script language="Javascript">
88 <!--
89 function playSCO(scoid) {
90 document.navform.scoid.value=scoid;
91 document.navform.submit();
92 }
93
94 function expandCollide(which,list) {
95 var nn=document.ids?true:false
96 var w3c=document.getElementById?true:false
97 var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
98 var mid=w3c?").style":".style";
99
100 if (eval(beg+list+mid+".display") != "none") {
101 which.src = "pix/plus.gif";
102 eval(beg+list+mid+".display='none';");
103 } else {
104 which.src = "pix/minus.gif";
105 eval(beg+list+mid+".display='block';");
106 }
107
108 }
109 -->
110 </script>
111 <style type="text/css">
112 .scormlist { list-style-type:none; }
113 </style>
114 <?php
115 print_simple_box_start("CENTER");
116 echo "<table>\n";
117 echo " <tr><th>".get_string("coursestruct","scorm")."</th></tr>\n";
118 echo " <tr><td nowrap>\n<ul class=\"scormlist\"'>\n";
119 $incomplete = false;
120 if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){
121 $level=0;
122 $sublist=0;
123 $parents[$level]="/";
124 foreach ($scoes as $sco) {
125 if ($parents[$level]!=$sco->parent) {
126 if ($level>0 && $parents[$level-1]==$sco->parent) {
127 echo " </ul></li>\n";
128 $level--;
129 } else {
130 echo " <li><ul id='".$sublist."' class=\"scormlist\"'>\n";
131 $level++;
132 $parents[$level]=$sco->parent;
133 }
134 }
135 echo " <li>\n";
136 $nextsco = next($scoes);
137 if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent != $parents[$level-1])))) {
138 $sublist++;
139 echo " <img src=\"pix/minus.gif\" onClick='expandCollide(this,".$sublist.");'/>\n";
140 } else {
141 echo " <img src=\"pix/spacer.gif\" />\n";
142 }
143
144 if ($sco->launch) {
145 $startbold = '';
146 $endbold = '';
147 if ($sco->id == $currentSCO) {
02f5d439 148 $startbold = '-> <b>';
149 $endbold = '</b> <-';
150 }
151 if (($currentSCO == "") && ($mode != "normal")) {
152 $currentSCO = $sco->id;
153 $startbold = '-> <b>';
154 $endbold = '</b> <-';
76d35423 155 }
156 if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) {
157 if ( $sco_user->cmi_core_lesson_status == "")
158 $sco_user->cmi_core_lesson_status = "not attempted";
159 echo " <img src=\"pix/".scorm_remove_spaces($sco_user->cmi_core_lesson_status).".gif\" alt=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" title=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" />\n";
160 if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete")) {
161 if ($currentSCO == "") {
162 $incomplete = true;
163 $currentSCO = $sco->id;
02f5d439 164 $startbold = '-> <b>';
165 $endbold = '</b> <-';
76d35423 166 }
167 }
168 } else {
169 echo " <img src=\"pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" />";
170 $incomplete = true;
171 }
02f5d439 172 $score = "";
173 if (($sco_user->cmi_core_lesson_status == "passed") || ($sco_user->cmi_core_lesson_status == "failed"))
174 $score = "(".get_string("score","scorm").": ".$sco_user->cmi_core_score_raw.")";
175 echo " &nbsp;$startbold<a href=\"javascript:playSCO(".$sco->id.");\">$sco->title</a> $score$endbold\n </li>\n";
76d35423 176 } else {
177 echo " &nbsp;$sco->title\n </li>\n";
178 }
179 }
180 for ($i=0;$i<$level;$i++){
181 echo " </ul></li>\n";
182 }
183 }
184 echo "</ul></td></tr>\n";
185 echo "</table>\n";
186 print_simple_box_end();
b98eebbf 187
188 }
189
190 echo "<table width=\"100%\">\n <tr>\n";
191 echo " <td align=\"center\" nowrap>
192 <iframe name=\"cmi\" width=\"1\" height=\"1\" src=\"cmi.php?id=$cm->id\" style=\"visibility: hidden;\"></iframe>
193 <form name=\"navform\" method=\"POST\" action=\"playscorm.php?id=$cm->id\" target=\"_top\">
194 <input name=\"scoid\" type=\"hidden\" />
195 <input name=\"mode\" type=\"hidden\" value=\"".$mode."\" />
196 <input name=\"prev\" type=\"button\" value=\"".get_string("prev","scorm")."\" onClick=\"top.changeSco('prev');\" />&nbsp;\n";
197
198 if ($scorm->popup == "") {
199 if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){
200 $level=0;
201 $parents[$level]="/";
202 foreach ($scoes as $sco) {
203 if ($parents[$level]!=$sco->parent) {
204 if ($level>0 && $parents[$level-1]==$sco->parent) {
205 $level--;
206 } else {
207 $level++;
208 $parents[$level]=$sco->parent;
209 }
210 }
211 $indenting = "";
212 for ($i=0;$i<$level;$i++) {
213 $indenting .= "-";
214 }
215 $options[$sco->id] = $indenting."&gt; ".$sco->title;
216 }
217 }
218 choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();");
219 }
220 echo " &nbsp;<input name=\"next\" type=\"button\" value=\"".get_string("next","scorm")."\" onClick=\"top.changeSco('next')\" />\n";
221 echo " </form>
222 </td>\n";
223
224 echo "</tr>\n</table>\n";
225
226 if ($scorm->popup != "") {
227 ?>
228 <script language="Javascript">
b98eebbf 229 SCOInitialize();
230 </script>
231 <?php
76d35423 232 }
b98eebbf 233
c5163bfd 234 echo "</body>\n</html>\n";
235 } else {
76d35423 236 if ($scorm->popup == "") {
237 //
238 // Frameset
239 //
b98eebbf 240 echo "<html>\n";
241 echo "<head><title>$course->shortname: $scorm->name</title></head>\n";
242 echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&mode=".$mode.$scoid."\"></script>\n";
76d35423 243 echo "<frameset rows=\"$CFG->scorm_framesize,*\" onLoad=\"SCOInitialize();\">\n";
02f5d439 244 echo "\t <frame name=\"nav\" src=\"playscorm.php?id=$cm->id&mode=".$mode."&frameset=top\">\n";
245 echo "\t <frame name=\"main\" src=\"\">\n";
b98eebbf 246 echo "</frameset>\n";
247 echo "</html>\n";
76d35423 248 }
98ca59f6 249 }
250?>