Updated the HEAD build version to 20100722
[moodle.git] / mod / scorm / player.php
CommitLineData
5c508e3f 1<?PHP
f9d5371b 2
3/// This page prints a particular instance of aicc/scorm package
4
5 require_once('../../config.php');
86996ffe 6 require_once($CFG->dirroot.'/mod/scorm/locallib.php');
f9d5371b 7 //
8 // Checkin' script parameters
9 //
3d00d6ab 10 $id = optional_param('cm', '', PARAM_INT); // Course Module ID, or
f9d5371b 11 $a = optional_param('a', '', PARAM_INT); // scorm ID
12 $scoid = required_param('scoid', PARAM_INT); // sco ID
13 $mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode
14 $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
15 $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
e73457e4 16
15d0fae4
DM
17 //IE 6 Bug workaround
18 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && ini_get('zlib.output_compression') == 'On') {
19 ini_set('zlib.output_compression', 'Off');
20 }
21
f9d5371b 22 if (!empty($id)) {
23 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
08b56f93 24 print_error('invalidcoursemodule');
f9d5371b 25 }
bf347041 26 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
08b56f93 27 print_error('coursemisconf');
f9d5371b 28 }
bf347041 29 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
08b56f93 30 print_error('invalidcoursemodule');
f9d5371b 31 }
32 } else if (!empty($a)) {
bf347041 33 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
08b56f93 34 print_error('invalidcoursemodule');
f9d5371b 35 }
bf347041 36 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
08b56f93 37 print_error('coursemisconf');
f9d5371b 38 }
39 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
08b56f93 40 print_error('invalidcoursemodule');
f9d5371b 41 }
42 } else {
08b56f93 43 print_error('missingparameter');
f9d5371b 44 }
45
3d00d6ab 46 $url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id));
5c508e3f 47 if ($mode !== 'normal') {
48 $url->param('mode', $mode);
49 }
50 if ($currentorg !== '') {
51 $url->param('currentorg', $currentorg);
52 }
53 if ($newattempt !== 'off') {
54 $url->param('newattempt', $newattempt);
55 }
56 $PAGE->set_url($url);
57
f9d5371b 58 require_login($course->id, false, $cm);
59
f9d5371b 60 $strscorms = get_string('modulenameplural', 'scorm');
61 $strscorm = get_string('modulename', 'scorm');
62 $strpopup = get_string('popup','scorm');
bb8f1433 63 $strexit = get_string('exitactivity','scorm');
f9d5371b 64
f9d5371b 65 $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
52869011 66 $PAGE->set_title($pagetitle);
67 $PAGE->set_heading($course->fullname);
43f4e520 68
52869011 69 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE,$course->id))) {
70 echo $OUTPUT->header();
f9d5371b 71 notice(get_string("activityiscurrentlyhidden"));
670bc3e7 72 echo $OUTPUT->footer();
d54e2145 73 die;
f9d5371b 74 }
d54e2145 75
76 //check if scorm closed
77 $timenow = time();
78 if ($scorm->timeclose !=0) {
79 if ($scorm->timeopen > $timenow) {
52869011 80 echo $OUTPUT->header();
6aff538a 81 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
670bc3e7 82 echo $OUTPUT->footer();
d54e2145 83 die;
84 } elseif ($timenow > $scorm->timeclose) {
52869011 85 echo $OUTPUT->header();
6aff538a 86 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
670bc3e7 87 echo $OUTPUT->footer();
d54e2145 88 die;
89 }
90 }
91
f9d5371b 92 //
93 // TOC processing
94 //
2b3447c3 95 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
dbe7e6f6 96 if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
faf01ee4 97 $scorm->version = 'scorm_12';
98 }
2b3447c3 99 require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
100 $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
f9d5371b 101 if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
102 $attempt++;
a30b6819 103 $mode = 'normal';
f9d5371b 104 }
105 $attemptstr = '&amp;attempt=' . $attempt;
106
f9d5371b 107 $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true);
108 $sco = $result->sco;
109
110 if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
111 $mode = 'normal';
112 }
113 if ($mode != 'browse') {
f9d5371b 114 if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) {
115 if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
116 $mode = 'review';
f9d5371b 117 } else {
118 $mode = 'normal';
f9d5371b 119 }
57d52eeb 120 } else {
121 $mode = 'normal';
f9d5371b 122 }
123 }
124
3d00d6ab 125 add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
43f4e520 126
f9d5371b 127
128 $scoidstr = '&amp;scoid='.$sco->id;
129 $scoidpop = '&scoid='.$sco->id;
130 $modestr = '&amp;mode='.$mode;
131 if ($mode == 'browse') {
132 $modepop = '&mode='.$mode;
133 } else {
134 $modepop = '';
135 }
136 $orgstr = '&currentorg='.$currentorg;
137
138 $SESSION->scorm_scoid = $sco->id;
139 $SESSION->scorm_status = 'Not Initialized';
140 $SESSION->scorm_mode = $mode;
2b3447c3 141 $SESSION->scorm_attempt = $attempt;
f9d5371b 142
143 //
144 // Print the page header
145 //
146 $bodyscript = '';
147 if ($scorm->popup == 1) {
148 $bodyscript = 'onunload="main.close();"';
149 }
4e204f89 150
bb8f1433 151 $exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
43f4e520 152
0a1f8f8f 153 $PAGE->set_button($exitlink);
bd257031 154
cd9729e4 155 $PAGE->requires->data_for_js('scormplayerdata', Array('cwidth'=>$scorm->width,'cheight'=>$scorm->height), true);
60409fe1
PS
156 $PAGE->requires->js('/mod/scorm/request.js', true);
157 $PAGE->requires->js('/lib/cookies.js', true);
158 $PAGE->requires->js('/mod/scorm/loaddatamodel.php?id='.$cm->id.$scoidstr.$modestr.$attemptstr, true);
159 $PAGE->requires->js('/mod/scorm/rd.js', true);
52869011 160
161 echo $OUTPUT->header();
bd257031 162
52869011 163 $PAGE->requires->js_function_call('attach_resize_event');
b3659259 164 if (($sco->previd != 0) && ((!isset($sco->previous)) || ($sco->previous == 0))) {
f9d5371b 165 $scostr = '&scoid='.$sco->previd;
2a4181a6 166 $PAGE->requires->js_function_call('scorm_set_prev', Array($CFG->wwwroot.'/mod/scorm/player.php?cm='.$cm->id.$orgstr.$modepop.$scostr));
f9d5371b 167 } else {
bd257031 168 $PAGE->requires->js_function_call('scorm_set_prev', Array($CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id));
f9d5371b 169 }
b3659259 170 if (($sco->nextid != 0) && ((!isset($sco->next)) || ($sco->next == 0))) {
f9d5371b 171 $scostr = '&scoid='.$sco->nextid;
2a4181a6 172 $PAGE->requires->js_function_call('scorm_set_next', Array($CFG->wwwroot.'/mod/scorm/player.php?cm='.$cm->id.$orgstr.$modepop.$scostr));
f9d5371b 173 } else {
bd257031 174 $PAGE->requires->js_function_call('scorm_set_next', Array($CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id));
f9d5371b 175 }
176?>
177 <div id="scormpage">
43f4e520 178<?php
f9d5371b 179 if ($scorm->hidetoc == 0) {
180?>
9438ede6 181 <div id="tocbox">
9438ede6 182<?php
9438ede6 183 if ($scorm->hidenav ==0){
9438ede6 184?>
9438ede6 185 <!-- Bottons nav at left-->
9438ede6 186 <div id="tochead">
2a4181a6 187 <form name="tochead" method="post" action="player.php?cm=<?php echo $cm->id ?>" target="_top">
9438ede6 188<?php
9438ede6 189 $orgstr = '&amp;currentorg='.$currentorg;
6aebf2e1 190 if (($scorm->hidenav == 0) && ($sco->previd != 0) && (!isset($sco->previous) || $sco->previous == 0)) {
9438ede6 191 // Print the prev LO button
9438ede6 192 $scostr = '&amp;scoid='.$sco->previd;
2a4181a6 193 $url = $CFG->wwwroot.'/mod/scorm/player.php?cm='.$cm->id.$orgstr.$modestr.$scostr;
9438ede6 194?>
9438ede6 195 <input name="prev" type="button" value="<?php print_string('prev','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
9438ede6 196<?php
9438ede6 197 }
6aebf2e1 198 if (($scorm->hidenav == 0) && ($sco->nextid != 0) && (!isset($sco->next) || $sco->next == 0)) {
9438ede6 199 // Print the next LO button
9438ede6 200 $scostr = '&amp;scoid='.$sco->nextid;
2a4181a6 201 $url = $CFG->wwwroot.'/mod/scorm/player.php?cm='.$cm->id.$orgstr.$modestr.$scostr;
9438ede6 202?>
9438ede6 203 <input name="next" type="button" value="<?php print_string('next','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
9438ede6 204<?php
9438ede6 205 }
9438ede6 206?>
9438ede6 207 </form>
9438ede6 208 </div> <!-- tochead -->
9438ede6 209<?php
9438ede6 210 }
211?>
212 <div id="toctree" class="generalbox">
f9d5371b 213 <?php echo $result->toc; ?>
9438ede6 214 </div> <!-- toctree -->
9438ede6 215 </div> <!-- tocbox -->
f9d5371b 216<?php
217 $class = ' class="toc"';
218 } else {
219 $class = ' class="no-toc"';
220 }
221?>
9438ede6 222 <div id="scormbox"<?php echo $class; if(($scorm->hidetoc == 2) || ($scorm->hidetoc == 1)){echo 'style="width:100%"';}?>>
f9d5371b 223<?php
224 // This very big test check if is necessary the "scormtop" div
225 if (
226 ($mode != 'normal') || // We are not in normal mode so review or browse text will displayed
227 (
228 ($scorm->hidenav == 0) && // Teacher want to display navigation links
9438ede6 229 ($scorm->hidetoc != 0) && // The buttons has not been displayed
f9d5371b 230 (
231 (
232 ($sco->previd != 0) && // This is not the first learning object of the package
b3659259 233 ((!isset($sco->previous)) || ($sco->previous == 0)) // Moodle must manage the previous link
43f4e520 234 ) ||
f9d5371b 235 (
236 ($sco->nextid != 0) && // This is not the last learning object of the package
b3659259 237 ((!isset($sco->next)) || ($sco->next == 0)) // Moodle must manage the next link
43f4e520 238 )
f9d5371b 239 )
43f4e520 240 ) || ($scorm->hidetoc == 2) // Teacher want to display toc in a small dropdown menu
f9d5371b 241 ) {
242?>
243 <div id="scormtop">
52a9a9b5 244 <?php echo $mode == 'browse' ? '<div id="scormmode" class="scorm-left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>
245 <?php echo $mode == 'review' ? '<div id="scormmode" class="scorm-left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>
f9d5371b 246<?php
9438ede6 247 if (($scorm->hidenav == 0) || ($scorm->hidetoc == 2) || ($scorm->hidetoc == 1)) {
f9d5371b 248?>
52a9a9b5 249 <div id="scormnav" class="scorm-right">
f9d5371b 250 <?php
251 $orgstr = '&amp;currentorg='.$currentorg;
6aebf2e1 252 if (($scorm->hidenav == 0) && ($sco->previd != 0) && (!isset($sco->previous) || $sco->previous == 0) && (($scorm->hidetoc == 2) || ($scorm->hidetoc == 1)) ) {
9438ede6 253 // Print the prev LO button
f9d5371b 254 $scostr = '&amp;scoid='.$sco->previd;
2a4181a6 255 $url = $CFG->wwwroot.'/mod/scorm/player.php?cm='.$cm->id.$orgstr.$modestr.$scostr;
9438ede6 256?>
2a4181a6 257 <form name="scormnavprev" method="post" action="player.php?cm=<?php echo $cm->id ?>" target="_top" style= "display:inline">
9438ede6 258 <input name="prev" type="button" value="<?php print_string('prev','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
9438ede6 259 </form>
9438ede6 260<?php
f9d5371b 261 }
262 if ($scorm->hidetoc == 2) {
263 echo $result->tocmenu;
264 }
6aebf2e1 265 if (($scorm->hidenav == 0) && ($sco->nextid != 0) && (!isset($sco->next) || $sco->next == 0) && (($scorm->hidetoc == 2) || ($scorm->hidetoc == 1))) {
9438ede6 266 // Print the next LO button
f9d5371b 267 $scostr = '&amp;scoid='.$sco->nextid;
2a4181a6 268 $url = $CFG->wwwroot.'/mod/scorm/player.php?cm='.$cm->id.$orgstr.$modestr.$scostr;
9438ede6 269?>
2a4181a6 270 <form name="scormnavnext" method="post" action="player.php?cm=<?php echo $cm->id ?>" target="_top" style= "display:inline">
9438ede6 271 <input name="next" type="button" value="<?php print_string('next','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
9438ede6 272 </form>
9438ede6 273<?php
f9d5371b 274 }
275 ?>
f9d5371b 276 </div>
277<?php
43f4e520 278 }
f9d5371b 279?>
9438ede6 280 </div> <!-- Scormtop -->
f9d5371b 281<?php
282 } // The end of the very big test
283?>
52a9a9b5 284 <div id="scormobject" class="scorm-right">
f9d5371b 285 <noscript>
286 <div id="noscript">
287 <?php print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>
288
289 </div>
290 </noscript>
291<?php
292 if ($result->prerequisites) {
293 if ($scorm->popup == 0) {
9438ede6 294 $fullurl="loadSCO.php?id=".$cm->id.$scoidstr.$modestr;
485f4ce6 295 ?>
ac2032dc 296 <!--[if IE]>
485f4ce6 297 <iframe id="scoframe1" class="scoframe" name="scoframe1" src="<?php echo $fullurl; ?>"></iframe>
ac2032dc 298 <![endif]-->
45b7e14f 299 <![if !IE]>
485f4ce6 300 <object id="scoframe1" class="scoframe" type="text/html" data="<?php echo $fullurl; ?>"></object>
45b7e14f 301 <![endif]>
33f54da3
PH
302
303<?php
304 if (scorm_debugging($scorm)) {
305?>
306 <script>
307 // Add in a JS controlled link for toggling the Debug logging
308 var logButton = document.createElement('a');
309 logButton.id = 'mod-scorm-log-toggle';
310 logButton.name = 'logToggle';
311 logButton.href = 'javascript:toggleLog();';
312 if (getLoggingActive() == "A") {
313 logButton.innerHTML = '<?php print_string('scormloggingon','scorm') ?>';
314 } else {
315 logButton.innerHTML = '<?php print_string('scormloggingoff','scorm') ?>';
316 }
317 var content = safeGetElement(document, 'scormpage');
318 content.insertBefore(logButton, content.firstChild);
319 </script>
485f4ce6 320<?php
33f54da3 321 }
f3665549 322 $PAGE->requires->js_function_call('scorm_resize');
f9d5371b 323 } else {
61fa8a09 324 // Clean the name for the window as IE is fussy
6dbcacee 325 $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
61fa8a09 326 if (!$name) {
327 $name = 'DefaultPlayerWindow';
328 }
329 $name = 'scorm_'.$name;
f9d5371b 330
6c772bcb
PS
331 echo html_writer::script(js_writer::function_call('scorm_resize'));
332 echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
333 echo html_writer::script(js_writer::function_call('scorm_openpopup', Array("loadSCO.php?id=".$cm->id.$scoidpop, $name, $scorm->options, $scorm->width, $scorm->height)));
f3665549 334 ?>
485f4ce6 335 <noscript>
ac2032dc 336 <!--[if IE]>
ec678a9a 337 <iframe id="main" class="scoframe" name="main" src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></iframe>
ac2032dc
DM
338 <![endif]-->
339 <!--[if !IE]>
ec678a9a 340 <object id="main" class="scoframe" type="text/html" data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></object>
ac2032dc 341 <![endif]-->
485f4ce6 342 </noscript>
43f4e520 343<?php
30fc6e2d 344 //Added incase javascript popups are blocked
be918730
DM
345 $link = '<a href="'.$CFG->wwwroot.'/mod/scorm/loadSCO.php?id='.$cm->id.$scoidstr.$modestr.'" target="_blank">'.get_string('popupblockedlinkname','scorm').'</a>';
346 echo $OUTPUT->box(get_string('popupblocked','scorm',$link), 'generalbox', 'altpopuplink');
5edcafb7
DM
347 $linkcourse = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'">' . get_string('finishscormlinkname','scorm') . '</a>';
348 echo $OUTPUT->box(get_string('finishscorm','scorm',$linkcourse), 'generalbox', 'altfinishlink');
f9d5371b 349 }
350 } else {
5c508e3f 351 echo $OUTPUT->box(get_string('noprerequisites','scorm'));
f9d5371b 352 }
353?>
354 </div> <!-- SCORM object -->
355 </div> <!-- SCORM box -->
5b89dfbb 356 </div> <!-- SCORM page -->
b3611e0d
DM
357<?php
358$completion=new completion_info($course);
359$completion->set_module_viewed($cm);
360
361echo $OUTPUT->footer();