lib-cookies MDL-19737 Removed need to include cookies.js on every page
[moodle.git] / mod / scorm / loaddatamodel.php
CommitLineData
03f5a0f8 1<?php
2
3 require_once("../../config.php");
4 require_once('locallib.php');
9528568b 5
03f5a0f8 6 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
7 $a = optional_param('a', '', PARAM_INT); // scorm ID
8 $scoid = required_param('scoid', PARAM_INT); // sco ID
9 $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
10 $attempt = required_param('attempt', PARAM_INT); // new attempt
11
12 if (!empty($id)) {
13 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
08b56f93 14 print_error('invalidcoursemodule');
03f5a0f8 15 }
bf347041 16 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
08b56f93 17 print_error('coursemisconf');
03f5a0f8 18 }
bf347041 19 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
08b56f93 20 print_error('invalidcoursemodule');
03f5a0f8 21 }
22 } else if (!empty($a)) {
bf347041 23 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
08b56f93 24 print_error('invalidcoursemodule');
03f5a0f8 25 }
bf347041 26 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
08b56f93 27 print_error('coursemisconf');
03f5a0f8 28 }
29 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
08b56f93 30 print_error('invalidcoursemodule');
03f5a0f8 31 }
32 } else {
08b56f93 33 print_error('missingparameter');
03f5a0f8 34 }
35
9528568b 36 require_login($course, false, $cm);
dac958fc 37
38 if ($usertrack = scorm_get_tracks($scoid,$USER->id,$attempt)) {
2aaf134c 39 if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || ($scorm->version != "SCORM_1.3")) {
dac958fc 40 foreach ($usertrack as $key => $value) {
41 $userdata->$key = addslashes_js($value);
42 }
2aaf134c 43 } else {
44 $userdata->status = '';
45 $userdata->score_raw = '';
46 }
03f5a0f8 47 } else {
48 $userdata->status = '';
49 $userdata->score_raw = '';
50 }
dac958fc 51 $userdata->student_id = addslashes_js($USER->username);
52 $userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname);
03f5a0f8 53 $userdata->mode = 'normal';
54 if (isset($mode)) {
55 $userdata->mode = $mode;
56 }
57 if ($userdata->mode == 'normal') {
58 $userdata->credit = 'credit';
59 } else {
60 $userdata->credit = 'no-credit';
9528568b 61 }
b3659259 62 if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
63 foreach ($scodatas as $key => $value) {
dac958fc 64 $userdata->$key = addslashes_js($value);
2aaf134c 65 }
03f5a0f8 66 } else {
08b56f93 67 print_error('cannotfindsco', 'scorm');
03f5a0f8 68 }
2aa9a35e 69 if (!$sco = scorm_get_sco($scoid)) {
70 print_error('cannotfindsco', 'scorm');
71 }
03f5a0f8 72 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
ac310b3a 73 $PAGE->requires->js('lib/cookies.js')->asap();
03f5a0f8 74 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
75 include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
76 } else {
77 include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
78 }
51c1c4e1 79
80 // set the start time of this SCO
81 scorm_insert_track($USER->id,$scorm->id,$scoid,$attempt,'x.start.time',time());
03f5a0f8 82?>
83
84var errorCode = "0";
85function underscore(str) {
d5f3bdc9 86 str = String(str).replace(/.N/g,".");
03f5a0f8 87 return str.replace(/\./g,"__");
88}