calendar/lib: calendar_set_filters() use pre-fetched context and course recs
[moodle-pu.git] / mod / scorm / player.php
blob66a8be8caafe5c01d2845a265f9228d1d1a1a8fe
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"));
73 // TOC processing
75 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
76 if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
77 $scorm->version = 'scorm_12';
79 require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
80 $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
81 if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
82 $attempt++;
83 $mode = 'normal';
85 $attemptstr = '&amp;attempt=' . $attempt;
87 $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true);
88 $sco = $result->sco;
90 if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
91 $mode = 'normal';
93 if ($mode != 'browse') {
94 if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) {
95 if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
96 $mode = 'review';
97 } else {
98 $mode = 'normal';
100 } else {
101 $mode = 'normal';
105 add_to_log($course->id, 'scorm', 'view', "player.php?id=$cm->id&scoid=$sco->id", "$scorm->id");
107 $scoidstr = '&amp;scoid='.$sco->id;
108 $scoidpop = '&scoid='.$sco->id;
109 $modestr = '&amp;mode='.$mode;
110 if ($mode == 'browse') {
111 $modepop = '&mode='.$mode;
112 } else {
113 $modepop = '';
115 $orgstr = '&currentorg='.$currentorg;
117 $SESSION->scorm_scoid = $sco->id;
118 $SESSION->scorm_status = 'Not Initialized';
119 $SESSION->scorm_mode = $mode;
120 $SESSION->scorm_attempt = $attempt;
123 // Print the page header
125 $bodyscript = '';
126 if ($scorm->popup == 1) {
127 $bodyscript = 'onunload="main.close();"';
130 $navlinks[] = array('name' => format_string($scorm->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
131 $navigation = build_navigation($navlinks);
132 $exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
134 print_header($pagetitle, $course->fullname,
135 $navigation,
136 '', '', true, $exitlink.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript);
137 //if ($sco->scormtype == 'sco') {
139 <script type="text/javascript" src="request.js"></script>
140 <script type="text/javascript" src="api.php?id=<?php echo $cm->id.$scoidstr.$modestr.$attemptstr ?>"></script>
141 <?php
143 if (($sco->previd != 0) && ((!isset($sco->previous)) || ($sco->previous == 0))) {
144 $scostr = '&scoid='.$sco->previd;
145 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";
146 } else {
147 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var prev="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";\n//]]>\n</script>\n";
149 if (($sco->nextid != 0) && ((!isset($sco->next)) || ($sco->next == 0))) {
150 $scostr = '&scoid='.$sco->nextid;
151 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";
152 } else {
153 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var next="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";\n//]]>\n</script>\n";
156 <div id="scormpage">
157 <?php
158 if ($scorm->hidetoc == 0) {
160 <div id="tocbox" class="generalbox">
161 <div id="tochead" class="header"><?php print_string('contents','scorm') ?></div>
162 <div id="toctree">
163 <?php echo $result->toc; ?>
164 </div>
165 </div>
166 <?php
167 $class = ' class="toc"';
168 } else {
169 $class = ' class="no-toc"';
172 <div id="scormbox"<?php echo $class ?>>
173 <?php
174 // This very big test check if is necessary the "scormtop" div
175 if (
176 ($mode != 'normal') || // We are not in normal mode so review or browse text will displayed
178 ($scorm->hidenav == 0) && // Teacher want to display navigation links
181 ($sco->previd != 0) && // This is not the first learning object of the package
182 ((!isset($sco->previous)) || ($sco->previous == 0)) // Moodle must manage the previous link
183 ) ||
185 ($sco->nextid != 0) && // This is not the last learning object of the package
186 ((!isset($sco->next)) || ($sco->next == 0)) // Moodle must manage the next link
189 ) || ($scorm->hidetoc == 2) // Teacher want to display toc in a small dropdown menu
192 <div id="scormtop">
193 <?php echo $mode == 'browse' ? '<div id="scormmode" class="left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>
194 <?php echo $mode == 'review' ? '<div id="scormmode" class="left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>
195 <?php
196 if (($scorm->hidenav == 0) || ($scorm->hidetoc == 2)) {
198 <div id="scormnav" class="right">
199 <?php
200 $orgstr = '&amp;currentorg='.$currentorg;
201 if (($scorm->hidenav == 0) && ($sco->previd != 0) && ((!isset($sco->previous)) || ($sco->previous == 0))) {
202 /// Print the prev LO link
203 $scostr = '&amp;scoid='.$sco->previd;
204 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
205 echo '<a href="'.$url.'">&lt; '.get_string('prev','scorm').'</a>';
207 if ($scorm->hidetoc == 2) {
208 echo $result->tocmenu;
210 if (($scorm->hidenav == 0) && ($sco->nextid != 0) && ((!isset($sco->next)) || ($sco->next == 0))) {
211 /// Print the next LO link
212 $scostr = '&amp;scoid='.$sco->nextid;
213 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
214 echo ' &nbsp;<a href="'.$url.'">'.get_string('next','scorm').' &gt;</a>';
218 </div>
219 <?php
222 </div>
223 <?php
224 } // The end of the very big test
226 <div id="scormobject" class="right">
227 <noscript>
228 <div id="noscript">
229 <?php print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>
231 </div>
232 </noscript>
233 <?php
234 if ($result->prerequisites) {
235 if ($scorm->popup == 0) {
237 <iframe id="main"
238 class="scoframe"
239 width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>"
240 height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>"
241 src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">
242 </iframe>
243 <?php
244 } else {
246 <script type="text/javascript">
247 //<![CDATA[
248 function openpopup(url,name,options,width,height) {
249 fullurl = "<?php echo $CFG->wwwroot.'/mod/scorm/' ?>" + url;
250 windowobj = window.open(fullurl,name,options);
251 if ((width==100) && (height==100)) {
252 // Fullscreen
253 windowobj.moveTo(0,0);
255 if (width<=100) {
256 width = Math.round(screen.availWidth * width / 100);
258 if (height<=100) {
259 height = Math.round(screen.availHeight * height / 100);
261 windowobj.resizeTo(width,height);
262 windowobj.focus();
263 return windowobj;
266 url = "loadSCO.php?id=<?php echo $cm->id.$scoidpop ?>";
267 width = <?php p($scorm->width) ?>;
268 height = <?php p($scorm->height) ?>;
269 var main = openpopup(url, "scormpopup", "<?php p($scorm->options) ?>", width, height);
270 //]]>
271 </script>
272 <noscript>
273 <iframe id="main"
274 class="scoframe"
275 width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>"
276 height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>"
277 src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">
278 </iframe>
279 </noscript>
280 <?php
282 } else {
283 print_simple_box(get_string('noprerequisites','scorm'),'center');
286 </div> <!-- SCORM object -->
287 </div> <!-- SCORM box -->
288 </div> <!-- SCORM content -->
289 <?php if (!empty($THEME->customcorners)) {
290 require_once($CFG->dirroot.'/lib/custom_corners_lib.php');
291 print_custom_corners_end();
292 } ?>
293 <div class="clearer">&nbsp;</div>
294 <?php print_footer(); ?>