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