Initial XMLDB schema for data tables. Using FKs where they are obvious.
[moodle.git] / mod / scorm / player.php
CommitLineData
1a50a1f9 1<?PHP // $Id$\r
2\r
3/// This page prints a particular instance of aicc/scorm package\r
4\r
5 require_once('../../config.php');\r
6 require_once('locallib.php');\r
7 require_once('sequencinglib.php');\r
8 \r
9 //\r
10 // Checkin' script parameters\r
11 //\r
12 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or\r
13 $a = optional_param('a', '', PARAM_INT); // scorm ID\r
14 $scoid = required_param('scoid', PARAM_INT); // sco ID\r
15 $mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode\r
16 $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization\r
17 $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt\r
18\r
19 if (!empty($id)) {\r
20 if (! $cm = get_record("course_modules", "id", $id)) {\r
21 error("Course Module ID was incorrect");\r
22 }\r
23 if (! $course = get_record("course", "id", $cm->course)) {\r
24 error("Course is misconfigured");\r
25 }\r
26 if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r
27 error("Course module is incorrect");\r
28 }\r
29 } else if (!empty($a)) {\r
30 if (! $scorm = get_record("scorm", "id", $a)) {\r
31 error("Course module is incorrect");\r
32 }\r
33 if (! $course = get_record("course", "id", $scorm->course)) {\r
34 error("Course is misconfigured");\r
35 }\r
36 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r
37 error("Course Module ID was incorrect");\r
38 }\r
39 } else {\r
40 error('A required parameter is missing');\r
41 }\r
42\r
43 require_login($course->id, false, $cm);\r
44\r
45 //$f = "D:\\test.txt";\r
46 //@$ft = fopen($f,"a");\r
47 //fwrite($ft,"\n ++ Thong tin quyen set attempt ".$USER->setAttempt);\r
48 $strscorms = get_string('modulenameplural', 'scorm');\r
49 $strscorm = get_string('modulename', 'scorm');\r
50 $strpopup = get_string('popup','scorm');\r
51\r
1a50a1f9 52 $attempt = scorm_get_last_attempt($scorm->id,$USER->id); \r
53 \r
54 //Kiem tra xem co phai la tiep tuc khong \r
3eabd4cf 55 if ($mode=='continue') {\r
1a50a1f9 56 $scoid = scorm_get_suspendscoid($scorm->id,$USER->id);\r
57 $USER->setAttempt = 'set';\r
58 $mode = 'normal';\r
59 }\r
3eabd4cf 60 if (($mode == 'normal') && ($USER->setAttempt == 'notset')) {\r
1a50a1f9 61 $attempt++;\r
62 $USER->setAttempt = 'set';\r
63 }\r
64 //Thuc hien Sequencing\r
65\r
3eabd4cf 66 if ($mode!='review') {\r
67 $sequencingResult = scorm_sequecingrule_implement($scorm->id,$scoid,$USER->id);\r
68 //echo "<script language='JavaScript'>";\r
69 // echo "alert('Sequencing');";\r
70 //echo "<script>";\r
1a50a1f9 71 if (($sequencingResult->rule == 'pre') && ($sequencingResult->action == 'disabled')){\r
72 echo "<script language='JavaScript'>";\r
73 echo "alert('Disabling');";\r
74 echo "</script>"; \r
75 }\r
76 if (($sequencingResult->rule == 'exit') && ($sequencingResult->action == 'exit')){\r
77 $exitscoid = get_sco_after_exit($scoid,$scorm->id);\r
78 //fwrite($ft,"\n ++ Thong tin exit sco la ".$exitscoid);\r
79 $orgstr = '&currentorg='.$currentorg;\r
80 $modepop = '&mode='.$mode;\r
81 $scostr = '&scoid='.$exitscoid;\r
82 echo "<script language='JavaScript'>";\r
83 echo "alert('Exiting');";\r
84 echo "location.href='".$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."';";\r
85 echo "</script>"; \r
1a50a1f9 86 } \r
87 } \r
88\r
89 //Thiet lap attempt_status cho scoid\r
90 scorm_set_attempt($scoid,$USER->id);\r
91 //Ket thuc thiet lap attemp_status\r
3eabd4cf 92 if ($mode!='review') {\r
93 //Update trang thai\r
94 scorm_rollup_updatestatus($scorm->id,$scoid,$USER->id);\r
95 //------------------------------\r
1a50a1f9 96 } \r
97 //Thiet lap thong tin lien quan truy xuat Scorm\r
98 $statistic = get_record('scorm_statistic',"scormid",$scorm->id,"userid",$USER->id);\r
3eabd4cf 99 if (empty($statistic)) {\r
1a50a1f9 100 $statisticInput->accesstime = time();\r
101 $statisticInput->durationtime = 0;\r
102 $statisticInput->status = 'during';\r
103 $statisticInput->attemptnumber = $attempt;\r
104 $statisticInput->scormid = $scorm->id;\r
105 $statisticInput->userid = $USER->id;\r
106 $statisticid = scorm_insert_statistic($statisticInput);\r
3eabd4cf 107 } else {\r
108 if ($statistic->status=='suspend') {\r
109 $statisticInput->accesstime = time();\r
110 $statisticInput->durationtime = $statistic->durationtime;\r
111 $statisticInput->status = 'during';\r
112 $statisticInput->attemptnumber = $attempt;\r
113 $statisticInput->scormid = $scorm->id;\r
114 $statisticInput->userid = $USER->id;\r
1a50a1f9 115 }\r
116 } \r
117\r
118 //---------------------Ket thuc thiet lap thoi gian ---------------\r
119\r
120 //Lay thoi gian toi da cho phep\r
121 $absoluteTimeLimit = scorm_get_AbsoluteTimeLimit($scoid);\r
3eabd4cf 122 if ($absoluteTimeLimit > 0) { \r
1a50a1f9 123 echo "<script type='text/javascript'>"; \r
124 echo "alert('Bai nay co thoi gian lam la: ".$absoluteTimeLimit."');";\r
125 echo "function remind(msg1) {"; \r
126 echo "var msg = 'Da het gio lam bai ' + msg1 +' Secs.Lua chon bai khac de tiep tuc';";\r
127 echo "alert(msg);"; \r
128 echo "window.location.href = 'view.php?id=".$scorm->id."';";\r
129 echo "}";\r
130 echo "setTimeout('remind(".$absoluteTimeLimit.")',".$absoluteTimeLimit.");";\r
131 echo "</script>";\r
132 }\r
133 //--------------------------------\r
134\r
135 \r
136 if ($course->category != 0) {\r
137 $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";\r
138 if ($scorms = get_all_instances_in_course('scorm', $course)) {\r
139 // The module SCORM activity with the least id is the course \r
140 $firstscorm = current($scorms);\r
141 if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) {\r
142 $navigation .= "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";\r
143 }\r
144 }\r
145 } else {\r
146 $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";\r
147 }\r
148\r
149 $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));\r
150\r
151 if (!$cm->visible and !isteacher($course->id)) {\r
152 print_header($pagetitle, "$course->fullname",\r
153 "$navigation <a target='{$CFG->framename}' href='view.php?id=$cm->id'>".format_string($scorm->name,true)."</a>",\r
154 '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);\r
155 notice(get_string("activityiscurrentlyhidden"));\r
156 }\r
157\r
158 //\r
159 // TOC processing\r
160 //\r
161 //$attempt = scorm_get_last_attempt($scorm->id, $USER->id);\r
162 //$f = "D:\\test.txt";\r
163 //@$ft = fopen($f,"a");\r
164 ////fwrite($ft,"\n ++ ++ + ++ Gia tri $attempt lay duoc la ".$attempt);\r
165\r
166 //if ($mode=='normal'){\r
167 // $newattempt = 'on';\r
168 //}\r
169 if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {\r
170 $attempt++;\r
3eabd4cf 171 //$f = "D:\\test.txt";\r
172 //@$ft = fopen($f,"a");\r
1a50a1f9 173 //fwrite($ft,"\n ----New attempt------- ".$attempt);\r
174\r
175 }\r
176 $attemptstr = '&amp;attempt=' . $attempt;\r
177\r
178 //fwrite($ft,"\n ----Gia tri attempt bay gio la------- ".$attempt);\r
179 $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true);\r
180 $sco = $result->sco;\r
181\r
182 if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {\r
183 $mode = 'normal';\r
184 }\r
185 if ($mode != 'browse') {\r
186 ////fwrite($ft,"\n ++ ++ + ++ Gia tri $mode khac browser ".$mode);\r
187 if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) {\r
188 if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {\r
189 $mode = 'review';\r
190 ////fwrite($ft,"\n ++ ++ + ++ Gia tri $mode ".$mode);\r
191 } else {\r
192 $mode = 'normal';\r
193 ////fwrite($ft,"\n ++ ++ + ++ Gia tri $mode ".$mode);\r
1a50a1f9 194 }\r
195 }\r
196 }\r
197\r
198 add_to_log($course->id, 'scorm', 'view', "player.php?id=$cm->id&scoid=$sco->id", "$scorm->id");\r
199\r
200 $scoidstr = '&amp;scoid='.$sco->id;\r
201 $scoidpop = '&scoid='.$sco->id;\r
202 $modestr = '&amp;mode='.$mode;\r
203 if ($mode == 'browse') {\r
204 $modepop = '&mode='.$mode;\r
205 } else {\r
206 $modepop = '';\r
207 }\r
208 $orgstr = '&currentorg='.$currentorg;\r
209\r
210 $SESSION->scorm_scoid = $sco->id;\r
211 $SESSION->scorm_status = 'Not Initialized';\r
212 $SESSION->scorm_mode = $mode;\r
213 $SESSION->attempt = $attempt;\r
214\r
215 // Doan code them\r
216 ////fwrite($ft,"\n ++ ++ + ++ Gia tri attempt duoc gan cho user la ".$attempt);\r
217 $USER->attempt = $attempt;\r
218 //------------Ket thuc doan them\r
219\r
220 //\r
221 // Print the page header\r
222 //\r
223 $bodyscript = '';\r
224 if ($scorm->popup == 1) {\r
225 $bodyscript = 'onunload="main.close();"';\r
226 }\r
227\r
228 // Kiem tra xem co duoc exit khong\r
3eabd4cf 229 if (scorm_isChoiceexit($sco->scorm,$sco->id)) {\r
230 $exitlink = '(<a href="'.$CFG->wwwroot.'/course/view.php?id='.$cm->course.'">'.get_string('exit','scorm').'</a>)&nbsp;';\r
231 } else {\r
232 $exitlink = get_string('exitisnotallowed','scorm');\r
1a50a1f9 233 }\r
234\r
235 //Luu giu khoa hoc thoat ra\r
236 $suspend = '(<a href="suspend.php?scorm='.$sco->scorm.'&sco='.$sco->id.'&userid='.$USER->id.'&id='.$cm->course.'">'.get_string('suspend','scorm').'</a>)&nbsp;';\r
237\r
238 print_header($pagetitle, "$course->fullname",\r
239 "$navigation <a target='{$CFG->framename}' href='view.php?id=$cm->id'>".format_string($scorm->name,true)."</a>",\r
240 '', '', true, $exitlink.$suspend.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript);\r
241 if ($sco->scormtype == 'sco') {\r
242?>\r
243 <script language="JavaScript" type="text/javascript" src="request.js"></script>\r
244 <script language="JavaScript" type="text/javascript" src="api.php?id=<?php echo $cm->id.$scoidstr.$modestr.$attemptstr ?>"></script>\r
245<?php\r
246 }\r
247 if (($sco->previd != 0) && ($sco->previous == 0)) {\r
248 $scostr = '&scoid='.$sco->previd;\r
249 echo ' <script language="javascript">var prev="'.$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."\";</script>\n";\r
250 } else {\r
251 echo ' <script language="javascript">var prev="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";</script>\n";\r
252 }\r
253 if (($sco->nextid != 0) && ($sco->next == 0)) {\r
254 $scostr = '&scoid='.$sco->nextid;\r
255 echo ' <script language="javascript">var next="'.$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."\";</script>\n";\r
256 } else {\r
257 echo ' <script language="javascript">var next="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";</script>\n";\r
258 }\r
259?>\r
260 <div id="scormpage">\r
261<?php \r
262 if ($scorm->hidetoc == 0) {\r
263?>\r
264 <div id="tocbox" class="generalbox">\r
265 <div id="tochead" class="header"><?php print_string('coursestruct','scorm') ?></div>\r
266 <div id="toctree">\r
267 <?php echo $result->toc; ?>\r
268 </div>\r
269 </div>\r
270<?php\r
271 $class = ' class="toc"';\r
272 } else {\r
273 $class = ' class="no-toc"';\r
274 }\r
275?>\r
276 <div id="scormbox"<?php echo $class ?>>\r
277<?php\r
278 // This very big test check if is necessary the "scormtop" div\r
279 if (\r
280 ($mode != 'normal') || // We are not in normal mode so review or browse text will displayed\r
281 (\r
282 ($scorm->hidenav == 0) && // Teacher want to display navigation links\r
283 (\r
284 (\r
285 ($sco->previd != 0) && // This is not the first learning object of the package\r
286 ($sco->previous == 0) // Moodle must manage the previous link\r
287 ) || \r
288 (\r
289 ($sco->nextid != 0) && // This is not the last learning object of the package\r
290 ($sco->next == 0) // Moodle must manage the next link\r
291 ) \r
292 )\r
293 ) || ($scorm->hidetoc == 2) // Teacher want to display toc in a small dropdown menu \r
294 ) {\r
295?>\r
296 <div id="scormtop">\r
297 <?php echo $mode == 'browse' ? '<div id="scormmode" class="left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>\r
298 <?php echo $mode == 'review' ? '<div id="scormmode" class="left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>\r
299<?php\r
300 if (($scorm->hidenav == 0) || ($scorm->hidetoc == 2)) {\r
301?>\r
302 <div id="scormnav" class="right">\r
303 <?php\r
304 $orgstr = '&amp;currentorg='.$currentorg;\r
305 if (($scorm->hidenav == 0) && ($sco->previd != 0) && ($sco->previous == 0)) {\r
306 /// Print the prev LO link\r
307 $scostr = '&amp;scoid='.$sco->previd;\r
308 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;\r
309 echo '<a href="'.$url.'">&lt; '.get_string('prev','scorm').'</a>';\r
310 }\r
311 if ($scorm->hidetoc == 2) {\r
312 echo $result->tocmenu;\r
313 }\r
314 if (($scorm->hidenav == 0) && ($sco->nextid != 0) && ($sco->next == 0)) {\r
315 /// Print the next LO link\r
316 $scostr = '&amp;scoid='.$sco->nextid;\r
317 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;\r
318 echo ' &nbsp;<a href="'.$url.'">'.get_string('next','scorm').' &gt;</a>';\r
319 }\r
320 ?>\r
321\r
322 </div>\r
323<?php\r
324 } \r
325?>\r
326 </div>\r
327<?php\r
328 } // The end of the very big test\r
329?>\r
330 <div id="scormobject" class="right">\r
331 <noscript>\r
332 <div id="noscript">\r
333 <?php print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>\r
334\r
335 </div>\r
336 </noscript>\r
337<?php\r
338 if ($result->prerequisites) {\r
339 if ($scorm->popup == 0) {\r
340 if (strpos('MSIE',$_SERVER['HTTP_USER_AGENT']) === false) { \r
341 /// Internet Explorer does not has full support to objects\r
342?>\r
7cef1dfd 343 <iframe id="main" \r
344 class="scoframe"\r
1a50a1f9 345 width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" \r
346 height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" \r
347 src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">\r
348 </iframe>\r
349<?php\r
350 } else {\r
351?>\r
352 <object id="main" \r
353 class="scoframe" \r
354 width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" \r
355 height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" \r
356 data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>"\r
357 type="text/html">\r
358 <?php print_string('noobjectsupport', 'scorm'); ?>\r
359 </object>\r
360<?php\r
361 }\r
362 } else {\r
363?>\r
364 <script lanuguage="javascript">\r
365 function openpopup(url,name,options,width,height) {\r
366 fullurl = "<?php echo $CFG->wwwroot.'/mod/scorm/' ?>" + url;\r
367 windowobj = window.open(fullurl,name,options);\r
368 if ((width==100) && (height==100)) {\r
369 // Fullscreen\r
370 windowobj.moveTo(0,0);\r
371 } \r
372 if (width<=100) {\r
373 width = Math.round(screen.availWidth * width / 100);\r
374 }\r
375 if (height<=100) {\r
376 height = Math.round(screen.availHeight * height / 100);\r
377 }\r
378 windowobj.resizeTo(width,height);\r
379 windowobj.focus();\r
380 return windowobj;\r
381 }\r
382\r
383 url = "loadSCO.php?id=<?php echo $cm->id.$scoidpop ?>";\r
384 width = <?php p($scorm->width) ?>;\r
385 height = <?php p($scorm->height) ?>;\r
386 var main = openpopup(url, "<?php p($scorm->name) ?>", "<?php p($scorm->options) ?>", width, height);\r
387 </script>\r
388 <noscript>\r
389<?php\r
390 if (strpos('MSIE',$_SERVER['HTTP_USER_AGENT']) === false) { \r
391 /// Internet Explorer does not has full support to objects\r
392?>\r
393 <iframe id="main"\r
7cef1dfd 394 class="scoframe"\r
1a50a1f9 395 width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" \r
396 height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" \r
397 src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">\r
398 </iframe>\r
399<?php\r
400 } else {\r
401?>\r
402 <object id="main" \r
403 class="scoframe" \r
404 width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" \r
405 height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" \r
406 data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>"\r
407 type="text/html">\r
408 <?php print_string('noobjectsupport', 'scorm'); ?>\r
409 </object>\r
410<?php\r
411 }\r
412?>\r
413 </noscript>\r
414<?php \r
415 }\r
416 } else {\r
417 print_simple_box(get_string('noprerequisites','scorm'),'center');\r
418 }\r
419?>\r
420 </div> <!-- SCORM object -->\r
421 </div> <!-- SCORM box -->\r
422 </div> <!-- SCORM content -->\r
423 </div> <!-- Content -->\r
424 </div> <!-- Page -->\r
425\r
426</body>\r
427</html>\r
428\r