diff options
Diffstat (limited to 'app/Controller/Config.php')
-rw-r--r-- | app/Controller/Config.php | 124 |
1 files changed, 93 insertions, 31 deletions
diff --git a/app/Controller/Config.php b/app/Controller/Config.php index 4c3018c1..869d4331 100644 --- a/app/Controller/Config.php +++ b/app/Controller/Config.php @@ -11,59 +11,118 @@ namespace Controller; class Config extends Base { /** - * Display the settings page + * Common layout for config views * - * @access public + * @access private + * @param string $template Template name + * @param array $params Template parameters + * @return string */ - public function index() + private function layout($template, array $params) { - $this->response->html($this->template->layout('config_index', array( - 'db_size' => $this->config->getDatabaseSize(), - 'languages' => $this->config->getLanguages(), - 'values' => $this->config->getAll(), - 'errors' => array(), - 'menu' => 'config', - 'title' => t('Settings'), - 'timezones' => $this->config->getTimezones(), - 'default_columns' => implode(', ', $this->board->getDefaultColumns()), - ))); + $params['values'] = $this->config->getAll(); + $params['errors'] = array(); + $params['menu'] = 'config'; + $params['config_content_for_layout'] = $this->template->load($template, $params); + + return $this->template->layout('config_layout', $params); } /** - * Validate and save settings + * Common method between pages * - * @access public + * @access private + * @param string $redirect Action to redirect after saving the form */ - public function save() + private function common($redirect) { - $values = $this->request->getValues(); - list($valid, $errors) = $this->config->validateModification($values); + if ($this->request->isPost()) { - if ($valid) { + $values = $this->request->getValues(); if ($this->config->save($values)) { $this->config->reload(); $this->session->flash(t('Settings saved successfully.')); - } else { + } + else { $this->session->flashError(t('Unable to save your settings.')); } - $this->response->redirect('?controller=config'); + $this->response->redirect('?controller=config&action='.$redirect); } + } - $this->response->html($this->template->layout('config_index', array( + /** + * Display the about page + * + * @access public + */ + public function index() + { + $this->response->html($this->layout('config_about', array( 'db_size' => $this->config->getDatabaseSize(), + 'title' => t('About'), + ))); + } + + /** + * Display the application settings page + * + * @access public + */ + public function application() + { + $this->common('application'); + + $this->response->html($this->layout('config_application', array( + 'title' => t('Application settings'), 'languages' => $this->config->getLanguages(), - 'values' => $values, - 'errors' => $errors, - 'menu' => 'config', - 'title' => t('Settings'), 'timezones' => $this->config->getTimezones(), + ))); + } + + /** + * Display the board settings page + * + * @access public + */ + public function board() + { + $this->common('board'); + + $this->response->html($this->layout('config_board', array( + 'title' => t('Board settings'), 'default_columns' => implode(', ', $this->board->getDefaultColumns()), ))); } /** + * Display the webhook settings page + * + * @access public + */ + public function webhook() + { + $this->common('webhook'); + + $this->response->html($this->layout('config_webhook', array( + 'title' => t('Webhook settings'), + ))); + } + + /** + * Display the api settings page + * + * @access public + */ + public function api() + { + $this->response->html($this->layout('config_api', array( + 'title' => t('API'), + ))); + } + + /** * Download the Sqlite database * * @access public @@ -89,15 +148,18 @@ class Config extends Base } /** - * Regenerate all application tokens + * Regenerate webhook token * * @access public */ - public function tokens() + public function token() { + $type = $this->request->getStringParam('type'); + $this->checkCSRFParam(); - $this->config->regenerateTokens(); - $this->session->flash(t('All tokens have been regenerated.')); - $this->response->redirect('?controller=config'); + $this->config->regenerateToken($type.'_token'); + + $this->session->flash(t('Token regenerated.')); + $this->response->redirect('?controller=config&action='.$type); } } |