MDL-14741: use the default html editor, as chosen in the admin settings
[moodle.git] / mod / scorm / loadSCO.php
CommitLineData
f4ba7e1a 1<?php // $Id$
b3659259 2 require_once('../../config.php');
03f5a0f8 3 require_once('locallib.php');
4
5 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
6 $a = optional_param('a', '', PARAM_INT); // scorm ID
7 $scoid = required_param('scoid', PARAM_INT); // sco ID
8
8949f8df 9 $delayseconds = 2; // Delay time before sco launch, used to give time to browser to define API
10
03f5a0f8 11 if (!empty($id)) {
12 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
5a2a5331 13 print_error('Course Module ID was incorrect');
03f5a0f8 14 }
b3659259 15 if (! $course = get_record('course', 'id', $cm->course)) {
5a2a5331 16 print_error('Course is misconfigured');
03f5a0f8 17 }
b3659259 18 if (! $scorm = get_record('scorm', 'id', $cm->instance)) {
5a2a5331 19 print_error('Course module is incorrect');
03f5a0f8 20 }
21 } else if (!empty($a)) {
b3659259 22 if (! $scorm = get_record('scorm', 'id', $a)) {
5a2a5331 23 print_error('Course module is incorrect');
03f5a0f8 24 }
b3659259 25 if (! $course = get_record('course', 'id', $scorm->course)) {
5a2a5331 26 print_error('Course is misconfigured');
03f5a0f8 27 }
b3659259 28 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
5a2a5331 29 print_error('Course Module ID was incorrect');
03f5a0f8 30 }
31 } else {
5a2a5331 32 print_error('A required parameter is missing');
03f5a0f8 33 }
34
35 require_login($course->id, false, $cm);
36 if (!empty($scoid)) {
37 //
38 // Direct SCO request
39 //
b3659259 40 if ($sco = scorm_get_sco($scoid)) {
03f5a0f8 41 if ($sco->launch == '') {
42 // Search for the next launchable sco
b3659259 43 if ($scoes = get_records_select('scorm_scoes','scorm='.$scorm->id." AND launch<>'' AND id>".$sco->id,'id ASC')) {
03f5a0f8 44 $sco = current($scoes);
45 }
46 }
47 }
48 }
49 //
50 // If no sco was found get the first of SCORM package
51 //
52 if (!isset($sco)) {
b3659259 53 $scoes = get_records_select('scorm_scoes','scorm='.$scorm->id." AND launch<>''",'id ASC');
03f5a0f8 54 $sco = current($scoes);
55 }
56
3c6c4eaf 57 if ($sco->scormtype == 'asset') {
58 $attempt = scorm_get_last_attempt($scorm->id,$USER->id);
59 $element = $scorm->version == 'scorm_13'?'cmi.completion_status':'cmi.core.lesson_status';
60 $value = 'completed';
61 $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
62 }
63
03f5a0f8 64 //
65 // Forge SCO URL
66 //
67 $connector = '';
68 $version = substr($scorm->version,0,4);
b3659259 69 if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) {
03f5a0f8 70 if (stripos($sco->launch,'?') !== false) {
71 $connector = '&';
72 } else {
73 $connector = '?';
74 }
b3659259 75 if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) {
03f5a0f8 76 $sco->parameters = substr($sco->parameters,1);
77 }
78 }
79
80 if ($version == 'AICC') {
b3659259 81 if (isset($sco->parameters) && (!empty($sco->parameters))) {
03f5a0f8 82 $sco->parameters = '&'. $sco->parameters;
83 }
3c6c4eaf 84 $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters;
03f5a0f8 85 } else {
b3659259 86 if (isset($sco->parameters) && (!empty($sco->parameters))) {
87 $launcher = $sco->launch.$connector.$sco->parameters;
88 } else {
89 $launcher = $sco->launch;
90 }
03f5a0f8 91 }
92
93 if (scorm_external_link($sco->launch)) {
8949f8df 94 // Remote learning activity
03f5a0f8 95 $result = $launcher;
96 } else if ($scorm->reference[0] == '#') {
8949f8df 97 // Repository
03f5a0f8 98 require_once($repositoryconfigfile);
99 $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
100 } else {
8949f8df 101 if ((basename($scorm->reference) == 'imsmanifest.xml') && scorm_external_link($scorm->reference)) {
102 // Remote manifest
103 $result = dirname($scorm->reference).'/'.$launcher;
03f5a0f8 104 } else {
8949f8df 105 // Moodle internal package/manifest or remote (auto-imported) package
106 if (basename($scorm->reference) == 'imsmanifest.xml') {
107 $basedir = dirname($scorm->reference);
108 } else {
109 $basedir = $CFG->moddata.'/scorm/'.$scorm->id;
110 }
111 if ($CFG->slasharguments) {
112 $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
113 } else {
114 $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;
115 }
03f5a0f8 116 }
117 }
118?>
119<html>
120 <head>
121 <title>LoadSCO</title>
f4ba7e1a 122 <script type="text/javascript">
123 //<![CDATA[
8949f8df 124 setTimeout('document.location = "<?php echo $result ?>";',<?php echo $delayseconds ?>000);
f4ba7e1a 125 //]]>
03f5a0f8 126 </script>
127 <noscript>
8949f8df 128 <meta http-equiv="refresh" content="<?php echo $delayseconds ?>;url=<?php echo $result ?>" />
03f5a0f8 129 </noscript>
130 </head>
131 <body>
132 &nbsp;
133 </body>
134</html>