Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / scorm / player.php
blob020885e1486c42e96c8c9bc2b0749ae99086d912
1 <?PHP // $Id$
3 /// This page prints a particular instance of aicc/scorm package
5 require_once('../../config.php');
6 require_once('locallib.php');
8 //
9 // Checkin' script parameters
11 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
12 $a = optional_param('a', '', PARAM_INT); // scorm ID
13 $scoid = required_param('scoid', PARAM_INT); // sco ID
14 $mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode
15 $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
16 $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
18 if (!empty($id)) {
19 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
20 error("Course Module ID was incorrect");
22 if (! $course = get_record("course", "id", $cm->course)) {
23 error("Course is misconfigured");
25 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
26 error("Course module is incorrect");
28 } else if (!empty($a)) {
29 if (! $scorm = get_record("scorm", "id", $a)) {
30 error("Course module is incorrect");
32 if (! $course = get_record("course", "id", $scorm->course)) {
33 error("Course is misconfigured");
35 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
36 error("Course Module ID was incorrect");
38 } else {
39 error('A required parameter is missing');
42 require_login($course->id, false, $cm);
44 $strscorms = get_string('modulenameplural', 'scorm');
45 $strscorm = get_string('modulename', 'scorm');
46 $strpopup = get_string('popup','scorm');
47 $strexit = get_string('exitactivity','scorm');
49 $navlinks = array();
51 if ($course->id != SITEID) {
52 if ($scorms = get_all_instances_in_course('scorm', $course)) {
53 // The module SCORM/AICC activity with the first id is the course
54 $firstscorm = current($scorms);
55 if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) {
56 $navlinks[] = array('name' => $strscorms, 'link' => "index.php?id=$course->id", 'type' => 'activity');
61 $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
63 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE,$course->id))) {
64 $navlinks[] = array('name' => format_string($scorm->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
65 $navigation = build_navigation($navlinks);
67 print_header($pagetitle, $course->fullname, $navigation,
68 '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);
69 notice(get_string("activityiscurrentlyhidden"));
72 // TOC processing
74 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
75 if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
76 $scorm->version = 'scorm_12';
78 require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
79 $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
80 if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
81 $attempt++;
82 $mode = 'normal';
84 $attemptstr = '&amp;attempt=' . $attempt;
86 $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true);
87 $sco = $result->sco;
89 if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
90 $mode = 'normal';
92 if ($mode != 'browse') {
93 if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) {
94 if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
95 $mode = 'review';
96 } else {
97 $mode = 'normal';
99 } else {
100 $mode = 'normal';
104 add_to_log($course->id, 'scorm', 'view', "player.php?id=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
106 $scoidstr = '&amp;scoid='.$sco->id;
107 $scoidpop = '&scoid='.$sco->id;
108 $modestr = '&amp;mode='.$mode;
109 if ($mode == 'browse') {
110 $modepop = '&mode='.$mode;
111 } else {
112 $modepop = '';
114 $orgstr = '&currentorg='.$currentorg;
116 $SESSION->scorm_scoid = $sco->id;
117 $SESSION->scorm_status = 'Not Initialized';
118 $SESSION->scorm_mode = $mode;
119 $SESSION->scorm_attempt = $attempt;
122 // Print the page header
124 $bodyscript = '';
125 if ($scorm->popup == 1) {
126 $bodyscript = 'onunload="main.close();"';
129 $navlinks[] = array('name' => format_string($scorm->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
130 $navigation = build_navigation($navlinks);
131 $exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
133 print_header($pagetitle, $course->fullname,
134 $navigation,
135 '', '', true, $exitlink.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript);
137 <script type="text/javascript" src="request.js"></script>
138 <script type="text/javascript" src="api.php?id=<?php echo $cm->id.$scoidstr.$modestr.$attemptstr ?>"></script>
139 <script type="text/javascript" src="<?php echo $CFG->wwwroot; ?>/mod/scorm/rd.js"></script>
140 <script type="text/javascript">
141 <!--
142 window.onresize = function() {
143 scorm_resize(<?php echo $scorm->width.", ".$scorm->height; ?>);
145 -->
146 </script>
147 <?php
149 if (($sco->previd != 0) && ((!isset($sco->previous)) || ($sco->previous == 0))) {
150 $scostr = '&scoid='.$sco->previd;
151 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var prev="'.$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."\";\n//]]>\n</script>\n";
152 } else {
153 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var prev="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";\n//]]>\n</script>\n";
155 if (($sco->nextid != 0) && ((!isset($sco->next)) || ($sco->next == 0))) {
156 $scostr = '&scoid='.$sco->nextid;
157 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var next="'.$CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modepop.$scostr."\";\n//]]>\n</script>\n";
158 } else {
159 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var next="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";\n//]]>\n</script>\n";
162 <div id="scormpage">
163 <?php
164 if ($scorm->hidetoc == 0) {
166 <div id="tocbox">
167 <?php
168 if ($scorm->hidenav ==0){
170 <!-- Bottons nav at left-->
171 <div id="tochead">
172 <form name="tochead" method="post" action="player.php?id=<?php echo $cm->id ?>" target="_top">
173 <?php
174 $orgstr = '&amp;currentorg='.$currentorg;
175 if (($scorm->hidenav == 0) && ($sco->previd != 0) && (!isset($sco->previous) || $sco->previous == 0)) {
176 // Print the prev LO button
177 $scostr = '&amp;scoid='.$sco->previd;
178 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
180 <input name="prev" type="button" value="<?php print_string('prev','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
181 <?php
183 if (($scorm->hidenav == 0) && ($sco->nextid != 0) && (!isset($sco->next) || $sco->next == 0)) {
184 // Print the next LO button
185 $scostr = '&amp;scoid='.$sco->nextid;
186 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
188 <input name="next" type="button" value="<?php print_string('next','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
189 <?php
192 </form>
193 </div> <!-- tochead -->
194 <?php
197 <div id="toctree" class="generalbox">
198 <?php echo $result->toc; ?>
199 </div> <!-- toctree -->
200 </div> <!-- tocbox -->
201 <?php
202 $class = ' class="toc"';
203 } else {
204 $class = ' class="no-toc"';
207 <div id="scormbox"<?php echo $class; if(($scorm->hidetoc == 2) || ($scorm->hidetoc == 1)){echo 'style="width:100%"';}?>>
208 <?php
209 // This very big test check if is necessary the "scormtop" div
210 if (
211 ($mode != 'normal') || // We are not in normal mode so review or browse text will displayed
213 ($scorm->hidenav == 0) && // Teacher want to display navigation links
214 ($scorm->hidetoc != 0) && // The buttons has not been displayed
217 ($sco->previd != 0) && // This is not the first learning object of the package
218 ((!isset($sco->previous)) || ($sco->previous == 0)) // Moodle must manage the previous link
219 ) ||
221 ($sco->nextid != 0) && // This is not the last learning object of the package
222 ((!isset($sco->next)) || ($sco->next == 0)) // Moodle must manage the next link
225 ) || ($scorm->hidetoc == 2) // Teacher want to display toc in a small dropdown menu
228 <div id="scormtop">
229 <?php echo $mode == 'browse' ? '<div id="scormmode" class="scorm-left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>
230 <?php echo $mode == 'review' ? '<div id="scormmode" class="scorm-left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>
231 <?php
232 if (($scorm->hidenav == 0) || ($scorm->hidetoc == 2) || ($scorm->hidetoc == 1)) {
234 <div id="scormnav" class="scorm-right">
235 <?php
236 $orgstr = '&amp;currentorg='.$currentorg;
237 if (($scorm->hidenav == 0) && ($sco->previd != 0) && (!isset($sco->previous) || $sco->previous == 0) && (($scorm->hidetoc == 2) || ($scorm->hidetoc == 1)) ) {
239 // Print the prev LO button
240 $scostr = '&amp;scoid='.$sco->previd;
241 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
243 <form name="scormnavprev" method="post" action="player.php?id=<?php echo $cm->id ?>" target="_top" style= "display:inline">
244 <input name="prev" type="button" value="<?php print_string('prev','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
245 </form>
246 <?php
248 if ($scorm->hidetoc == 2) {
249 echo $result->tocmenu;
251 if (($scorm->hidenav == 0) && ($sco->nextid != 0) && (!isset($sco->next) || $sco->next == 0) && (($scorm->hidetoc == 2) || ($scorm->hidetoc == 1))) {
252 // Print the next LO button
253 $scostr = '&amp;scoid='.$sco->nextid;
254 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
256 <form name="scormnavnext" method="post" action="player.php?id=<?php echo $cm->id ?>" target="_top" style= "display:inline">
257 <input name="next" type="button" value="<?php print_string('next','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
258 </form>
259 <?php
262 </div>
263 <?php
266 </div> <!-- Scormtop -->
267 <?php
268 } // The end of the very big test
270 <div id="scormobject" class="scorm-right">
271 <noscript>
272 <div id="noscript">
273 <?php print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>
274 </div>
275 </noscript>
276 <?php
277 if ($result->prerequisites) {
278 if ($scorm->popup == 0) {
279 echo " <script type=\"text/javascript\">scorm_resize(".$scorm->width.", ".$scorm->height.");</script>\n";
280 $fullurl="loadSCO.php?id=".$cm->id.$scoidstr.$modestr;
281 echo " <iframe id=\"scoframe1\" class=\"scoframe\" name=\"scoframe1\" src=\"{$fullurl}\"></iframe>\n";
282 } else {
283 // Clean the name for the window as IE is fussy
284 $name = ereg_replace("[^A-Za-z0-9]", "", $scorm->name);
285 if (!$name) {
286 $name = 'DefaultPlayerWindow';
288 $name = 'scorm_'.$name;
290 <script type="text/javascript">
291 //<![CDATA[
292 scorm_resize(<?php echo $scorm->width.", ". $scorm->height; ?>);
293 function openpopup(url,name,options,width,height) {
294 fullurl = "<?php echo $CFG->wwwroot.'/mod/scorm/' ?>" + url;
295 windowobj = window.open(fullurl,name,options);
296 if ((width==100) && (height==100)) {
297 // Fullscreen
298 windowobj.moveTo(0,0);
300 if (width<=100) {
301 width = Math.round(screen.availWidth * width / 100);
303 if (height<=100) {
304 height = Math.round(screen.availHeight * height / 100);
306 windowobj.resizeTo(width,height);
307 windowobj.focus();
308 return windowobj;
311 url = "loadSCO.php?id=<?php echo $cm->id.$scoidpop ?>";
312 width = <?php p($scorm->width) ?>;
313 height = <?php p($scorm->height) ?>;
314 var main = openpopup(url, "<?php p($name) ?>", "<?php p($scorm->options) ?>", width, height);
315 //]]>
316 </script>
317 <noscript>
318 <iframe id="main" class="scoframe" src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">
319 </iframe>
320 </noscript>
321 <?php
323 } else {
324 print_simple_box(get_string('noprerequisites','scorm'),'center');
327 </div> <!-- SCORM object -->
328 </div> <!-- SCORM box -->
329 </div> <!-- SCORM page -->
330 <?php print_footer('none'); ?>