summaryrefslogtreecommitdiff
path: root/app/Controller/Config.php
blob: 53f7cdb64e6dc49142a9f8f6473d51d865826bac (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php

namespace Kanboard\Controller;

/**
 * Config controller
 *
 * @package  controller
 * @author   Frederic Guillot
 */
class Config extends Base
{
    /**
     * Common method between pages
     *
     * @access private
     * @param  string     $redirect    Action to redirect after saving the form
     */
    private function common($redirect)
    {
        if ($this->request->isPost()) {
            $values =  $this->request->getValues();

            switch ($redirect) {
                case 'application':
                    $values += array('password_reset' => 0);
                    break;
                case 'project':
                    $values += array('subtask_restriction' => 0, 'subtask_time_tracking' => 0, 'cfd_include_closed_tasks' => 0);
                    break;
                case 'integrations':
                    $values += array('integration_gravatar' => 0);
                    break;
                case 'calendar':
                    $values += array('calendar_user_subtasks_time_tracking' => 0);
                    break;
            }

            if ($this->config->save($values)) {
                $this->config->reload();
                $this->flash->success(t('Settings saved successfully.'));
            } else {
                $this->flash->failure(t('Unable to save your settings.'));
            }

            $this->response->redirect($this->helper->url->to('config', $redirect));
        }
    }

    /**
     * Display the about page
     *
     * @access public
     */
    public function index()
    {
        $this->response->html($this->helper->layout->config('config/about', array(
            'db_size' => $this->config->getDatabaseSize(),
            'title' => t('Settings').' &gt; '.t('About'),
        )));
    }

    /**
     * Display the plugin page
     *
     * @access public
     */
    public function plugins()
    {
        $this->response->html($this->helper->layout->config('config/plugins', array(
            'plugins' => $this->pluginLoader->plugins,
            'title' => t('Settings').' &gt; '.t('Plugins'),
        )));
    }

    /**
     * Display the application settings page
     *
     * @access public
     */
    public function application()
    {
        $this->common('application');

        $this->response->html($this->helper->layout->config('config/application', array(
            'languages' => $this->config->getLanguages(),
            'timezones' => $this->config->getTimezones(),
            'date_formats' => $this->dateParser->getAvailableFormats(),
            'title' => t('Settings').' &gt; '.t('Application settings'),
        )));
    }

    /**
     * Display the project settings page
     *
     * @access public
     */
    public function project()
    {
        $this->common('project');

        $this->response->html($this->helper->layout->config('config/project', array(
            'colors' => $this->color->getList(),
            'default_columns' => implode(', ', $this->board->getDefaultColumns()),
            'title' => t('Settings').' &gt; '.t('Project settings'),
        )));
    }

    /**
     * Display the board settings page
     *
     * @access public
     */
    public function board()
    {
        $this->common('board');

        $this->response->html($this->helper->layout->config('config/board', array(
            'title' => t('Settings').' &gt; '.t('Board settings'),
        )));
    }

    /**
     * Display the calendar settings page
     *
     * @access public
     */
    public function calendar()
    {
        $this->common('calendar');

        $this->response->html($this->helper->layout->config('config/calendar', array(
            'title' => t('Settings').' &gt; '.t('Calendar settings'),
        )));
    }

    /**
     * Display the integration settings page
     *
     * @access public
     */
    public function integrations()
    {
        $this->common('integrations');

        $this->response->html($this->helper->layout->config('config/integrations', array(
            'title' => t('Settings').' &gt; '.t('Integrations'),
        )));
    }

    /**
     * Display the webhook settings page
     *
     * @access public
     */
    public function webhook()
    {
        $this->common('webhook');

        $this->response->html($this->helper->layout->config('config/webhook', array(
            'title' => t('Settings').' &gt; '.t('Webhook settings'),
        )));
    }

    /**
     * Display the api settings page
     *
     * @access public
     */
    public function api()
    {
        $this->response->html($this->helper->layout->config('config/api', array(
            'title' => t('Settings').' &gt; '.t('API'),
        )));
    }

    /**
     * Download the Sqlite database
     *
     * @access public
     */
    public function downloadDb()
    {
        $this->checkCSRFParam();
        $this->response->forceDownload('db.sqlite.gz');
        $this->response->binary($this->config->downloadDatabase());
    }

    /**
     * Optimize the Sqlite database
     *
     * @access public
     */
    public function optimizeDb()
    {
        $this->checkCSRFParam();
        $this->config->optimizeDatabase();
        $this->flash->success(t('Database optimization done.'));
        $this->response->redirect($this->helper->url->to('config', 'index'));
    }

    /**
     * Regenerate webhook token
     *
     * @access public
     */
    public function token()
    {
        $type = $this->request->getStringParam('type');

        $this->checkCSRFParam();
        $this->config->regenerateToken($type.'_token');

        $this->flash->success(t('Token regenerated.'));
        $this->response->redirect($this->helper->url->to('config', $type));
    }
}