summaryrefslogtreecommitdiff
path: root/app/Controller/Config.php
blob: b4a5b8d337badf52fd8016314c9e8a944c05a6e2 (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
<?php

namespace Controller;

/**
 * Config controller
 *
 * @package  controller
 * @author   Frederic Guillot
 */
class Config extends Base
{
    /**
     * Display the settings page
     *
     * @access public
     */
    public function index()
    {
        $this->response->html($this->template->layout('config_index', array(
            'db_size' => $this->config->getDatabaseSize(),
            'user' => $_SESSION['user'],
            'projects' => $this->project->getList(),
            'languages' => $this->config->getLanguages(),
            'values' => $this->config->getAll(),
            'errors' => array(),
            'menu' => 'config',
            'title' => t('Settings'),
            'timezones' => $this->config->getTimezones(),
            'remember_me_sessions' => $this->rememberMe->getAll($this->acl->getUserId()),
            'last_logins' => $this->lastLogin->getAll($this->acl->getUserId()),
        )));
    }

    /**
     * Validate and save settings
     *
     * @access public
     */
    public function save()
    {
        $values = $this->request->getValues();
        list($valid, $errors) = $this->config->validateModification($values);

        if ($valid) {

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

            $this->response->redirect('?controller=config');
        }

        $this->response->html($this->template->layout('config_index', array(
            'db_size' => $this->config->getDatabaseSize(),
            'user' => $_SESSION['user'],
            'projects' => $this->project->getList(),
            'languages' => $this->config->getLanguages(),
            'values' => $values,
            'errors' => $errors,
            'menu' => 'config',
            'title' => t('Settings'),
            'timezones' => $this->config->getTimezones(),
            'remember_me_sessions' => $this->rememberMe->getAll($this->acl->getUserId()),
            'last_logins' => $this->lastLogin->getAll($this->acl->getUserId()),
        )));
    }

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

    /**
     * Optimize the Sqlite database
     *
     * @access public
     */
    public function optimizeDb()
    {
        $this->config->optimizeDatabase();
        $this->session->flash(t('Database optimization done.'));
        $this->response->redirect('?controller=config');
    }

    /**
     * Regenerate all application tokens
     *
     * @access public
     */
    public function tokens()
    {
        $this->config->regenerateTokens();
        $this->session->flash(t('All tokens have been regenerated.'));
        $this->response->redirect('?controller=config');
    }

    /**
     * Remove a "RememberMe" token
     *
     * @access public
     */
    public function removeRememberMeToken()
    {
        $this->rememberMe->remove($this->request->getIntegerParam('id'));
        $this->response->redirect('?controller=config&action=index#remember-me');
    }
}