lp_content.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Script that displays an error message when no content could be loaded.
  6. *
  7. * @package chamilo.learnpath
  8. *
  9. * @author Yannick Warnier <ywarnier@beeznest.org>
  10. */
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. $debug = 0;
  13. if ($debug > 0) {
  14. error_log('New lp - In lp_content.php');
  15. }
  16. if (empty($lp_controller_touched)) {
  17. if ($debug > 0) {
  18. error_log('New lp - In lp_content.php - Redirecting to lp_controller');
  19. }
  20. header('Location: lp_controller.php?action=content&lp_id='.intval($_REQUEST['lp_id']).'&item_id='.intval($_REQUEST['item_id']).'&'.api_get_cidreq());
  21. exit;
  22. }
  23. /** @var learnpath $learnPath */
  24. $learnPath = Session::read('oLP');
  25. $learnPath->error = '';
  26. $lpType = $learnPath->get_type();
  27. $lpItemId = $learnPath->get_current_item_id();
  28. /**
  29. * Get a link to the corresponding document.
  30. */
  31. $src = '';
  32. if ($debug > 0) {
  33. error_log('New lp - In lp_content.php - Looking for file url');
  34. error_log("lp_type $lpType");
  35. error_log("lp_item_id $lpItemId");
  36. }
  37. $list = $learnPath->get_toc();
  38. $dir = false;
  39. foreach ($list as $toc) {
  40. if ($toc['id'] == $lpItemId && $toc['type'] == 'dir') {
  41. $dir = true;
  42. }
  43. }
  44. if ($dir) {
  45. $src = 'blank.php';
  46. } else {
  47. switch ($lpType) {
  48. case 1:
  49. $learnPath->stop_previous_item();
  50. $prerequisiteCheck = $learnPath->prerequisites_match($lpItemId);
  51. if ($prerequisiteCheck === true) {
  52. $src = $learnPath->get_link('http', $lpItemId);
  53. $learnPath->start_current_item(); // starts time counter manually if asset
  54. $src = $learnPath->fixBlockedLinks($src);
  55. if (WhispeakAuthPlugin::isLpItemMarked($lpItemId)) {
  56. ChamiloSession::write(
  57. WhispeakAuthPlugin::SESSION_LP_ITEM,
  58. ['lp' => $learnPath->lp_id, 'lp_item' => $lpItemId, 'src' => $src]
  59. );
  60. $src = api_get_path(WEB_PLUGIN_PATH).'whispeakauth/authentify.php';
  61. }
  62. break;
  63. }
  64. $src = 'blank.php?error=prerequisites&prerequisite_message='.Security::remove_XSS($learnPath->error);
  65. break;
  66. case 2:
  67. $learnPath->stop_previous_item();
  68. $prerequisiteCheck = $learnPath->prerequisites_match($lpItemId);
  69. if ($prerequisiteCheck === true) {
  70. $src = $learnPath->get_link('http', $lpItemId);
  71. $learnPath->start_current_item(); // starts time counter manually if asset
  72. } else {
  73. $src = 'blank.php?error=prerequisites&prerequisite_message='.Security::remove_XSS($learnPath->error);
  74. }
  75. break;
  76. case 3:
  77. // save old if asset
  78. $learnPath->stop_previous_item(); // save status manually if asset
  79. $prerequisiteCheck = $learnPath->prerequisites_match($lpItemId);
  80. if ($prerequisiteCheck === true) {
  81. $src = $learnPath->get_link('http', $lpItemId);
  82. $learnPath->start_current_item(); // starts time counter manually if asset
  83. } else {
  84. $src = 'blank.php';
  85. }
  86. break;
  87. case 4:
  88. break;
  89. }
  90. }
  91. if ($debug > 0) {
  92. error_log('New lp - In lp_content.php - File url is '.$src);
  93. }
  94. $learnPath->set_previous_item($lpItemId);
  95. if (api_is_in_gradebook()) {
  96. $interbreadcrumb[] = [
  97. 'url' => Category::getUrl(),
  98. 'name' => get_lang('ToolGradebook'),
  99. ];
  100. }
  101. // Define the 'doc.inc.php' as language file.
  102. $nameTools = $learnPath->get_name();
  103. $interbreadcrumb[] = [
  104. 'url' => api_get_path(WEB_CODE_PATH).'lp/lp_list.php?'.api_get_cidreq(),
  105. 'name' => get_lang('Doc'),
  106. ];
  107. // Update global setting to avoid displaying right menu.
  108. $save_setting = api_get_setting('show_navigation_menu');
  109. global $_setting;
  110. $_setting['show_navigation_menu'] = false;
  111. if ($debug > 0) {
  112. error_log('New LP - In lp_content.php - Loading '.$src);
  113. }
  114. Session::write('oLP', $learnPath);
  115. header('Location: '.urldecode($src));
  116. exit;