Completed
Push — master ( e8cd69...b36e09 )
by Angel Fernando Quiroz
49:31 queued 21:24
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
// @todo change root .htaccess
5
header('Location: web/app_dev.php');
6
exit;
7
8
use ChamiloSession as Session;
9
10
/**
11
 * @package chamilo.main
12
 */
13
14
define('CHAMILO_HOMEPAGE', true);
15
define('CHAMILO_LOAD_WYSIWYG', false);
16
17
/* Flag forcing the 'current course' reset, as we're not inside a course anymore. */
18
// Maybe we should change this into an api function? an example: CourseManager::unset();
19
$cidReset = true;
20
21
require_once 'main/inc/global.inc.php';
22
//require_once 'main/auth/external_login/facebook.inc.php';
23
24
// The section (for the tabs).
25
$this_section = SECTION_CAMPUS;
26
27
$header_title = null;
28
if (!api_is_anonymous()) {
29
    $header_title = ' ';
30
}
31
32
$controller = new IndexManager($header_title);
33
34
//Actions
35
$loginFailed = isset($_GET['loginFailed']) ? true : isset($loginFailed);
36
37
if (!empty($_GET['logout'])) {
38
    $redirect = !empty($_GET['no_redirect']) ? false : true;
39
    $controller->logout($redirect);
40
}
41
42
/**
43
 * Registers in the track_e_default table (view in important activities in admin
44
 * interface) a possible attempted break in, sending auth data through get.
45
 * @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.
46
 */
47
if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
48
    $i = api_get_anonymous_id();
49
    Event::addEvent(
50
        LOG_ATTEMPTED_FORCED_LOGIN,
51
        'tried_hacking_get',
52
        $_SERVER['REMOTE_ADDR'].(empty($_POST['login'])?'':'/'.$_POST['login']),
53
        null,
54
        $i
55
    );
56
    echo 'Attempted breakin - sysadmins notified.';
57
    session_destroy();
58
    die();
59
}
60
61
// Delete session item necessary to check for legal terms
62
if (api_get_setting('allow_terms_conditions') === 'true') {
63
    Session::erase('term_and_condition');
64
}
65
//If we are not logged in and customapages activated
66
if (!api_get_user_id() && CustomPages::enabled()) {
67
    if (Request::get('loggedout')) {
68
        CustomPages::display(CustomPages::LOGGED_OUT);
69
    } else {
70
        CustomPages::display(CustomPages::INDEX_UNLOGGED);
71
    }
72
}
73
74
/**
75
 * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
76
 * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
77
 *       the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
78
 *       on api_get_setting('page_after_login').
79
 */
80
81
if (!empty($_POST['submitAuth'])) {
82
    // The user has been already authenticated, we are now to find the last login of the user.
83
    if (isset ($_user['user_id'])) {
84
        $track_login_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
85
        $sql = "SELECT UNIX_TIMESTAMP(login_date)
86
                FROM $track_login_table
87
                WHERE login_user_id = '".$_user['user_id']."'
88
                ORDER BY login_date DESC LIMIT 1";
89
        $result_last_login = Database::query($sql);
90 View Code Duplication
        if (!$result_last_login) {
91
            if (Database::num_rows($result_last_login) > 0) {
92
                $user_last_login_datetime = Database::fetch_array($result_last_login);
93
                $user_last_login_datetime = $user_last_login_datetime[0];
94
                Session::write('user_last_login_datetime', $user_last_login_datetime);
95
            }
96
        }
97
    }
98
} else {
99
    // Only if login form was not sent because if the form is sent the user was already on the page.
100
    Event::event_open();
101
}
102
103
if (api_get_setting('display_categories_on_homepage') === 'true') {
104
    $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...
105
}
106
107
$controller->set_login_form();
108
109
//@todo move this inside the IndexManager
110
if (!api_is_anonymous()) {
111
    $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...
112
    $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...
113
114
    if (api_is_platform_admin()) {
115
        $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...
116
    } else {
117
        $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...
118
    }
119
}
120
121
$hot_courses = '';
122
$announcements_block = '';
123
124
// Display the Site Use Cookie Warning Validation
125
$useCookieValidation = api_get_setting('cookie_warning');
126 View Code Duplication
if ($useCookieValidation === 'true') {
127
    if (isset($_POST['acceptCookies'])) {
128
        api_set_site_use_cookie_warning_cookie();
129
    } else if (!api_site_use_cookie_warning_cookie_exist()) {
130
        if (Template::isToolBarDisplayedForUser()) {
131
            $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...
132
        } else {
133
            $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...
134
        }
135
        $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...
136
    }
137
}
138
139
// When loading a chamilo page do not include the hot courses and news
140
141
if (!isset($_REQUEST['include'])) {
142
    if (api_get_setting('show_hot_courses') == 'true') {
143
        $hot_courses = $controller->return_hot_courses();
144
    }
145
    $announcements_block = $controller->return_announcements();
146
}
147
148
$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...
149
$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...
150
$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...
151
$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...
152
$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...
153
//$controller->tpl->assign('main_navigation_block', $controller->return_navigation_links());
154
$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...
155
156
if (api_is_platform_admin() || api_is_drh()) {
157
    $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...
158
}
159
160
if (api_is_anonymous()) {
161
    $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...
162
}
163
164
// direct login to course
165
if (isset($_GET['firstpage'])) {
166
    api_set_firstpage_parameter($_GET['firstpage']);
167
    // if we are already logged, go directly to course
168
    if (api_user_is_login()) {
169
        echo "<script>self.location.href='index.php?firstpage=".Security::remove_XSS($_GET['firstpage'])."'</script>";
170
    }
171
} else {
172
    api_delete_firstpage_parameter();
173
}
174
175
$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...
176