Completed
Pull Request — 1.11.x (#1274)
by José
554:53 queued 513:46
created

index.php (18 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
/**
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
// Facebook connexion, if activated
28
/*if (api_is_facebook_auth_activated() && !api_get_user_id()) {
29
    facebookConnect();
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
/* Table definitions */
44
45
/* Constants and CONFIGURATION parameters */
46
/** @todo these configuration settings should move to the Chamilo config settings. */
47
48
/** Defines wether or not anonymous visitors can see a list of the courses on the Chamilo homepage that are open to the world. */
49
$_setting['display_courses_to_anonymous_users'] = 'true';
50
51
/* LOGIN */
52
53
/**
54
 * Registers in the track_e_default table (view in important activities in admin
55
 * interface) a possible attempted break in, sending auth data through get.
56
 * @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.
57
 */
58
if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
59
    $i = api_get_anonymous_id();
60
    Event::addEvent(
61
        LOG_ATTEMPTED_FORCED_LOGIN,
62
        'tried_hacking_get',
63
        $_SERVER['REMOTE_ADDR'].(empty($_POST['login'])?'':'/'.$_POST['login']),
64
        null,
65
        $i
66
    );
67
    echo 'Attempted breakin - sysadmins notified.';
68
    session_destroy();
69
    die();
70
}
71
72
// Delete session item necessary to check for legal terms
73
if (api_get_setting('allow_terms_conditions') == 'true') {
74
    Session::erase('term_and_condition');
75
}
76
//If we are not logged in and customapages activated
77
if (!api_get_user_id() && CustomPages::enabled()) {
78
    if (Request::get('loggedout')) {
79
        CustomPages::display(CustomPages::LOGGED_OUT);
80
    } else {
81
        CustomPages::display(CustomPages::INDEX_UNLOGGED);
82
    }
83
}
84
85
/**
86
 * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
87
 * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
88
 *       the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
89
 *       on api_get_setting('page_after_login').
90
 */
91
92
if (!empty($_POST['submitAuth'])) {
93
    // The user has been already authenticated, we are now to find the last login of the user.
94
    if (isset ($_user['user_id'])) {
95
        $track_login_table      = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
96
        $sql_last_login = "SELECT UNIX_TIMESTAMP(login_date)
97
                                FROM $track_login_table
98
                                WHERE login_user_id = '".$_user['user_id']."'
99
                                ORDER BY login_date DESC LIMIT 1";
100
        $result_last_login = Database::query($sql_last_login);
101
        if (!$result_last_login) {
102
            if (Database::num_rows($result_last_login) > 0) {
103
                $user_last_login_datetime = Database::fetch_array($result_last_login);
104
                $user_last_login_datetime = $user_last_login_datetime[0];
105
                Session::write('user_last_login_datetime',$user_last_login_datetime);
106
            }
107
        }
108
        //Event::event_login();
109
    }
110
    // End login -- if ($_POST['submitAuth'])
111
} else {
112
    // Only if login form was not sent because if the form is sent the user was already on the page.
113
    Event::event_open();
114
}
115
116
if (api_get_setting('display_categories_on_homepage') == 'true') {
117
    $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...
118
}
119
120
$controller->set_login_form();
121
122
//@todo move this inside the IndexManager
123
if (!api_is_anonymous()) {
124
    $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...
125
    $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...
126
127
    if (api_is_platform_admin()) {
128
        $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...
129
    } else {
130
        $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...
131
    }
132
}
133
134
$hot_courses = null;
135
$announcements_block = null;
136
137
138
// Display the Site Use Cookie Warning Validation
139
$useCookieValidation = api_get_setting('cookie_warning');
140 View Code Duplication
if ($useCookieValidation === 'true') {
141
    if (isset($_POST['acceptCookies'])) {
142
        api_set_site_use_cookie_warning_cookie();
143
    } else if (!api_site_use_cookie_warning_cookie_exist()) {
144
        if (Template::isToolBarDisplayedForUser()) {
145
            $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...
146
        } else {
147
            $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...
148
        }
149
        $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...
150
    }
151
}
152
153
// When loading a chamilo page do not include the hot courses and news
154
155
if (!isset($_REQUEST['include'])) {
156
    if (api_get_setting('show_hot_courses') == 'true') {
157
        $hot_courses = $controller->return_hot_courses();
158
    }
159
    $announcements_block = $controller->return_announcements();
160
}
161
162
$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...
163
$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...
164
$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...
165
$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...
166
$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...
167
$controller->tpl->assign('main_navigation_block', $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...
168
$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...
169
170
if (api_is_platform_admin() || api_is_drh()) {
171
    $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...
172
}
173
174
if (api_is_anonymous()) {
175
    $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...
176
}
177
178
// direct login to course
179
if (isset($_GET['firstpage'])) {
180
    api_set_firstpage_parameter($_GET['firstpage']);
181
    // if we are already logged, go directly to course
182
    if (api_user_is_login()) {
183
        echo "<script type='text/javascript'>self.location.href='index.php?firstpage=".Security::remove_XSS($_GET['firstpage'])."'</script>";
184
    }
185
} else {
186
    api_delete_firstpage_parameter();
187
}
188
189
$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...
190