lp_view_item.php 4.7 KB

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