/mod/scorm/loaddatamodel.php

https://github.com/viggof/moodle · PHP · 111 lines · 87 code · 8 blank · 16 comment · 30 complexity · c9e4550aab57f7b8ee73f5817d893ab6 MD5 · raw file

  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. require_once("../../config.php");
  17. require_once('locallib.php');
  18. $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
  19. $a = optional_param('a', '', PARAM_INT); // scorm ID
  20. $scoid = required_param('scoid', PARAM_INT); // sco ID
  21. $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
  22. $attempt = required_param('attempt', PARAM_INT); // new attempt
  23. //IE 6 Bug workaround
  24. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && ini_get('zlib.output_compression') == 'On') {
  25. ini_set('zlib.output_compression', 'Off');
  26. }
  27. if (!empty($id)) {
  28. if (! $cm = get_coursemodule_from_id('scorm', $id)) {
  29. print_error('invalidcoursemodule');
  30. }
  31. if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
  32. print_error('coursemisconf');
  33. }
  34. if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
  35. print_error('invalidcoursemodule');
  36. }
  37. } else if (!empty($a)) {
  38. if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
  39. print_error('invalidcoursemodule');
  40. }
  41. if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
  42. print_error('coursemisconf');
  43. }
  44. if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
  45. print_error('invalidcoursemodule');
  46. }
  47. } else {
  48. print_error('missingparameter');
  49. }
  50. $url = new moodle_url('/mod/scorm/loaddatamodel.php', array('scoid'=>$scoid, 'id'=>$cm->id, 'attempt'=>$attempt));
  51. if ($mode !== '') {
  52. $url->param('mode', $mode);
  53. }
  54. $PAGE->set_url($url);
  55. require_login($course, false, $cm);
  56. if ($usertrack = scorm_get_tracks($scoid, $USER->id, $attempt)) {
  57. if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || (!scorm_version_check($scorm->version, SCORM_13))) {
  58. foreach ($usertrack as $key => $value) {
  59. $userdata->$key = addslashes_js($value);
  60. }
  61. } else {
  62. $userdata->status = '';
  63. $userdata->score_raw = '';
  64. }
  65. } else {
  66. $userdata->status = '';
  67. $userdata->score_raw = '';
  68. }
  69. $userdata->student_id = addslashes_js($USER->username);
  70. $userdata->student_name = addslashes_js($USER->lastname .', '. $USER->firstname);
  71. $userdata->mode = 'normal';
  72. if (isset($mode)) {
  73. $userdata->mode = $mode;
  74. }
  75. if ($userdata->mode == 'normal') {
  76. $userdata->credit = 'credit';
  77. } else {
  78. $userdata->credit = 'no-credit';
  79. }
  80. if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
  81. foreach ($scodatas as $key => $value) {
  82. $userdata->$key = addslashes_js($value);
  83. }
  84. } else {
  85. print_error('cannotfindsco', 'scorm');
  86. }
  87. if (!$sco = scorm_get_sco($scoid)) {
  88. print_error('cannotfindsco', 'scorm');
  89. }
  90. $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
  91. if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
  92. include($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
  93. } else {
  94. include($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
  95. }
  96. // set the start time of this SCO
  97. scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, 'x.start.time', time());
  98. ?>
  99. var errorCode = "0";
  100. function underscore(str) {
  101. str = String(str).replace(/.N/g,".");
  102. return str.replace(/\./g,"__");
  103. }