Added a time marker for tracks
[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 }
2a0407b7 12
1a12b1f1 13 if (! $course = get_record('course', 'id', $cm->course)) {
14 error('Course is misconfigured');
98ca59f6 15 }
2a0407b7 16
1a12b1f1 17 if (! $scorm = get_record('scorm', 'id', $cm->instance)) {
18 error('Course module is incorrect');
98ca59f6 19 }
20
21 } else {
1a12b1f1 22 if (! $scorm = get_record('scorm', 'id', $a)) {
23 error('Course module is incorrect');
98ca59f6 24 }
1a12b1f1 25 if (! $course = get_record('course', 'id', $scorm->course)) {
26 error('Course is misconfigured');
98ca59f6 27 }
1a12b1f1 28 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
29 error('Course Module ID was incorrect');
98ca59f6 30 }
31 }
32
ec81373f 33 require_login($course->id, false, $cm);
92a489eb 34
a5463b34 35 if (confirm_sesskey() && (isset($SESSION->scorm_scoid))) {
5e5b6b7f 36 $scoid = $SESSION->scorm_scoid;
37 $result = true;
38 foreach ($_GET as $element => $value) {
39 if (substr($element,0,3) == 'cmi') {
40 $element = str_replace('__','.',$element);
41 $element = preg_replace('/_(\d+)/',".\$1",$element);
42 if ($track = get_record_select('scorm_scoes_track',"userid='$USER->id' AND scormid='$scorm->id' AND scoid='$scoid' AND element='$element'")) {
43 $track->value = $value;
44 $result = update_record('scorm_scoes_track',$track) && $result;
45 } else {
46 $track->userid = $USER->id;
47 $track->scormid = $scorm->id;
48 $track->scoid = $scoid;
49 $track->element = $element;
50 $track->value = $value;
51 $result = insert_record('scorm_scoes_track',$track) && $result;
52 }
53 //print_r($track);
54 }
55 }
56 if ($result) {
57 echo "true\n0";
58 } else {
59 echo "false\n101";
60 }
98ca59f6 61 }
62?>
92a489eb 63