index.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. $language_file = array('courses', 'index', 'userInfo');
  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 api_get_path(LIBRARY_PATH).'userportal.lib.php';
  14. require_once 'main/chat/chat_functions.lib.php';
  15. // The section (for the tabs).
  16. $this_section = SECTION_CAMPUS;
  17. $header_title = null;
  18. if (!api_is_anonymous()) {
  19. $header_title = " ";
  20. }
  21. $htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider'));
  22. $htmlHeadXtra[] ='
  23. <script type="text/javascript">
  24. $(document).ready(function(){
  25. $("#slider").bxSlider({
  26. infiniteLoop : true,
  27. auto : true,
  28. pager : true,
  29. autoHover : true,
  30. pause : 10000
  31. });
  32. });
  33. </script>';
  34. //set cookie for check if client browser are cookies enabled
  35. setcookie('TestCookie', 'cookies_yes', time()+3600*24*31*12);
  36. $controller = new IndexManager($header_title);
  37. //Actions
  38. $loginFailed = isset($_GET['loginFailed']) ? true : isset($loginFailed);
  39. if (!empty($_GET['logout'])) {
  40. $controller->logout();
  41. }
  42. /* Table definitions */
  43. /* Constants and CONFIGURATION parameters */
  44. /** @todo these configuration settings should move to the Chamilo config settings. */
  45. /** Defines wether or not anonymous visitors can see a list of the courses on the Chamilo homepage that are open to the world. */
  46. $_setting['display_courses_to_anonymous_users'] = 'true';
  47. /* LOGIN */
  48. /**
  49. * Registers in the track_e_default table (view in important activities in admin
  50. * interface) a possible attempted break in, sending auth data through get.
  51. * @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.
  52. */
  53. if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
  54. $i = api_get_anonymous_id();
  55. event_system(LOG_ATTEMPTED_FORCED_LOGIN, 'tried_hacking_get', $_SERVER['REMOTE_ADDR'].(empty($_POST['login'])?'':'/'.$_POST['login']),null,$i);
  56. echo 'Attempted breakin - sysadmins notified.';
  57. session_destroy();
  58. die();
  59. }
  60. // Delete session neccesary for legal terms
  61. if (api_get_setting('allow_terms_conditions') == 'true') {
  62. unset($_SESSION['term_and_condition']);
  63. }
  64. //If we are not logged in and customapages activated
  65. if (!api_get_user_id() && CustomPages::enabled()) {
  66. if (Request::get('loggedout')) {
  67. CustomPages::display(CustomPages::LOGGED_OUT);
  68. } else {
  69. CustomPages::display(CustomPages::INDEX_UNLOGGED);
  70. }
  71. }
  72. /**
  73. * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
  74. * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
  75. * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
  76. * on api_get_setting('page_after_login').
  77. */
  78. if (!empty($_POST['submitAuth'])) {
  79. // The user has been already authenticated, we are now to find the last login of the user.
  80. if (isset ($_user['user_id'])) {
  81. $track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  82. $sql_last_login = "SELECT UNIX_TIMESTAMP(login_date)
  83. FROM $track_login_table
  84. WHERE login_user_id = '".$_user['user_id']."'
  85. ORDER BY login_date DESC LIMIT 1";
  86. $result_last_login = Database::query($sql_last_login);
  87. if (!$result_last_login) {
  88. if (Database::num_rows($result_last_login) > 0) {
  89. $user_last_login_datetime = Database::fetch_array($result_last_login);
  90. $user_last_login_datetime = $user_last_login_datetime[0];
  91. Session::write('user_last_login_datetime',$user_last_login_datetime);
  92. }
  93. }
  94. Database::free_result($result_last_login);
  95. //event_login();
  96. if (api_is_platform_admin()) {
  97. // decode all open event informations and fill the track_c_* tables
  98. include api_get_path(LIBRARY_PATH).'stats.lib.inc.php';
  99. decodeOpenInfos();
  100. }
  101. }
  102. // End login -- if ($_POST['submitAuth'])
  103. }
  104. else {
  105. // Only if login form was not sent because if the form is sent the user was already on the page.
  106. event_open();
  107. }
  108. if (api_get_setting('display_categories_on_homepage') == 'true') {
  109. $controller->tpl->assign('course_category_block', $controller->return_courses_in_categories());
  110. }
  111. // Facebook connexion, if activated
  112. if (api_is_facebook_auth_activated() && !api_get_user_id()) {
  113. facebook_connect();
  114. }
  115. $controller->set_login_form();
  116. //@todo move this inside the IndexManager
  117. if (!api_is_anonymous()) {
  118. $controller->tpl->assign('profile_block', $controller->return_profile_block());
  119. $controller->tpl->assign('user_image_block', $controller->return_user_image_block());
  120. if (api_is_platform_admin()) {
  121. $controller->tpl->assign('course_block', $controller->return_course_block());
  122. }
  123. else {
  124. $controller->tpl->assign('teacher_block', $controller->return_teacher_link());
  125. }
  126. }
  127. $hot_courses = null;
  128. $announcements_block = null;
  129. // When loading a chamilo page do not include the hot courses and news
  130. if (!isset($_REQUEST['include'])) {
  131. if (api_get_setting('show_hot_courses') == 'true') {
  132. $hot_courses = $controller->return_hot_courses();
  133. }
  134. $announcements_block = $controller->return_announcements();
  135. }
  136. $controller->tpl->assign('hot_courses', $hot_courses);
  137. $controller->tpl->assign('announcements_block', $announcements_block);
  138. $controller->tpl->assign('home_page_block', $controller->return_home_page());
  139. $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
  140. $controller->tpl->assign('notice_block', $controller->return_notice());
  141. $controller->tpl->assign('main_navigation_block', $controller->return_navigation_links());
  142. $controller->tpl->assign('help_block', $controller->return_help());
  143. if (api_is_platform_admin() || api_is_drh()) {
  144. $controller->tpl->assign('skills_block', $controller->return_skills_links());
  145. }
  146. if (api_is_anonymous()) {
  147. $controller->tpl->setLoginBodyClass();
  148. }
  149. // direct login to course
  150. if (isset($_GET['firstpage'])) {
  151. api_set_firstpage_parameter($_GET['firstpage']);
  152. // if we are already logged, go directly to course
  153. if (api_user_is_login()) {
  154. echo "<script type='text/javascript'>self.location.href='index.php?firstpage=".$_GET['firstpage']."'</script>";
  155. }
  156. } else {
  157. api_delete_firstpage_parameter();
  158. }
  159. $controller->tpl->display_two_col_template();