index.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.main
  5. */
  6. define('CHAMILO_HOMEPAGE', true);
  7. $language_file = array('courses', 'index');
  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. $htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider'));
  21. $htmlHeadXtra[] ='
  22. <script type="text/javascript">
  23. $(document).ready(function(){
  24. $("#slider").bxSlider({
  25. infiniteLoop : true,
  26. auto : true,
  27. pager : true,
  28. autoHover : true,
  29. pause : 10000
  30. });
  31. });
  32. if(navigator.cookieEnabled==false){
  33. document.writeln("'.addslashes(Display::return_message(get_lang("NoCookies"), 'error')).'");
  34. }
  35. </script>
  36. <noscript>
  37. '.addslashes(Display::return_message(get_lang("NoJavascript"), 'error')).'
  38. </noscript>
  39. ';
  40. //@todo add this in the template
  41. //check if javascript is enabled
  42. /*
  43. echo '<noscript>';
  44. echo Display::display_error_message(get_lang("NoJavascript"));
  45. echo '</noscript>';
  46. */
  47. //check if cookies are enabled
  48. /*
  49. ?>
  50. <script language="JavaScript">
  51. if(navigator.cookieEnabled==false){
  52. document.writeln('<?php Display::display_error_message(get_lang("NoCookies")); ?>');
  53. }
  54. </script>
  55. <?php
  56. */
  57. $controller = new IndexManager($header_title);
  58. //Actions
  59. $loginFailed = isset($_GET['loginFailed']) ? true : isset($loginFailed);
  60. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  61. if (!empty($_GET['logout'])) {
  62. $controller->logout();
  63. }
  64. /* Table definitions */
  65. /* Constants and CONFIGURATION parameters */
  66. /** @todo these configuration settings should move to the Chamilo config settings. */
  67. /** Defines wether or not anonymous visitors can see a list of the courses on the Chamilo homepage that are open to the world. */
  68. $_setting['display_courses_to_anonymous_users'] = 'true';
  69. /* LOGIN */
  70. /**
  71. * @todo This piece of code should probably move to local.inc.php where the actual login / logout procedure is handled.
  72. * @todo Consider removing this piece of code because does nothing.
  73. */
  74. if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
  75. // nice lie!!!
  76. echo 'Attempted breakin - sysadmins notified.';
  77. session_destroy();
  78. die();
  79. }
  80. // Delete session neccesary for legal terms
  81. if (api_get_setting('allow_terms_conditions') == 'true') {
  82. unset($_SESSION['update_term_and_condition']);
  83. unset($_SESSION['info_current_user']);
  84. }
  85. //If we are not logged in and customapages activated
  86. if (!api_get_user_id() && api_get_setting('use_custom_pages') == 'true' ){
  87. require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';
  88. CustomPages::displayPage('index-unlogged');
  89. }
  90. /**
  91. * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
  92. * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
  93. * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
  94. * on api_get_setting('page_after_login').
  95. */
  96. if (!empty($_POST['submitAuth'])) {
  97. // The user has been already authenticated, we are now to find the last login of the user.
  98. if (isset ($_user['user_id'])) {
  99. $track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  100. $sql_last_login = "SELECT UNIX_TIMESTAMP(login_date)
  101. FROM $track_login_table
  102. WHERE login_user_id = '".$_user['user_id']."'
  103. ORDER BY login_date DESC LIMIT 1";
  104. $result_last_login = Database::query($sql_last_login);
  105. if (!$result_last_login) {
  106. if (Database::num_rows($result_last_login) > 0) {
  107. $user_last_login_datetime = Database::fetch_array($result_last_login);
  108. $user_last_login_datetime = $user_last_login_datetime[0];
  109. api_session_register('user_last_login_datetime');
  110. }
  111. }
  112. Database::free_result($result_last_login);
  113. //event_login();
  114. if (api_is_platform_admin()) {
  115. // decode all open event informations and fill the track_c_* tables
  116. include api_get_path(LIBRARY_PATH).'stats.lib.inc.php';
  117. decodeOpenInfos();
  118. }
  119. }
  120. // End login -- if ($_POST['submitAuth'])
  121. } else {
  122. // Only if login form was not sent because if the form is sent the user was already on the page.
  123. event_open();
  124. }
  125. //@todo add this in the template
  126. // Plugins for loginpage_main AND campushomepage_main.
  127. if (!api_get_user_id()) {
  128. api_plugin('loginpage_main');
  129. } else {
  130. api_plugin('campushomepage_main');
  131. }
  132. //@todo add this in the template
  133. if (api_get_setting('display_categories_on_homepage') == 'true') {
  134. echo '<div class="home_cats">';
  135. $controller->display_anonymous_course_list();
  136. echo '</div>';
  137. }
  138. $controller->set_login_form();
  139. //@todo move this inside the IndexManager
  140. if (!api_is_anonymous()) {
  141. $controller->tpl->assign('profile_block', $controller->return_profile_block());
  142. if (api_is_platform_admin()) {
  143. $controller->tpl->assign('account_block', $controller->return_account_block());
  144. } else {
  145. $controller->tpl->assign('teacher_block', $controller->return_teacher_link());
  146. }
  147. }
  148. $controller->tpl->assign('announcements_block', $controller->return_announcements());
  149. $controller->tpl->assign('home_page_block', $controller->return_home_page());
  150. $controller->tpl->assign('notice_block', $controller->return_notice());
  151. $controller->tpl->assign('plugin_campushomepage', $controller->return_plugin_campushomepage());
  152. $controller->tpl->display_two_col_template();