PageRenderTime 55ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/scorm/player.php

https://bitbucket.org/kudutest/moodlegit
PHP | 289 lines | 235 code | 26 blank | 28 comment | 74 complexity | 5d0a4b1391f74bb7dcc3294dd0ba771a MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /// This page prints a particular instance of aicc/scorm package
  17. require_once('../../config.php');
  18. require_once($CFG->dirroot.'/mod/scorm/locallib.php');
  19. require_once($CFG->libdir . '/completionlib.php');
  20. $id = optional_param('cm', '', PARAM_INT); // Course Module ID, or
  21. $a = optional_param('a', '', PARAM_INT); // scorm ID
  22. $scoid = required_param('scoid', PARAM_INT); // sco ID
  23. $mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode
  24. $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
  25. $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
  26. $displaymode = optional_param('display','',PARAM_ALPHA);
  27. // IE 9 workaround for Flash bug: MDL-29213
  28. // Note that it's not clear if appending the meta tag via $CFG->additionalhtmlhead
  29. // is correct at all, both because of the mechanism itself and because MS says
  30. // the tag must be used *before* including other stuff. See the issue for more info.
  31. // TODO: Once we implement some way to inject meta tags, change this to use it. MDL-30039
  32. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 9') !== false) {
  33. if (!isset($CFG->additionalhtmlhead)) { //check to make sure set first - that way we can use .=
  34. $CFG->additionalhtmlhead = '';
  35. }
  36. $CFG->additionalhtmlhead .= '<meta http-equiv="X-UA-Compatible" content="IE=8" />';
  37. }
  38. if (!empty($id)) {
  39. if (! $cm = get_coursemodule_from_id('scorm', $id)) {
  40. print_error('invalidcoursemodule');
  41. }
  42. if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
  43. print_error('coursemisconf');
  44. }
  45. if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
  46. print_error('invalidcoursemodule');
  47. }
  48. } else if (!empty($a)) {
  49. if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
  50. print_error('invalidcoursemodule');
  51. }
  52. if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
  53. print_error('coursemisconf');
  54. }
  55. if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
  56. print_error('invalidcoursemodule');
  57. }
  58. } else {
  59. print_error('missingparameter');
  60. }
  61. $url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id));
  62. if ($mode !== 'normal') {
  63. $url->param('mode', $mode);
  64. }
  65. if ($currentorg !== '') {
  66. $url->param('currentorg', $currentorg);
  67. }
  68. if ($newattempt !== 'off') {
  69. $url->param('newattempt', $newattempt);
  70. }
  71. $PAGE->set_url($url);
  72. $forcejs = get_config('scorm', 'forcejavascript');
  73. if (!empty($forcejs)) {
  74. $PAGE->add_body_class('forcejavascript');
  75. }
  76. require_login($course, false, $cm);
  77. $strscorms = get_string('modulenameplural', 'scorm');
  78. $strscorm = get_string('modulename', 'scorm');
  79. $strpopup = get_string('popup', 'scorm');
  80. $strexit = get_string('exitactivity', 'scorm');
  81. $coursecontext = context_course::instance($course->id);
  82. if ($displaymode == 'popup') {
  83. $PAGE->set_pagelayout('popup');
  84. } else {
  85. $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
  86. $pagetitle = strip_tags("$shortname: ".format_string($scorm->name));
  87. $PAGE->set_title($pagetitle);
  88. $PAGE->set_heading($course->fullname);
  89. }
  90. if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
  91. echo $OUTPUT->header();
  92. notice(get_string("activityiscurrentlyhidden"));
  93. echo $OUTPUT->footer();
  94. die;
  95. }
  96. //check if scorm closed
  97. $timenow = time();
  98. if ($scorm->timeclose !=0) {
  99. if ($scorm->timeopen > $timenow) {
  100. echo $OUTPUT->header();
  101. echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
  102. echo $OUTPUT->footer();
  103. die;
  104. } else if ($timenow > $scorm->timeclose) {
  105. echo $OUTPUT->header();
  106. echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
  107. echo $OUTPUT->footer();
  108. die;
  109. }
  110. }
  111. // TOC processing
  112. $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
  113. if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
  114. $scorm->version = 'scorm_12';
  115. }
  116. require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
  117. $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
  118. if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
  119. $attempt++;
  120. $mode = 'normal';
  121. }
  122. $attemptstr = '&amp;attempt=' . $attempt;
  123. $result = scorm_get_toc($USER, $scorm, $cm->id, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true);
  124. $sco = $result->sco;
  125. if ($scorm->lastattemptlock == 1 && $result->attemptleft == 0) {
  126. echo $OUTPUT->header();
  127. echo $OUTPUT->notification(get_string('exceededmaxattempts', 'scorm'));
  128. echo $OUTPUT->footer();
  129. exit;
  130. }
  131. if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
  132. $mode = 'normal';
  133. }
  134. if ($mode != 'browse') {
  135. if ($trackdata = scorm_get_tracks($sco->id, $USER->id, $attempt)) {
  136. if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
  137. $mode = 'review';
  138. } else {
  139. $mode = 'normal';
  140. }
  141. } else {
  142. $mode = 'normal';
  143. }
  144. }
  145. add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
  146. $scoidstr = '&amp;scoid='.$sco->id;
  147. $scoidpop = '&scoid='.$sco->id;
  148. $modestr = '&amp;mode='.$mode;
  149. if ($mode == 'browse') {
  150. $modepop = '&mode='.$mode;
  151. } else {
  152. $modepop = '';
  153. }
  154. $orgstr = '&currentorg='.$currentorg;
  155. $SESSION->scorm = new stdClass();
  156. $SESSION->scorm->scoid = $sco->id;
  157. $SESSION->scorm->scormstatus = 'Not Initialized';
  158. $SESSION->scorm->scormmode = $mode;
  159. $SESSION->scorm->attempt = $attempt;
  160. // Mark module viewed
  161. $completion = new completion_info($course);
  162. $completion->set_module_viewed($cm);
  163. // Print the page header
  164. if (empty($scorm->popup) || $displaymode=='popup') {
  165. $exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
  166. $PAGE->set_button($exitlink);
  167. }
  168. $PAGE->requires->data_for_js('scormplayerdata', Array('launch' => false,
  169. 'currentorg' => '',
  170. 'sco' => 0,
  171. 'scorm' => 0,
  172. 'courseid' => $scorm->course,
  173. 'cwidth' => $scorm->width,
  174. 'cheight' => $scorm->height,
  175. 'popupoptions' => $scorm->options), true);
  176. $PAGE->requires->js('/mod/scorm/request.js', true);
  177. $PAGE->requires->js('/lib/cookies.js', true);
  178. echo $OUTPUT->header();
  179. // NEW IMS TOC
  180. $PAGE->requires->string_for_js('navigation', 'scorm');
  181. $PAGE->requires->string_for_js('toc', 'scorm');
  182. $PAGE->requires->string_for_js('hide', 'moodle');
  183. $PAGE->requires->string_for_js('show', 'moodle');
  184. $PAGE->requires->string_for_js('popupsblocked', 'scorm');
  185. $name = false;
  186. ?>
  187. <div id="scormpage">
  188. <div id="tocbox">
  189. <div id='scormapi-parent'>
  190. <script id="external-scormapi" type="text/JavaScript"></script>
  191. </div>
  192. <?php
  193. if ($scorm->hidetoc == SCORM_TOC_POPUP or $mode=='browse' or $mode=='review') {
  194. echo '<div id="scormtop">';
  195. echo $mode == 'browse' ? '<div id="scormmode" class="scorm-left">'.get_string('browsemode', 'scorm')."</div>\n" : '';
  196. echo $mode == 'review' ? '<div id="scormmode" class="scorm-left">'.get_string('reviewmode', 'scorm')."</div>\n" : '';
  197. if ($scorm->hidetoc == SCORM_TOC_POPUP) {
  198. echo '<div id="scormnav" class="scorm-right">'.$result->tocmenu.'</div>';
  199. }
  200. echo '</div>';
  201. }
  202. ?>
  203. <div id="toctree">
  204. <?php
  205. if (empty($scorm->popup) || $displaymode == 'popup') {
  206. echo $result->toc;
  207. } else {
  208. //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.
  209. $linkcourse = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'">' . get_string('finishscormlinkname', 'scorm') . '</a>';
  210. echo $OUTPUT->box(get_string('finishscorm', 'scorm', $linkcourse), 'generalbox', 'altfinishlink');
  211. }?>
  212. </div> <!-- toctree -->
  213. </div> <!-- tocbox -->
  214. <noscript>
  215. <div id="noscript">
  216. <?php print_string('noscriptnoscorm', 'scorm'); // No Martin(i), No Party ;-) ?>
  217. </div>
  218. </noscript>
  219. <?php
  220. if ($result->prerequisites) {
  221. if ($scorm->popup != 0 && $displaymode !=='popup') {
  222. // Clean the name for the window as IE is fussy
  223. $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
  224. if (!$name) {
  225. $name = 'DefaultPlayerWindow';
  226. }
  227. $name = 'scorm_'.$name;
  228. echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
  229. $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup'));
  230. echo html_writer::script(
  231. js_writer::function_call('scorm_openpopup', Array($url->out(false),
  232. $name, $scorm->options,
  233. $scorm->width, $scorm->height)));
  234. ?>
  235. <noscript>
  236. <!--[if IE]>
  237. <iframe id="main" class="scoframe" name="main" src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></iframe>
  238. <![endif]-->
  239. <!--[if !IE]>
  240. <object id="main" class="scoframe" type="text/html" data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></object>
  241. <![endif]-->
  242. </noscript>
  243. <?php
  244. }
  245. } else {
  246. echo $OUTPUT->box(get_string('noprerequisites', 'scorm'));
  247. }
  248. ?>
  249. </div> <!-- SCORM page -->
  250. <?php
  251. $scoes = scorm_get_toc_object($USER, $scorm, "", $sco->id, $mode, $attempt);
  252. $adlnav = scorm_get_adlnav_json($scoes['scoes']);
  253. // NEW IMS TOC
  254. if (empty($scorm->popup) || $displaymode == 'popup') {
  255. if (!isset($result->toctitle)) {
  256. $result->toctitle = get_string('toc', 'scorm');
  257. }
  258. $PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->hidenav, $scorm->hidetoc, $result->toctitle, $name, $sco->id, $adlnav));
  259. }
  260. if (!empty($forcejs)) {
  261. echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
  262. }
  263. echo $OUTPUT->footer();