MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / scorm / datamodel.php
blobbcb4dc3a21015db2c3032ce2636c9ab0ead539ad
1 <?php
2 require_once('../../config.php');
3 require_once('locallib.php');
5 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
6 $a = optional_param('a', '', PARAM_INT); // scorm ID
7 $scoid = required_param('scoid', PARAM_INT); // sco ID
8 $attempt = required_param('attempt', PARAM_INT); // attempt number
9 // $attempt = $SESSION->scorm_attempt;
12 if (!empty($id)) {
13 if (! $cm = get_record("course_modules", "id", $id)) {
14 error("Course Module ID was incorrect");
16 if (! $course = get_record("course", "id", $cm->course)) {
17 error("Course is misconfigured");
19 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
20 error("Course module is incorrect");
22 } else if (!empty($a)) {
23 if (! $scorm = get_record("scorm", "id", $a)) {
24 error("Course module is incorrect");
26 if (! $course = get_record("course", "id", $scorm->course)) {
27 error("Course is misconfigured");
29 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
30 error("Course Module ID was incorrect");
32 } else {
33 error('A required parameter is missing');
36 require_login($course->id, false, $cm);
38 if (confirm_sesskey() && (!empty($scoid))) {
39 $result = true;
40 $request = null;
41 if (has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE,$cm->id))) {
42 foreach ($_POST as $element => $value) {
43 $element = str_replace('__','.',$element);
44 if (substr($element,0,3) == 'cmi') {
45 $netelement = preg_replace('/\.N(\d+)\./',"\.\$1\.",$element);
46 $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $netelement, $value) && $result;
48 if (substr($element,0,15) == 'adl.nav.request') {
49 // SCORM 2004 Sequencing Request
50 require_once('datamodels/sequencinglib.php');
52 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@', '@exit@', '@exitAll@', '@abandon@', '@abandonAll@');
53 $replace = array('continue_', 'previous_', '\1', 'exit_', 'exitall_', 'abandon_', 'abandonall');
54 $action = preg_replace($search, $replace, $value);
56 if ($action != $value) {
57 // Evaluating navigation request
58 $valid = scorm_sequencing_overall ($scoid,$USER->id,$action);
59 $valid = 'true';
61 // Set valid request
62 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@');
63 $replace = array('true', 'true', 'true');
64 $matched = preg_replace($search, $replace, $value);
65 if ($matched == 'true') {
66 $request = 'adl.nav.request_valid["'.$action.'"] = "'.$valid.'";';
72 if ($result) {
73 echo "true\n0";
74 } else {
75 echo "false\n101";
77 if ($request != null) {
78 echo "\n".$request;