index.php 6.3 KB

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