PageRenderTime 29ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/scorm/player.php

https://github.com/200896596/moodle
PHP | 259 lines | 218 code | 27 blank | 14 comment | 65 complexity | 943dddb2058292fb7ddcaa9d9ac3a0d8 MD5 | raw file
  1. <?PHP
  2. /// This page prints a particular instance of aicc/scorm package
  3. require_once('../../config.php');
  4. require_once($CFG->dirroot.'/mod/scorm/locallib.php');
  5. require_once($CFG->libdir . '/completionlib.php');
  6. $id = optional_param('cm', '', PARAM_INT); // Course Module ID, or
  7. $a = optional_param('a', '', PARAM_INT); // scorm ID
  8. $scoid = required_param('scoid', PARAM_INT); // sco ID
  9. $mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode
  10. $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
  11. $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
  12. $displaymode = optional_param('display','',PARAM_ALPHA);
  13. //IE 6 Bug workaround
  14. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) {
  15. @ini_set('zlib.output_compression', 'Off');
  16. @apache_setenv('no-gzip', 1);
  17. }
  18. if (!empty($id)) {
  19. if (! $cm = get_coursemodule_from_id('scorm', $id)) {
  20. print_error('invalidcoursemodule');
  21. }
  22. if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
  23. print_error('coursemisconf');
  24. }
  25. if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
  26. print_error('invalidcoursemodule');
  27. }
  28. } else if (!empty($a)) {
  29. if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
  30. print_error('invalidcoursemodule');
  31. }
  32. if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
  33. print_error('coursemisconf');
  34. }
  35. if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
  36. print_error('invalidcoursemodule');
  37. }
  38. } else {
  39. print_error('missingparameter');
  40. }
  41. $url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id));
  42. if ($mode !== 'normal') {
  43. $url->param('mode', $mode);
  44. }
  45. if ($currentorg !== '') {
  46. $url->param('currentorg', $currentorg);
  47. }
  48. if ($newattempt !== 'off') {
  49. $url->param('newattempt', $newattempt);
  50. }
  51. $PAGE->set_url($url);
  52. $forcejs = get_config('scorm','forcejavascript');
  53. if (!empty($forcejs)) {
  54. $PAGE->add_body_class('forcejavascript');
  55. }
  56. require_login($course->id, false, $cm);
  57. $strscorms = get_string('modulenameplural', 'scorm');
  58. $strscorm = get_string('modulename', 'scorm');
  59. $strpopup = get_string('popup','scorm');
  60. $strexit = get_string('exitactivity','scorm');
  61. if ($displaymode == 'popup') {
  62. $PAGE->set_pagelayout('popup');
  63. } else {
  64. $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
  65. $PAGE->set_title($pagetitle);
  66. $PAGE->set_heading($course->fullname);
  67. }
  68. if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE,$course->id))) {
  69. echo $OUTPUT->header();
  70. notice(get_string("activityiscurrentlyhidden"));
  71. echo $OUTPUT->footer();
  72. die;
  73. }
  74. //check if scorm closed
  75. $timenow = time();
  76. if ($scorm->timeclose !=0) {
  77. if ($scorm->timeopen > $timenow) {
  78. echo $OUTPUT->header();
  79. echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
  80. echo $OUTPUT->footer();
  81. die;
  82. } elseif ($timenow > $scorm->timeclose) {
  83. echo $OUTPUT->header();
  84. echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
  85. echo $OUTPUT->footer();
  86. die;
  87. }
  88. }
  89. //
  90. // TOC processing
  91. //
  92. $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
  93. if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
  94. $scorm->version = 'scorm_12';
  95. }
  96. require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
  97. $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
  98. if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
  99. $attempt++;
  100. $mode = 'normal';
  101. }
  102. $attemptstr = '&amp;attempt=' . $attempt;
  103. $result = scorm_get_toc($USER, $scorm, $cm->id, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true);
  104. $sco = $result->sco;
  105. if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
  106. $mode = 'normal';
  107. }
  108. if ($mode != 'browse') {
  109. if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) {
  110. if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
  111. $mode = 'review';
  112. } else {
  113. $mode = 'normal';
  114. }
  115. } else {
  116. $mode = 'normal';
  117. }
  118. }
  119. add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
  120. $scoidstr = '&amp;scoid='.$sco->id;
  121. $scoidpop = '&scoid='.$sco->id;
  122. $modestr = '&amp;mode='.$mode;
  123. if ($mode == 'browse') {
  124. $modepop = '&mode='.$mode;
  125. } else {
  126. $modepop = '';
  127. }
  128. $orgstr = '&currentorg='.$currentorg;
  129. $SESSION->scorm_scoid = $sco->id;
  130. $SESSION->scorm_status = 'Not Initialized';
  131. $SESSION->scorm_mode = $mode;
  132. $SESSION->scorm_attempt = $attempt;
  133. // Mark module viewed
  134. $completion = new completion_info($course);
  135. $completion->set_module_viewed($cm);
  136. //
  137. // Print the page header
  138. //
  139. if (empty($scorm->popup) || $displaymode=='popup') {
  140. $exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
  141. $PAGE->set_button($exitlink);
  142. }
  143. $PAGE->requires->yui2_lib('connection');
  144. $PAGE->requires->data_for_js('scormplayerdata', Array('cwidth'=>$scorm->width,'cheight'=>$scorm->height,
  145. 'popupoptions' => $scorm->options), true);
  146. $PAGE->requires->js('/mod/scorm/request.js', true);
  147. $PAGE->requires->js('/lib/cookies.js', true);
  148. $PAGE->requires->css('/mod/scorm/styles.css');
  149. echo $OUTPUT->header();
  150. // NEW IMS TOC
  151. $PAGE->requires->string_for_js('navigation', 'scorm');
  152. $PAGE->requires->string_for_js('toc', 'scorm');
  153. $PAGE->requires->string_for_js('hide', 'moodle');
  154. $PAGE->requires->string_for_js('show', 'moodle');
  155. $PAGE->requires->string_for_js('popupsblocked', 'scorm');
  156. $name = false;
  157. ?>
  158. <div id="scormpage">
  159. <div id="tocbox">
  160. <div id='scormapi-parent'>
  161. <script id="external-scormapi" type="text/JavaScript"></script>
  162. </div>
  163. <div id="scormtop">
  164. <?php echo $mode == 'browse' ? '<div id="scormmode" class="scorm-left">'.get_string('browsemode','scorm')."</div>\n" : ''; ?>
  165. <?php echo $mode == 'review' ? '<div id="scormmode" class="scorm-left">'.get_string('reviewmode','scorm')."</div>\n" : ''; ?>
  166. <div id="scormnav" class="scorm-right">
  167. <?php
  168. if ($scorm->hidetoc == SCORM_TOC_POPUP) {
  169. echo $result->tocmenu;
  170. }
  171. ?>
  172. </div> <!-- Scormnav -->
  173. </div> <!-- Scormtop -->
  174. <div id="toctree" class="generalbox">
  175. <?php
  176. if (empty($scorm->popup) || $displaymode == 'popup') {
  177. echo $result->toc;
  178. } else {
  179. //Added incase javascript popups are blocked we don't provide a direct link to the pop-up as JS communication can fail - the user must disable their pop-up blocker.
  180. $linkcourse = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'">' . get_string('finishscormlinkname', 'scorm') . '</a>';
  181. echo $OUTPUT->box(get_string('finishscorm', 'scorm', $linkcourse), 'generalbox', 'altfinishlink');
  182. }?>
  183. </div> <!-- toctree -->
  184. </div> <!-- tocbox -->
  185. <noscript>
  186. <div id="noscript">
  187. <?php print_string('noscriptnoscorm','scorm'); // No Martin(i), No Party ;-) ?>
  188. </div>
  189. </noscript>
  190. <?php
  191. if ($result->prerequisites) {
  192. if ($scorm->popup != 0 && $displaymode !=='popup') {
  193. // Clean the name for the window as IE is fussy
  194. $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
  195. if (!$name) {
  196. $name = 'DefaultPlayerWindow';
  197. }
  198. $name = 'scorm_'.$name;
  199. echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
  200. $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup'));
  201. echo html_writer::script(
  202. js_writer::function_call('scorm_openpopup', Array($url->out(false),
  203. $name, $scorm->options,
  204. $scorm->width, $scorm->height)));
  205. ?>
  206. <noscript>
  207. <!--[if IE]>
  208. <iframe id="main" class="scoframe" name="main" src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></iframe>
  209. <![endif]-->
  210. <!--[if !IE]>
  211. <object id="main" class="scoframe" type="text/html" data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></object>
  212. <![endif]-->
  213. </noscript>
  214. <?php
  215. }
  216. } else {
  217. echo $OUTPUT->box(get_string('noprerequisites','scorm'));
  218. }
  219. ?>
  220. </div> <!-- SCORM page -->
  221. <?php
  222. // NEW IMS TOC
  223. if (empty($scorm->popup) || $displaymode == 'popup') {
  224. if (!isset($result->toctitle)) {
  225. $result->toctitle = get_string('toc', 'scorm');
  226. }
  227. $PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->hidenav, $scorm->hidetoc, $result->toctitle, $name, $sco->id));
  228. }
  229. if (!empty($forcejs)) {
  230. echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
  231. }
  232. echo $OUTPUT->footer();