2014-07-21 22:56:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Controller;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Config controller
|
|
|
|
*
|
|
|
|
* @package controller
|
|
|
|
* @author Frederic Guillot
|
|
|
|
*/
|
|
|
|
class Config extends Base
|
|
|
|
{
|
|
|
|
/**
|
2014-11-23 20:13:38 +01:00
|
|
|
* Common layout for config views
|
2014-07-21 22:56:35 +02:00
|
|
|
*
|
2014-11-23 20:13:38 +01:00
|
|
|
* @access private
|
|
|
|
* @param string $template Template name
|
|
|
|
* @param array $params Template parameters
|
|
|
|
* @return string
|
2014-07-21 22:56:35 +02:00
|
|
|
*/
|
2014-11-23 20:13:38 +01:00
|
|
|
private function layout($template, array $params)
|
2014-07-21 22:56:35 +02:00
|
|
|
{
|
2015-01-16 14:23:05 +01:00
|
|
|
$params['board_selector'] = $this->projectPermission->getAllowedProjects($this->userSession->getId());
|
2014-11-23 20:13:38 +01:00
|
|
|
$params['values'] = $this->config->getAll();
|
|
|
|
$params['errors'] = array();
|
2015-01-16 14:23:05 +01:00
|
|
|
$params['config_content_for_layout'] = $this->template->render($template, $params);
|
2014-11-23 20:13:38 +01:00
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
return $this->template->layout('config/layout', $params);
|
2014-07-21 22:56:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-23 20:13:38 +01:00
|
|
|
* Common method between pages
|
2014-07-21 22:56:35 +02:00
|
|
|
*
|
2014-11-23 20:13:38 +01:00
|
|
|
* @access private
|
|
|
|
* @param string $redirect Action to redirect after saving the form
|
2014-07-21 22:56:35 +02:00
|
|
|
*/
|
2014-11-23 20:13:38 +01:00
|
|
|
private function common($redirect)
|
2014-07-21 22:56:35 +02:00
|
|
|
{
|
2014-11-23 20:13:38 +01:00
|
|
|
if ($this->request->isPost()) {
|
2014-07-21 22:56:35 +02:00
|
|
|
|
2014-11-23 20:13:38 +01:00
|
|
|
$values = $this->request->getValues();
|
2014-07-21 22:56:35 +02:00
|
|
|
|
|
|
|
if ($this->config->save($values)) {
|
|
|
|
$this->config->reload();
|
|
|
|
$this->session->flash(t('Settings saved successfully.'));
|
2014-11-23 20:13:38 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-07-21 22:56:35 +02:00
|
|
|
$this->session->flashError(t('Unable to save your settings.'));
|
|
|
|
}
|
|
|
|
|
2014-11-23 20:13:38 +01:00
|
|
|
$this->response->redirect('?controller=config&action='.$redirect);
|
2014-07-21 22:56:35 +02:00
|
|
|
}
|
2014-11-23 20:13:38 +01:00
|
|
|
}
|
2014-07-21 22:56:35 +02:00
|
|
|
|
2014-11-23 20:13:38 +01:00
|
|
|
/**
|
|
|
|
* Display the about page
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2014-12-22 19:15:38 +01:00
|
|
|
$this->response->html($this->layout('config/about', array(
|
2014-07-21 22:56:35 +02:00
|
|
|
'db_size' => $this->config->getDatabaseSize(),
|
2014-12-22 19:15:38 +01:00
|
|
|
'title' => t('Settings').' > '.t('About'),
|
2014-11-23 20:13:38 +01:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the application settings page
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function application()
|
|
|
|
{
|
|
|
|
$this->common('application');
|
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
$this->response->html($this->layout('config/application', array(
|
2014-07-21 22:56:35 +02:00
|
|
|
'languages' => $this->config->getLanguages(),
|
|
|
|
'timezones' => $this->config->getTimezones(),
|
2014-11-23 20:13:38 +01:00
|
|
|
'date_formats' => $this->dateParser->getAvailableFormats(),
|
2014-12-22 19:15:38 +01:00
|
|
|
'title' => t('Settings').' > '.t('Application settings'),
|
2014-11-23 20:13:38 +01:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the board settings page
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function board()
|
|
|
|
{
|
|
|
|
$this->common('board');
|
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
$this->response->html($this->layout('config/board', array(
|
2014-10-22 19:59:09 +02:00
|
|
|
'default_columns' => implode(', ', $this->board->getDefaultColumns()),
|
2014-12-22 19:15:38 +01:00
|
|
|
'title' => t('Settings').' > '.t('Board settings'),
|
2014-07-21 22:56:35 +02:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2014-11-23 20:13:38 +01:00
|
|
|
/**
|
|
|
|
* Display the webhook settings page
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function webhook()
|
|
|
|
{
|
|
|
|
$this->common('webhook');
|
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
$this->response->html($this->layout('config/webhook', array(
|
|
|
|
'title' => t('Settings').' > '.t('Webhook settings'),
|
2014-11-23 20:13:38 +01:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the api settings page
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
public function api()
|
|
|
|
{
|
2014-12-22 19:15:38 +01:00
|
|
|
$this->response->html($this->layout('config/api', array(
|
|
|
|
'title' => t('Settings').' > '.t('API'),
|
2014-11-23 20:13:38 +01:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2014-07-21 22:56:35 +02:00
|
|
|
/**
|
|
|
|
* 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->session->flash(t('Database optimization done.'));
|
|
|
|
$this->response->redirect('?controller=config');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-23 20:13:38 +01:00
|
|
|
* Regenerate webhook token
|
2014-07-21 22:56:35 +02:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2014-11-23 20:13:38 +01:00
|
|
|
public function token()
|
2014-07-21 22:56:35 +02:00
|
|
|
{
|
2014-11-23 20:13:38 +01:00
|
|
|
$type = $this->request->getStringParam('type');
|
|
|
|
|
2014-07-21 22:56:35 +02:00
|
|
|
$this->checkCSRFParam();
|
2014-11-23 20:13:38 +01:00
|
|
|
$this->config->regenerateToken($type.'_token');
|
|
|
|
|
|
|
|
$this->session->flash(t('Token regenerated.'));
|
|
|
|
$this->response->redirect('?controller=config&action='.$type);
|
2014-07-21 22:56:35 +02:00
|
|
|
}
|
|
|
|
}
|