on-demand release 3.7dev+
[moodle.git] / mod / scorm / datamodel.php
blob612efd0a082473d6e28a751f296e951bdaf07ec5
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.
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/>.
17 require_once('../../config.php');
18 require_once($CFG->dirroot.'/mod/scorm/locallib.php');
20 $id = optional_param('id', '', 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 $attempt = required_param('attempt', PARAM_INT); // attempt number.
25 if (!empty($id)) {
26 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
27 print_error('invalidcoursemodule');
29 if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
30 print_error('coursemisconf');
32 if (! $scorm = $DB->get_record("scorm", array("id" => $cm->instance))) {
33 print_error('invalidcoursemodule');
35 } else if (!empty($a)) {
36 if (! $scorm = $DB->get_record("scorm", array("id" => $a))) {
37 print_error('invalidcoursemodule');
39 if (! $course = $DB->get_record("course", array("id" => $scorm->course))) {
40 print_error('coursemisconf');
42 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
43 print_error('invalidcoursemodule');
45 } else {
46 print_error('missingparameter');
49 $PAGE->set_url('/mod/scorm/datamodel.php', array('scoid' => $scoid, 'attempt' => $attempt, 'id' => $cm->id));
51 require_login($course, false, $cm);
53 if (confirm_sesskey() && (!empty($scoid))) {
54 $result = true;
55 $request = null;
56 if (has_capability('mod/scorm:savetrack', context_module::instance($cm->id))) {
57 // Preload all current tracking data.
58 $trackdata = $DB->get_records('scorm_scoes_track', array('userid' => $USER->id, 'scormid' => $scorm->id, 'scoid' => $scoid,
59 'attempt' => $attempt), '', 'element, id, value, timemodified');
60 foreach (data_submitted() as $element => $value) {
61 $element = str_replace('__', '.', $element);
62 if (substr($element, 0, 3) == 'cmi') {
63 $netelement = preg_replace('/\.N(\d+)\./', "\.\$1\.", $element);
64 $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $element, $value, $scorm->forcecompleted,
65 $trackdata) && $result;
67 if (substr($element, 0, 15) == 'adl.nav.request') {
68 // SCORM 2004 Sequencing Request.
69 require_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_13lib.php');
71 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@', '@exit@',
72 '@exitAll@', '@abandon@', '@abandonAll@');
73 $replace = array('continue_', 'previous_', '\1', 'exit_', 'exitall_', 'abandon_', 'abandonall');
74 $action = preg_replace($search, $replace, $value);
76 if ($action != $value) {
77 // Evaluating navigation request.
78 $valid = scorm_seq_overall ($scoid, $USER->id, $action, $attempt);
79 $valid = 'true';
81 // Set valid request.
82 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@');
83 $replace = array('true', 'true', 'true');
84 $matched = preg_replace($search, $replace, $value);
85 if ($matched == 'true') {
86 $request = 'adl.nav.request_valid["'.$action.'"] = "'.$valid.'";';
92 if ($result) {
93 echo "true\n0";
94 } else {
95 echo "false\n101";
97 if ($request != null) {
98 echo "\n".$request;