aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/settings/userdomains.php
blob: eda8bcc659c09d732965ea5b61b3361c751b951e (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
<?php
/**
 * Settings_DomainsController - Administration of all user domains related
 * settings
 *
 * 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      Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 * @since       2.4
 */

require_once 'settings.php';

class Settings_UserdomainsController extends Settings_SettingsController
{
    /**
     * Set up this controller.
     *
     * @param String $action Name of the action to be invoked
     * @param Array $args    Arguments to be passed to the action method
     */
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        PageLayout::setHelpKeyword('Basis.HomepageNutzerdomänen');
        PageLayout::setTitle(_('Nutzerdomänen bearbeiten'));
        Navigation::activateItem('/profile/edit/userdomains');
    }

    /**
     * Displays the user domain settings of a user.
     */
    public function index_action()
    {
        $this->allow_change = !StudipAuthAbstract::CheckField("userdomain_id", $this->user->auth_plugin)
                              && $GLOBALS['perm']->have_perm('admin');
        $this->user_domains = UserDomain::getUserDomainsForUser($this->user->user_id);
        $all_domains        = UserDomain::getUserDomains();
        $this->domains      = array_diff($all_domains, $this->user_domains);
    }

    /**
     * Stores the user domain settings of a user.
     */
    public function store_action()
    {
        $this->check_ticket();

        $any_change = false;

        $userdomain_delete = Request::getArray('userdomain_delete');
        if (count($userdomain_delete) > 0) {
            foreach ($userdomain_delete as $id) {
                $domain = UserDomain::find($id);
                $domain->removeUser($this->user->user_id);
            }

            $any_change = true;
        }

        $new_userdomain = Request::get('new_userdomain');
        if ($new_userdomain && $new_userdomain != 'none') {
            $domain = UserDomain::find($new_userdomain);
            $domain->addUser($this->user->user_id);

            $any_change = true;
        }

        if ($any_change) {
            PageLayout::postSuccess(_('Die Zuordnung zu Nutzerdomänen wurde geändert.'));

            setTempLanguage($this->user->user_id);
            $this->postPrivateMessage(_("Die Zuordnung zu Nutzerdomänen wurde geändert!\n"));
            restoreLanguage();
        }

        $this->redirect('settings/userdomains');
    }
}