Merge branch 'm20_MDL-26176_cleanup' of github.com:danmarsden/moodle
[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');
134c8644
DM
7 require_once($CFG->libdir . '/completionlib.php');
8
f9d5371b 9 //
10 // Checkin' script parameters
11 //
3d00d6ab 12 $id = optional_param('cm', '', PARAM_INT); // Course Module ID, or
f9d5371b 13 $a = optional_param('a', '', PARAM_INT); // scorm ID
14 $scoid = required_param('scoid', PARAM_INT); // sco ID
15 $mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode
16 $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
17 $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
e73457e4 18
15d0fae4
DM
19 //IE 6 Bug workaround
20 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && ini_get('zlib.output_compression') == 'On') {
21 ini_set('zlib.output_compression', 'Off');
22 }
23
f9d5371b 24 if (!empty($id)) {
25 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
08b56f93 26 print_error('invalidcoursemodule');
f9d5371b 27 }
bf347041 28 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
08b56f93 29 print_error('coursemisconf');
f9d5371b 30 }
bf347041 31 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
08b56f93 32 print_error('invalidcoursemodule');
f9d5371b 33 }
34 } else if (!empty($a)) {
bf347041 35 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
08b56f93 36 print_error('invalidcoursemodule');
f9d5371b 37 }
bf347041 38 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
08b56f93 39 print_error('coursemisconf');
f9d5371b 40 }
41 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
08b56f93 42 print_error('invalidcoursemodule');
f9d5371b 43 }
44 } else {
08b56f93 45 print_error('missingparameter');
f9d5371b 46 }
47
3d00d6ab 48 $url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id));
5c508e3f 49 if ($mode !== 'normal') {
50 $url->param('mode', $mode);
51 }
52 if ($currentorg !== '') {
53 $url->param('currentorg', $currentorg);
54 }
55 if ($newattempt !== 'off') {
56 $url->param('newattempt', $newattempt);
57 }
58 $PAGE->set_url($url);
59
f9d5371b 60 require_login($course->id, false, $cm);
61
f9d5371b 62 $strscorms = get_string('modulenameplural', 'scorm');
63 $strscorm = get_string('modulename', 'scorm');
64 $strpopup = get_string('popup','scorm');
bb8f1433 65 $strexit = get_string('exitactivity','scorm');
f9d5371b 66
f9d5371b 67 $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
52869011 68 $PAGE->set_title($pagetitle);
69 $PAGE->set_heading($course->fullname);
43f4e520 70
52869011 71 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE,$course->id))) {
72 echo $OUTPUT->header();
f9d5371b 73 notice(get_string("activityiscurrentlyhidden"));
670bc3e7 74 echo $OUTPUT->footer();
d54e2145 75 die;
f9d5371b 76 }
d54e2145 77
78 //check if scorm closed
79 $timenow = time();
80 if ($scorm->timeclose !=0) {
81 if ($scorm->timeopen > $timenow) {
52869011 82 echo $OUTPUT->header();
6aff538a 83 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
670bc3e7 84 echo $OUTPUT->footer();
d54e2145 85 die;
86 } elseif ($timenow > $scorm->timeclose) {
52869011 87 echo $OUTPUT->header();
6aff538a 88 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
670bc3e7 89 echo $OUTPUT->footer();
d54e2145 90 die;
91 }
92 }
93
f9d5371b 94 //
95 // TOC processing
96 //
2b3447c3 97 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
dbe7e6f6 98 if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
faf01ee4 99 $scorm->version = 'scorm_12';
100 }
2b3447c3 101 require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
102 $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
f9d5371b 103 if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
104 $attempt++;
a30b6819 105 $mode = 'normal';
f9d5371b 106 }
107 $attemptstr = '&amp;attempt=' . $attempt;
108
08868f58 109 $result = scorm_get_toc($USER, $scorm, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true);
f9d5371b 110 $sco = $result->sco;
111
112 if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
113 $mode = 'normal';
114 }
115 if ($mode != 'browse') {
f9d5371b 116 if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) {
117 if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
118 $mode = 'review';
f9d5371b 119 } else {
120 $mode = 'normal';
f9d5371b 121 }
57d52eeb 122 } else {
123 $mode = 'normal';
f9d5371b 124 }
125 }
126
3d00d6ab 127 add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
43f4e520 128
f9d5371b 129
130 $scoidstr = '&amp;scoid='.$sco->id;
131 $scoidpop = '&scoid='.$sco->id;
132 $modestr = '&amp;mode='.$mode;
133 if ($mode == 'browse') {
134 $modepop = '&mode='.$mode;
135 } else {
136 $modepop = '';
137 }
138 $orgstr = '&currentorg='.$currentorg;
139
140 $SESSION->scorm_scoid = $sco->id;
141 $SESSION->scorm_status = 'Not Initialized';
142 $SESSION->scorm_mode = $mode;
2b3447c3 143 $SESSION->scorm_attempt = $attempt;
f9d5371b 144
145 //
146 // Print the page header
147 //
148 $bodyscript = '';
149 if ($scorm->popup == 1) {
150 $bodyscript = 'onunload="main.close();"';
151 }
4e204f89 152
bb8f1433 153 $exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
43f4e520 154
0a1f8f8f 155 $PAGE->set_button($exitlink);
bd257031 156
d1cf56e7
PH
157 $PAGE->requires->data_for_js('scormplayerdata', Array('cwidth'=>$scorm->width,'cheight'=>$scorm->height,
158 'popupoptions' => $scorm->options), true);
60409fe1
PS
159 $PAGE->requires->js('/mod/scorm/request.js', true);
160 $PAGE->requires->js('/lib/cookies.js', true);
5c2aa157
DM
161 //$PAGE->requires->js('/mod/scorm/loaddatamodel.php?id='.$cm->id.$scoidstr.$modestr.$attemptstr, true);
162 $PAGE->requires->css('/mod/scorm/styles.css');
52869011 163
164 echo $OUTPUT->header();
bd257031 165
5c2aa157
DM
166 // NEW IMS TOC
167 $PAGE->requires->string_for_js('navigation', 'scorm');
168 $PAGE->requires->string_for_js('toc', 'scorm');
169 $PAGE->requires->string_for_js('hide', 'moodle');
170 $PAGE->requires->string_for_js('show', 'moodle');
fe3b9da3 171 $PAGE->requires->string_for_js('popupsblocked', 'scorm');
5c2aa157
DM
172
173 $name = false;
174
f9d5371b 175?>
176 <div id="scormpage">
5c2aa157
DM
177
178 <div id="tocbox">
179 <div id='scormapi-parent'>
180 <script id="external-scormapi" type="text/JavaScript"></script>
181 </div>
182 <div id="scormtop">
43f4e520 183<?php
5c2aa157
DM
184 if ($result->prerequisites) {
185 if ($scorm->popup != 0) {
5d21c260 186 //Added incase javascript popups are blocked we don't provide a direct link to the pop-up as JS communication can fail - the user must disable their pop-up blocker.
5c2aa157 187 $linkcourse = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'">' . get_string('finishscormlinkname','scorm') . '</a>';
31845fcd 188 echo $OUTPUT->box(get_string('finishscorm','scorm',$linkcourse), 'generalbox', 'altfinishlink');
9438ede6 189 }
f9d5371b 190 }
191?>
52a9a9b5 192 <?php echo $mode == 'browse' ? '<div id="scormmode" class="scorm-left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>
193 <?php echo $mode == 'review' ? '<div id="scormmode" class="scorm-left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>
5c2aa157 194 <div id="scormnav" class="scorm-right">
f9d5371b 195<?php
5c2aa157
DM
196 if ($scorm->hidetoc == 2) {
197 echo $result->tocmenu;
43f4e520 198 }
f9d5371b 199?>
5c2aa157
DM
200 </div> <!-- Scormnav -->
201 </div> <!-- Scormtop -->
202 <div id="toctree" class="generalbox">
203 <?php echo $result->toc; ?>
204 </div> <!-- toctree -->
205 </div> <!-- tocbox -->
f9d5371b 206 <noscript>
207 <div id="noscript">
208 <?php print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>
209
210 </div>
211 </noscript>
212<?php
213 if ($result->prerequisites) {
22a79674 214 if ($scorm->popup != 0) {
61fa8a09 215 // Clean the name for the window as IE is fussy
6dbcacee 216 $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
61fa8a09 217 if (!$name) {
218 $name = 'DefaultPlayerWindow';
219 }
220 $name = 'scorm_'.$name;
f9d5371b 221
6c772bcb
PS
222 echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
223 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 224 ?>
485f4ce6 225 <noscript>
ac2032dc 226 <!--[if IE]>
ec678a9a 227 <iframe id="main" class="scoframe" name="main" src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></iframe>
ac2032dc
DM
228 <![endif]-->
229 <!--[if !IE]>
ec678a9a 230 <object id="main" class="scoframe" type="text/html" data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></object>
ac2032dc 231 <![endif]-->
485f4ce6 232 </noscript>
43f4e520 233<?php
f9d5371b 234 }
235 } else {
5c508e3f 236 echo $OUTPUT->box(get_string('noprerequisites','scorm'));
f9d5371b 237 }
238?>
5b89dfbb 239 </div> <!-- SCORM page -->
b3611e0d 240<?php
5c2aa157
DM
241// NEW IMS TOC
242if (!isset($result->toctitle)) {
243 $result->toctitle = get_string('toc', 'scorm');
244}
245
fe3b9da3 246$PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->hidenav, $scorm->hidetoc, $result->toctitle, $name, $sco->id));
5c2aa157
DM
247
248
b3611e0d
DM
249$completion=new completion_info($course);
250$completion->set_module_viewed($cm);
251
252echo $OUTPUT->footer();