aboutsummaryrefslogtreecommitdiff
path: root/public/index.php
blob: 429a35e9b0c353f0f2ca69a8005dede9772a1b88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TEST
# Lifter010: TODO
/**
 * index.php - Startseite von Stud.IP (anhaengig vom Status)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      Stefan Suchi <suchi@gmx.de>
 * @author      Ralf Stockmann <rstockm@gwdg.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 */

require '../lib/bootstrap.php';

page_open(['sess' => 'Seminar_Session', 'auth' => 'Seminar_Default_Auth', 'perm' => 'Seminar_Perm', 'user' => 'Seminar_User']);

$auth->login_if(Request::get('again') && ($auth->auth['uid'] == 'nobody'));

// if desired, switch to high contrast stylesheet and store when user logs in
if (Request::get('unset_contrast')) {
    unset($_SESSION['contrast']);
}
if (Request::get('set_contrast') ) {
    $_SESSION['contrast'] = true;
}

// evaluate language clicks
// has to be done before seminar_open to get switching back to german (no init of i18n at all))
if (Request::get('set_language')) {
    if(array_key_exists(Request::get('set_language'), $GLOBALS['INSTALLED_LANGUAGES'])) {
        $_SESSION['forced_language'] = Request::get('set_language');
        $_SESSION['_language'] = Request::get('set_language');
    }
}

// store user-specific language preference
if ($auth->is_authenticated() && $user->id != 'nobody') {
    // store last language click
    if (!empty($_SESSION['forced_language'])) {
        $query = "UPDATE user_info SET preferred_language = ? WHERE user_id = ?";
        $statement = DBManager::get()->prepare($query);
        $statement->execute([$_SESSION['forced_language'], $user->id]);

        $_SESSION['_language'] = $_SESSION['forced_language'];
    }
    $_SESSION['forced_language'] = null;
}

// -- wir sind jetzt definitiv in keinem Seminar, also... --
closeObject();

include 'lib/seminar_open.php'; // initialise Stud.IP-Session

// if new start page is in use, redirect there (if logged in)
if ($auth->is_authenticated() && $user->id != 'nobody') {
    header('Location: ' . URLHelper::getURL('dispatch.php/start'));
    die;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * *   L O G I N - P A G E   ( N O B O D Y - U S E R )   * *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

PageLayout::setHelpKeyword("Basis.Startseite"); // set keyword for new help
PageLayout::setTitle(_("Startseite"));
Navigation::activateItem('/start');
PageLayout::setTabNavigation(NULL); // disable display of tabs

// Start of Output
include 'lib/include/html_head.inc.php'; // Output of html head
include 'lib/include/header.php';

// Prüfen, ob PortalPlugins vorhanden sind.
// TODO: Remove for Stud.IP 6.0
/** @deprecated */
$portalplugins = PluginEngine::getPlugins('PortalPlugin');
$layout = $GLOBALS['template_factory']->open('shared/index_box');

$plugin_contents = [];
foreach ($portalplugins as $portalplugin) {
    $template = $portalplugin->getPortalTemplate();

    if ($template) {
        $plugin_contents[] = $template->render(NULL, $layout);
        $layout->clear_attributes();
    }
}


$index_nobody_template = $GLOBALS['template_factory']->open('index_nobody');
$cache = StudipCacheFactory::getCache();
$stat = $cache->read('LOGINFORM_STATISTICS');
if (!is_array($stat)) {
    $stat = [];
    $stat['num_active_courses'] = Course::countBySQL();
    $stat['num_registered_users'] = User::countBySQL();
    $cache->write('LOGINFORM_STATISTICS', $stat, 3600);
}
$index_nobody_template->set_attributes(array_merge($stat, [
    'num_online_users' => get_users_online_count(),
    'plugin_contents'  => $plugin_contents,
    'logout'           =>  Request::bool('logout'),
]));

echo $index_nobody_template->render();

page_close();

include 'lib/include/html_end.inc.php';