Updated the 19 build version to 20080928
[moodle.git] / mod / scorm / datamodel.php
blob33e05f7c994fa35046b892967063277951331b7b
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
10 if (!empty($id)) {
11 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
12 error("Course Module ID was incorrect");
14 if (! $course = get_record("course", "id", $cm->course)) {
15 error("Course is misconfigured");
17 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
18 error("Course module is incorrect");
20 } else if (!empty($a)) {
21 if (! $scorm = get_record("scorm", "id", $a)) {
22 error("Course module is incorrect");
24 if (! $course = get_record("course", "id", $scorm->course)) {
25 error("Course is misconfigured");
27 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
28 error("Course Module ID was incorrect");
30 } else {
31 error('A required parameter is missing');
34 require_login($course->id, false, $cm);
36 if (confirm_sesskey() && (!empty($scoid))) {
37 $result = true;
38 $request = null;
39 if (has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE,$cm->id))) {
40 foreach ($_POST as $element => $value) {
41 $element = str_replace('__','.',$element);
42 if (substr($element,0,3) == 'cmi') {
43 $netelement = preg_replace('/\.N(\d+)\./',"\.\$1\.",$element);
44 $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $netelement, $value) && $result;
46 if (substr($element,0,15) == 'adl.nav.request') {
47 // SCORM 2004 Sequencing Request
48 require_once('datamodels/sequencinglib.php');
50 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@', '@exit@', '@exitAll@', '@abandon@', '@abandonAll@');
51 $replace = array('continue_', 'previous_', '\1', 'exit_', 'exitall_', 'abandon_', 'abandonall');
52 $action = preg_replace($search, $replace, $value);
54 if ($action != $value) {
55 // Evaluating navigation request
56 $valid = scorm_seq_overall ($scoid,$USER->id,$action,$attempt);
57 $valid = 'true';
59 // Set valid request
60 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@');
61 $replace = array('true', 'true', 'true');
62 $matched = preg_replace($search, $replace, $value);
63 if ($matched == 'true') {
64 $request = 'adl.nav.request_valid["'.$action.'"] = "'.$valid.'";';
68 // // Log every datamodel update requested
69 // if (substr($element,0,15) == 'adl.nav.request' || substr($element,0,3) == 'cmi') {
70 // if (debugging('',DEBUG_DEVELOPER)) {
71 // add_to_log($course->id, 'scorm', 'trk: '.trim($scorm->name).' at: '.$attempt, 'view.php?id='.$cm->id, "$element => $value", $cm->id);
72 // }
73 // }
76 if ($result) {
77 echo "true\n0";
78 } else {
79 echo "false\n101";
81 if ($request != null) {
82 echo "\n".$request;