lp_view_item.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 __DIR__.'/../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. if (isset($_SESSION['oLP']) && isset($_GET['id'])) {
  38. $_SESSION['oLP'] -> current = intval($_GET['id']);
  39. }
  40. $this_section = SECTION_COURSES;
  41. /* Header and action code */
  42. /* Constants and variables */
  43. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  44. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  45. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  46. $tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW);
  47. $isStudentView = (empty($_REQUEST['isStudentView']) ? 0 : (int) $_REQUEST['isStudentView']);
  48. $learnpath_id = (int) $_REQUEST['lp_id'];
  49. if ((!$is_allowed_to_edit) || $isStudentView) {
  50. error_log('New LP - User not authorized in lp_view_item.php');
  51. header('Location: '.api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=view&lp_id='.$learnpath_id.'&'.api_get_cidreq());
  52. exit;
  53. }
  54. // From here on, we are admin because of the previous condition, so don't check anymore.
  55. $course_id = api_get_course_int_id();
  56. $sql = "SELECT * FROM $tbl_lp
  57. WHERE c_id = $course_id AND id = $learnpath_id";
  58. $result = Database::query($sql);
  59. $therow = Database::fetch_array($result);
  60. /* SHOWING THE ADMIN TOOLS */
  61. if (api_is_in_gradebook()) {
  62. $interbreadcrumb[] = array(
  63. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  64. 'name' => get_lang('ToolGradebook')
  65. );
  66. }
  67. $interbreadcrumb[] = array(
  68. 'url' => api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=list&'.api_get_cidreq(),
  69. 'name' => get_lang('LearningPaths')
  70. );
  71. $interbreadcrumb[] = array(
  72. 'url' => api_get_self()."?action=build&lp_id=$learnpath_id&".api_get_cidreq(),
  73. 'name' => $therow['name']
  74. );
  75. $interbreadcrumb[] = array(
  76. 'url' => api_get_self()."?action=add_item&type=step&lp_id=$learnpath_id&".api_get_cidreq(),
  77. 'name' => get_lang('NewStep')
  78. );
  79. // Theme calls
  80. $show_learn_path = true;
  81. if (isset($_SESSION['oLP']) && is_object($_SESSION['oLP'])) {
  82. $lp_theme_css = $_SESSION['oLP']->get_theme();
  83. }
  84. if ($mode == 'fullpage') {
  85. Display::display_header(get_lang('Item'), 'Path');
  86. }
  87. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  88. ?>
  89. <script>
  90. function stripslashes(str) {
  91. str=str.replace(/\\'/g,'\'');
  92. str=str.replace(/\\"/g,'"');
  93. str=str.replace(/\\\\/g,'\\');
  94. str=str.replace(/\\0/g,'\0');
  95. return str;
  96. }
  97. function confirmation(name) {
  98. name=stripslashes(name);
  99. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  100. return true;
  101. } else {
  102. return false;
  103. }
  104. }
  105. </script>
  106. <?php
  107. $id = isset($new_item_id) ? $new_item_id : $_GET['id'];
  108. if (is_object($_SESSION['oLP'])) {
  109. switch ($mode) {
  110. case 'fullpage':
  111. echo $_SESSION['oLP']->build_action_menu();
  112. echo '<div class="row">';
  113. echo '<div class="col-md-3">';
  114. echo $_SESSION['oLP']->return_new_tree();
  115. echo '</div>';
  116. echo '<div class="col-md-9">';
  117. echo $_SESSION['oLP']->display_item($id);
  118. echo '</div>';
  119. echo '</div>';
  120. Display::display_footer();
  121. break;
  122. case 'preview_document':
  123. echo $_SESSION['oLP']->display_item($id, null, false);
  124. break;
  125. }
  126. }