New 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 }
ec81373f 17
98ca59f6 18 if (! $course = get_record("course", "id", $cm->course)) {
19 error("Course is misconfigured");
20 }
ec81373f 21
98ca59f6 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
ec81373f 38 require_login($course->id, false, $cm);
39
98ca59f6 40
98ca59f6 41 $strscorms = get_string("modulenameplural", "scorm");
42 $strscorm = get_string("modulename", "scorm");
ec81373f 43
98ca59f6 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)) {
ec81373f 54 print_header($pagetitle, "$course->fullname", "$navigation $scorm->name", "", "", true,
98ca59f6 55 update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
56 notice(get_string("activityiscurrentlyhidden"));
57 }
ec81373f 58
b98eebbf 59 if (!empty($_POST["scoid"]))
ec81373f 60 $scoid = "&amp;scoid=".$_POST["scoid"];
2c508ab9 61 if (!empty($_POST['currentorg'])) {
ec81373f 62 $currentorg = $_POST['currentorg'];
2c508ab9 63 }
b98eebbf 64 if (($scorm->popup != "") && (!empty($_POST["mode"])))
ec81373f 65 $mode = $_POST["mode"];
b98eebbf 66 if (($scorm->popup == "") && (!empty($_GET["mode"])))
ec81373f 67 $mode = $_GET["mode"];
68
b98eebbf 69 if (($frameset == "top") || ($scorm->popup != "")) {
ec81373f 70 add_to_log($course->id, "scorm", "view", "playscorm.php?id=$cm->id", "$scorm->id");
71 //
72 // Print the page header
73 //
74 $bodyscripts = "";
75 if ($scorm->popup != "") {
76 $bodyscripts = "onload='SCOInitialize();' onunload='SCOFinish(); closeMain();'";
77 }
78 print_header($pagetitle, "$course->fullname",
79 "$navigation <a target=\"{$CFG->framename}\" href=\"view.php?id=$cm->id\" title=\"$scorm->summary\">$scorm->name</a>",
80 "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top'),"",$bodyscripts);
81
82 echo "<table width=\"100%\">\n <tr><td align=\"center\">".text_to_html($scorm->summary, true, false)."</td>\n";
83 if ($mode == "browse")
84 echo "<td align=\"right\" width=\"10%\" nowrap=\"nowrap\">".get_string("browsemode","scorm")."</td>\n";
85 echo " </tr>\n</table>\n";
86
87 if ($scorm->popup != "") {
88 echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&amp;mode=".$mode.$scoid."\"></script>\n";
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) {
ec81373f 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
104 var beg=nn?"document.ids.":w3c?"document.getElementById('":"document.all.";
105 var mid=w3c?"').style":".style";
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 }
76d35423 116 -->
117 </script>
76d35423 118 <?php
59c71f4b 119 $liststyle = "style=\"list-style-type:none;\"";
120 print_simple_box_start("center");
ec81373f 121 echo "<table>\n";
122 echo " <tr><th>".get_string("coursestruct","scorm")."</th></tr>\n";
123 echo " <tr><td nowrap=\"nowrap\">\n<ul $liststyle>\n";
124 $incomplete = false;
125 if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$currentorg' order by id ASC")){
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 {
135 $i = $level;
136 $closelist = "";
137 while (($i > 0) && ($parents[$level] != $sco->parent)) {
138 $closelist .= " </ul></li>\n";
139 $i--;
140 }
141 if (($i == 0) && ($sco->parent != $currentorg)) {
142 echo " <li><ul id='s".$sublist."' $liststyle>\n";
143 $level++;
144 } else {
145 echo $closelist;
146 $level = $i;
147 }
148 $parents[$level]=$sco->parent;
149 }
150 }
151 echo " <li>\n";
152 $nextsco = next($scoes);
153 if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
154 $sublist++;
155 echo " <img src=\"pix/minus.gif\" onclick='expandCollide(this,\"s".$sublist."\");' alt=\"-\" title=\"".get_string('collide','scorm')."\" />\n";
156 } else {
157 echo " <img src=\"pix/spacer.gif\" alt=\" \" />\n";
158 }
159
160 if ($sco->launch) {
161 $startbold = '';
162 $endbold = '';
163 if ($sco->id == $currentSCO) {
164 $startbold = '-&gt; <b>';
165 $endbold = '</b> &lt;-';
166 }
167 if (($currentSCO == "") && ($mode != "normal")) {
168 $currentSCO = $sco->id;
169 $startbold = '-&gt; <b>';
170 $endbold = '</b> &gt;-';
171 }
172 $score = "";
173 if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) {
174 if ( $sco_user->cmi_core_lesson_status == "") {
175 $sco_user->cmi_core_lesson_status = "not attempted";
176 }
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;
182 $startbold = '-> <b>';
183 $endbold = '</b> <-';
184 }
185 }
186 if ($sco_user->cmi_core_score_raw > 0) {
187 $score = "(".get_string("score","scorm").":&nbsp;".$sco_user->cmi_core_score_raw.")";
188 }
189 } else {
190 if ($sco->type == 'sco') {
191 echo " <img src=\"pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" title=\"".get_string("notattempted","scorm")."\" />";
192 $incomplete = true;
193 } else {
194 echo " <img src=\"pix/asset.gif\" alt=\"".get_string("asset","scorm")."\" title=\"".get_string("asset","scorm")."\" />";
195 }
196 }
197 echo " &nbsp;$startbold<a href=\"javascript:playSCO(".$sco->id.");\">$sco->title</a> $score$endbold\n </li>\n";
198 } else {
199 echo " &nbsp;$sco->title\n </li>\n";
200 }
201 }
202 for ($i=0;$i<$level;$i++){
203 echo " </ul></li>\n";
b98eebbf 204 }
ec81373f 205 }
206 echo "</ul></td></tr>\n";
207 echo "</table>\n";
208 print_simple_box_end();
209
210 }
211
212 echo "<table width=\"100%\">\n <tr>\n";
213 echo " <td align=\"center\" nowrap=\"nowrap\">
214 <iframe name=\"cmi\" width=\"1\" height=\"1\" src=\"cmi.php?id=$cm->id\" style=\"visibility: hidden\"></iframe>
215 <form name=\"navform\" method=\"post\" action=\"playscorm.php?id=$cm->id\" target=\"_top\">
216 <input name=\"scoid\" type=\"hidden\" />
217 <input name=\"currentorg\" type=\"hidden\" value=\"$currentorg\" />
218 <input name=\"mode\" type=\"hidden\" value=\"".$mode."\" />
219 <input name=\"prev\" type=\"button\" value=\"".get_string("prev","scorm")."\" onclick=\"top.changeSco('previous');\" />&nbsp;\n";
220
221 if ($scorm->popup == "") {
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")){
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 {
234 $i = $level;
235 while (($i > 0) && ($parents[$level] != $sco->parent)) {
236 $i--;
237 }
238 if (($i == 0) && ($sco->parent != $currentorg)) {
239 $level++;
240 } else {
241 $level = $i;
242 }
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 }
255 echo " &nbsp;<input name=\"next\" type=\"button\" value=\"".get_string("next","scorm")."\" onclick=\"top.changeSco('continue')\" />\n";
256 echo " </form>
257 </td>\n";
258
259 echo "</tr>\n</table>\n";
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 == "") {
ec81373f 267 //
268 // Frameset
269 //
270 echo "<html>\n";
b98eebbf 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";
ec81373f 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?>