|
Moodle
2.2.1
http://www.collinsharper.com
|
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($CFG->dirroot.'/mod/scorm/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 $attempt = required_param('attempt', PARAM_INT); // attempt number 00024 00025 if (!empty($id)) { 00026 if (! $cm = get_coursemodule_from_id('scorm', $id)) { 00027 print_error('invalidcoursemodule'); 00028 } 00029 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { 00030 print_error('coursemisconf'); 00031 } 00032 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) { 00033 print_error('invalidcoursemodule'); 00034 } 00035 } else if (!empty($a)) { 00036 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) { 00037 print_error('invalidcoursemodule'); 00038 } 00039 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) { 00040 print_error('coursemisconf'); 00041 } 00042 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { 00043 print_error('invalidcoursemodule'); 00044 } 00045 } else { 00046 print_error('missingparameter'); 00047 } 00048 00049 $PAGE->set_url('/mod/scorm/datamodel.php', array('scoid'=>$scoid, 'attempt'=>$attempt, 'id'=>$cm->id)); 00050 00051 require_login($course->id, false, $cm); 00052 00053 if (confirm_sesskey() && (!empty($scoid))) { 00054 $result = true; 00055 $request = null; 00056 if (has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE, $cm->id))) { 00057 foreach (data_submitted() as $element => $value) { 00058 $element = str_replace('__', '.', $element); 00059 if (substr($element, 0, 3) == 'cmi') { 00060 $netelement = preg_replace('/\.N(\d+)\./', "\.\$1\.", $element); 00061 $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $element, $value, $scorm->forcecompleted) && $result; 00062 } 00063 if (substr($element, 0, 15) == 'adl.nav.request') { 00064 // SCORM 2004 Sequencing Request 00065 require_once($CFG->dirroot.'/mod/scorm/datamodels/sequencinglib.php'); 00066 00067 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@', '@exit@', '@exitAll@', '@abandon@', '@abandonAll@'); 00068 $replace = array('continue_', 'previous_', '\1', 'exit_', 'exitall_', 'abandon_', 'abandonall'); 00069 $action = preg_replace($search, $replace, $value); 00070 00071 if ($action != $value) { 00072 // Evaluating navigation request 00073 $valid = scorm_seq_overall ($scoid, $USER->id, $action, $attempt); 00074 $valid = 'true'; 00075 00076 // Set valid request 00077 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@'); 00078 $replace = array('true', 'true', 'true'); 00079 $matched = preg_replace($search, $replace, $value); 00080 if ($matched == 'true') { 00081 $request = 'adl.nav.request_valid["'.$action.'"] = "'.$valid.'";'; 00082 } 00083 } 00084 } 00085 // Log every datamodel update requested 00086 if (substr($element, 0, 15) == 'adl.nav.request' || substr($element, 0, 3) == 'cmi') { 00087 if (scorm_debugging($scorm)) { 00088 add_to_log($course->id, 'scorm', 'trk: scoid/'.$scoid.' at: '.$attempt, 'view.php?id='.$cm->id, "$element => $value", $cm->id); 00089 } 00090 } 00091 } 00092 } 00093 if ($result) { 00094 echo "true\n0"; 00095 } else { 00096 echo "false\n101"; 00097 } 00098 if ($request != null) { 00099 echo "\n".$request; 00100 } 00101 }