index.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.main
  5. */
  6. use \ChamiloSession as Session;
  7. define('CHAMILO_HOMEPAGE', true);
  8. /* Flag forcing the 'current course' reset, as we're not inside a course anymore. */
  9. // Maybe we should change this into an api function? an example: CourseManager::unset();
  10. $cidReset = true;
  11. require_once 'main/inc/global.inc.php';
  12. require_once api_get_path(LIBRARY_PATH).'userportal.lib.php';
  13. require_once 'main/chat/chat_functions.lib.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. $controller->logout();
  25. }
  26. /* Table definitions */
  27. /* Constants and CONFIGURATION parameters */
  28. /** @todo these configuration settings should move to the Chamilo config settings. */
  29. /** Defines wether or not anonymous visitors can see a list of the courses on the Chamilo homepage that are open to the world. */
  30. $_setting['display_courses_to_anonymous_users'] = 'true';
  31. /* LOGIN */
  32. /**
  33. * Registers in the track_e_default table (view in important activities in admin
  34. * interface) a possible attempted break in, sending auth data through get.
  35. * @todo This piece of code should probably move to local.inc.php where the actual login / logout procedure is handled. The real use of this code block should be seriously considered as well. This form should just use a security token and get done with it.
  36. */
  37. if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
  38. $i = api_get_anonymous_id();
  39. Event::addEvent(
  40. LOG_ATTEMPTED_FORCED_LOGIN,
  41. 'tried_hacking_get',
  42. $_SERVER['REMOTE_ADDR'].(empty($_POST['login'])?'':'/'.$_POST['login']),
  43. null,
  44. $i
  45. );
  46. echo 'Attempted breakin - sysadmins notified.';
  47. session_destroy();
  48. die();
  49. }
  50. // Delete session neccesary for legal terms
  51. if (api_get_setting('allow_terms_conditions') == 'true') {
  52. unset($_SESSION['term_and_condition']);
  53. }
  54. //If we are not logged in and customapages activated
  55. if (!api_get_user_id() && CustomPages::enabled()) {
  56. if (Request::get('loggedout')) {
  57. CustomPages::display(CustomPages::LOGGED_OUT);
  58. } else {
  59. CustomPages::display(CustomPages::INDEX_UNLOGGED);
  60. }
  61. }
  62. /**
  63. * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
  64. * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
  65. * the code does the stuff 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_last_login = "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_last_login);
  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. Database::free_result($result_last_login);
  85. //Event::event_login();
  86. if (api_is_platform_admin()) {
  87. // decode all open event informations and fill the track_c_* tables
  88. include api_get_path(LIBRARY_PATH).'stats.lib.inc.php';
  89. decodeOpenInfos();
  90. }
  91. }
  92. // End login -- if ($_POST['submitAuth'])
  93. } else {
  94. // Only if login form was not sent because if the form is sent the user was already on the page.
  95. Event::event_open();
  96. }
  97. if (api_get_setting('display_categories_on_homepage') == 'true') {
  98. $controller->tpl->assign('course_category_block', $controller->return_courses_in_categories());
  99. }
  100. // Facebook connexion, if activated
  101. if (api_is_facebook_auth_activated() && !api_get_user_id()) {
  102. facebook_connect();
  103. }
  104. $controller->set_login_form();
  105. //@todo move this inside the IndexManager
  106. if (!api_is_anonymous()) {
  107. $controller->tpl->assign('profile_block', $controller->return_profile_block());
  108. $controller->tpl->assign('user_image_block', $controller->return_user_image_block());
  109. if (api_is_platform_admin()) {
  110. $controller->tpl->assign('course_block', $controller->return_course_block());
  111. } else {
  112. $controller->tpl->assign('teacher_block', $controller->return_teacher_link());
  113. }
  114. }
  115. $hot_courses = null;
  116. $announcements_block = null;
  117. // Display the Site Use Cookie Warning Validation
  118. $useCookieValidation = api_get_configuration_value('cookie_warning');
  119. if ($useCookieValidation) {
  120. if (isset($_POST['acceptCookies'])) {
  121. api_set_site_use_cookie_warning_cookie();
  122. } else if (!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. $hot_courses = $controller->return_hot_courses();
  135. }
  136. $announcements_block = $controller->return_announcements();
  137. }
  138. $controller->tpl->assign('hot_courses', $hot_courses);
  139. $controller->tpl->assign('announcements_block', $announcements_block);
  140. $controller->tpl->assign('home_page_block', $controller->return_home_page());
  141. $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
  142. $controller->tpl->assign('notice_block', $controller->return_notice());
  143. $controller->tpl->assign('main_navigation_block', $controller->return_navigation_links());
  144. $controller->tpl->assign('help_block', $controller->return_help());
  145. if (api_is_platform_admin() || api_is_drh()) {
  146. $controller->tpl->assign('skills_block', $controller->return_skills_links());
  147. }
  148. if (api_is_anonymous()) {
  149. $controller->tpl->setLoginBodyClass();
  150. }
  151. // direct login to course
  152. if (isset($_GET['firstpage'])) {
  153. api_set_firstpage_parameter($_GET['firstpage']);
  154. // if we are already logged, go directly to course
  155. if (api_user_is_login()) {
  156. echo "<script type='text/javascript'>self.location.href='index.php?firstpage=".Security::remove_XSS($_GET['firstpage'])."'</script>";
  157. }
  158. } else {
  159. api_delete_firstpage_parameter();
  160. }
  161. $controller->tpl->display_two_col_template();