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