changed all the POST with option/required_param functions
[moodle.git] / mod / scorm / loadSCO.php
CommitLineData
2a0407b7 1<?php
2 require_once("../../config.php");
3 require_once("lib.php");
4
7b873234 5 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
6 $a = optional_param('a', '', PARAM_INT); // scorm ID
7 $scoid = optional_param('scoid', '', PARAM_INT); // sco ID
8 $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
2a0407b7 9
7b873234 10 if (!empty($id)) {
5e5b6b7f 11 if (! $cm = get_record("course_modules", "id", $id)) {
12 error("Course Module ID was incorrect");
13 }
5e5b6b7f 14 if (! $course = get_record("course", "id", $cm->course)) {
15 error("Course is misconfigured");
16 }
5e5b6b7f 17 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
18 error("Course module is incorrect");
19 }
7b873234 20 } else if (!empty($a)) {
5e5b6b7f 21 if (! $scorm = get_record("scorm", "id", $a)) {
22 error("Course module is incorrect");
23 }
24 if (! $course = get_record("course", "id", $scorm->course)) {
25 error("Course is misconfigured");
26 }
27 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
28 error("Course Module ID was incorrect");
29 }
7b873234 30 } else {
31 error('A required parameter is missing');
2a0407b7 32 }
33
34 require_login($course->id, false, $cm);
9633a423 35 if (!empty($scoid)) {
4928a2f3 36 //
37 // Direct sco request
38 //
5e5b6b7f 39 if ($sco = get_record("scorm_scoes","id",$scoid)) {
40 if ($sco->launch == '') {
9633a423 41 // Search for the next launchable sco
42 if ($scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' AND id>".$sco->id,"id ASC")) {
43 $sco = current($scoes);
44 }
5e5b6b7f 45 }
46 }
2a0407b7 47 } else {
4928a2f3 48 //
49 // Search for first incomplete sco
50 //
9633a423 51 if ( $scoes_track = get_records_select("scorm_scoes_track","userid=".$USER->id." AND element='cmi.core.lesson_status' AND scormid=".$scorm->id,"scoid ASC") ) {
52 $sco_track = current($scoes_track);
5e5b6b7f 53 while ((($sco_track->value == "completed") || ($sco_track->value == "passed") || ($sco_track->value == "failed")) && ($mode == "normal")) {
9633a423 54 $sco_track = next($scoes_track);
5e5b6b7f 55 }
56 $sco = get_record("scorm_scoes","id",$sco_track->scoid);
57 }
9633a423 58 }
59 //
4928a2f3 60 // If no sco was found get the first of SCORM package
61 //
62 if (!isset($sco)) {
5e5b6b7f 63 $scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>''","id ASC");
64 $sco = current($scoes);
4928a2f3 65 }
66
2a0407b7 67 //
68 // Forge SCO URL
69 //
d0dd5c4b 70 $connector = '';
3332df21 71 $version = substr($scorm->version,0,4);
72 if (!empty($sco->parameters) || ($version == 'AICC')) {
5e5b6b7f 73 if (stripos($sco->launch,'?') !== false) {
74 $connector = '&';
75 } else {
9633a423 76 $connector = '?';
77 }
d0dd5c4b 78 }
2a0407b7 79 if (scorm_external_link($sco->launch)) {
5e5b6b7f 80 if ($version == 'AICC') {
81 if (!empty($sco->parameters)) {
9633a423 82 $sco->parameters = '&'. $sco->parameters;
5e5b6b7f 83 }
84 $result = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters;
85 } else {
86 $result = $sco->launch.$connector.$sco->parameters;
87 }
2a0407b7 88 } else {
5e5b6b7f 89 if ($CFG->slasharguments) {
90 $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/moddata/scorm/'.$scorm->id.'/'.$sco->launch.$connector.$sco->parameters;
91 } else {
92 $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/moddata/scorm/'.$scorm->id.'/'.$sco->launch.$connector.$sco->parameters;
93 }
2a0407b7 94 }
95?>
96<html>
97 <head>
5e5b6b7f 98 <title>LoadSCO</title>
9633a423 99 <script language="javascript" type="text/javascript">
100 <!--
101 setTimeout('document.location = "<?php echo $result ?>";',1000);
102 -->
103 </script>
2a0407b7 104 </head>
105 <body>
5e5b6b7f 106 &nbsp;
2a0407b7 107 </body>
88f75516 108</html>