aboutsummaryrefslogtreecommitdiff
path: root/lib/navigation/ProfileNavigation.php
blob: ffff06cbeb40678dab0e7c1cb88c67f25f4e2444 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
 * ProfilNavigation.php - navigation for user profile page
 *
 * Navigation for the user's profile page. This page includes all
 * information about a user and allows editing this data.
 *
 * @author   Elmar Ludwig
 * @license  GPL version 2 or any later version
 * @category Stud.IP
 */
class ProfileNavigation extends Navigation
{
    /**
     * Initialize a new Navigation instance.
     */
    public function __construct()
    {
        parent::__construct(_('Profil'));
    }

    public function initItem()
    {
        parent::initItem();

        $this->setURL('dispatch.php/profile');
        $this->setImage(Icon::create('person', Icon::ROLE_NAVIGATION));
    }

    /**
     * Determine whether this navigation item is active.
     */
    public function isActive()
    {
        $active = parent::isActive();

        if ($active) {
            URLHelper::addLinkParam('username', Request::username('username'));
        }

        return $active;
    }

    /**
     * Initialize the subnavigation of this item. This method
     * is called once before the first item is added or removed.
     */
    public function initSubNavigation()
    {
        global $user, $perm;

        parent::initSubNavigation();

        $username = Request::username('username', $user->username);
        $current_user = User::findByUsername($username);

        // profile
        $navigation = new Navigation(_('Profil'), 'dispatch.php/profile/index');
        $this->addSubNavigation('index', $navigation);

        if ($current_user && $perm->have_profile_perm('user', $current_user->user_id)) {
            // profile data
            $navigation = new Navigation(_('Persönliche Angaben'));
            $navigation->addSubNavigation('profile', new Navigation(_('Grunddaten'), 'dispatch.php/settings/account'));
            if (
                !StudipAuthAbstract::CheckField('auth_user_md5.password', $current_user->auth_plugin)
                && (
                    $perm->get_profile_perm($current_user->user_id) === 'user'
                    || (
                        $perm->have_perm('root')
                        && Config::get()->ALLOW_ADMIN_USERACCESS
                    )
                )
            ) {
                $navigation->addSubNavigation('password', new Navigation(
                    _('Passwort ändern'),
                    'dispatch.php/settings/password'
                ));
            }
            $navigation->addSubNavigation('details', new Navigation(_('Weitere Daten'), 'dispatch.php/settings/details'));

            if (!in_array($current_user->perms, words('user admin root'))) {
                $navigation->addSubNavigation('studies', new Navigation(_('Studiendaten'), 'dispatch.php/settings/studies'));
            }

            if ($current_user->perms !== 'root') {
                if (count(UserDomain::getUserDomains()) > 0) {
                    $navigation->addSubNavigation('userdomains', new Navigation(_('Nutzerdomänen'), 'dispatch.php/settings/userdomains'));
                }

                if ($perm->is_staff_member($current_user->user_id)) {
                    $navigation->addSubNavigation('statusgruppen', new Navigation(_('Einrichtungsdaten'), 'dispatch.php/settings/statusgruppen'));
                }
            }

            $this->addSubNavigation('edit', $navigation);

            if ($perm->have_perm('autor')) {
                $navigation = new Navigation(_('Einstellungen'));

                $navigation->addSubNavigation('general', new Navigation(_('Allgemeines'), 'dispatch.php/settings/general'));
                $navigation->addSubNavigation('privacy', new Navigation(_('Privatsphäre'), 'dispatch.php/settings/privacy'));
                $navigation->addSubNavigation('messaging', new Navigation(_('Nachrichten'), 'dispatch.php/settings/messaging'));

                if (Config::get()->CALENDAR_ENABLE) {
                    $navigation->addSubNavigation('calendar_new', new Navigation(_('Terminkalender'), 'dispatch.php/settings/calendar'));
                }

                if (!$perm->have_perm('admin') && Config::get()->MAIL_NOTIFICATION_ENABLE) {
                    $navigation->addSubNavigation('notification', new Navigation(_('Benachrichtigung'), 'dispatch.php/settings/notification'));
                }

                if (Deputy::isActivated() && $perm->get_perm($current_user->user_id) === 'dozent') {
                    $navigation->addSubNavigation('deputies', new Navigation(_('Standardvertretung'), 'dispatch.php/settings/deputies'));
                }

                if (Config::Get()->API_ENABLED) {
                    $navigation->addSubNavigation('api', new Navigation(_('API-Berechtigungen'), 'dispatch.php/api/authorizations'));
                }

                if (TwoFactorAuth::isEnabledForUser()) {
                    $navigation->addSubNavigation('tfa', new Navigation(_('Zwei-Faktor-Authentifizierung'), 'dispatch.php/tfa'));
                }

                $navigation->addSubNavigation('oauth2', new Navigation(_('Drittanwendungen'), 'dispatch.php/api/oauth2/applications'));

                $navigation->addSubNavigation('accessibility', new Navigation(
                    _('Barrierefreiheit'),
                    'dispatch.php/settings/accessibility'
                ));

                $this->addSubNavigation('settings', $navigation);
            }

            // user defined sections
            $navigation = new Navigation(_('Kategorien'), 'dispatch.php/settings/categories');
            $this->addSubNavigation('categories', $navigation);
        }

        // Add consultations if appropriate
        if (Config::get()->CONSULTATION_ENABLED) {
            $plugin = PluginEngine::getPlugin('ConsultationModule');
            if ($current_user && $plugin && PluginManager::getInstance()->isPluginActivatedForUser($plugin->getPluginId(), $current_user->id)) {
                $this->addSubNavigation('consultation', new ConsultationNavigation($current_user));
            }
        }
    }
}