1 |
efrain |
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 |
require_once('../../config.php');
|
|
|
18 |
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
|
|
|
19 |
|
|
|
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.
|
|
|
24 |
|
|
|
25 |
if (!empty($id)) {
|
|
|
26 |
if (! $cm = get_coursemodule_from_id('scorm', $id)) {
|
|
|
27 |
throw new \moodle_exception('invalidcoursemodule');
|
|
|
28 |
}
|
|
|
29 |
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
|
|
|
30 |
throw new \moodle_exception('coursemisconf');
|
|
|
31 |
}
|
|
|
32 |
if (! $scorm = $DB->get_record("scorm", array("id" => $cm->instance))) {
|
|
|
33 |
throw new \moodle_exception('invalidcoursemodule');
|
|
|
34 |
}
|
|
|
35 |
} else if (!empty($a)) {
|
|
|
36 |
if (! $scorm = $DB->get_record("scorm", array("id" => $a))) {
|
|
|
37 |
throw new \moodle_exception('invalidcoursemodule');
|
|
|
38 |
}
|
|
|
39 |
if (! $course = $DB->get_record("course", array("id" => $scorm->course))) {
|
|
|
40 |
throw new \moodle_exception('coursemisconf');
|
|
|
41 |
}
|
|
|
42 |
if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
|
|
|
43 |
throw new \moodle_exception('invalidcoursemodule');
|
|
|
44 |
}
|
|
|
45 |
} else {
|
|
|
46 |
throw new \moodle_exception('missingparameter');
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
$PAGE->set_url('/mod/scorm/datamodel.php', array('scoid' => $scoid, 'attempt' => $attempt, 'id' => $cm->id));
|
|
|
50 |
|
|
|
51 |
require_login($course, false, $cm);
|
|
|
52 |
|
|
|
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 |
$sql = "SELECT e.element, v.value, v.timemodified, v.id as valueid
|
|
|
59 |
FROM {scorm_scoes_value} v
|
|
|
60 |
JOIN {scorm_attempt} a ON a.id = v.attemptid
|
|
|
61 |
JOIN {scorm_element} e on e.id = v.elementid
|
|
|
62 |
WHERE a.scormid = :scormid AND a.userid = :userid AND v.scoid = :scoid AND a.attempt = :attempt";
|
|
|
63 |
$trackdata = $DB->get_records_sql($sql, ['userid' => $USER->id, 'scormid' => $scorm->id,
|
|
|
64 |
'scoid' => $scoid, 'attempt' => $attempt]);
|
|
|
65 |
$attemptobject = scorm_get_attempt($USER->id, $scorm->id, $attempt);
|
|
|
66 |
foreach (data_submitted() as $element => $value) {
|
|
|
67 |
$element = str_replace('__', '.', $element);
|
|
|
68 |
if (substr($element, 0, 3) == 'cmi') {
|
|
|
69 |
$netelement = preg_replace('/\.N(\d+)\./', "\.\$1\.", $element);
|
|
|
70 |
$result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attemptobject, $element, $value,
|
|
|
71 |
$scorm->forcecompleted, $trackdata) && $result;
|
|
|
72 |
}
|
|
|
73 |
if (substr($element, 0, 15) == 'adl.nav.request') {
|
|
|
74 |
// SCORM 2004 Sequencing Request.
|
|
|
75 |
require_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_13lib.php');
|
|
|
76 |
|
|
|
77 |
$search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@', '@exit@',
|
|
|
78 |
'@exitAll@', '@abandon@', '@abandonAll@');
|
|
|
79 |
$replace = array('continue_', 'previous_', '\1', 'exit_', 'exitall_', 'abandon_', 'abandonall');
|
|
|
80 |
$action = preg_replace($search, $replace, $value);
|
|
|
81 |
|
|
|
82 |
if ($action != $value) {
|
|
|
83 |
// Evaluating navigation request.
|
|
|
84 |
$valid = scorm_seq_overall ($scoid, $USER->id, $action, $attempt);
|
|
|
85 |
$valid = 'true';
|
|
|
86 |
|
|
|
87 |
// Set valid request.
|
|
|
88 |
$search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@');
|
|
|
89 |
$replace = array('true', 'true', 'true');
|
|
|
90 |
$matched = preg_replace($search, $replace, $value);
|
|
|
91 |
if ($matched == 'true') {
|
|
|
92 |
$request = 'adl.nav.request_valid["'.$action.'"] = "'.$valid.'";';
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
if ($result) {
|
|
|
99 |
echo "true\n0";
|
|
|
100 |
} else {
|
|
|
101 |
echo "false\n101";
|
|
|
102 |
}
|
|
|
103 |
if ($request != null) {
|
|
|
104 |
echo "\n".$request;
|
|
|
105 |
}
|
|
|
106 |
}
|