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