lp_view_item.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a learning path creation and player tool in Chamilo - previously learnpath_handler.php
  5. *
  6. * @author Patrick Cool
  7. * @author Denes Nagy
  8. * @author Roan Embrechts, refactoring and code cleaning
  9. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool
  10. * @package chamilo.learnpath
  11. */
  12. // Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP
  13. require_once '../inc/global.inc.php';
  14. api_protect_course_script();
  15. if (isset($_GET['lp_item_id'])) {
  16. // Get parameter only came from lp_view.php.
  17. $lp_item_id = intval($_GET['lp_item_id']);
  18. if (isset($_SESSION['lpobject'])) {
  19. $oLP = unserialize($_SESSION['lpobject']);
  20. }
  21. if (is_object($oLP)) {
  22. $src = $oLP->get_link('http', $lp_item_id);
  23. }
  24. $url_info = parse_url($src);
  25. $real_url_info = parse_url(api_get_path(WEB_PATH));
  26. // The host must be the same.
  27. if ($url_info['host'] == $real_url_info['host']) {
  28. $url = Security::remove_XSS($src);
  29. header("Location: ".$url);
  30. exit;
  31. } else {
  32. header("Location: blank.php?error=document_not_found");
  33. exit;
  34. }
  35. }
  36. $mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : 'fullpage';
  37. $_SESSION['whereami'] = 'lp/build';
  38. if (isset($_SESSION['oLP']) && isset($_GET['id'])) {
  39. $_SESSION['oLP'] -> current = intval($_GET['id']);
  40. }
  41. $this_section = SECTION_COURSES;
  42. /* Header and action code */
  43. /* Constants and variables */
  44. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  45. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  46. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  47. $tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW);
  48. $isStudentView = (empty($_REQUEST['isStudentView']) ? 0 : (int)$_REQUEST['isStudentView']);
  49. $learnpath_id = (int)$_REQUEST['lp_id'];
  50. // Using the resource linker as a tool for adding resources to the learning path.
  51. if ($action == 'add' && $type == 'learnpathitem') {
  52. $htmlHeadXtra[] = "<script> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
  53. }
  54. if ((!$is_allowed_to_edit) || $isStudentView) {
  55. error_log('New LP - User not authorized in lp_view_item.php');
  56. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  57. exit;
  58. }
  59. // From here on, we are admin because of the previous condition, so don't check anymore.
  60. $course_id = api_get_course_int_id();
  61. $sql_query = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $learnpath_id";
  62. $result = Database::query($sql_query);
  63. $therow = Database::fetch_array($result);
  64. /* SHOWING THE ADMIN TOOLS */
  65. if (api_is_in_gradebook()) {
  66. $interbreadcrumb[] = array (
  67. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  68. 'name' => get_lang('ToolGradebook')
  69. );
  70. }
  71. $interbreadcrumb[] = array(
  72. 'url' => api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?action=list&'.api_get_cidreq(),
  73. 'name' => get_lang('LearningPaths')
  74. );
  75. $interbreadcrumb[] = array(
  76. 'url' => api_get_self()."?action=build&lp_id=$learnpath_id&".api_get_cidreq(),
  77. 'name' => $therow['name']
  78. );
  79. $interbreadcrumb[] = array(
  80. 'url' => api_get_self()."?action=add_item&type=step&lp_id=$learnpath_id&".api_get_cidreq(),
  81. 'name' => get_lang('NewStep')
  82. );
  83. // Theme calls
  84. $show_learn_path = true;
  85. if (isset($_SESSION['oLP']) && is_object($_SESSION['oLP'])) {
  86. $lp_theme_css = $_SESSION['oLP']->get_theme();
  87. }
  88. if ($mode == 'fullpage') {
  89. Display::display_header(get_lang('Item'), 'Path');
  90. }
  91. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  92. ?>
  93. <script>
  94. /* <![CDATA[ */
  95. function stripslashes(str) {
  96. str=str.replace(/\\'/g,'\'');
  97. str=str.replace(/\\"/g,'"');
  98. str=str.replace(/\\\\/g,'\\');
  99. str=str.replace(/\\0/g,'\0');
  100. return str;
  101. }
  102. function confirmation(name) {
  103. name=stripslashes(name);
  104. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  105. return true;
  106. } else {
  107. return false;
  108. }
  109. }
  110. </script>
  111. <?php
  112. $id = (isset($new_item_id)) ? $new_item_id : $_GET['id'];
  113. if (is_object($_SESSION['oLP'])) {
  114. switch ($mode) {
  115. case 'fullpage':
  116. echo $_SESSION['oLP']->build_action_menu();
  117. echo '<div class="row">';
  118. echo '<div class="col-md-3">';
  119. echo $_SESSION['oLP']->return_new_tree();
  120. echo '</div>';
  121. echo '<div class="col-md-9">';
  122. echo $_SESSION['oLP']->display_item($id);
  123. echo '</div>';
  124. echo '</div>';
  125. Display::display_footer();
  126. break;
  127. case 'preview_document':
  128. echo $_SESSION['oLP']->display_item($id, null, false);
  129. break;
  130. }
  131. }