index.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * @package chamilo.main
  6. */
  7. define('CHAMILO_HOMEPAGE', true);
  8. define('CHAMILO_LOAD_WYSIWYG', false);
  9. /* Flag forcing the 'current course' reset, as we're not inside a course anymore. */
  10. // Maybe we should change this into an api function? an example: CourseManager::unset();
  11. $cidReset = true;
  12. require_once 'main/inc/global.inc.php';
  13. //require_once 'main/auth/external_login/facebook.inc.php';
  14. // The section (for the tabs).
  15. $this_section = SECTION_CAMPUS;
  16. $header_title = null;
  17. if (!api_is_anonymous()) {
  18. $header_title = ' ';
  19. }
  20. $controller = new IndexManager($header_title);
  21. //Actions
  22. $loginFailed = isset($_GET['loginFailed']) ? true : isset($loginFailed);
  23. if (!empty($_GET['logout'])) {
  24. $redirect = !empty($_GET['no_redirect']) ? false : true;
  25. $controller->logout($redirect);
  26. }
  27. /**
  28. * Registers in the track_e_default table (view in important activities in admin
  29. * interface) a possible attempted break in, sending auth data through get.
  30. * @todo This piece of code should probably move to local.inc.php where the
  31. * actual login / logout procedure is handled.
  32. * The real use of this code block should be seriously considered as well.
  33. * This form should just use a security token and get done with it.
  34. */
  35. if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
  36. $i = api_get_anonymous_id();
  37. Event::addEvent(
  38. LOG_ATTEMPTED_FORCED_LOGIN,
  39. 'tried_hacking_get',
  40. $_SERVER['REMOTE_ADDR'].(empty($_POST['login']) ? '' : '/'.$_POST['login']),
  41. null,
  42. $i
  43. );
  44. echo 'Attempted breakin - sysadmins notified.';
  45. session_destroy();
  46. die();
  47. }
  48. // Delete session item necessary to check for legal terms
  49. if (api_get_setting('allow_terms_conditions') === 'true') {
  50. Session::erase('term_and_condition');
  51. }
  52. //If we are not logged in and customapages activated
  53. if (!api_get_user_id() && CustomPages::enabled()) {
  54. if (Request::get('loggedout')) {
  55. CustomPages::display(CustomPages::LOGGED_OUT);
  56. } else {
  57. CustomPages::display(CustomPages::INDEX_UNLOGGED);
  58. }
  59. }
  60. /**
  61. * @todo This piece of code should probably move to local.inc.php where the
  62. * actual login procedure is handled.
  63. * @todo Check if this code is used. I think this code is never executed because
  64. * after clicking the submit button the code does the stuff
  65. * in local.inc.php and then redirects to index.php or user_portal.php depending
  66. * on api_get_setting('page_after_login').
  67. */
  68. if (!empty($_POST['submitAuth'])) {
  69. // The user has been already authenticated, we are now to find the last login of the user.
  70. if (isset($_user['user_id'])) {
  71. $track_login_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  72. $sql = "SELECT UNIX_TIMESTAMP(login_date)
  73. FROM $track_login_table
  74. WHERE login_user_id = '".$_user['user_id']."'
  75. ORDER BY login_date DESC LIMIT 1";
  76. $result_last_login = Database::query($sql);
  77. if (!$result_last_login) {
  78. if (Database::num_rows($result_last_login) > 0) {
  79. $user_last_login_datetime = Database::fetch_array($result_last_login);
  80. $user_last_login_datetime = $user_last_login_datetime[0];
  81. Session::write('user_last_login_datetime', $user_last_login_datetime);
  82. }
  83. }
  84. }
  85. } else {
  86. // Only if login form was not sent because if the form is sent the user was already on the page.
  87. Event::event_open();
  88. }
  89. if (api_get_setting('display_categories_on_homepage') === 'true') {
  90. $controller->tpl->assign('course_category_block', $controller->return_courses_in_categories());
  91. }
  92. $controller->set_login_form();
  93. //@todo move this inside the IndexManager
  94. if (!api_is_anonymous()) {
  95. $controller->tpl->assign('profile_block', $controller->return_profile_block());
  96. $controller->tpl->assign('user_image_block', $controller->return_user_image_block());
  97. if (api_is_platform_admin()) {
  98. $controller->tpl->assign('course_block', $controller->return_course_block());
  99. } else {
  100. $controller->tpl->assign('teacher_block', $controller->return_teacher_link());
  101. }
  102. }
  103. $hot_courses = '';
  104. $announcements_block = '';
  105. // Display the Site Use Cookie Warning Validation
  106. $useCookieValidation = api_get_setting('cookie_warning');
  107. if ($useCookieValidation === 'true') {
  108. if (isset($_POST['acceptCookies'])) {
  109. api_set_site_use_cookie_warning_cookie();
  110. } elseif (!api_site_use_cookie_warning_cookie_exist()) {
  111. if (Template::isToolBarDisplayedForUser()) {
  112. $controller->tpl->assign('toolBarDisplayed', true);
  113. } else {
  114. $controller->tpl->assign('toolBarDisplayed', false);
  115. }
  116. $controller->tpl->assign('displayCookieUsageWarning', true);
  117. }
  118. }
  119. // When loading a chamilo page do not include the hot courses and news
  120. if (!isset($_REQUEST['include'])) {
  121. if (api_get_setting('show_hot_courses') == 'true') {
  122. $hot_courses = $controller->return_hot_courses();
  123. }
  124. $announcements_block = $controller->return_announcements();
  125. }
  126. $controller->tpl->assign('hot_courses', $hot_courses);
  127. $controller->tpl->assign('announcements_block', $announcements_block);
  128. $controller->tpl->assign('home_page_block', $controller->return_home_page());
  129. $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
  130. $controller->tpl->assign('notice_block', $controller->return_notice());
  131. //$controller->tpl->assign('main_navigation_block', $controller->return_navigation_links());
  132. $controller->tpl->assign('help_block', $controller->return_help());
  133. $controller->tpl->assign('total_users', UserManager::getCountActiveUsers());
  134. $controller->tpl->assign('total_courses', CourseManager::getCountOpenCourses());
  135. $controller->tpl->assign('total_exercises', CourseManager::getCountExercisesFromOpenCourse());
  136. if (api_is_platform_admin() || api_is_drh()) {
  137. $controller->tpl->assign('skills_block', $controller->return_skills_links());
  138. }
  139. if (api_is_anonymous()) {
  140. $controller->tpl->setLoginBodyClass();
  141. }
  142. // direct login to course
  143. if (isset($_GET['firstpage'])) {
  144. api_set_firstpage_parameter($_GET['firstpage']);
  145. // if we are already logged, go directly to course
  146. if (api_user_is_login()) {
  147. echo "<script>self.location.href='index.php?firstpage=".Security::remove_XSS($_GET['firstpage'])."'</script>";
  148. }
  149. } else {
  150. api_delete_firstpage_parameter();
  151. }
  152. $controller->tpl->display_two_col_template();