changed all the POST with option/required_param functions
[moodle.git] / mod / scorm / datamodel.php
CommitLineData
98ca59f6 1<?php
1a12b1f1 2 require_once('../../config.php');
3 require_once('lib.php');
2a0407b7 4
7b873234 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
98ca59f6 8
7b873234 9 if (!empty($id)) {
10 if (! $cm = get_record("course_modules", "id", $id)) {
11 error("Course Module ID was incorrect");
98ca59f6 12 }
7b873234 13 if (! $course = get_record("course", "id", $cm->course)) {
14 error("Course is misconfigured");
98ca59f6 15 }
7b873234 16 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
17 error("Course module is incorrect");
98ca59f6 18 }
7b873234 19 } else if (!empty($a)) {
20 if (! $scorm = get_record("scorm", "id", $a)) {
21 error("Course module is incorrect");
98ca59f6 22 }
7b873234 23 if (! $course = get_record("course", "id", $scorm->course)) {
24 error("Course is misconfigured");
98ca59f6 25 }
7b873234 26 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
27 error("Course Module ID was incorrect");
98ca59f6 28 }
7b873234 29 } else {
30 error('A required parameter is missing');
98ca59f6 31 }
32
ec81373f 33 require_login($course->id, false, $cm);
92a489eb 34
7b873234 35 if (confirm_sesskey() && (!empty($scoid))) {
5e5b6b7f 36 $result = true;
9633a423 37 foreach ($_POST as $element => $value) {
5e5b6b7f 38 if (substr($element,0,3) == 'cmi') {
39 $element = str_replace('__','.',$element);
40 $element = preg_replace('/_(\d+)/',".\$1",$element);
41 if ($track = get_record_select('scorm_scoes_track',"userid='$USER->id' AND scormid='$scorm->id' AND scoid='$scoid' AND element='$element'")) {
42 $track->value = $value;
9633a423 43 $track->timemodified = time();
5e5b6b7f 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;
9633a423 51 $track->timemodified = time();
5e5b6b7f 52 $result = insert_record('scorm_scoes_track',$track) && $result;
53 }
5e5b6b7f 54 }
55 }
56 if ($result) {
57 echo "true\n0";
58 } else {
59 echo "false\n101";
60 }
98ca59f6 61 }
62?>
92a489eb 63