Merging from STABLE:
[moodle.git] / mod / scorm / datamodel.php
CommitLineData
98ca59f6 1<?php
1a12b1f1 2 require_once('../../config.php');
3 require_once('lib.php');
2a0407b7 4
98ca59f6 5 optional_variable($id); // Course Module ID, or
a5463b34 6 optional_variable($a); // scorm IDa
98ca59f6 7
8 if ($id) {
1a12b1f1 9 if (! $cm = get_record('course_modules', 'id', $id)) {
10 error('Course Module ID was incorrect');
98ca59f6 11 }
1a12b1f1 12 if (! $course = get_record('course', 'id', $cm->course)) {
13 error('Course is misconfigured');
98ca59f6 14 }
1a12b1f1 15 if (! $scorm = get_record('scorm', 'id', $cm->instance)) {
16 error('Course module is incorrect');
98ca59f6 17 }
98ca59f6 18 } else {
1a12b1f1 19 if (! $scorm = get_record('scorm', 'id', $a)) {
20 error('Course module is incorrect');
98ca59f6 21 }
1a12b1f1 22 if (! $course = get_record('course', 'id', $scorm->course)) {
23 error('Course is misconfigured');
98ca59f6 24 }
1a12b1f1 25 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
26 error('Course Module ID was incorrect');
98ca59f6 27 }
28 }
29
ec81373f 30 require_login($course->id, false, $cm);
92a489eb 31
5c1dbdb8 32 if (confirm_sesskey() && (isset($_POST['scoid']))) {
33 $scoid = $_POST['scoid'];
5e5b6b7f 34 $result = true;
9633a423 35 foreach ($_POST as $element => $value) {
5e5b6b7f 36 if (substr($element,0,3) == 'cmi') {
37 $element = str_replace('__','.',$element);
38 $element = preg_replace('/_(\d+)/',".\$1",$element);
39 if ($track = get_record_select('scorm_scoes_track',"userid='$USER->id' AND scormid='$scorm->id' AND scoid='$scoid' AND element='$element'")) {
40 $track->value = $value;
9633a423 41 $track->timemodified = time();
5e5b6b7f 42 $result = update_record('scorm_scoes_track',$track) && $result;
43 } else {
44 $track->userid = $USER->id;
45 $track->scormid = $scorm->id;
46 $track->scoid = $scoid;
47 $track->element = $element;
48 $track->value = $value;
9633a423 49 $track->timemodified = time();
5e5b6b7f 50 $result = insert_record('scorm_scoes_track',$track) && $result;
51 }
5e5b6b7f 52 }
53 }
54 if ($result) {
55 echo "true\n0";
56 } else {
57 echo "false\n101";
58 }
98ca59f6 59 }
60?>
92a489eb 61