aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/settings/general.php
blob: 3c17eb66dab0c54e24a636ac5730a6c03714bb9e (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
<?php
/**
 * SettingsController - Administration of all general user 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_GeneralController 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::setTitle(_('Allgemeine Einstellungen anpassen'));
        Navigation::activateItem('/profile/settings/general');
        $this->show_room_management_autor_config = Config::get()->RESOURCES_ENABLE
                                                && (
                                                    ResourceManager::userHasGlobalPermission($this->user, 'autor')
                                                    ||
                                                    RoomManager::userHasRooms($this->user, 'autor')
                                                );
    }

    /**
     * Displays the general settings of a user.
     */
    public function index_action()
    {
        $this->user_language = getUserLanguage($this->user->id);
    }

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

        $language = Request::get('forced_language');
        if (array_key_exists($language, $GLOBALS['INSTALLED_LANGUAGES'])) {
            $this->user->preferred_language = $language;
            if ($GLOBALS['user']->id === $this->user->id) {
                $_SESSION['_language'] = $language;
            }
            $this->user->store();
        }

        $this->config->store('PERSONAL_STARTPAGE', Request::int('personal_startpage'));
        $this->config->store('SHOWSEM_ENABLE', Request::int('showsem_enable'));
        $this->config->store('SKIPLINKS_ENABLE', Request::int('skiplinks_enable'));
        $this->config->store('TOUR_AUTOSTART_DISABLE', Request::int('tour_autostart_disable'));
        $this->config->store('WIKI_COMMENTS_ENABLE', Request::int('wiki_comments_enable'));
        if ($this->show_room_management_autor_config) {
            $this->config->store('RESOURCES_CONFIRM_PLAN_DRAG_AND_DROP', Request::int('resources_confirm_plan_drag_and_drop'));
        }

        if (Config::get()->WYSIWYG) {
            $this->config->store('WYSIWYG_DISABLED', !Request::int('wysiwyg_enabled'));
        }

        if (Request::int('personal_notifications_activated')) {
            PersonalNotifications::activate($this->user->id);
        } else {
            PersonalNotifications::deactivate($this->user->id);
        }
        if (Request::int('personal_notifications_audio_activated')) {
            PersonalNotifications::activateAudioFeedback($this->user->id);
        } else {
            PersonalNotifications::deactivateAudioFeedback($this->user->id);
        }

        PageLayout::postSuccess(_('Die Einstellungen wurden gespeichert.'));
        $this->redirect('settings/general');
    }
}