Some more styles added
[moodle.git] / mod / scorm / playscorm.php
CommitLineData
d1290cec 1<?php // $Id$
98ca59f6 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"]))
839f2456 60 $scoid = "&amp;scoid=".$_POST["scoid"];
2c508ab9 61 if (!empty($_POST['currentorg'])) {
62 $currentorg = $_POST['currentorg'];
63 }
b98eebbf 64 if (($scorm->popup != "") && (!empty($_POST["mode"])))
65 $mode = $_POST["mode"];
66 if (($scorm->popup == "") && (!empty($_GET["mode"])))
67 $mode = $_GET["mode"];
68
69 if (($frameset == "top") || ($scorm->popup != "")) {
c5163bfd 70 add_to_log($course->id, "scorm", "view", "playscorm.php?id=$cm->id", "$scorm->id");
71 //
72 // Print the page header
73 //
1a12b1f1 74 $bodyscripts = "";
75 if ($scorm->popup != "") {
59c71f4b 76 $bodyscripts = "onload='SCOInitialize();' onunload='SCOFinish(); closeMain();'";
1a12b1f1 77 }
c5163bfd 78 print_header($pagetitle, "$course->fullname",
98ca59f6 79 "$navigation <a target=\"{$CFG->framename}\" href=\"view.php?id=$cm->id\" title=\"$scorm->summary\">$scorm->name</a>",
1a12b1f1 80 "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top'),"",$bodyscripts);
98ca59f6 81
76d35423 82 echo "<table width=\"100%\">\n <tr><td align=\"center\">".text_to_html($scorm->summary, true, false)."</td>\n";
b98eebbf 83 if ($mode == "browse")
d1290cec 84 echo "<td align=\"right\" width=\"10%\" nowrap=\"nowrap\">".get_string("browsemode","scorm")."</td>\n";
76d35423 85 echo " </tr>\n</table>\n";
86
b98eebbf 87 if ($scorm->popup != "") {
839f2456 88 echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&amp;mode=".$mode.$scoid."\"></script>\n";
76d35423 89 $currentSCO = "";
b98eebbf 90 if (!empty($_POST['scoid']))
91 $currentSCO = $_POST['scoid'];
76d35423 92 ?>
93 <br />
59c71f4b 94 <script language="Javascript" type="text/javascript">
76d35423 95 <!--
96 function playSCO(scoid) {
97 document.navform.scoid.value=scoid;
98 document.navform.submit();
99 }
100
101 function expandCollide(which,list) {
102 var nn=document.ids?true:false
103 var w3c=document.getElementById?true:false
59c71f4b 104 var beg=nn?"document.ids.":w3c?"document.getElementById('":"document.all.";
105 var mid=w3c?"').style":".style";
76d35423 106
107 if (eval(beg+list+mid+".display") != "none") {
108 which.src = "pix/plus.gif";
109 eval(beg+list+mid+".display='none';");
110 } else {
111 which.src = "pix/minus.gif";
112 eval(beg+list+mid+".display='block';");
113 }
114
115 }
116 -->
117 </script>
76d35423 118 <?php
59c71f4b 119 $liststyle = "style=\"list-style-type:none;\"";
120 print_simple_box_start("center");
76d35423 121 echo "<table>\n";
122 echo " <tr><th>".get_string("coursestruct","scorm")."</th></tr>\n";
59c71f4b 123 echo " <tr><td nowrap=\"nowrap\">\n<ul $liststyle>\n";
76d35423 124 $incomplete = false;
2c508ab9 125 if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$currentorg' order by id ASC")){
76d35423 126 $level=0;
127 $sublist=0;
128 $parents[$level]="/";
129 foreach ($scoes as $sco) {
130 if ($parents[$level]!=$sco->parent) {
131 if ($level>0 && $parents[$level-1]==$sco->parent) {
132 echo " </ul></li>\n";
133 $level--;
134 } else {
fc274a5f 135 $i = $level;
136 $closelist = "";
137 while (($i > 0) && ($parents[$level] != $sco->parent)) {
138 $closelist .= " </ul></li>\n";
139 $i--;
140 }
2c508ab9 141 if (($i == 0) && ($sco->parent != $currentorg)) {
59c71f4b 142 echo " <li><ul id='s".$sublist."' $liststyle>\n";
fc274a5f 143 $level++;
144 } else {
145 echo $closelist;
146 $level = $i;
147 }
76d35423 148 $parents[$level]=$sco->parent;
149 }
150 }
151 echo " <li>\n";
152 $nextsco = next($scoes);
fc274a5f 153 if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
76d35423 154 $sublist++;
59c71f4b 155 echo " <img src=\"pix/minus.gif\" onclick='expandCollide(this,\"s".$sublist."\");' alt=\"-\" title=\"".get_string('collide','scorm')."\" />\n";
76d35423 156 } else {
59c71f4b 157 echo " <img src=\"pix/spacer.gif\" alt=\" \" />\n";
76d35423 158 }
159
160 if ($sco->launch) {
161 $startbold = '';
162 $endbold = '';
163 if ($sco->id == $currentSCO) {
59c71f4b 164 $startbold = '-&gt; <b>';
165 $endbold = '</b> &lt;-';
02f5d439 166 }
167 if (($currentSCO == "") && ($mode != "normal")) {
168 $currentSCO = $sco->id;
59c71f4b 169 $startbold = '-&gt; <b>';
170 $endbold = '</b> &gt;-';
76d35423 171 }
2c508ab9 172 $score = "";
76d35423 173 if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) {
d64bc8ae 174 if ( $sco_user->cmi_core_lesson_status == "") {
76d35423 175 $sco_user->cmi_core_lesson_status = "not attempted";
d64bc8ae 176 }
76d35423 177 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";
178 if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete")) {
179 if ($currentSCO == "") {
180 $incomplete = true;
181 $currentSCO = $sco->id;
02f5d439 182 $startbold = '-> <b>';
183 $endbold = '</b> <-';
76d35423 184 }
185 }
2c508ab9 186 if ($sco_user->cmi_core_score_raw > 0) {
187 $score = "(".get_string("score","scorm").":&nbsp;".$sco_user->cmi_core_score_raw.")";
188 }
76d35423 189 } else {
d64bc8ae 190 if ($sco->type == 'sco') {
59c71f4b 191 echo " <img src=\"pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" title=\"".get_string("notattempted","scorm")."\" />";
d64bc8ae 192 $incomplete = true;
193 } else {
59c71f4b 194 echo " <img src=\"pix/asset.gif\" alt=\"".get_string("asset","scorm")."\" title=\"".get_string("asset","scorm")."\" />";
d64bc8ae 195 }
76d35423 196 }
2c508ab9 197 echo " &nbsp;$startbold<a href=\"javascript:playSCO(".$sco->id.");\">$sco->title</a> $score$endbold\n </li>\n";
76d35423 198 } else {
199 echo " &nbsp;$sco->title\n </li>\n";
200 }
201 }
202 for ($i=0;$i<$level;$i++){
203 echo " </ul></li>\n";
204 }
205 }
206 echo "</ul></td></tr>\n";
207 echo "</table>\n";
208 print_simple_box_end();
b98eebbf 209
210 }
211
212 echo "<table width=\"100%\">\n <tr>\n";
d1290cec 213 echo " <td align=\"center\" nowrap=\"nowrap\">
fc274a5f 214 <iframe name=\"cmi\" width=\"1\" height=\"1\" src=\"cmi.php?id=$cm->id\" style=\"visibility: hidden\"></iframe>
59c71f4b 215 <form name=\"navform\" method=\"post\" action=\"playscorm.php?id=$cm->id\" target=\"_top\">
b98eebbf 216 <input name=\"scoid\" type=\"hidden\" />
2c508ab9 217 <input name=\"currentorg\" type=\"hidden\" value=\"$currentorg\" />
b98eebbf 218 <input name=\"mode\" type=\"hidden\" value=\"".$mode."\" />
59c71f4b 219 <input name=\"prev\" type=\"button\" value=\"".get_string("prev","scorm")."\" onclick=\"top.changeSco('previous');\" />&nbsp;\n";
b98eebbf 220
221 if ($scorm->popup == "") {
2c508ab9 222 $currentorg = '';
223 if (isset($_GET['currentorg'])) {
224 $currentorg = $_GET['currentorg'];
225 }
226 if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$currentorg' order by id ASC")){
b98eebbf 227 $level=0;
228 $parents[$level]="/";
229 foreach ($scoes as $sco) {
230 if ($parents[$level]!=$sco->parent) {
231 if ($level>0 && $parents[$level-1]==$sco->parent) {
232 $level--;
233 } else {
fc274a5f 234 $i = $level;
235 while (($i > 0) && ($parents[$level] != $sco->parent)) {
236 $i--;
237 }
2c508ab9 238 if (($i == 0) && ($sco->parent != $currentorg)) {
fc274a5f 239 $level++;
240 } else {
241 $level = $i;
242 }
b98eebbf 243 $parents[$level]=$sco->parent;
244 }
245 }
246 $indenting = "";
247 for ($i=0;$i<$level;$i++) {
248 $indenting .= "-";
249 }
250 $options[$sco->id] = $indenting."&gt; ".$sco->title;
251 }
252 }
253 choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();");
254 }
59c71f4b 255 echo " &nbsp;<input name=\"next\" type=\"button\" value=\"".get_string("next","scorm")."\" onclick=\"top.changeSco('continue')\" />\n";
b98eebbf 256 echo " </form>
257 </td>\n";
258
259 echo "</tr>\n</table>\n";
2c508ab9 260 if ($scorm->popup == "") {
261 echo "</body>\n</html>\n";
262 } else {
263 print_footer($course);
264 }
c5163bfd 265 } else {
76d35423 266 if ($scorm->popup == "") {
267 //
268 // Frameset
269 //
b98eebbf 270 echo "<html>\n";
271 echo "<head><title>$course->shortname: $scorm->name</title></head>\n";
839f2456 272 echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&amp;mode=".$mode.$scoid."\"></script>\n";
7f02f534 273 echo "<frameset rows=\"$CFG->scorm_framesize,*\" onLoad=\"SCOInitialize();\" onUnload=\"SCOFinish();\">\n";
839f2456 274 echo "\t <frame name=\"navigation\" src=\"playscorm.php?id=$cm->id&amp;mode=".$mode.'&amp;currentorg='.$currentorg."&amp;frameset=top\">\n";
02f5d439 275 echo "\t <frame name=\"main\" src=\"\">\n";
b98eebbf 276 echo "</frameset>\n";
277 echo "</html>\n";
76d35423 278 }
98ca59f6 279 }
280?>