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