user_portal.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is the index file displayed when a user is logged in on Chamilo.
  5. *
  6. * It displays:
  7. * - personal course list
  8. * - menu bar
  9. * Search for CONFIGURATION parameters to modify settings
  10. * @package chamilo.main
  11. * @todo Shouldn't the SCRIPTVAL_ and CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
  12. * If these are really configuration settings then we can add those to the dokeos config settings.
  13. * @todo check for duplication of functions with index.php (user_portal.php is orginally a copy of index.php)
  14. * @todo display_digest, shouldn't this be removed and be made into an extension?
  15. */
  16. use \ChamiloSession as Session;
  17. /* Flag forcing the 'current course' reset, as we're not inside a course anymore */
  18. $cidReset = true;
  19. // For HTML editor repository.
  20. if (isset($_SESSION['this_section']))
  21. unset($_SESSION['this_section']);
  22. /* Included libraries */
  23. require_once './main/inc/global.inc.php';
  24. require_once api_get_path(LIBRARY_PATH).'userportal.lib.php';
  25. api_block_anonymous_users(); // Only users who are logged in can proceed.
  26. $userId = api_get_user_id();
  27. /* Constants and CONFIGURATION parameters */
  28. $load_dirs = api_get_setting('show_documents_preview');
  29. $controller = new IndexManager(get_lang('MyCourses'));
  30. // Main courses and session list
  31. $courseAndSessions = $controller->return_courses_and_sessions($userId);
  32. // Check if a user is enrolled only in one course for going directly to the course after the login.
  33. if (api_get_setting('go_to_course_after_login') == 'true') {
  34. $count_of_sessions = $courseAndSessions['session_count'];
  35. $count_of_courses_no_sessions = $courseAndSessions['course_count'];
  36. if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
  37. $sessions = SessionManager::get_sessions_by_user($userId);
  38. if (isset($sessions[0])) {
  39. $sessionInfo = $sessions[0];
  40. if (isset($sessionInfo['session_id'])) {
  41. $url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$sessionInfo['session_id'];
  42. header('Location:'.$url);
  43. exit;
  44. }
  45. }
  46. }
  47. if (!isset($_SESSION['coursesAlreadyVisited']) &&
  48. $count_of_sessions == 0 && $count_of_courses_no_sessions == 1
  49. ) {
  50. $courses = CourseManager::get_courses_list_by_user_id($userId);
  51. if (!empty($courses) && isset($courses[0]) && isset($courses[0]['code'])) {
  52. $courseInfo = api_get_course_info($courses[0]['code']);
  53. if (!empty($courseInfo)) {
  54. $courseUrl = $courseInfo['course_public_url'];
  55. header('Location:'.$courseUrl);
  56. exit;
  57. }
  58. }
  59. }
  60. }
  61. $nameTools = get_lang('MyCourses');
  62. $this_section = SECTION_COURSES;
  63. /*
  64. Header
  65. Include the HTTP, HTML headers plus the top banner.
  66. */
  67. if ($load_dirs) {
  68. $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
  69. $folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
  70. $close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
  71. $htmlHeadXtra[] = '<script>
  72. $(document).ready(function() {
  73. $(".document_preview_container").hide();
  74. $(".document_preview").click(function() {
  75. var my_id = this.id;
  76. var course_id = my_id.split("_")[2];
  77. var session_id = my_id.split("_")[3];
  78. //showing div
  79. $(".document_preview_container").hide();
  80. $("#document_result_" +course_id+"_" + session_id).show();
  81. //Loading
  82. var image = $("img", this);
  83. image.attr("src", "'.$close_icon.'");
  84. $.ajax({
  85. url: "'.$url.'",
  86. data: "course_id="+course_id+"&session_id="+session_id,
  87. success: function(return_value) {
  88. image.attr("src", "'.$folder_icon.'");
  89. $("#document_result_" +course_id+"_" + session_id).html(return_value);
  90. }
  91. });
  92. });
  93. });
  94. </script>';
  95. }
  96. //Show the chamilo mascot
  97. if (empty($courseAndSessions['html']) && !isset($_GET['history'])) {
  98. $controller->tpl->assign('welcome_to_course_block', $controller->return_welcome_to_course_block());
  99. }
  100. $controller->tpl->assign('content', $courseAndSessions['html']);
  101. if (api_get_setting('allow_browser_sniffer') == 'true') {
  102. if ($_SESSION['sniff_navigator']!="checked") {
  103. $controller->tpl->assign('show_sniff', 1);
  104. } else {
  105. $controller->tpl->assign('show_sniff', 0);
  106. }
  107. }
  108. // Display the Site Use Cookie Warning Validation
  109. $useCookieValidation = api_get_configuration_value('cookie_warning');
  110. if ($useCookieValidation) {
  111. if (isset($_POST['acceptCookies'])) {
  112. api_set_site_use_cookie_warning_cookie();
  113. } else {
  114. if (!api_site_use_cookie_warning_cookie_exist()) {
  115. if (Template::isToolBarDisplayedForUser()) {
  116. $controller->tpl->assign('toolBarDisplayed', true);
  117. } else {
  118. $controller->tpl->assign('toolBarDisplayed', false);
  119. }
  120. $controller->tpl->assign('displayCookieUsageWarning', true);
  121. }
  122. }
  123. }
  124. //check for flash and message
  125. $sniff_notification = '';
  126. $some_activex = isset($_SESSION['sniff_check_some_activex']) ? $_SESSION['sniff_check_some_activex'] : null;
  127. $some_plugins = isset($_SESSION['sniff_check_some_plugins']) ? $_SESSION['sniff_check_some_plugins'] : null;
  128. if(!empty($some_activex) || !empty($some_plugins)){
  129. if (! preg_match("/flash_yes/", $some_activex) && ! preg_match("/flash_yes/", $some_plugins)) {
  130. $sniff_notification = Display::return_message(get_lang('NoFlash'), 'warning', true);
  131. //js verification - To annoying of redirecting every time the page
  132. $controller->tpl->assign('sniff_notification', $sniff_notification);
  133. }
  134. }
  135. $controller->tpl->assign('profile_block', $controller->return_profile_block());
  136. $controller->tpl->assign('user_image_block', $controller->return_user_image_block());
  137. $controller->tpl->assign('course_block', $controller->return_course_block());
  138. $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
  139. $controller->tpl->assign('search_block', $controller->return_search_block());
  140. $controller->tpl->assign('classes_block', $controller->return_classes_block());
  141. //if (api_is_platform_admin() || api_is_drh()) {
  142. $controller->tpl->assign('skills_block', $controller->return_skills_links());
  143. //}
  144. $controller->tpl->display_two_col_template();
  145. // Deleting the session_id.
  146. Session::erase('session_id');
  147. api_remove_in_gradebook('in_gradebook');