chamilo /
chamilo-lms
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /* For licensing terms, see /license.txt */ |
||
| 3 | |||
| 4 | /** |
||
| 5 | * @package chamilo.main |
||
| 6 | */ |
||
| 7 | |||
| 8 | use \ChamiloSession as Session; |
||
| 9 | define('CHAMILO_HOMEPAGE', true); |
||
| 10 | // Avoid loading CKeditor lib on homepage (very heavy lib) |
||
| 11 | define('CHAMILO_LOAD_WYSIWYG', false); |
||
| 12 | |||
| 13 | /* Flag forcing the 'current course' reset, as we're not inside a course anymore. */ |
||
| 14 | // Maybe we should change this into an api function? an example: CourseManager::unset(); |
||
| 15 | $cidReset = true; |
||
| 16 | |||
| 17 | require_once 'main/inc/global.inc.php'; |
||
| 18 | //require_once 'main/auth/external_login/facebook.inc.php'; |
||
| 19 | |||
| 20 | // The section (for the tabs). |
||
| 21 | $this_section = SECTION_CAMPUS; |
||
| 22 | |||
| 23 | $header_title = null; |
||
| 24 | if (!api_is_anonymous()) { |
||
| 25 | $header_title = " "; |
||
| 26 | } |
||
| 27 | |||
| 28 | // Facebook connexion, if activated |
||
| 29 | /*if (api_is_facebook_auth_activated() && !api_get_user_id()) { |
||
| 30 | facebookConnect(); |
||
| 31 | } |
||
| 32 | */ |
||
| 33 | $controller = new IndexManager($header_title); |
||
| 34 | |||
| 35 | //Actions |
||
| 36 | $loginFailed = isset($_GET['loginFailed']) ? true : isset($loginFailed); |
||
| 37 | |||
| 38 | if (!empty($_GET['logout'])) { |
||
| 39 | $redirect = !empty($_GET['no_redirect']) ? false : true; |
||
| 40 | $controller->logout($redirect); |
||
| 41 | } |
||
| 42 | |||
| 43 | |||
| 44 | /* Table definitions */ |
||
| 45 | |||
| 46 | /* Constants and CONFIGURATION parameters */ |
||
| 47 | /** @todo these configuration settings should move to the Chamilo config settings. */ |
||
| 48 | |||
| 49 | /** Defines wether or not anonymous visitors can see a list of the courses on the Chamilo homepage that are open to the world. */ |
||
| 50 | $_setting['display_courses_to_anonymous_users'] = 'true'; |
||
| 51 | |||
| 52 | /* LOGIN */ |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Registers in the track_e_default table (view in important activities in admin |
||
| 56 | * interface) a possible attempted break in, sending auth data through get. |
||
| 57 | * @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. |
||
| 58 | */ |
||
| 59 | if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) { |
||
| 60 | $i = api_get_anonymous_id(); |
||
| 61 | Event::addEvent( |
||
| 62 | LOG_ATTEMPTED_FORCED_LOGIN, |
||
| 63 | 'tried_hacking_get', |
||
| 64 | $_SERVER['REMOTE_ADDR'].(empty($_POST['login'])?'':'/'.$_POST['login']), |
||
| 65 | null, |
||
| 66 | $i |
||
| 67 | ); |
||
| 68 | echo 'Attempted breakin - sysadmins notified.'; |
||
| 69 | session_destroy(); |
||
| 70 | die(); |
||
| 71 | } |
||
| 72 | |||
| 73 | // Delete session item necessary to check for legal terms |
||
| 74 | if (api_get_setting('allow_terms_conditions') == 'true') { |
||
| 75 | Session::erase('term_and_condition'); |
||
| 76 | } |
||
| 77 | //If we are not logged in and customapages activated |
||
| 78 | if (!api_get_user_id() && CustomPages::enabled()) { |
||
| 79 | if (Request::get('loggedout')) { |
||
| 80 | CustomPages::display(CustomPages::LOGGED_OUT); |
||
| 81 | } else { |
||
| 82 | CustomPages::display(CustomPages::INDEX_UNLOGGED); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled. |
||
| 88 | * @todo Check if this code is used. I think this code is never executed because after clicking the submit button |
||
| 89 | * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending |
||
| 90 | * on api_get_setting('page_after_login'). |
||
| 91 | */ |
||
| 92 | |||
| 93 | if (!empty($_POST['submitAuth'])) { |
||
| 94 | // The user has been already authenticated, we are now to find the last login of the user. |
||
| 95 | if (isset ($_user['user_id'])) { |
||
| 96 | $track_login_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); |
||
| 97 | $sql_last_login = "SELECT UNIX_TIMESTAMP(login_date) |
||
| 98 | FROM $track_login_table |
||
| 99 | WHERE login_user_id = '".$_user['user_id']."' |
||
| 100 | ORDER BY login_date DESC LIMIT 1"; |
||
| 101 | $result_last_login = Database::query($sql_last_login); |
||
| 102 | View Code Duplication | if (!$result_last_login) { |
|
| 103 | if (Database::num_rows($result_last_login) > 0) { |
||
| 104 | $user_last_login_datetime = Database::fetch_array($result_last_login); |
||
| 105 | $user_last_login_datetime = $user_last_login_datetime[0]; |
||
| 106 | Session::write('user_last_login_datetime',$user_last_login_datetime); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | //Event::event_login(); |
||
| 110 | } |
||
| 111 | // End login -- if ($_POST['submitAuth']) |
||
| 112 | } else { |
||
| 113 | // Only if login form was not sent because if the form is sent the user was already on the page. |
||
| 114 | Event::event_open(); |
||
| 115 | } |
||
| 116 | |||
| 117 | if (api_get_setting('display_categories_on_homepage') == 'true') { |
||
| 118 | $controller->tpl->assign('course_category_block', $controller->return_courses_in_categories()); |
||
|
0 ignored issues
–
show
|
|||
| 119 | } |
||
| 120 | |||
| 121 | $controller->set_login_form(); |
||
| 122 | |||
| 123 | //@todo move this inside the IndexManager |
||
| 124 | if (!api_is_anonymous()) { |
||
| 125 | $controller->tpl->assign('profile_block', $controller->return_profile_block()); |
||
|
0 ignored issues
–
show
|
|||
| 126 | $controller->tpl->assign('user_image_block', $controller->return_user_image_block()); |
||
|
0 ignored issues
–
show
|
|||
| 127 | |||
| 128 | if (api_is_platform_admin()) { |
||
| 129 | $controller->tpl->assign('course_block', $controller->return_course_block()); |
||
|
0 ignored issues
–
show
|
|||
| 130 | } else { |
||
| 131 | $controller->tpl->assign('teacher_block', $controller->return_teacher_link()); |
||
|
0 ignored issues
–
show
|
|||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | $hot_courses = null; |
||
| 136 | $announcements_block = null; |
||
| 137 | |||
| 138 | |||
| 139 | // Display the Site Use Cookie Warning Validation |
||
| 140 | $useCookieValidation = api_get_setting('cookie_warning'); |
||
| 141 | View Code Duplication | if ($useCookieValidation === 'true') { |
|
| 142 | if (isset($_POST['acceptCookies'])) { |
||
| 143 | api_set_site_use_cookie_warning_cookie(); |
||
| 144 | } else if (!api_site_use_cookie_warning_cookie_exist()) { |
||
| 145 | if (Template::isToolBarDisplayedForUser()) { |
||
| 146 | $controller->tpl->assign('toolBarDisplayed', true); |
||
|
0 ignored issues
–
show
|
|||
| 147 | } else { |
||
| 148 | $controller->tpl->assign('toolBarDisplayed', false); |
||
|
0 ignored issues
–
show
|
|||
| 149 | } |
||
| 150 | $controller->tpl->assign('displayCookieUsageWarning', true); |
||
|
0 ignored issues
–
show
|
|||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | // When loading a chamilo page do not include the hot courses and news |
||
| 155 | |||
| 156 | if (!isset($_REQUEST['include'])) { |
||
| 157 | if (api_get_setting('show_hot_courses') == 'true') { |
||
| 158 | $hot_courses = $controller->return_hot_courses(); |
||
| 159 | } |
||
| 160 | $announcements_block = $controller->return_announcements(); |
||
| 161 | } |
||
| 162 | |||
| 163 | $controller->tpl->assign('hot_courses', $hot_courses); |
||
|
0 ignored issues
–
show
|
|||
| 164 | $controller->tpl->assign('announcements_block', $announcements_block); |
||
|
0 ignored issues
–
show
|
|||
| 165 | $controller->tpl->assign('home_page_block', $controller->return_home_page()); |
||
|
0 ignored issues
–
show
|
|||
| 166 | $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links()); |
||
|
0 ignored issues
–
show
|
|||
| 167 | $controller->tpl->assign('notice_block', $controller->return_notice()); |
||
|
0 ignored issues
–
show
|
|||
| 168 | $controller->tpl->assign('main_navigation_block', $controller->return_navigation_links()); |
||
|
0 ignored issues
–
show
|
|||
| 169 | $controller->tpl->assign('help_block', $controller->return_help()); |
||
|
0 ignored issues
–
show
|
|||
| 170 | |||
| 171 | if (api_is_platform_admin() || api_is_drh()) { |
||
| 172 | $controller->tpl->assign('skills_block', $controller->return_skills_links()); |
||
|
0 ignored issues
–
show
|
|||
| 173 | } |
||
| 174 | |||
| 175 | if (api_is_anonymous()) { |
||
| 176 | $controller->tpl->setLoginBodyClass(); |
||
|
0 ignored issues
–
show
|
|||
| 177 | } |
||
| 178 | |||
| 179 | // direct login to course |
||
| 180 | if (isset($_GET['firstpage'])) { |
||
| 181 | api_set_firstpage_parameter($_GET['firstpage']); |
||
| 182 | // if we are already logged, go directly to course |
||
| 183 | if (api_user_is_login()) { |
||
| 184 | echo "<script type='text/javascript'>self.location.href='index.php?firstpage=".Security::remove_XSS($_GET['firstpage'])."'</script>"; |
||
| 185 | } |
||
| 186 | } else { |
||
| 187 | api_delete_firstpage_parameter(); |
||
| 188 | } |
||
| 189 | |||
| 190 | $controller->tpl->display_two_col_template(); |
||
|
0 ignored issues
–
show
|
|||
| 191 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.