Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/scorm/player.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00018 
00019 require_once('../../config.php');
00020 require_once($CFG->dirroot.'/mod/scorm/locallib.php');
00021 require_once($CFG->libdir . '/completionlib.php');
00022 
00023 $id = optional_param('cm', '', PARAM_INT);       // Course Module ID, or
00024 $a = optional_param('a', '', PARAM_INT);         // scorm ID
00025 $scoid = required_param('scoid', PARAM_INT);  // sco ID
00026 $mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode
00027 $currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
00028 $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
00029 $displaymode = optional_param('display','',PARAM_ALPHA);
00030 
00031 //IE 6 Bug workaround
00032 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) {
00033     @ini_set('zlib.output_compression', 'Off');
00034     @apache_setenv('no-gzip', 1);
00035 }
00036 
00037 // IE 9 workaround for Flash bug: MDL-29213
00038 // Note that it's not clear if appending the meta tag via $CFG->additionalhtmlhead
00039 // is correct at all, both because of the mechanism itself and because MS says
00040 // the tag must be used *before* including other stuff. See the issue for more info.
00041 // TODO: Once we implement some way to inject meta tags, change this to use it. MDL-30039
00042 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 9') !== false) {
00043     if (!isset($CFG->additionalhtmlhead)) { //check to make sure set first - that way we can use .=
00044         $CFG->additionalhtmlhead = '';
00045     }
00046     $CFG->additionalhtmlhead .= '<meta http-equiv="X-UA-Compatible" content="IE=8" />';
00047 }
00048 
00049 if (!empty($id)) {
00050     if (! $cm = get_coursemodule_from_id('scorm', $id)) {
00051         print_error('invalidcoursemodule');
00052     }
00053     if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
00054         print_error('coursemisconf');
00055     }
00056     if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
00057         print_error('invalidcoursemodule');
00058     }
00059 } else if (!empty($a)) {
00060     if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
00061         print_error('invalidcoursemodule');
00062     }
00063     if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
00064         print_error('coursemisconf');
00065     }
00066     if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
00067         print_error('invalidcoursemodule');
00068     }
00069 } else {
00070     print_error('missingparameter');
00071 }
00072 
00073 $url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id));
00074 if ($mode !== 'normal') {
00075     $url->param('mode', $mode);
00076 }
00077 if ($currentorg !== '') {
00078     $url->param('currentorg', $currentorg);
00079 }
00080 if ($newattempt !== 'off') {
00081     $url->param('newattempt', $newattempt);
00082 }
00083 $PAGE->set_url($url);
00084 $forcejs = get_config('scorm', 'forcejavascript');
00085 if (!empty($forcejs)) {
00086     $PAGE->add_body_class('forcejavascript');
00087 }
00088 
00089 require_login($course->id, false, $cm);
00090 
00091 $strscorms = get_string('modulenameplural', 'scorm');
00092 $strscorm  = get_string('modulename', 'scorm');
00093 $strpopup = get_string('popup', 'scorm');
00094 $strexit = get_string('exitactivity', 'scorm');
00095 
00096 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00097 
00098 if ($displaymode == 'popup') {
00099     $PAGE->set_pagelayout('popup');
00100 } else {
00101     $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
00102     $pagetitle = strip_tags("$shortname: ".format_string($scorm->name));
00103     $PAGE->set_title($pagetitle);
00104     $PAGE->set_heading($course->fullname);
00105 }
00106 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
00107     echo $OUTPUT->header();
00108     notice(get_string("activityiscurrentlyhidden"));
00109     echo $OUTPUT->footer();
00110     die;
00111 }
00112 
00113 //check if scorm closed
00114 $timenow = time();
00115 if ($scorm->timeclose !=0) {
00116     if ($scorm->timeopen > $timenow) {
00117         echo $OUTPUT->header();
00118         echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
00119         echo $OUTPUT->footer();
00120         die;
00121     } else if ($timenow > $scorm->timeclose) {
00122         echo $OUTPUT->header();
00123         echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
00124         echo $OUTPUT->footer();
00125 
00126         die;
00127     }
00128 }
00129 // TOC processing
00130 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR));   // Just to be safe
00131 if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
00132     $scorm->version = 'scorm_12';
00133 }
00134 require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
00135 $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
00136 if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
00137     $attempt++;
00138     $mode = 'normal';
00139 }
00140 $attemptstr = '&amp;attempt=' . $attempt;
00141 
00142 $result = scorm_get_toc($USER, $scorm, $cm->id, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true);
00143 $sco = $result->sco;
00144 
00145 if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
00146     $mode = 'normal';
00147 }
00148 if ($mode != 'browse') {
00149     if ($trackdata = scorm_get_tracks($sco->id, $USER->id, $attempt)) {
00150         if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
00151             $mode = 'review';
00152         } else {
00153             $mode = 'normal';
00154         }
00155     } else {
00156         $mode = 'normal';
00157     }
00158 }
00159 
00160 add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
00161 
00162 
00163 $scoidstr = '&amp;scoid='.$sco->id;
00164 $scoidpop = '&scoid='.$sco->id;
00165 $modestr = '&amp;mode='.$mode;
00166 if ($mode == 'browse') {
00167     $modepop = '&mode='.$mode;
00168 } else {
00169     $modepop = '';
00170 }
00171 $orgstr = '&currentorg='.$currentorg;
00172 
00173 $SESSION->scorm->scoid = $sco->id;
00174 $SESSION->scorm->scormstatus = 'Not Initialized';
00175 $SESSION->scorm->scormmode = $mode;
00176 $SESSION->scorm->attempt = $attempt;
00177 
00178 // Mark module viewed
00179 $completion = new completion_info($course);
00180 $completion->set_module_viewed($cm);
00181 
00182 // Print the page header
00183 if (empty($scorm->popup) || $displaymode=='popup') {
00184     $exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
00185     $PAGE->set_button($exitlink);
00186 }
00187 
00188 $PAGE->requires->yui2_lib('connection');
00189 $PAGE->requires->data_for_js('scormplayerdata', Array('cwidth'=>$scorm->width,
00190                                                       'cheight'=>$scorm->height,
00191                                                       'popupoptions' => $scorm->options), true);
00192 $PAGE->requires->js('/mod/scorm/request.js', true);
00193 $PAGE->requires->js('/lib/cookies.js', true);
00194 $PAGE->requires->css('/mod/scorm/styles.css');
00195 echo $OUTPUT->header();
00196 
00197 // NEW IMS TOC
00198 $PAGE->requires->string_for_js('navigation', 'scorm');
00199 $PAGE->requires->string_for_js('toc', 'scorm');
00200 $PAGE->requires->string_for_js('hide', 'moodle');
00201 $PAGE->requires->string_for_js('show', 'moodle');
00202 $PAGE->requires->string_for_js('popupsblocked', 'scorm');
00203 
00204 $name = false;
00205 
00206 ?>
00207     <div id="scormpage">
00208 
00209       <div id="tocbox">
00210         <div id='scormapi-parent'>
00211             <script id="external-scormapi" type="text/JavaScript"></script>
00212         </div>
00213 <?php
00214 if ($scorm->hidetoc == SCORM_TOC_POPUP or $mode=='browse' or $mode=='review') {
00215     echo '<div id="scormtop">';
00216     echo $mode == 'browse' ? '<div id="scormmode" class="scorm-left">'.get_string('browsemode', 'scorm')."</div>\n" : '';
00217     echo $mode == 'review' ? '<div id="scormmode" class="scorm-left">'.get_string('reviewmode', 'scorm')."</div>\n" : '';
00218     if ($scorm->hidetoc == SCORM_TOC_POPUP) {
00219         echo '<div id="scormnav" class="scorm-right">'.$result->tocmenu.'</div>';
00220     }
00221     echo '</div>';
00222 }
00223 ?>
00224             <div id="toctree">
00225                 <?php
00226                 if (empty($scorm->popup) || $displaymode == 'popup') {
00227                     echo $result->toc;
00228                 } else {
00229                     //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.
00230                     $linkcourse = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'">' . get_string('finishscormlinkname', 'scorm') . '</a>';
00231                     echo $OUTPUT->box(get_string('finishscorm', 'scorm', $linkcourse), 'generalbox', 'altfinishlink');
00232                 }?>
00233             </div> <!-- toctree -->
00234         </div> <!--  tocbox -->
00235                 <noscript>
00236                     <div id="noscript">
00237                         <?php print_string('noscriptnoscorm', 'scorm'); // No Martin(i), No Party ;-) ?>
00238 
00239                     </div>
00240                 </noscript>
00241 <?php
00242 if ($result->prerequisites) {
00243     if ($scorm->popup != 0 && $displaymode !=='popup') {
00244         // Clean the name for the window as IE is fussy
00245         $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
00246         if (!$name) {
00247             $name = 'DefaultPlayerWindow';
00248         }
00249         $name = 'scorm_'.$name;
00250         echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
00251         $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup'));
00252         echo html_writer::script(
00253             js_writer::function_call('scorm_openpopup', Array($url->out(false),
00254                                                        $name, $scorm->options,
00255                                                        $scorm->width, $scorm->height)));
00256         ?>
00257             <noscript>
00258             <!--[if IE]>
00259                 <iframe id="main" class="scoframe" name="main" src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></iframe>
00260             <![endif]-->
00261             <!--[if !IE]>
00262                 <object id="main" class="scoframe" type="text/html" data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></object>
00263             <![endif]-->
00264             </noscript>
00265         <?php
00266     }
00267 } else {
00268     echo $OUTPUT->box(get_string('noprerequisites', 'scorm'));
00269 }
00270 ?>
00271     </div> <!-- SCORM page -->
00272 <?php
00273 // NEW IMS TOC
00274 if (empty($scorm->popup) || $displaymode == 'popup') {
00275     if (!isset($result->toctitle)) {
00276         $result->toctitle = get_string('toc', 'scorm');
00277     }
00278     $PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->hidenav, $scorm->hidetoc, $result->toctitle, $name, $sco->id));
00279 }
00280 if (!empty($forcejs)) {
00281     echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
00282 }
00283 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations