index.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. $request = $app['request'];
  39. //Actions
  40. $logout = $request->get('logout');
  41. if (!empty($logout)) {
  42. $this->logout();
  43. }
  44. //$article = $app['orm.em']->getRepository('Entity\EntityCourse');
  45. //$courses_query = $app['orm.em']->createQuery('SELECT a FROM Entity\EntityCourse a');
  46. //$a = new EntityCourse();
  47. //require_once '/var/www/chamilo11/main/inc/Entity/EntityCourse.php';
  48. //$article = $app['orm.em']->getRepository('EntityCourse');
  49. //var_dump($article);
  50. //$courses_query = $app['orm.em']->createQuery('SELECT a FROM Entity\EntityCourse a');
  51. /*
  52. $paginator = new Doctrine\ORM\Tools\Pagination\Paginator($courses_query, $fetchJoinCollection = true);
  53. $c = count($paginator);
  54. foreach ($paginator as $course) {
  55. echo $course->getCode() . "\n";
  56. }
  57. exit;*/
  58. //$app['orm.em']->find('EntityCourse', 1);
  59. //var_dump($app['orm.ems']['mysql']);
  60. // Defines wether or not anonymous visitors can see a list of the courses on the Chamilo homepage that are open to the world.
  61. //$_setting['display_courses_to_anonymous_users'] = 'true';
  62. // Delete session neccesary for legal terms
  63. if (api_get_setting('allow_terms_conditions') == 'true') {
  64. unset($_SESSION['term_and_condition']);
  65. }
  66. //If we are not logged in and customapages activated
  67. if (!api_get_user_id() && CustomPages::enabled()) {
  68. $logged_out = $request->get('loggedout');
  69. if ($logged_out) {
  70. CustomPages::display(CustomPages::LOGGED_OUT);
  71. } else {
  72. CustomPages::display(CustomPages::INDEX_UNLOGGED);
  73. }
  74. }
  75. //$this->check_last_login();
  76. if (api_get_setting('display_categories_on_homepage') == 'true') {
  77. $app['template']->assign('course_category_block', PageController::return_courses_in_categories());
  78. }
  79. // Facebook connexion, if activated
  80. if (api_is_facebook_auth_activated() && !api_get_user_id()) {
  81. facebook_connect();
  82. }
  83. $this->set_login_form($app);
  84. if (!api_is_anonymous()) {
  85. PageController::return_profile_block();
  86. PageController::return_user_image_block();
  87. if (api_is_platform_admin()) {
  88. PageController::return_course_block();
  89. } else {
  90. PageController::return_teacher_link();
  91. }
  92. }
  93. //Hot courses & announcements
  94. $hot_courses = null;
  95. $announcements_block = null;
  96. // When loading a chamilo page do not include the hot courses and news
  97. if (!isset($_REQUEST['include'])) {
  98. if (api_get_setting('show_hot_courses') == 'true') {
  99. $hot_courses = PageController::return_hot_courses();
  100. }
  101. $announcements_block = PageController::return_announcements();
  102. }
  103. $app['template']->assign('hot_courses', $hot_courses);
  104. $app['template']->assign('announcements_block', $announcements_block);
  105. //Homepage
  106. $app['template']->assign('home_page_block', PageController::return_home_page());
  107. //Navigation links
  108. $nav_links = $app['template']->return_navigation_links();
  109. $app['template']->assign('navigation_course_links', $nav_links);
  110. $app['template']->assign('main_navigation_block', $nav_links);
  111. PageController::return_notice();
  112. PageController::return_help();
  113. if (api_is_platform_admin() || api_is_drh()) {
  114. PageController::return_skills_links();
  115. }
  116. $response = $app['template']->render_layout('layout_2_col.tpl');
  117. //return new Response($response, 200, array('Cache-Control' => 's-maxage=3600, public'));
  118. return new Response($response, 200, array());
  119. }
  120. /**
  121. *
  122. * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
  123. * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
  124. * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
  125. * on api_get_setting('page_after_login').
  126. * @deprecated seems not to be used
  127. */
  128. function check_last_login() {
  129. if (!empty($_POST['submitAuth'])) {
  130. // The user has been already authenticated, we are now to find the last login of the user.
  131. if (!empty($this->user_id)) {
  132. $track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  133. $sql_last_login = "SELECT login_date
  134. FROM $track_login_table
  135. WHERE login_user_id = '".$this->user_id."'
  136. ORDER BY login_date DESC LIMIT 1";
  137. $result_last_login = Database::query($sql_last_login);
  138. if (!$result_last_login) {
  139. if (Database::num_rows($result_last_login) > 0) {
  140. $user_last_login_datetime = Database::fetch_array($result_last_login);
  141. $user_last_login_datetime = $user_last_login_datetime[0];
  142. Session::write('user_last_login_datetime', $user_last_login_datetime);
  143. }
  144. }
  145. Database::free_result($result_last_login);
  146. if (api_is_platform_admin()) {
  147. // decode all open event informations and fill the track_c_* tables
  148. include api_get_path(LIBRARY_PATH).'stats.lib.inc.php';
  149. decodeOpenInfos();
  150. }
  151. }
  152. // End login -- if ($_POST['submitAuth'])
  153. } else {
  154. // Only if login form was not sent because if the form is sent the user was already on the page.
  155. event_open();
  156. }
  157. }
  158. function set_login_form(Application $app) {
  159. $user_id = api_get_user_id();
  160. $login_form = null;
  161. if (!$user_id || api_is_anonymous($user_id)) {
  162. // Only display if the user isn't logged in.
  163. $app['template']->assign('login_language_form', api_display_language_form(true));
  164. //self::display_login_form($app);
  165. $app['template']->assign('login_form', self::display_login_form($app));
  166. if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
  167. $login_form .= '<ul class="nav nav-list">';
  168. if (api_get_setting('allow_registration') != 'false') {
  169. $login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  170. }
  171. if (api_get_setting('allow_lostpassword') == 'true') {
  172. $login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
  173. }
  174. $login_form .= '</ul>';
  175. }
  176. $app['template']->assign('login_options', $login_form);
  177. }
  178. }
  179. function logout() {
  180. $user_id = api_get_user_id();
  181. online_logout($user_id, true);
  182. }
  183. function display_login_form(Application $app) {
  184. /*{{ form_widget(form) }}
  185. $form = $app['form.factory']->createBuilder('form')
  186. ->add('name')
  187. ->add('email')
  188. ->add('gender', 'choice', array(
  189. 'choices' => array(1 => 'male', 2 => 'female'),
  190. 'expanded' => true,
  191. ))
  192. ->getForm();
  193. return $app['template']->assign('form', $form->createView());
  194. */
  195. $form = new FormValidator('formLogin', 'POST', null, null, array('class'=>'form-vertical'));
  196. $form->addElement('text', 'login', get_lang('UserName'), array('class' => 'span2 autocapitalize_off', 'autofocus' => 'autofocus'));
  197. $form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2'));
  198. $form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));
  199. $html = $form->return_form();
  200. if (api_get_setting('openid_authentication') == 'true') {
  201. include_once 'main/auth/openid/login.php';
  202. $html .= '<div>'.openid_form().'</div>';
  203. }
  204. return $html;
  205. }
  206. }
  207. $app->match('/', 'IndexController::indexAction', 'POST|GET');
  208. $app->run();
  209. //$app['http_cache']->run();