aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/settings/messaging.php
blob: 23e6d7945e4612224b8a1456a663afe6513662cf (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
<?php
/*
 * SettingsController - Controller for all setting related pages (formerly edit_about)
 *
 * 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_MessagingController extends Settings_SettingsController
{
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        PageLayout::setHelpKeyword('Basis.MyStudIPMessaging');
        PageLayout::setTitle(_('Einstellungen des Nachrichtensystems anpassen'));
        Navigation::activateItem('/profile/settings/messaging');

        $this->settings = $this->config->MESSAGING_SETTINGS;
        $all_settings_fields = [
            'save_snd',
            'request_mail_forward',
            'show_adressees',
            'logout_markreaded'
        ];
        foreach ($all_settings_fields as $field) {
            if (!array_key_exists($field, $this->settings)) {
                $this->settings[$field] = 0;
            }
        }
    }

    public function index_action()
    {
        if (Request::submitted('store')) {
            $this->check_ticket();

            if (Request::get('new_smsforward_rec')) {
                $this->user->smsforward_rec  = get_userid(Request::get('new_smsforward_rec'));
                $this->user->smsforward_copy = 1;
            } else if (Request::int('smsforward_copy') && !$this->user->smsforward_copy) {
                $this->user->smsforward_copy = 1;
            } else if (!Request::int('smsforward_copy') && $this->user->smsforward_copy) {
                $this->user->smsforward_copy = 0;
            }

            $this->user->email_forward = Request::int('send_as_email');
            $this->user->store();

            // write to user config table
            $this->config->store('ONLINE_NAME_FORMAT', Request::option('online_format'));
            $this->config->store('MAIL_AS_HTML', Request::int('mail_format'));

            $settings = $this->settings;

            $settings['sms_sig']              = Request::get('sms_sig');
            $settings['logout_markreaded']    = Request::int('logout_markreaded');
            $settings['save_snd']             = Request::int('save_snd', 2);
            $settings['request_mail_forward'] = Request::int('request_mail_forward', 0);
            $settings['show_adressees'] = Request::int('show_adressees', 0);

            $this->config->store('MESSAGING_SETTINGS', $settings);

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

        if (!$this->user->smsforward_rec && Request::submitted('gosearch')) {
            $vis_query = get_vis_query('auth_user_md5');
            $query = "SELECT user_id, username, {$GLOBALS['_fullname_sql']['full_rev']} AS fullname, perms
                      FROM auth_user_md5
                      LEFT JOIN user_info USING (user_id)
                      WHERE (username LIKE CONCAT('%', :needle, '%') OR
                             Vorname LIKE CONCAT('%', :needle, '%') OR
                             Nachname LIKE CONCAT('%', :needle, '%'))
                        AND user_id != :user_id AND {$vis_query}
                      ORDER BY Nachname ASC, Vorname ASC";
            $statement = DBManager::get()->prepare($query);
            $statement->bindValue(':needle', Request::get('search_exp'));
            $statement->bindValue(':user_id', $this->user->user_id);
            $statement->execute();
            $matches = $statement->fetchAll(PDO::FETCH_ASSOC);
        } else {
            $matches = false;
        }

        $this->matches = $matches;
    }

    public function verify_action($action)
    {
        if ($action === 'reset') {
            $question = _('Durch das Zurücksetzen werden die persönliche Messaging-Einstellungen '
                         .'auf die Startwerte zurückgesetzt und die persönlichen Nachrichten-Ordner '
                         .'gelöscht. ' . "\n\n" . 'Nachrichten werden nicht entfernt.');
            PageLayout::postQuestion(
                $question,
                $this->url_for('settings/messaging/reset/reset/1')
            )->includeTicket();
        } elseif ($action === 'forward_receiver') {
            PageLayout::postQuestion(
                _('Wollen Sie wirklich die eingestellte Weiterleitung entfernen?'),
                $this->url_for('settings/messaging/reset/forward_receiver/1')
            )->includeTicket();
        }

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

    public function reset_action($action = 'reset', $verified = false)
    {
        if ($verified) {
            $this->check_ticket();

            if ($action === 'reset') {
                $this->user->smsforward_rec  = '';
                $this->user->smsforward_copy = 0;
                $this->user->store();

                $this->config->delete('MESSAGING_SETTINGS');

                PageLayout::postSuccess(_('Ihre Einstellungen wurden erfolgreich zurückgesetzt.'));
            } else if ($action === 'forward_receiver') {
                $this->user->smsforward_rec  = '';
                $this->user->smsforward_copy = 0;
                $this->user->store();

                PageLayout::postSuccess(_('Empfänger und Weiterleitung wurden erfolgreich gelöscht'));
            }
        }
        $this->redirect('settings/messaging');
    }
}