Completed
Push — 1.11.x ( ca7787...41c0f2 )
by José
31:51
created

index.php (17 issues)

Upgrade to new PHP Analysis Engine

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
use ChamiloSession as Session;
5
6
/**
7
 * @package chamilo.main
8
 */
9
10
define('CHAMILO_HOMEPAGE', true);
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
$controller = new IndexManager($header_title);
29
30
//Actions
31
$loginFailed = isset($_GET['loginFailed']) ? true : isset($loginFailed);
32
33
if (!empty($_GET['logout'])) {
34
    $redirect = !empty($_GET['no_redirect']) ? false : true;
35
    $controller->logout($redirect);
36
}
37
38
/**
39
 * Registers in the track_e_default table (view in important activities in admin
40
 * interface) a possible attempted break in, sending auth data through get.
41
 * @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.
42
 */
43
if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
44
    $i = api_get_anonymous_id();
45
    Event::addEvent(
46
        LOG_ATTEMPTED_FORCED_LOGIN,
47
        'tried_hacking_get',
48
        $_SERVER['REMOTE_ADDR'].(empty($_POST['login'])?'':'/'.$_POST['login']),
49
        null,
50
        $i
51
    );
52
    echo 'Attempted breakin - sysadmins notified.';
53
    session_destroy();
54
    die();
55
}
56
57
// Delete session item necessary to check for legal terms
58
if (api_get_setting('allow_terms_conditions') === 'true') {
59
    Session::erase('term_and_condition');
60
}
61
//If we are not logged in and customapages activated
62
if (!api_get_user_id() && CustomPages::enabled()) {
63
    if (Request::get('loggedout')) {
64
        CustomPages::display(CustomPages::LOGGED_OUT);
65
    } else {
66
        CustomPages::display(CustomPages::INDEX_UNLOGGED);
67
    }
68
}
69
70
/**
71
 * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
72
 * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
73
 *       the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
74
 *       on api_get_setting('page_after_login').
75
 */
76
77
if (!empty($_POST['submitAuth'])) {
78
    // The user has been already authenticated, we are now to find the last login of the user.
79
    if (isset ($_user['user_id'])) {
80
        $track_login_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
81
        $sql = "SELECT UNIX_TIMESTAMP(login_date)
82
                FROM $track_login_table
83
                WHERE login_user_id = '".$_user['user_id']."'
84
                ORDER BY login_date DESC LIMIT 1";
85
        $result_last_login = Database::query($sql);
86 View Code Duplication
        if (!$result_last_login) {
87
            if (Database::num_rows($result_last_login) > 0) {
88
                $user_last_login_datetime = Database::fetch_array($result_last_login);
89
                $user_last_login_datetime = $user_last_login_datetime[0];
90
                Session::write('user_last_login_datetime', $user_last_login_datetime);
91
            }
92
        }
93
    }
94
} else {
95
    // Only if login form was not sent because if the form is sent the user was already on the page.
96
    Event::event_open();
97
}
98
99
if (api_get_setting('display_categories_on_homepage') === 'true') {
100
    $controller->tpl->assign('course_category_block', $controller->return_courses_in_categories());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
101
}
102
103
$controller->set_login_form();
104
105
//@todo move this inside the IndexManager
106
if (!api_is_anonymous()) {
107
    $controller->tpl->assign('profile_block', $controller->return_profile_block());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
108
    $controller->tpl->assign('user_image_block', $controller->return_user_image_block());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
109
110
    if (api_is_platform_admin()) {
111
        $controller->tpl->assign('course_block', $controller->return_course_block());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
112
    } else {
113
        $controller->tpl->assign('teacher_block', $controller->return_teacher_link());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
114
    }
115
}
116
117
$hot_courses = '';
118
$announcements_block = '';
119
120
// Display the Site Use Cookie Warning Validation
121
$useCookieValidation = api_get_setting('cookie_warning');
122 View Code Duplication
if ($useCookieValidation === 'true') {
123
    if (isset($_POST['acceptCookies'])) {
124
        api_set_site_use_cookie_warning_cookie();
125
    } else if (!api_site_use_cookie_warning_cookie_exist()) {
126
        if (Template::isToolBarDisplayedForUser()) {
127
            $controller->tpl->assign('toolBarDisplayed', true);
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
128
        } else {
129
            $controller->tpl->assign('toolBarDisplayed', false);
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
130
        }
131
        $controller->tpl->assign('displayCookieUsageWarning', true);
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
132
    }
133
}
134
135
// When loading a chamilo page do not include the hot courses and news
136
137
if (!isset($_REQUEST['include'])) {
138
    if (api_get_setting('show_hot_courses') == 'true') {
139
        $hot_courses = $controller->return_hot_courses();
140
    }
141
    $announcements_block = $controller->return_announcements();
142
}
143
144
$controller->tpl->assign('hot_courses', $hot_courses);
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
145
$controller->tpl->assign('announcements_block', $announcements_block);
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
146
$controller->tpl->assign('home_page_block', $controller->return_home_page());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
147
$controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
148
$controller->tpl->assign('notice_block', $controller->return_notice());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
149
//$controller->tpl->assign('main_navigation_block', $controller->return_navigation_links());
150
$controller->tpl->assign('help_block', $controller->return_help());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
151
152
if (api_is_platform_admin() || api_is_drh()) {
153
    $controller->tpl->assign('skills_block', $controller->return_skills_links());
0 ignored issues
show
The method assign cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
154
}
155
156
if (api_is_anonymous()) {
157
    $controller->tpl->setLoginBodyClass();
0 ignored issues
show
The method setLoginBodyClass cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
158
}
159
160
// direct login to course
161
if (isset($_GET['firstpage'])) {
162
    api_set_firstpage_parameter($_GET['firstpage']);
163
    // if we are already logged, go directly to course
164
    if (api_user_is_login()) {
165
        echo "<script>self.location.href='index.php?firstpage=".Security::remove_XSS($_GET['firstpage'])."'</script>";
166
    }
167
} else {
168
    api_delete_firstpage_parameter();
169
}
170
171
$controller->tpl->display_two_col_template();
0 ignored issues
show
The method display_two_col_template cannot be called on $controller->tpl (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
172