SCORM MDL-22168 fix accidental revert - set start time of SCO correctly
[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
15d0fae4
DM
12 //IE 6 Bug workaround
13 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && ini_get('zlib.output_compression') == 'On') {
14 ini_set('zlib.output_compression', 'Off');
15 }
16
03f5a0f8 17 if (!empty($id)) {
18 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
08b56f93 19 print_error('invalidcoursemodule');
03f5a0f8 20 }
bf347041 21 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
08b56f93 22 print_error('coursemisconf');
03f5a0f8 23 }
bf347041 24 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
08b56f93 25 print_error('invalidcoursemodule');
03f5a0f8 26 }
27 } else if (!empty($a)) {
bf347041 28 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
08b56f93 29 print_error('invalidcoursemodule');
03f5a0f8 30 }
bf347041 31 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
08b56f93 32 print_error('coursemisconf');
03f5a0f8 33 }
34 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
08b56f93 35 print_error('invalidcoursemodule');
03f5a0f8 36 }
37 } else {
08b56f93 38 print_error('missingparameter');
03f5a0f8 39 }
40
a6855934 41 $url = new moodle_url('/mod/scorm/loaddatamodel.php', array('scoid'=>$scoid, 'id'=>$cm->id,'attempt'=>$attempt));
5c508e3f 42 if ($mode !== '') {
43 $url->param('mode', $mode);
44 }
45 $PAGE->set_url($url);
46
9528568b 47 require_login($course, false, $cm);
dac958fc 48
49 if ($usertrack = scorm_get_tracks($scoid,$USER->id,$attempt)) {
2aaf134c 50 if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || ($scorm->version != "SCORM_1.3")) {
dac958fc 51 foreach ($usertrack as $key => $value) {
52 $userdata->$key = addslashes_js($value);
53 }
2aaf134c 54 } else {
55 $userdata->status = '';
56 $userdata->score_raw = '';
57 }
03f5a0f8 58 } else {
59 $userdata->status = '';
60 $userdata->score_raw = '';
61 }
dac958fc 62 $userdata->student_id = addslashes_js($USER->username);
63 $userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname);
03f5a0f8 64 $userdata->mode = 'normal';
65 if (isset($mode)) {
66 $userdata->mode = $mode;
67 }
68 if ($userdata->mode == 'normal') {
69 $userdata->credit = 'credit';
70 } else {
71 $userdata->credit = 'no-credit';
9528568b 72 }
b3659259 73 if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
74 foreach ($scodatas as $key => $value) {
dac958fc 75 $userdata->$key = addslashes_js($value);
2aaf134c 76 }
03f5a0f8 77 } else {
08b56f93 78 print_error('cannotfindsco', 'scorm');
03f5a0f8 79 }
2aa9a35e 80 if (!$sco = scorm_get_sco($scoid)) {
81 print_error('cannotfindsco', 'scorm');
82 }
03f5a0f8 83 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
84 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
25b6fe05 85 include($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
03f5a0f8 86 } else {
25b6fe05 87 include($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
03f5a0f8 88 }
5435ff27
DM
89 // set the start time of this SCO
90 scorm_insert_track($USER->id,$scorm->id,$scoid,$attempt,'x.start.time',time());
03f5a0f8 91?>
92
93var errorCode = "0";
94function underscore(str) {
d5f3bdc9 95 str = String(str).replace(/.N/g,".");
03f5a0f8 96 return str.replace(/\./g,"__");
97}