index.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 'main/chat/chat_functions.lib.php';
  13. // The section (for the tabs).
  14. $this_section = SECTION_CAMPUS;
  15. $htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider'));
  16. $htmlHeadXtra[] ='
  17. <script>
  18. $(document).ready(function(){
  19. $("#slider").bxSlider({
  20. infiniteLoop : true,
  21. auto : true,
  22. pager : true,
  23. autoHover : true,
  24. pause : 10000
  25. });
  26. });
  27. </script>';
  28. //set cookie for check if client browser are cookies enabled
  29. //setcookie('TestCookie', 'cookies_yes', time()+3600*24*31*12);
  30. //use Symfony\Component\HttpFoundation\Cookie;
  31. //$cookie = new Cookie('TestCookie', 'cookies_yes', time()+3600*24*31*12);
  32. //$response->headers->setCookie($cookie);
  33. use Silex\Application;
  34. use Symfony\Component\HttpFoundation\Response;
  35. class IndexController
  36. {
  37. public function indexAction(Application $app)
  38. {
  39. $request = $app['request'];
  40. //Actions
  41. $logout = $request->get('logout');
  42. if (!empty($logout)) {
  43. $this->logout();
  44. }
  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. // Delete session neccesary for legal terms
  48. if (api_get_setting('allow_terms_conditions') == 'true') {
  49. unset($_SESSION['term_and_condition']);
  50. }
  51. //If we are not logged in and customapages activated
  52. if (!api_get_user_id() && CustomPages::enabled()) {
  53. $loggedout = $request->get('loggedout');
  54. if ($loggedout) {
  55. CustomPages::display(CustomPages::LOGGED_OUT);
  56. } else {
  57. CustomPages::display(CustomPages::INDEX_UNLOGGED);
  58. }
  59. }
  60. $this->check_last_login();
  61. if (api_get_setting('display_categories_on_homepage') == 'true') {
  62. $app['template']->assign('course_category_block', PageController::return_courses_in_categories());
  63. }
  64. // Facebook connexion, if activated
  65. if (api_is_facebook_auth_activated() && !api_get_user_id()) {
  66. facebook_connect();
  67. }
  68. $this->set_login_form($app);
  69. //@todo move this inside the IndexManager
  70. if (!api_is_anonymous()) {
  71. $app['template']->assign('profile_block', PageController::return_profile_block());
  72. $app['template']->assign('user_image_block', PageController::return_user_image_block());
  73. if (api_is_platform_admin()) {
  74. $app['template']->assign('course_block', PageController::return_course_block());
  75. } else {
  76. $app['template']->assign('teacher_block', PageController::return_teacher_link());
  77. }
  78. }
  79. $hot_courses = null;
  80. $announcements_block = null;
  81. // When loading a chamilo page do not include the hot courses and news
  82. if (!isset($_REQUEST['include'])) {
  83. if (api_get_setting('show_hot_courses') == 'true') {
  84. $hot_courses = PageController::return_hot_courses();
  85. }
  86. $announcements_block = PageController::return_announcements();
  87. }
  88. $app['template']->assign('hot_courses', $hot_courses);
  89. $app['template']->assign('announcements_block', $announcements_block);
  90. $app['template']->assign('home_page_block', PageController::return_home_page());
  91. $nav_links = $app['template']->return_navigation_links();
  92. $app['template']->assign('navigation_course_links', $nav_links);
  93. $app['template']->assign('main_navigation_block', $nav_links);
  94. $app['template']->assign('notice_block', PageController::return_notice());
  95. $app['template']->assign('help_block', PageController::return_help());
  96. if (api_is_platform_admin() || api_is_drh()) {
  97. $app['template']->assign('skills_block', PageController::return_skills_links());
  98. }
  99. $response = $app['template']->render_layout('layout_2_col.tpl');
  100. return new Response($response, 200, array('Cache-Control' => 's-maxage=3600, public'));
  101. //return new Response($response, 200, array());
  102. }
  103. function check_last_login() {
  104. //
  105. // * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
  106. // * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
  107. // * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
  108. // * on api_get_setting('page_after_login').
  109. //
  110. if (!empty($_POST['submitAuth'])) {
  111. // The user has been already authenticated, we are now to find the last login of the user.
  112. if (!empty($this->user_id)) {
  113. $track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  114. $sql_last_login = "SELECT login_date
  115. FROM $track_login_table
  116. WHERE login_user_id = '".$this->user_id."'
  117. ORDER BY login_date DESC LIMIT 1";
  118. $result_last_login = Database::query($sql_last_login);
  119. if (!$result_last_login) {
  120. if (Database::num_rows($result_last_login) > 0) {
  121. $user_last_login_datetime = Database::fetch_array($result_last_login);
  122. $user_last_login_datetime = $user_last_login_datetime[0];
  123. Session::write('user_last_login_datetime', $user_last_login_datetime);
  124. }
  125. }
  126. Database::free_result($result_last_login);
  127. if (api_is_platform_admin()) {
  128. // decode all open event informations and fill the track_c_* tables
  129. include api_get_path(LIBRARY_PATH).'stats.lib.inc.php';
  130. decodeOpenInfos();
  131. }
  132. }
  133. // End login -- if ($_POST['submitAuth'])
  134. } else {
  135. // Only if login form was not sent because if the form is sent the user was already on the page.
  136. event_open();
  137. }
  138. }
  139. function set_login_form(Application $app) {
  140. $login_form = '';
  141. $user_id = api_get_user_id();
  142. if (!($user_id) || api_is_anonymous($user_id)) {
  143. // Only display if the user isn't logged in.
  144. $app['template']->assign('login_language_form', api_display_language_form(true));
  145. $app['template']->assign('login_form', self::display_login_form());
  146. if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
  147. $login_form .= '<ul class="nav nav-list">';
  148. if (api_get_setting('allow_registration') != 'false') {
  149. $login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  150. }
  151. if (api_get_setting('allow_lostpassword') == 'true') {
  152. $login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
  153. }
  154. $login_form .= '</ul>';
  155. }
  156. $app['template']->assign('login_options', $login_form);
  157. }
  158. }
  159. function logout() {
  160. $user_id = api_get_user_id();
  161. online_logout($user_id, true);
  162. }
  163. function display_login_form() {
  164. $form = new FormValidator('formLogin', 'POST', null, null, array('class'=>'form-vertical'));
  165. $form->addElement('text', 'login', get_lang('UserName'), array('class' => 'span2 autocapitalize_off', 'autofocus' => 'autofocus'));
  166. $form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2'));
  167. $form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));
  168. $html = $form->return_form();
  169. if (api_get_setting('openid_authentication') == 'true') {
  170. include_once 'main/auth/openid/login.php';
  171. $html .= '<div>'.openid_form().'</div>';
  172. }
  173. return $html;
  174. }
  175. }
  176. $app->match('/', 'IndexController::indexAction', 'POST|GET');
  177. $app->run();
  178. //$app['http_cache']->run();