3 /// This page prints a particular instance of aicc/scorm package
5 require_once('../../config.php');
6 require_once('locallib.php');
8 // Checkin' script parameters
10 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
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
18 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
19 print_error('invalidcoursemodule');
21 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
22 print_error('coursemisconf');
24 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
25 print_error('invalidcoursemodule');
27 } else if (!empty($a)) {
28 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
29 print_error('invalidcoursemodule');
31 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
32 print_error('coursemisconf');
34 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
35 print_error('invalidcoursemodule');
38 print_error('missingparameter');
41 require_login($course->id, false, $cm);
43 $strscorms = get_string('modulenameplural', 'scorm');
44 $strscorm = get_string('modulename', 'scorm');
45 $strpopup = get_string('popup','scorm');
46 $strexit = get_string('exitactivity','scorm');
50 if ($course->id != SITEID) {
51 if ($scorms = get_all_instances_in_course('scorm', $course)) {
52 // The module SCORM/AICC activity with the first id is the course
53 $firstscorm = current($scorms);
54 if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) {
55 $navlinks[] = array('name' => $strscorms, 'link' => "index.php?id=$course->id", 'type' => 'activity');
60 $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
61 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE,$course->id))) {
62 $navlinks[] = array('name' => format_string($scorm->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
63 $navigation = build_navigation($navlinks);
65 print_header($pagetitle, $course->fullname, $navigation,
66 '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);
67 notice(get_string("activityiscurrentlyhidden"));
72 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
73 if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
74 $scorm->version = 'scorm_12';
76 require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
77 $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
78 if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
82 $attemptstr = '&attempt=' . $attempt;
84 $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true);
87 if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
90 if ($mode != 'browse') {
91 if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) {
92 if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
102 add_to_log($course->id, 'scorm', 'view', "player.php?id=$cm->id&scoid=$sco->id", "$scorm->id");
104 $scoidstr = '&scoid='.$sco->id;
105 $scoidpop = '&scoid='.$sco->id;
106 $modestr = '&mode='.$mode;
107 if ($mode == 'browse') {
108 $modepop = '&mode='.$mode;
112 $orgstr = '¤torg='.$currentorg;
114 $SESSION->scorm_scoid = $sco->id;
115 $SESSION->scorm_status = 'Not Initialized';
116 $SESSION->scorm_mode = $mode;
117 $SESSION->scorm_attempt = $attempt;
120 // Print the page header
123 if ($scorm->popup == 1) {
124 $bodyscript = 'onunload="main.close();"';
127 $navlinks[] = array('name' => format_string($scorm->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
128 $navigation = build_navigation($navlinks);
129 $exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
131 print_header($pagetitle, $course->fullname,
133 '', '', true, $exitlink.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript);
134 //if ($sco->scormtype == 'sco') {
136 <script type="text/javascript" src="request.js"></script>
137 <script type="text/javascript" src="api.php?id=<?php echo $cm->id.$scoidstr.$modestr.$attemptstr ?>"></script>
138 <script type="text/javascript" src="<?=$CFG->wwwroot?>/mod/scorm/rd.js"></script>
139 <script type="text/javascript">
141 window.onresize = function() {
148 if (($sco->previd != 0) && ((!isset($sco->previous)) || ($sco->previous == 0))) {
149 $scostr = '&scoid='.$sco->previd;
150 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 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var prev="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";\n//]]>\n</script>\n";
154 if (($sco->nextid != 0) && ((!isset($sco->next)) || ($sco->next == 0))) {
155 $scostr = '&scoid='.$sco->nextid;
156 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 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var next="'.$CFG->wwwroot.'/mod/scorm/view.php?id='.$cm->id."\";\n//]]>\n</script>\n";
163 if ($scorm->hidetoc == 0) {
170 if ($scorm->hidenav ==0){
174 <!-- Bottons nav at left-->
178 <form name="tochead" method="post" action="player.php?id=<?php echo $cm->id ?>" target="_top">
182 $orgstr = '&currentorg='.$currentorg;
184 if (($scorm->hidenav == 0) && ($sco->previd != 0) && ($sco->previous == 0)) {
186 // Print the prev LO button
188 $scostr = '&scoid='.$sco->previd;
190 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
194 <input name="prev" type="button" value="<?php print_string('prev','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
202 if (($scorm->hidenav == 0) && ($sco->nextid != 0) && ($sco->next == 0)) {
204 // Print the next LO button
206 $scostr = '&scoid='.$sco->nextid;
208 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
212 <input name="next" type="button" value="<?php print_string('next','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
222 </div> <!-- tochead -->
228 <div id="toctree" class="generalbox">
229 <?php echo $result->toc; ?>
230 </div> <!-- toctree -->
232 </div> <!-- tocbox -->
234 $class = ' class="toc"';
236 $class = ' class="no-toc"';
239 <div id="scormbox"<?php echo $class; if(($scorm->hidetoc == 2) || ($scorm->hidetoc == 1)){echo 'style="width:100%"';}?>>
241 // This very big test check if is necessary the "scormtop" div
243 ($mode != 'normal') || // We are not in normal mode so review or browse text will displayed
245 ($scorm->hidenav == 0) && // Teacher want to display navigation links
246 ($scorm->hidetoc != 0) && // The buttons has not been displayed
249 ($sco->previd != 0) && // This is not the first learning object of the package
250 ((!isset($sco->previous)) || ($sco->previous == 0)) // Moodle must manage the previous link
253 ($sco->nextid != 0) && // This is not the last learning object of the package
254 ((!isset($sco->next)) || ($sco->next == 0)) // Moodle must manage the next link
257 ) || ($scorm->hidetoc == 2) // Teacher want to display toc in a small dropdown menu
261 <?php echo $mode == 'browse' ? '<div id="scormmode" class="left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>
262 <?php echo $mode == 'review' ? '<div id="scormmode" class="left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>
264 if (($scorm->hidenav == 0) || ($scorm->hidetoc == 2) || ($scorm->hidetoc == 1)) {
266 <div id="scormnav" class="right">
268 $orgstr = '&currentorg='.$currentorg;
269 if (($scorm->hidenav == 0) && ($sco->previd != 0) && ($sco->previous == 0) && (($scorm->hidetoc == 2) || ($scorm->hidetoc == 1)) ) {
271 // Print the prev LO button
272 $scostr = '&scoid='.$sco->previd;
273 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
276 <form name="scormnavprev" method="post" action="player.php?id=<?php echo $cm->id ?>" target="_top" style= "display:inline">
278 <input name="prev" type="button" value="<?php print_string('prev','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
284 if ($scorm->hidetoc == 2) {
285 echo $result->tocmenu;
287 if (($scorm->hidenav == 0) && ($sco->nextid != 0) && ($sco->next == 0) && (($scorm->hidetoc == 2) || ($scorm->hidetoc == 1))) {
289 // Print the next LO button
290 $scostr = '&scoid='.$sco->nextid;
291 $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr;
294 <form name="scormnavnext" method="post" action="player.php?id=<?php echo $cm->id ?>" target="_top" style= "display:inline">
296 <input name="next" type="button" value="<?php print_string('next','scorm') ?>" onClick="document.location.href=' <?php echo $url; ?> '"/>
308 </div> <!-- Scormtop -->
310 } // The end of the very big test
312 <div id="scormobject" class="right">
315 <?php print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>
320 if ($result->prerequisites) {
321 if ($scorm->popup == 0) {
322 echo " <script type=\"text/javascript\">scorm_resize();</script>\n";
324 $fullurl="loadSCO.php?id=".$cm->id.$scoidstr.$modestr;
326 echo " <iframe id=\"scoframe1\" class=\"scoframe\" name=\"scoframe1\" src=\"{$fullurl}\"></iframe>\n";
329 <script type="text/javascript">
332 function openpopup(url,name,options,width,height) {
333 fullurl = "<?php echo $CFG->wwwroot.'/mod/scorm/' ?>" + url;
334 windowobj = window.open(fullurl,name,options);
335 if ((width==100) && (height==100)) {
337 windowobj.moveTo(0,0);
340 width = Math.round(screen.availWidth * width / 100);
343 height = Math.round(screen.availHeight * height / 100);
345 windowobj.resizeTo(width,height);
350 url = "loadSCO.php?id=<?php echo $cm->id.$scoidpop ?>";
351 width = <?php p($scorm->width) ?>;
352 height = <?php p($scorm->height) ?>;
353 var main = openpopup(url, "<?php p($scorm->name) ?>", "<?php p($scorm->options) ?>", width, height);
356 <iframe id="main" class="scoframe" src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">
362 print_simple_box(get_string('noprerequisites','scorm'),'center');
365 </div> <!-- SCORM object -->
366 </div> <!-- SCORM box -->
367 </div> <!-- SCORM content -->
368 <?php if (!empty($THEME->customcorners)) {
369 print_container_end();
371 </div> <!-- Content -->