summaryrefslogtreecommitdiff
path: root/app/Controller/Config.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-05-22 12:28:28 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-05-22 12:28:28 -0400
commit2230dd4e6b148346c0ec596b9e3e12996a762ed8 (patch)
treeef99ccde4f8b18592a3fb06a6ec45162c501fe38 /app/Controller/Config.php
parenta750b8ab2a0cb715da6fd9025a7ec8375db68a4d (diff)
Code refactoring (add autoloader and change files organization)
Diffstat (limited to 'app/Controller/Config.php')
-rw-r--r--app/Controller/Config.php117
1 files changed, 117 insertions, 0 deletions
diff --git a/app/Controller/Config.php b/app/Controller/Config.php
new file mode 100644
index 00000000..b4a5b8d3
--- /dev/null
+++ b/app/Controller/Config.php
@@ -0,0 +1,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');
+ }
+}