Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/scorm/api.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 
00017 require_once("../../config.php");
00018 require_once('locallib.php');
00019 
00020 $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or
00021 $a = optional_param('a', '', PARAM_INT);         // scorm ID
00022 $scoid = required_param('scoid', PARAM_INT);     // sco ID
00023 $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
00024 $attempt = required_param('attempt', PARAM_INT); // new attempt
00025 
00026 //IE 6 Bug workaround
00027 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) {
00028     @ini_set('zlib.output_compression', 'Off');
00029     @apache_setenv('no-gzip', 1);
00030     header( 'Content-Type: application/javascript' );
00031 }
00032 
00033 if (!empty($id)) {
00034     if (! $cm = get_coursemodule_from_id('scorm', $id)) {
00035         print_error('invalidcoursemodule');
00036     }
00037     if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
00038         print_error('coursemisconf');
00039     }
00040     if (! $scorm = $DB->get_record('scorm', array('id'=>$cm->instance))) {
00041         print_error('invalidcoursemodule');
00042     }
00043 } else if (!empty($a)) {
00044     if (! $scorm = $DB->get_record('scorm', array('id'=>$a))) {
00045         print_error('coursemisconf');
00046     }
00047     if (! $course = $DB->get_record('course', array('id'=>$scorm->course))) {
00048         print_error('coursemisconf');
00049     }
00050     if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
00051         print_error('invalidcoursemodule');
00052     }
00053 } else {
00054     print_error('missingparameter');
00055 }
00056 
00057 $PAGE->set_url('/mod/scorm/api.php', array('scoid'=>$scoid, 'id'=>$cm->id));
00058 
00059 require_login($course->id, false, $cm);
00060 
00061 if ($usertrack = scorm_get_tracks($scoid, $USER->id, $attempt)) {
00062     //according to SCORM 2004 spec(RTE V1, 4.2.8), only cmi.exit==suspend should allow previous datamodel elements on re-launch
00063     if (!scorm_version_check($scorm->version, SCORM_13) || (isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} == 'suspend'))) {
00064         foreach ($usertrack as $key => $value) {
00065             $userdata->$key = addslashes_js($value);
00066         }
00067     } else {
00068         $userdata->status = '';
00069         $userdata->score_raw = '';
00070     }
00071 } else {
00072     $userdata->status = '';
00073     $userdata->score_raw = '';
00074 }
00075 $userdata->student_id = addslashes_js($USER->username);
00076 $userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname);
00077 $userdata->mode = 'normal';
00078 if (!empty($mode)) {
00079     $userdata->mode = $mode;
00080 }
00081 if ($userdata->mode == 'normal') {
00082     $userdata->credit = 'credit';
00083 } else {
00084     $userdata->credit = 'no-credit';
00085 }
00086 if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
00087     foreach ($scodatas as $key => $value) {
00088         $userdata->$key = addslashes_js($value);
00089     }
00090 } else {
00091     print_error('cannotfindsco', 'scorm');
00092 }
00093 if (!$sco = scorm_get_sco($scoid)) {
00094     print_error('cannotfindsco', 'scorm');
00095 }
00096 if (scorm_version_check($scorm->version, SCORM_13)) {
00097     $userdata->{'cmi.scaled_passing_score'} = $DB->get_field('scorm_seq_objective', 'minnormalizedmeasure', array('scoid'=>$scoid));
00098 }
00099 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR));   // Just to be safe
00100 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
00101     include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
00102 } else {
00103     include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
00104 }
00105 // set the start time of this SCO
00106 scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, 'x.start.time', time());
00107 ?>
00108 
00109 
00110 var errorCode = "0";
00111 function underscore(str) {
00112     str = String(str).replace(/.N/g,".");
00113     return str.replace(/\./g,"__");
00114 }
 All Data Structures Namespaces Files Functions Variables Enumerations