1a50a1f9 |
1 | <?php\r |
2 | require_once("../../config.php");\r |
3 | require_once('locallib.php');\r |
5c1ac70c |
4 | \r |
1a50a1f9 |
5 | $id = optional_param('id', '', PARAM_INT); // Course Module ID, or\r |
6 | $a = optional_param('a', '', PARAM_INT); // scorm ID\r |
5c1ac70c |
7 | $scoid = required_param('scoid', PARAM_INT); // sco ID\r |
1a50a1f9 |
8 | \r |
9 | if (!empty($id)) {\r |
f9d5371b |
10 | if (! $cm = get_coursemodule_from_id('scorm', $id)) {\r |
1a50a1f9 |
11 | error("Course Module ID was incorrect");\r |
12 | }\r |
13 | if (! $course = get_record("course", "id", $cm->course)) {\r |
14 | error("Course is misconfigured");\r |
15 | }\r |
16 | if (! $scorm = get_record("scorm", "id", $cm->instance)) {\r |
17 | error("Course module is incorrect");\r |
18 | }\r |
19 | } else if (!empty($a)) {\r |
20 | if (! $scorm = get_record("scorm", "id", $a)) {\r |
21 | error("Course module is incorrect");\r |
22 | }\r |
23 | if (! $course = get_record("course", "id", $scorm->course)) {\r |
24 | error("Course is misconfigured");\r |
25 | }\r |
26 | if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {\r |
27 | error("Course Module ID was incorrect");\r |
28 | }\r |
29 | } else {\r |
30 | error('A required parameter is missing');\r |
31 | }\r |
32 | \r |
33 | require_login($course->id, false, $cm);\r |
34 | if (!empty($scoid)) {\r |
35 | //\r |
5c1ac70c |
36 | // Direct SCO request\r |
1a50a1f9 |
37 | //\r |
38 | if ($sco = get_record("scorm_scoes","id",$scoid)) {\r |
39 | if ($sco->launch == '') {\r |
5c1ac70c |
40 | // Search for the next launchable sco\r |
1a50a1f9 |
41 | if ($scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' AND id>".$sco->id,"id ASC")) {\r |
42 | $sco = current($scoes);\r |
43 | }\r |
44 | }\r |
45 | }\r |
46 | }\r |
47 | //\r |
48 | // If no sco was found get the first of SCORM package\r |
49 | //\r |
50 | if (!isset($sco)) {\r |
51 | $scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>''","id ASC");\r |
52 | $sco = current($scoes);\r |
53 | }\r |
54 | \r |
55 | //\r |
56 | // Forge SCO URL\r |
57 | //\r |
58 | $connector = '';\r |
59 | $version = substr($scorm->version,0,4);\r |
60 | if (!empty($sco->parameters) || ($version == 'AICC')) {\r |
61 | if (stripos($sco->launch,'?') !== false) {\r |
62 | $connector = '&';\r |
63 | } else {\r |
64 | $connector = '?';\r |
65 | }\r |
66 | if (!empty($sco->parameters) && ($sco->parameters[0] == '?')) {\r |
67 | $sco->parameters = substr($sco->parameters,1);\r |
68 | }\r |
69 | }\r |
70 | \r |
71 | if ($version == 'AICC') {\r |
72 | if (!empty($sco->parameters)) {\r |
73 | $sco->parameters = '&'. $sco->parameters;\r |
74 | }\r |
2b3447c3 |
75 | $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/type/aicc/aicc.php'.$sco->parameters;\r |
1a50a1f9 |
76 | } else {\r |
77 | $launcher = $sco->launch.$connector.$sco->parameters;\r |
78 | }\r |
79 | \r |
80 | if (scorm_external_link($sco->launch)) {\r |
81 | $result = $launcher;\r |
5c1ac70c |
82 | } else if ($scorm->reference[0] == '#') {\r |
83 | require_once($repositoryconfigfile);\r |
84 | $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;\r |
1a50a1f9 |
85 | } else {\r |
86 | if (basename($scorm->reference) == 'imsmanifest.xml') {\r |
87 | $basedir = dirname($scorm->reference);\r |
88 | } else {\r |
89 | $basedir = 'moddata/scorm/'.$scorm->id;\r |
90 | }\r |
91 | if ($CFG->slasharguments) {\r |
92 | $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;\r |
93 | } else {\r |
94 | $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;\r |
95 | }\r |
96 | }\r |
97 | ?>\r |
98 | <html>\r |
99 | <head>\r |
100 | <title>LoadSCO</title>\r |
101 | <script language="javascript" type="text/javascript">\r |
102 | <!--\r |
2b3447c3 |
103 | setTimeout('document.location = "<?php echo $result ?>";',2000);\r |
1a50a1f9 |
104 | -->\r |
105 | </script>\r |
106 | <noscript>\r |
2b3447c3 |
107 | <meta http-equiv="refresh" content="2;url=<?php echo $result ?>" />\r |
1a50a1f9 |
108 | </noscript> \r |
109 | </head>\r |
110 | <body>\r |
111 | \r |
112 | </body>\r |
113 | </html>\r |