index.php 7.6 KB

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