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