lp_content.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. break;
  56. }
  57. $src = 'blank.php?error=prerequisites&prerequisite_message='.Security::remove_XSS($learnPath->error);
  58. break;
  59. case 2:
  60. $learnPath->stop_previous_item();
  61. $prerequisiteCheck = $learnPath->prerequisites_match($lpItemId);
  62. if ($prerequisiteCheck === true) {
  63. $src = $learnPath->get_link('http', $lpItemId);
  64. $learnPath->start_current_item(); // starts time counter manually if asset
  65. } else {
  66. $src = 'blank.php?error=prerequisites&prerequisite_message='.Security::remove_XSS($learnPath->error);
  67. }
  68. break;
  69. case 3:
  70. // save old if asset
  71. $learnPath->stop_previous_item(); // save status manually if asset
  72. $prerequisiteCheck = $learnPath->prerequisites_match($lpItemId);
  73. if ($prerequisiteCheck === true) {
  74. $src = $learnPath->get_link('http', $lpItemId);
  75. $learnPath->start_current_item(); // starts time counter manually if asset
  76. } else {
  77. $src = 'blank.php';
  78. }
  79. break;
  80. case 4:
  81. break;
  82. }
  83. }
  84. if ($debug > 0) {
  85. error_log('New lp - In lp_content.php - File url is '.$src);
  86. }
  87. $learnPath->set_previous_item($lpItemId);
  88. if (api_is_in_gradebook()) {
  89. $interbreadcrumb[] = [
  90. 'url' => Category::getUrl(),
  91. 'name' => get_lang('Assessments'),
  92. ];
  93. }
  94. // Define the 'doc.inc.php' as language file.
  95. $nameTools = $learnPath->getNameNoTags();
  96. $interbreadcrumb[] = [
  97. 'url' => api_get_path(WEB_CODE_PATH).'lp/lp_list.php?'.api_get_cidreq(),
  98. 'name' => get_lang('Document'),
  99. ];
  100. // Update global setting to avoid displaying right menu.
  101. $save_setting = api_get_setting('show_navigation_menu');
  102. global $_setting;
  103. $_setting['show_navigation_menu'] = false;
  104. if ($debug > 0) {
  105. error_log('New LP - In lp_content.php - Loading '.$src);
  106. }
  107. Session::write('oLP', $learnPath);
  108. header('Location: '.urldecode($src));
  109. exit;