3 /// This page prints a particular instance of aicc/scorm package
5 require_once('../../config.php');
6 require_once('locallib.php');
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
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");
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');
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"));
74 $scorm->version
= strtolower(clean_param($scorm->version
, PARAM_SAFEDIR
)); // Just to be safe
75 if (!file_exists($CFG->dirroot
.'/mod/scorm/datamodels/'.$scorm->version
.'lib.php')) {
76 $scorm->version
= 'scorm_12';
78 require_once($CFG->dirroot
.'/mod/scorm/datamodels/'.$scorm->version
.'lib.php');
79 $attempt = scorm_get_last_attempt($scorm->id
, $USER->id
);
80 if (($newattempt=='on') && (($attempt < $scorm->maxattempt
) ||
($scorm->maxattempt
== 0))) {
84 $attemptstr = '&attempt=' . $attempt;
86 $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true);
89 if (($mode == 'browse') && ($scorm->hidebrowse
== 1)) {
92 if ($mode != 'browse') {
93 if ($trackdata = scorm_get_tracks($sco->id
,$USER->id
,$attempt)) {
94 if (($trackdata->status
== 'completed') ||
($trackdata->status
== 'passed') ||
($trackdata->status
== 'failed')) {
104 add_to_log($course->id
, 'scorm', 'view', "player.php?id=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id
);
106 $scoidstr = '&scoid='.$sco->id
;
107 $scoidpop = '&scoid='.$sco->id
;
108 $modestr = '&mode='.$mode;
109 if ($mode == 'browse') {
110 $modepop = '&mode='.$mode;
114 $orgstr = '¤torg='.$currentorg;
116 $SESSION->scorm_scoid
= $sco->id
;
117 $SESSION->scorm_status
= 'Not Initialized';
118 $SESSION->scorm_mode
= $mode;
119 $SESSION->scorm_attempt
= $attempt;
122 // Print the page header
125 if ($scorm->popup
== 1) {
126 $bodyscript = 'onunload="main.close();"';
129 $navlinks[] = array('name' => format_string($scorm->name
,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
130 $navigation = build_navigation($navlinks);
131 $exitlink = '<a href="'.$CFG->wwwroot
.'/course/view.php?id='.$scorm->course
.'" title="'.$strexit.'">'.$strexit.'</a> ';
133 print_header($pagetitle, $course->fullname
,
135 '', '', true, $exitlink.update_module_button($cm->id
, $course->id
, $strscorm), '', false, $bodyscript);
137 <script type
="text/javascript" src
="request.js"></script
>
138 <script type
="text/javascript" src
="api.php?id=<?php echo $cm->id.$scoidstr.$modestr.$attemptstr ?>"></script
>
139 <script type
="text/javascript" src
="<?php echo $CFG->wwwroot; ?>/mod/scorm/rd.js"></script
>
140 <script type
="text/javascript">
142 window
.onresize
= function() {
143 scorm_resize(<?php
echo $scorm->width
.", ".$scorm->height
; ?
>);
149 if (($sco->previd
!= 0) && ((!isset($sco->previous
)) ||
($sco->previous
== 0))) {
150 $scostr = '&scoid='.$sco->previd
;
151 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";
153 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var prev="'.$CFG->wwwroot
.'/mod/scorm/view.php?id='.$cm->id
."\";\n//]]>\n</script>\n";
155 if (($sco->nextid
!= 0) && ((!isset($sco->next
)) ||
($sco->next
== 0))) {
156 $scostr = '&scoid='.$sco->nextid
;
157 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";
159 echo ' <script type="text/javascript">'."\n//<![CDATA[\n".'var next="'.$CFG->wwwroot
.'/mod/scorm/view.php?id='.$cm->id
."\";\n//]]>\n</script>\n";
164 if ($scorm->hidetoc
== 0) {
168 if ($scorm->hidenav
==0){
170 <!-- Bottons nav at left
-->
172 <form name
="tochead" method
="post" action
="player.php?id=<?php echo $cm->id ?>" target
="_top">
174 $orgstr = '&currentorg='.$currentorg;
175 if (($scorm->hidenav
== 0) && ($sco->previd
!= 0) && (!isset($sco->previous
) ||
$sco->previous
== 0)) {
176 // Print the prev LO button
177 $scostr = '&scoid='.$sco->previd
;
178 $url = $CFG->wwwroot
.'/mod/scorm/player.php?id='.$cm->id
.$orgstr.$modestr.$scostr;
180 <input name
="prev" type
="button" value
="<?php print_string('prev','scorm') ?>" onClick
="document.location.href=' <?php echo $url; ?> '"/>
183 if (($scorm->hidenav
== 0) && ($sco->nextid
!= 0) && (!isset($sco->next
) ||
$sco->next
== 0)) {
184 // Print the next LO button
185 $scostr = '&scoid='.$sco->nextid
;
186 $url = $CFG->wwwroot
.'/mod/scorm/player.php?id='.$cm->id
.$orgstr.$modestr.$scostr;
188 <input name
="next" type
="button" value
="<?php print_string('next','scorm') ?>" onClick
="document.location.href=' <?php echo $url; ?> '"/>
193 </div
> <!-- tochead
-->
197 <div id
="toctree" class="generalbox">
198 <?php
echo $result->toc
; ?
>
199 </div
> <!-- toctree
-->
200 </div
> <!-- tocbox
-->
202 $class = ' class="toc"';
204 $class = ' class="no-toc"';
207 <div id
="scormbox"<?php
echo $class; if(($scorm->hidetoc
== 2) ||
($scorm->hidetoc
== 1)){echo 'style="width:100%"';}?
>>
209 // This very big test check if is necessary the "scormtop" div
211 ($mode != 'normal') ||
// We are not in normal mode so review or browse text will displayed
213 ($scorm->hidenav
== 0) && // Teacher want to display navigation links
214 ($scorm->hidetoc
!= 0) && // The buttons has not been displayed
217 ($sco->previd
!= 0) && // This is not the first learning object of the package
218 ((!isset($sco->previous
)) ||
($sco->previous
== 0)) // Moodle must manage the previous link
221 ($sco->nextid
!= 0) && // This is not the last learning object of the package
222 ((!isset($sco->next
)) ||
($sco->next
== 0)) // Moodle must manage the next link
225 ) ||
($scorm->hidetoc
== 2) // Teacher want to display toc in a small dropdown menu
229 <?php
echo $mode == 'browse' ?
'<div id="scormmode" class="scorm-left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?
>
230 <?php
echo $mode == 'review' ?
'<div id="scormmode" class="scorm-left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?
>
232 if (($scorm->hidenav
== 0) ||
($scorm->hidetoc
== 2) ||
($scorm->hidetoc
== 1)) {
234 <div id
="scormnav" class="scorm-right">
236 $orgstr = '&currentorg='.$currentorg;
237 if (($scorm->hidenav
== 0) && ($sco->previd
!= 0) && (!isset($sco->previous
) ||
$sco->previous
== 0) && (($scorm->hidetoc
== 2) ||
($scorm->hidetoc
== 1)) ) {
239 // Print the prev LO button
240 $scostr = '&scoid='.$sco->previd
;
241 $url = $CFG->wwwroot
.'/mod/scorm/player.php?id='.$cm->id
.$orgstr.$modestr.$scostr;
243 <form name
="scormnavprev" method
="post" action
="player.php?id=<?php echo $cm->id ?>" target
="_top" style
= "display:inline">
244 <input name
="prev" type
="button" value
="<?php print_string('prev','scorm') ?>" onClick
="document.location.href=' <?php echo $url; ?> '"/>
248 if ($scorm->hidetoc
== 2) {
249 echo $result->tocmenu
;
251 if (($scorm->hidenav
== 0) && ($sco->nextid
!= 0) && (!isset($sco->next
) ||
$sco->next
== 0) && (($scorm->hidetoc
== 2) ||
($scorm->hidetoc
== 1))) {
252 // Print the next LO button
253 $scostr = '&scoid='.$sco->nextid
;
254 $url = $CFG->wwwroot
.'/mod/scorm/player.php?id='.$cm->id
.$orgstr.$modestr.$scostr;
256 <form name
="scormnavnext" method
="post" action
="player.php?id=<?php echo $cm->id ?>" target
="_top" style
= "display:inline">
257 <input name
="next" type
="button" value
="<?php print_string('next','scorm') ?>" onClick
="document.location.href=' <?php echo $url; ?> '"/>
266 </div
> <!-- Scormtop
-->
268 } // The end of the very big test
270 <div id
="scormobject" class="scorm-right">
273 <?php
print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>
277 if ($result->prerequisites
) {
278 if ($scorm->popup
== 0) {
279 echo " <script type=\"text/javascript\">scorm_resize(".$scorm->width
.", ".$scorm->height
.");</script>\n";
280 $fullurl="loadSCO.php?id=".$cm->id
.$scoidstr.$modestr;
281 echo " <iframe id=\"scoframe1\" class=\"scoframe\" name=\"scoframe1\" src=\"{$fullurl}\"></iframe>\n";
283 // Clean the name for the window as IE is fussy
284 $name = ereg_replace("[^A-Za-z0-9]", "", $scorm->name
);
286 $name = 'DefaultPlayerWindow';
288 $name = 'scorm_'.$name;
290 <script type
="text/javascript">
292 scorm_resize(<?php
echo $scorm->width
.", ". $scorm->height
; ?
>);
293 function openpopup(url
,name
,options
,width
,height
) {
294 fullurl
= "<?php echo $CFG->wwwroot.'/mod/scorm/' ?>" + url
;
295 windowobj
= window
.open(fullurl
,name
,options
);
296 if ((width
==100) && (height
==100)) {
298 windowobj
.moveTo(0,0);
301 width
= Math
.round(screen
.availWidth
* width
/ 100);
304 height
= Math
.round(screen
.availHeight
* height
/ 100);
306 windowobj
.resizeTo(width
,height
);
311 url
= "loadSCO.php?id=<?php echo $cm->id.$scoidpop ?>";
312 width
= <?php
p($scorm->width
) ?
>;
313 height
= <?php
p($scorm->height
) ?
>;
314 var main
= openpopup(url
, "<?php p($name) ?>", "<?php p($scorm->options) ?>", width
, height
);
318 <iframe id
="main" class="scoframe" src
="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr ?>">
324 print_simple_box(get_string('noprerequisites','scorm'),'center');
327 </div
> <!-- SCORM
object -->
328 </div
> <!-- SCORM box
-->
329 </div
> <!-- SCORM page
-->
330 <?php
print_footer('none'); ?
>