"MDL-15502, added a filter to selec users who have never logged in, merged from 1...
[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
5c508e3f 36 $url = new moodle_url($CFG->wwwroot.'/mod/scorm/loaddatamodel.php', array('scoid'=>$scoid, 'id'=>$cm->id,'attempt'=>$attempt));
37 if ($mode !== '') {
38 $url->param('mode', $mode);
39 }
40 $PAGE->set_url($url);
41
9528568b 42 require_login($course, false, $cm);
dac958fc 43
44 if ($usertrack = scorm_get_tracks($scoid,$USER->id,$attempt)) {
2aaf134c 45 if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || ($scorm->version != "SCORM_1.3")) {
dac958fc 46 foreach ($usertrack as $key => $value) {
47 $userdata->$key = addslashes_js($value);
48 }
2aaf134c 49 } else {
50 $userdata->status = '';
51 $userdata->score_raw = '';
52 }
03f5a0f8 53 } else {
54 $userdata->status = '';
55 $userdata->score_raw = '';
56 }
dac958fc 57 $userdata->student_id = addslashes_js($USER->username);
58 $userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname);
03f5a0f8 59 $userdata->mode = 'normal';
60 if (isset($mode)) {
61 $userdata->mode = $mode;
62 }
63 if ($userdata->mode == 'normal') {
64 $userdata->credit = 'credit';
65 } else {
66 $userdata->credit = 'no-credit';
9528568b 67 }
b3659259 68 if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
69 foreach ($scodatas as $key => $value) {
dac958fc 70 $userdata->$key = addslashes_js($value);
2aaf134c 71 }
03f5a0f8 72 } else {
08b56f93 73 print_error('cannotfindsco', 'scorm');
03f5a0f8 74 }
2aa9a35e 75 if (!$sco = scorm_get_sco($scoid)) {
76 print_error('cannotfindsco', 'scorm');
77 }
03f5a0f8 78 $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
ac310b3a 79 $PAGE->requires->js('lib/cookies.js')->asap();
03f5a0f8 80 if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
81 include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
82 } else {
83 include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
84 }
51c1c4e1 85
86 // set the start time of this SCO
87 scorm_insert_track($USER->id,$scorm->id,$scoid,$attempt,'x.start.time',time());
03f5a0f8 88?>
89
90var errorCode = "0";
91function underscore(str) {
d5f3bdc9 92 str = String(str).replace(/.N/g,".");
03f5a0f8 93 return str.replace(/\./g,"__");
94}