lp_view_item.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. /* INIT SECTION */
  38. $_SESSION['whereami'] = 'lp/build';
  39. if (isset($_SESSION['oLP']) && isset($_GET['id'])) {
  40. $_SESSION['oLP'] -> current = intval($_GET['id']);
  41. }
  42. $this_section = SECTION_COURSES;
  43. /* Header and action code */
  44. /* Constants and variables */
  45. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  46. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  47. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  48. $tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW);
  49. $isStudentView = (empty($_REQUEST['isStudentView']) ? 0 : (int) $_REQUEST['isStudentView']);
  50. $learnpath_id = (int) $_REQUEST['lp_id'];
  51. // Using the resource linker as a tool for adding resources to the learning path.
  52. if ($action == 'add' && $type == 'learnpathitem') {
  53. $htmlHeadXtra[] = "<script> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
  54. }
  55. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  56. error_log('New LP - User not authorized in lp_view_item.php');
  57. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  58. exit;
  59. }
  60. // From here on, we are admin because of the previous condition, so don't check anymore.
  61. $course_id = api_get_course_int_id();
  62. $sql_query = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $learnpath_id";
  63. $result=Database::query($sql_query);
  64. $therow=Database::fetch_array($result);
  65. /* SHOWING THE ADMIN TOOLS */
  66. if (isset($_SESSION['gradebook'])) {
  67. $gradebook = $_SESSION['gradebook'];
  68. }
  69. if (!empty($gradebook) && $gradebook == 'view') {
  70. $interbreadcrumb[] = array (
  71. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  72. 'name' => get_lang('ToolGradebook')
  73. );
  74. }
  75. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  76. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $therow['name']);
  77. $interbreadcrumb[] = array('url' => api_get_self()."?action=add_item&type=step&lp_id=$learnpath_id", 'name' => get_lang('NewStep'));
  78. // Theme calls
  79. $show_learn_path = true;
  80. if (isset($_SESSION['oLP']) && is_object($_SESSION['oLP'])) {
  81. $lp_theme_css = $_SESSION['oLP']->get_theme();
  82. }
  83. if ($mode == 'fullpage') {
  84. Display::display_header(get_lang('Item'), 'Path');
  85. }
  86. $suredel = trim(get_lang('AreYouSureToDelete'));
  87. ?>
  88. <script>
  89. /* <![CDATA[ */
  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. }