lp_view_item.php 5.0 KB

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