index.php 7.1 KB

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