changed all the POST with option/required_param functions
[moodle.git] / mod / scorm / playscorm.php
CommitLineData
2a0407b7 1<?PHP // $Id$
98ca59f6 2
3/// This page prints a particular instance of scorm
98ca59f6 4
4928a2f3 5 require_once('../../config.php');
6 require_once('lib.php');
98ca59f6 7
7b873234 8 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
9 $a = optional_param('a', '', PARAM_INT); // scorm ID
10 $scoid = required_param('scoid', '', PARAM_INT); // sco ID
11 $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
12 $currentorg = optional_param('currentorg', '', PARAM_); // selected organization
13
14 //
15 // Checkin script parameters
16 //
17 $modestring = '';
18 $scoidstring = '';
19 $currentorgstring = '';
20 if (!empty($mode)) {
21 $modestring = '&mode='.$mode;
22 }
23 if (!empty($scoid)) {
24 $scoidstring = '&scoid='.$scoid;
25 }
26 if (!empty($currentorg)) {
27 $currentorgstring = '&currentorg='.$currentorg;
28 }
98ca59f6 29
7b873234 30 if (!empty($id)) {
31 if (! $cm = get_record("course_modules", "id", $id)) {
32 error("Course Module ID was incorrect");
98ca59f6 33 }
7b873234 34 if (! $course = get_record("course", "id", $cm->course)) {
35 error("Course is misconfigured");
98ca59f6 36 }
7b873234 37 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
38 error("Course module is incorrect");
98ca59f6 39 }
7b873234 40 } else if (!empty($a)) {
41 if (! $scorm = get_record("scorm", "id", $a)) {
42 error("Course module is incorrect");
98ca59f6 43 }
7b873234 44 if (! $course = get_record("course", "id", $scorm->course)) {
45 error("Course is misconfigured");
98ca59f6 46 }
7b873234 47 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
48 error("Course Module ID was incorrect");
98ca59f6 49 }
7b873234 50 } else {
51 error('A required parameter is missing');
98ca59f6 52 }
53
ec81373f 54 require_login($course->id, false, $cm);
9633a423 55
4928a2f3 56 $strscorms = get_string('modulenameplural', 'scorm');
57 $strscorm = get_string('modulename', 'scorm');
7b873234 58 $strexpand = get_string('expcoll','scorm');
59 $strpopup = get_string('popup','scorm');
9633a423 60
98ca59f6 61 if ($course->category) {
62 $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
63 <a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
64 } else {
65 $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
66 }
67
d858c876 68 $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
98ca59f6 69
70 if (!$cm->visible and !isteacher($course->id)) {
9633a423 71 print_header($pagetitle, "$course->fullname", "$navigation ".format_string($scorm->name), '', '', true,
98ca59f6 72 update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
73 notice(get_string("activityiscurrentlyhidden"));
74 }
9633a423 75
261ee0b0 76 //
77 // TOC processing
78 //
79 $result = scorm_get_toc($scorm,'structurelist',$currentorg,$scoid,$mode,true);
80 $sco = $result->sco;
81 if ($mode == 'normal') {
82 if ($trackdata = scorm_get_tracks($USER->id,$sco->id)) {
83 if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
84 $mode = 'review';
85 }
86 }
87 }
88 add_to_log($course->id, 'scorm', 'view', "playscorm.php?id=$cm->id&scoid=$sco->id", "$scorm->id");
89 $scoidstring = '&scoid='.$sco->id;
90 $modestring = '&mode='.$mode;
91
92 $SESSION->scorm_scoid = $sco->id;
93
b7ddb4a6 94 //
95 // Print the page header
96 //
b5127f1e 97 $scripts = '';
28d32305 98 if ($scorm->popup == 1) {
2ddb242f 99 $scripts = 'onunload="top.main.close();"';
b5127f1e 100 }
261ee0b0 101
b7ddb4a6 102 print_header($pagetitle, "$course->fullname",
9633a423 103 "$navigation <a target='{$CFG->framename}' href='view.php?id=$cm->id'>".format_string($scorm->name,true)."</a>",
b5127f1e 104 '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false, $scripts);
b7ddb4a6 105?>
261ee0b0 106 <script language="JavaScript" type="text/javascript" src="request.js"></script>
107 <script language="JavaScript" type="text/javascript" src="api.php?id=<?php echo $cm->id.$scoidstring.$modestring ?>"></script>
7b873234 108
9633a423 109 <table class="fullscreen">
7b873234 110 <tr>
261ee0b0 111<?php
112 if ($scorm->hidetoc == 0) {
113?>
7b873234 114 <td class="top">
115 <table class='generalbox'>
116 <tr>
117 <td class="structurehead"><?php print_string('coursestruct','scorm') ?></td>
118 </tr>
119 <tr>
120 <td><?php echo $result->toc; ?></td>
121 </tr>
122 </table>
123 </td>
b7ddb4a6 124<?php
26b3d26d 125 }
7b873234 126 $browseclass = '';
127 if ($scorm->popup == 0) {
128 $browseclass = 'class="left"';
129 }
98ca59f6 130?>
7b873234 131 <td class="top">
132 <table class="fullscreen">
133 <tr>
134 <?php echo $mode == 'browse' ? '<td '.$browseclass.'>'.get_string('browsemode','scorm').'</td>' : ''; ?>
135 <td class="right">
9633a423 136 <form name="navform" method="post" action="playscorm.php?id=<?php echo $cm->id ?>" target="_top">
7b873234 137 <input name="scoid" type="hidden" />
138 <input name="currentorg" type="hidden" value="<?php echo $currentorg ?>" />
139 <input name="mode" type="hidden" value="<?php echo $mode ?>" />
140 <input name="prev" type="<?php if (($sco->prev == 0) || ($sco->showprev == 1)) { echo 'hidden'; } else { echo 'button'; } ?>" value="<?php print_string('prev','scorm') ?>" onClick="prevSCO();" />
141 <input name="next" type="<?php if (($sco->next == 0) || ($sco->shownext == 1)) { echo 'hidden'; } else { echo 'button'; } ?>" value="<?php print_string('next','scorm') ?>" onClick="nextSCO();" />
142 <input name="exit" type="button" value="<?php print_string('exit','scorm') ?>" onClick="playSCO(0)" />
143 </form>
144 </td>
145 </tr>
b5127f1e 146<?php
147 if ($scorm->popup == 0) {
148?>
7b873234 149 <tr><td class="right">
150 <iframe name="main" class="scoframe" width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" src="loadSCO.php?id=<?php echo $cm->id.$scoidstring.$modestring ?>"></iframe>
151 </td></tr>
152 </table>
b5127f1e 153<?php
154 }
155?>
7b873234 156 </td>
b5127f1e 157 </tr>
b7ddb4a6 158 </table>
7b873234 159
23f6c62b 160 <script language="javascript" type="text/javascript">
5f18d4e7 161 <!--
b5127f1e 162<?php
163 if ($scorm->popup == 1) {
164?>
261ee0b0 165 top.main = window.open("loadSCO.php?id=<?php echo $cm->id.$scoidstring.$modestring ?>","","width=<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>,height=<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>,scrollbars=1");
b5127f1e 166<?php
167 }
168?>
5f18d4e7 169 function playSCO(scoid) {
170 if (scoid == 0) {
2ddb242f 171 //top.main.close();
9633a423 172 document.location = '<?php echo $CFG->wwwroot ?>/course/view.php?id=<?php echo $cm->course ?>';
5f18d4e7 173 } else {
9633a423 174 document.navform.scoid.value=scoid;
175 document.navform.submit();
5f18d4e7 176 }
177 }
178
9633a423 179 function prevSCO() {
180 playSCO(<?php echo $sco->prev ?>);
181 }
5f18d4e7 182
9633a423 183 function nextSCO() {
184 playSCO(<?php echo $sco->next ?>);
185 }
5f18d4e7 186
187 function expandCollide(which,list) {
9633a423 188 var nn=document.ids?true:false
189 var w3c=document.getElementById?true:false
190 var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
191 var mid=w3c?").style":".style";
192
193 if (eval(beg+list+mid+".display") != "none") {
194 which.src = "pix/plus.gif";
195 eval(beg+list+mid+".display='none';");
196 } else {
197 which.src = "pix/minus.gif";
198 eval(beg+list+mid+".display='block';");
199 }
200 }
5f18d4e7 201 -->
202 </script>
b7ddb4a6 203</body>
7b873234 204</html>