2 require_once('../../config.php');
3 require_once($CFG->dirroot
.'/mod/scorm/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;
13 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
14 print_error('invalidcoursemodule');
16 if (! $course = $DB->get_record("course", array("id"=>$cm->course
))) {
17 print_error('coursemisconf');
19 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance
))) {
20 print_error('invalidcoursemodule');
22 } else if (!empty($a)) {
23 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
24 print_error('invalidcoursemodule');
26 if (! $course = $DB->get_record("course", array("id"=>$scorm->course
))) {
27 print_error('coursemisconf');
29 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id
, $course->id
)) {
30 print_error('invalidcoursemodule');
33 print_error('missingparameter');
36 $PAGE->set_url('/mod/scorm/datamodel.php', array('scoid'=>$scoid,'attempt'=>$attempt, 'id'=>$cm->id
));
38 require_login($course->id
, false, $cm);
40 if (confirm_sesskey() && (!empty($scoid))) {
43 if (has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE
,$cm->id
))) {
44 foreach (data_submitted() as $element => $value) {
45 $element = str_replace('__','.',$element);
46 if (substr($element,0,3) == 'cmi') {
47 $netelement = preg_replace('/\.N(\d+)\./',"\.\$1\.",$element);
48 $result = scorm_insert_track($USER->id
, $scorm->id
, $scoid, $attempt, $element, $value, $scorm->forcecompleted
) && $result;
50 if (substr($element,0,15) == 'adl.nav.request') {
51 // SCORM 2004 Sequencing Request
52 require_once($CFG->dirroot
.'/mod/scorm/datamodels/sequencinglib.php');
54 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@', '@exit@', '@exitAll@', '@abandon@', '@abandonAll@');
55 $replace = array('continue_', 'previous_', '\1', 'exit_', 'exitall_', 'abandon_', 'abandonall');
56 $action = preg_replace($search, $replace, $value);
58 if ($action != $value) {
59 // Evaluating navigation request
60 $valid = scorm_seq_overall ($scoid,$USER->id
,$action,$attempt);
64 $search = array('@continue@', '@previous@', '@\{target=(\S+)\}choice@');
65 $replace = array('true', 'true', 'true');
66 $matched = preg_replace($search, $replace, $value);
67 if ($matched == 'true') {
68 $request = 'adl.nav.request_valid["'.$action.'"] = "'.$valid.'";';
72 // Log every datamodel update requested
73 if (substr($element,0,15) == 'adl.nav.request' ||
substr($element,0,3) == 'cmi') {
74 if (scorm_debugging($scorm)) {
75 add_to_log($course->id
, 'scorm', 'trk: '.trim($scorm->name
).' at: '.$attempt, 'view.php?id='.$cm->id
, "$element => $value", $cm->id
);
85 if ($request != null) {