[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 17 // This page prints a particular instance of aicc/scorm package. 18 19 require_once('../../config.php'); 20 require_once($CFG->dirroot.'/mod/scorm/locallib.php'); 21 require_once($CFG->libdir . '/completionlib.php'); 22 23 $id = optional_param('cm', '', PARAM_INT); // Course Module ID, or 24 $a = optional_param('a', '', PARAM_INT); // scorm ID 25 $scoid = required_param('scoid', PARAM_INT); // sco ID 26 $mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode 27 $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization 28 $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt. 29 $displaymode = optional_param('display', '', PARAM_ALPHA); 30 31 if (!empty($id)) { 32 if (! $cm = get_coursemodule_from_id('scorm', $id)) { 33 print_error('invalidcoursemodule'); 34 } 35 if (! $course = $DB->get_record("course", array("id" => $cm->course))) { 36 print_error('coursemisconf'); 37 } 38 if (! $scorm = $DB->get_record("scorm", array("id" => $cm->instance))) { 39 print_error('invalidcoursemodule'); 40 } 41 } else if (!empty($a)) { 42 if (! $scorm = $DB->get_record("scorm", array("id" => $a))) { 43 print_error('invalidcoursemodule'); 44 } 45 if (! $course = $DB->get_record("course", array("id" => $scorm->course))) { 46 print_error('coursemisconf'); 47 } 48 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { 49 print_error('invalidcoursemodule'); 50 } 51 } else { 52 print_error('missingparameter'); 53 } 54 // If new attempt is being triggered set normal mode and increment attempt number. 55 $attempt = scorm_get_last_attempt($scorm->id, $USER->id); 56 57 // Check mode is correct and set/validate mode/attempt/newattempt (uses pass by reference). 58 scorm_check_mode($scorm, $newattempt, $attempt, $USER->id, $mode); 59 60 $url = new moodle_url('/mod/scorm/player.php', array('scoid' => $scoid, 'cm' => $cm->id)); 61 if ($mode !== 'normal') { 62 $url->param('mode', $mode); 63 } 64 if ($currentorg !== '') { 65 $url->param('currentorg', $currentorg); 66 } 67 if ($newattempt !== 'off') { 68 $url->param('newattempt', $newattempt); 69 } 70 $PAGE->set_url($url); 71 $forcejs = get_config('scorm', 'forcejavascript'); 72 if (!empty($forcejs)) { 73 $PAGE->add_body_class('forcejavascript'); 74 } 75 $collapsetocwinsize = get_config('scorm', 'collapsetocwinsize'); 76 if (empty($collapsetocwinsize)) { 77 // Set as default window size to collapse TOC. 78 $collapsetocwinsize = 767; 79 } else { 80 $collapsetocwinsize = intval($collapsetocwinsize); 81 } 82 83 require_login($course, false, $cm); 84 85 $strscorms = get_string('modulenameplural', 'scorm'); 86 $strscorm = get_string('modulename', 'scorm'); 87 $strpopup = get_string('popup', 'scorm'); 88 $strexit = get_string('exitactivity', 'scorm'); 89 90 $coursecontext = context_course::instance($course->id); 91 92 if ($displaymode == 'popup') { 93 $PAGE->set_pagelayout('embedded'); 94 } else { 95 $shortname = format_string($course->shortname, true, array('context' => $coursecontext)); 96 $pagetitle = strip_tags("$shortname: ".format_string($scorm->name)); 97 $PAGE->set_title($pagetitle); 98 $PAGE->set_heading($course->fullname); 99 } 100 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', context_module::instance($cm->id))) { 101 echo $OUTPUT->header(); 102 notice(get_string("activityiscurrentlyhidden")); 103 echo $OUTPUT->footer(); 104 die; 105 } 106 107 // Check if scorm closed. 108 $timenow = time(); 109 if ($scorm->timeclose != 0) { 110 if ($scorm->timeopen > $timenow) { 111 echo $OUTPUT->header(); 112 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter"); 113 echo $OUTPUT->footer(); 114 die; 115 } else if ($timenow > $scorm->timeclose) { 116 echo $OUTPUT->header(); 117 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter"); 118 echo $OUTPUT->footer(); 119 120 die; 121 } 122 } 123 // TOC processing 124 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe. 125 if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) { 126 $scorm->version = 'scorm_12'; 127 } 128 require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php'); 129 130 $result = scorm_get_toc($USER, $scorm, $cm->id, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true); 131 $sco = $result->sco; 132 if ($scorm->lastattemptlock == 1 && $result->attemptleft == 0) { 133 echo $OUTPUT->header(); 134 echo $OUTPUT->notification(get_string('exceededmaxattempts', 'scorm')); 135 echo $OUTPUT->footer(); 136 exit; 137 } 138 139 $scoidstr = '&scoid='.$sco->id; 140 $modestr = '&mode='.$mode; 141 142 $SESSION->scorm = new stdClass(); 143 $SESSION->scorm->scoid = $sco->id; 144 $SESSION->scorm->scormstatus = 'Not Initialized'; 145 $SESSION->scorm->scormmode = $mode; 146 $SESSION->scorm->attempt = $attempt; 147 148 // Mark module viewed. 149 $completion = new completion_info($course); 150 $completion->set_module_viewed($cm); 151 152 // Print the page header. 153 if (empty($scorm->popup) || $displaymode == 'popup') { 154 $exitlink = html_writer::link($CFG->wwwroot.'/course/view.php?id='.$scorm->course, $strexit, array('title' => $strexit)); 155 $PAGE->set_button($exitlink); 156 } 157 158 $PAGE->requires->data_for_js('scormplayerdata', Array('launch' => false, 159 'currentorg' => '', 160 'sco' => 0, 161 'scorm' => 0, 162 'courseid' => $scorm->course, 163 'cwidth' => $scorm->width, 164 'cheight' => $scorm->height, 165 'popupoptions' => $scorm->options), true); 166 $PAGE->requires->js('/mod/scorm/request.js', true); 167 $PAGE->requires->js('/lib/cookies.js', true); 168 169 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js')) { 170 $PAGE->requires->js('/mod/scorm/datamodels/'.$scorm->version.'.js', true); 171 } else { 172 $PAGE->requires->js('/mod/scorm/datamodels/scorm_12.js', true); 173 } 174 175 echo $OUTPUT->header(); 176 if (!empty($scorm->displayactivityname)) { 177 echo $OUTPUT->heading(format_string($scorm->name)); 178 } 179 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 186 $name = false; 187 188 echo html_writer::start_div('', array('id' => 'scormpage')); 189 echo html_writer::start_div('', array('id' => 'tocbox')); 190 echo html_writer::div(html_writer::tag('script', '', array('id' => 'external-scormapi', 'type' => 'text/JavaScript')), '', 191 array('id' => 'scormapi-parent')); 192 193 if ($scorm->hidetoc == SCORM_TOC_POPUP or $mode == 'browse' or $mode == 'review') { 194 echo html_writer::start_div('', array('id' => 'scormtop')); 195 echo $mode == 'browse' ? html_writer::div(get_string('browsemode', 'scorm'), 'scorm-left', array('id' => 'scormmode')) : ''; 196 echo $mode == 'review' ? html_writer::div(get_string('reviewmode', 'scorm'), 'scorm-left', array('id' => 'scormmode')) : ''; 197 if ($scorm->hidetoc == SCORM_TOC_POPUP) { 198 echo html_writer::div($result->tocmenu, 'scorm-right', array('id' => 'scormnav')); 199 } 200 echo html_writer::end_div(); 201 } 202 203 echo html_writer::start_div('', array('id' => 'toctree')); 204 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 209 // to the pop-up as JS communication can fail - the user must disable their pop-up blocker. 210 $linkcourse = html_writer::link($CFG->wwwroot.'/course/view.php?id='. 211 $scorm->course, get_string('finishscormlinkname', 'scorm')); 212 echo $OUTPUT->box(get_string('finishscorm', 'scorm', $linkcourse), 'generalbox', 'altfinishlink'); 213 } 214 echo html_writer::end_div(); // Toc tree ends. 215 echo html_writer::end_div(); // Toc box ends. 216 echo html_writer::tag('noscript', html_writer::div(get_string('noscriptnoscorm', 'scorm'), '', array('id' => 'noscript'))); 217 218 if ($result->prerequisites) { 219 if ($scorm->popup != 0 && $displaymode !== 'popup') { 220 // Clean the name for the window as IE is fussy. 221 $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name); 222 if (!$name) { 223 $name = 'DefaultPlayerWindow'; 224 } 225 $name = 'scorm_'.$name; 226 echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js'); 227 $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup', 'mode' => $mode)); 228 echo html_writer::script( 229 js_writer::function_call('scorm_openpopup', Array($url->out(false), 230 $name, $scorm->options, 231 $scorm->width, $scorm->height))); 232 echo html_writer::tag('noscript', html_writer::tag('iframe', '', array('id' => 'main', 233 'class' => 'scoframe', 'name' => 'main', 'src' => 'loadSCO.php?id='.$cm->id.$scoidstr.$modestr))); 234 } 235 } else { 236 echo $OUTPUT->box(get_string('noprerequisites', 'scorm')); 237 } 238 echo html_writer::end_div(); // Scorm page ends. 239 240 $scoes = scorm_get_toc_object($USER, $scorm, $currentorg, $sco->id, $mode, $attempt); 241 $adlnav = scorm_get_adlnav_json($scoes['scoes']); 242 243 if (empty($scorm->popup) || $displaymode == 'popup') { 244 if (!isset($result->toctitle)) { 245 $result->toctitle = get_string('toc', 'scorm'); 246 } 247 $jsmodule = array( 248 'name' => 'mod_scorm', 249 'fullpath' => '/mod/scorm/module.js', 250 'requires' => array('json'), 251 ); 252 $scorm->nav = intval($scorm->nav); 253 $PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->nav, $scorm->navpositionleft, $scorm->navpositiontop, 254 $scorm->hidetoc, $collapsetocwinsize, $result->toctitle, $name, $sco->id, $adlnav), false, $jsmodule); 255 } 256 if (!empty($forcejs)) { 257 echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage"); 258 } 259 260 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.php')) { 261 include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.php'); 262 } else { 263 include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.php'); 264 } 265 266 // Add the checknet system to keep checking for a connection. 267 $PAGE->requires->string_for_js('networkdropped', 'mod_scorm'); 268 $PAGE->requires->yui_module('moodle-core-checknet', 'M.core.checknet.init', array(array( 269 'message' => array('networkdropped', 'mod_scorm'), 270 ))); 271 echo $OUTPUT->footer(); 272 273 // Set the start time of this SCO. 274 scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, 'x.start.time', time());
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |