lp_view_item.php 5.1 KB

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