user_portal.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 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. $this_section = SECTION_COURSES;
  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->returnCoursesAndSessions($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. // User is subscribe in 1 session and 0 courses.
  37. if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
  38. $sessions = SessionManager::get_sessions_by_user($userId);
  39. if (isset($sessions[0])) {
  40. $sessionInfo = $sessions[0];
  41. // Session only has 1 course.
  42. if (isset($sessionInfo['courses']) && count($sessionInfo['courses']) == 1) {
  43. $courseCode = $sessionInfo['courses'][0]['code'];
  44. $courseInfo = api_get_course_info_by_id($sessionInfo['courses'][0]['real_id']);
  45. $courseUrl = $courseInfo['course_public_url'].'?id_session='.$sessionInfo['session_id'];
  46. header('Location:'.$courseUrl);
  47. exit;
  48. }
  49. // Session has many courses.
  50. if (isset($sessionInfo['session_id'])) {
  51. $url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$sessionInfo['session_id'];
  52. header('Location:'.$url);
  53. exit;
  54. }
  55. }
  56. }
  57. // User is subscribed to 1 course.
  58. if (!isset($_SESSION['coursesAlreadyVisited']) &&
  59. $count_of_sessions == 0 && $count_of_courses_no_sessions == 1
  60. ) {
  61. $courses = CourseManager::get_courses_list_by_user_id($userId);
  62. if (!empty($courses) && isset($courses[0]) && isset($courses[0]['code'])) {
  63. $courseInfo = api_get_course_info_by_id($courses[0]['real_id']);
  64. if (!empty($courseInfo)) {
  65. $courseUrl = $courseInfo['course_public_url'];
  66. header('Location:'.$courseUrl);
  67. exit;
  68. }
  69. }
  70. }
  71. }
  72. $nameTools = get_lang('MyCourses');
  73. /*
  74. Header
  75. Include the HTTP, HTML headers plus the top banner.
  76. */
  77. if ($load_dirs) {
  78. $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
  79. $folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
  80. $close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
  81. $htmlHeadXtra[] = '<script>
  82. $(document).ready(function() {
  83. $(".document_preview_container").hide();
  84. $(".document_preview").click(function() {
  85. var my_id = this.id;
  86. var course_id = my_id.split("_")[2];
  87. var session_id = my_id.split("_")[3];
  88. //showing div
  89. $(".document_preview_container").hide();
  90. $("#document_result_" +course_id+"_" + session_id).show();
  91. //Loading
  92. var image = $("img", this);
  93. image.attr("src", "'.$close_icon.'");
  94. $.ajax({
  95. url: "'.$url.'",
  96. data: "course_id="+course_id+"&session_id="+session_id,
  97. success: function(return_value) {
  98. image.attr("src", "'.$folder_icon.'");
  99. $("#document_result_" +course_id+"_" + session_id).html(return_value);
  100. }
  101. });
  102. });
  103. });
  104. </script>';
  105. }
  106. //Show the chamilo mascot
  107. if (empty($courseAndSessions['html']) && !isset($_GET['history'])) {
  108. $controller->tpl->assign('welcome_to_course_block', $controller->return_welcome_to_course_block());
  109. }
  110. $controller->tpl->assign('content', $courseAndSessions['html']);
  111. if (api_get_setting('allow_browser_sniffer') == 'true') {
  112. if ($_SESSION['sniff_navigator']!="checked") {
  113. $controller->tpl->assign('show_sniff', 1);
  114. } else {
  115. $controller->tpl->assign('show_sniff', 0);
  116. }
  117. }
  118. // Display the Site Use Cookie Warning Validation
  119. $useCookieValidation = api_get_setting('cookie_warning');
  120. if ($useCookieValidation === 'true') {
  121. if (isset($_POST['acceptCookies'])) {
  122. api_set_site_use_cookie_warning_cookie();
  123. } else {
  124. if (!api_site_use_cookie_warning_cookie_exist()) {
  125. if (Template::isToolBarDisplayedForUser()) {
  126. $controller->tpl->assign('toolBarDisplayed', true);
  127. } else {
  128. $controller->tpl->assign('toolBarDisplayed', false);
  129. }
  130. $controller->tpl->assign('displayCookieUsageWarning', true);
  131. }
  132. }
  133. }
  134. //check for flash and message
  135. $sniff_notification = '';
  136. $some_activex = isset($_SESSION['sniff_check_some_activex']) ? $_SESSION['sniff_check_some_activex'] : null;
  137. $some_plugins = isset($_SESSION['sniff_check_some_plugins']) ? $_SESSION['sniff_check_some_plugins'] : null;
  138. if(!empty($some_activex) || !empty($some_plugins)){
  139. if (! preg_match("/flash_yes/", $some_activex) && ! preg_match("/flash_yes/", $some_plugins)) {
  140. $sniff_notification = Display::return_message(get_lang('NoFlash'), 'warning', true);
  141. //js verification - To annoying of redirecting every time the page
  142. $controller->tpl->assign('sniff_notification', $sniff_notification);
  143. }
  144. }
  145. $controller->tpl->assign('profile_block', $controller->return_profile_block());
  146. $controller->tpl->assign('user_image_block', $controller->return_user_image_block());
  147. $controller->tpl->assign('course_block', $controller->return_course_block());
  148. $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
  149. $controller->tpl->assign('search_block', $controller->return_search_block());
  150. $controller->tpl->assign('classes_block', $controller->return_classes_block());
  151. //if (api_is_platform_admin() || api_is_drh()) {
  152. $controller->tpl->assign('skills_block', $controller->return_skills_links());
  153. //}
  154. $controller->tpl->display_two_col_template();
  155. // Deleting the session_id.
  156. Session::erase('session_id');
  157. api_remove_in_gradebook('in_gradebook');