diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-01-04 22:34:59 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-01-04 22:34:59 -0500 |
commit | 99d27e0ce4f48454808d2325cb407b5b35cf5e88 (patch) | |
tree | 3c518cf08499890d46b9d2f65724d46617e1fc67 /app | |
parent | d1d04d6feeebeba2aea5333d7a4229fcec799f75 (diff) |
Allow users to override the timezone and the language
Diffstat (limited to 'app')
32 files changed, 153 insertions, 47 deletions
diff --git a/app/Auth/Database.php b/app/Auth/Database.php index bdb2aeb6..2804b9a8 100644 --- a/app/Auth/Database.php +++ b/app/Auth/Database.php @@ -33,7 +33,7 @@ class Database extends Base $user = $this->db->table(User::TABLE)->eq('username', $username)->eq('is_ldap_user', 0)->findOne(); if ($user && password_verify($password, $user['password'])) { - $this->user->updateSession($user); + $this->userSession->refresh($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; } diff --git a/app/Auth/GitHub.php b/app/Auth/GitHub.php index a785c494..0e335fb4 100644 --- a/app/Auth/GitHub.php +++ b/app/Auth/GitHub.php @@ -35,7 +35,7 @@ class GitHub extends Base $user = $this->user->getByGitHubId($github_id); if ($user) { - $this->user->updateSession($user); + $this->userSession->refresh($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; } diff --git a/app/Auth/Google.php b/app/Auth/Google.php index f779cfe5..e7abae08 100644 --- a/app/Auth/Google.php +++ b/app/Auth/Google.php @@ -36,7 +36,7 @@ class Google extends Base $user = $this->user->getByGoogleId($google_id); if ($user) { - $this->user->updateSession($user); + $this->userSession->refresh($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; } diff --git a/app/Auth/Ldap.php b/app/Auth/Ldap.php index b3c998f9..b3440614 100644 --- a/app/Auth/Ldap.php +++ b/app/Auth/Ldap.php @@ -54,7 +54,7 @@ class Ldap extends Base } // We open the session - $this->user->updateSession($user); + $this->userSession->refresh($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; diff --git a/app/Auth/RememberMe.php b/app/Auth/RememberMe.php index fc2ea78d..4736442e 100644 --- a/app/Auth/RememberMe.php +++ b/app/Auth/RememberMe.php @@ -101,7 +101,7 @@ class RememberMe extends Base ); // Create the session - $this->user->updateSession($this->user->getById($record['user_id'])); + $this->userSession->refresh($this->user->getById($record['user_id'])); $this->container['dispatcher']->dispatch( 'auth.success', diff --git a/app/Auth/ReverseProxy.php b/app/Auth/ReverseProxy.php index 9d766a5b..b84550cf 100644 --- a/app/Auth/ReverseProxy.php +++ b/app/Auth/ReverseProxy.php @@ -37,7 +37,7 @@ class ReverseProxy extends Base $user = $this->user->getByUsername($login); } - $this->user->updateSession($user); + $this->userSession->refresh($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; diff --git a/app/Console/Base.php b/app/Console/Base.php index 5927443c..aeafbefc 100644 --- a/app/Console/Base.php +++ b/app/Console/Base.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Command\Command; * @property \Model\ProjectPermission $projectPermission * @property \Model\ProjectAnalytic $projectAnalytic * @property \Model\ProjectDailySummary $projectDailySummary + * @property \Model\SubtaskExport $subtaskExport * @property \Model\Task $task * @property \Model\TaskExport $taskExport * @property \Model\TaskFinder $taskFinder diff --git a/app/Controller/User.php b/app/Controller/User.php index 00c2f104..7fddf705 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -151,6 +151,8 @@ class User extends Base public function create(array $values = array(), array $errors = array()) { $this->response->html($this->template->layout('user/new', array( + 'timezones' => $this->config->getTimezones(true), + 'languages' => $this->config->getLanguages(true), 'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()), 'projects' => $this->project->getList(), 'errors' => $errors, @@ -194,6 +196,8 @@ class User extends Base $this->response->html($this->layout('user/show', array( 'projects' => $this->projectPermission->getAllowedProjects($user['id']), 'user' => $user, + 'timezones' => $this->config->getTimezones(true), + 'languages' => $this->config->getLanguages(true), ))); } @@ -358,6 +362,8 @@ class User extends Base 'errors' => $errors, 'projects' => $this->projectPermission->filterProjects($this->project->getList(), $user['id']), 'user' => $user, + 'timezones' => $this->config->getTimezones(true), + 'languages' => $this->config->getLanguages(true), ))); } diff --git a/app/Core/Translator.php b/app/Core/Translator.php index 1954ee2f..0f5a77cc 100644 --- a/app/Core/Translator.php +++ b/app/Core/Translator.php @@ -181,5 +181,8 @@ class Translator if (file_exists($filename)) { self::$locales = require $filename; } + else { + self::$locales = array(); + } } } diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index 8b529d10..e66f5f8c 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index 58d99e8d..e10f3748 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index ab6518a5..a96abf34 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -453,7 +453,7 @@ return array( 'Notifications:' => 'Notificaciones:', // 'Notifications' => '', 'Group:' => 'Grupo:', - 'Regular user' => 'Usuario regular:', + 'Regular user' => 'Usuario regular', 'Account type:' => 'Tipo de Cuenta:', 'Edit profile' => 'Editar perfil', 'Change password' => 'Cambiar contraseña', @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index 0ba5acd2..462691a4 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index 298813da..bb2a386f 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -644,4 +644,7 @@ return array( 'Subtasks exportation for "%s"' => 'Exportation des sous-tâches pour le projet « %s »', 'Task Title' => 'Titre de la tâche', 'Untitled' => 'Sans nom', + 'Application default' => 'Valeur par défaut de l\'application', + 'Language:' => 'Langue :', + 'Timezone:' => 'Fuseau horaire :', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index 12123634..f769a405 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index 5d4f35a1..cb09ea95 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index dfa9a365..21275858 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 058ff567..77a4130a 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index f585bce8..b5441c17 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index 03eda536..3e86249b 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index 12b4b2e2..5d59f7bd 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index 4d2940de..6d9259b6 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index 15db3d68..e131b48e 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -644,4 +644,7 @@ return array( // 'Subtasks exportation for "%s"' => '', // 'Task Title' => '', // 'Untitled' => '', + // 'Application default' => '', + // 'Language:' => '', + // 'Timezone:' => '', ); diff --git a/app/Model/Config.php b/app/Model/Config.php index 1ee44a0e..e6d66734 100644 --- a/app/Model/Config.php +++ b/app/Model/Config.php @@ -25,24 +25,32 @@ class Config extends Base * Get available timezones * * @access public + * @param boolean $prepend Prepend a default value * @return array */ - public function getTimezones() + public function getTimezones($prepend = false) { $timezones = timezone_identifiers_list(); - return array_combine(array_values($timezones), $timezones); + $listing = array_combine(array_values($timezones), $timezones); + + if ($prepend) { + return array('' => t('Application default')) + $listing; + } + + return $listing; } /** * Get available languages * * @access public + * @param boolean $prepend Prepend a default value * @return array */ - public function getLanguages() + public function getLanguages($prepend = false) { // Sorted by value - return array( + $languages = array( 'da_DK' => 'Dansk', 'de_DE' => 'Deutsch', 'en_US' => 'English', @@ -59,6 +67,12 @@ class Config extends Base 'ja_JP' => '日本語', 'th_TH' => 'ไทย', ); + + if ($prepend) { + return array('' => t('Application default')) + $languages; + } + + return $languages; } /** @@ -138,10 +152,11 @@ class Config extends Base */ public function setupTranslations() { - $language = $this->get('application_language', 'en_US'); - - if ($language !== 'en_US') { - Translator::load($language); + if ($this->userSession->isLogged() && ! empty($this->session['user']['language'])) { + Translator::load($this->session['user']['language']); + } + else { + Translator::load($this->get('application_language', 'en_US')); } } @@ -152,7 +167,12 @@ class Config extends Base */ public function setupTimezone() { - date_default_timezone_set($this->get('application_timezone', 'UTC')); + if ($this->userSession->isLogged() && ! empty($this->session['user']['timezone'])) { + date_default_timezone_set($this->session['user']['timezone']); + } + else { + date_default_timezone_set($this->get('application_timezone', 'UTC')); + } } /** diff --git a/app/Model/User.php b/app/Model/User.php index 29def6d4..1bcc82b5 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -254,7 +254,7 @@ class User extends Base // If the user is connected refresh his session if (Session::isOpen() && $this->userSession->getId() == $values['id']) { - $this->updateSession(); + $this->userSession->refresh(); } return $result; @@ -295,30 +295,6 @@ class User extends Base } /** - * Update user session information - * - * @access public - * @param array $user User data - */ - public function updateSession(array $user = array()) - { - if (empty($user)) { - $user = $this->getById($this->userSession->getId()); - } - - if (isset($user['password'])) { - unset($user['password']); - } - - $user['id'] = (int) $user['id']; - $user['default_project_id'] = (int) $user['default_project_id']; - $user['is_admin'] = (bool) $user['is_admin']; - $user['is_ldap_user'] = (bool) $user['is_ldap_user']; - - $this->session['user'] = $user; - } - - /** * Common validation rules * * @access private diff --git a/app/Model/UserSession.php b/app/Model/UserSession.php index c27b3743..6d9a2ebc 100644 --- a/app/Model/UserSession.php +++ b/app/Model/UserSession.php @@ -2,6 +2,8 @@ namespace Model; +use Core\Translator; + /** * User Session * @@ -11,6 +13,30 @@ namespace Model; class UserSession extends Base { /** + * Update user session information + * + * @access public + * @param array $user User data + */ + public function refresh(array $user = array()) + { + if (empty($user)) { + $user = $this->user->getById($this->userSession->getId()); + } + + if (isset($user['password'])) { + unset($user['password']); + } + + $user['id'] = (int) $user['id']; + $user['default_project_id'] = (int) $user['default_project_id']; + $user['is_admin'] = (bool) $user['is_admin']; + $user['is_ldap_user'] = (bool) $user['is_ldap_user']; + + $this->session['user'] = $user; + } + + /** * Return true if the logged user is admin * * @access public diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 25ef86d5..05e8f14c 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -5,7 +5,13 @@ namespace Schema; use PDO; use Core\Security; -const VERSION = 40; +const VERSION = 41; + +function version_41($pdo) +{ + $pdo->exec('ALTER TABLE users ADD COLUMN timezone VARCHAR(50)'); + $pdo->exec('ALTER TABLE users ADD COLUMN language CHAR(5)'); +} function version_40($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index 75d184de..9d5aa7a7 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -5,7 +5,13 @@ namespace Schema; use PDO; use Core\Security; -const VERSION = 21; +const VERSION = 22; + +function version_22($pdo) +{ + $pdo->exec('ALTER TABLE users ADD COLUMN timezone VARCHAR(50)'); + $pdo->exec('ALTER TABLE users ADD COLUMN language CHAR(5)'); +} function version_21($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index 39a40ace..c6156065 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -5,7 +5,13 @@ namespace Schema; use Core\Security; use PDO; -const VERSION = 39; +const VERSION = 40; + +function version_40($pdo) +{ + $pdo->exec('ALTER TABLE users ADD COLUMN timezone TEXT'); + $pdo->exec('ALTER TABLE users ADD COLUMN language TEXT'); +} function version_39($pdo) { diff --git a/app/Template/user/edit.php b/app/Template/user/edit.php index 68b264ec..43171d29 100644 --- a/app/Template/user/edit.php +++ b/app/Template/user/edit.php @@ -20,6 +20,12 @@ <?= $this->formLabel(t('Default project'), 'default_project_id') ?> <?= $this->formSelect('default_project_id', $projects, $values, $errors) ?><br/> + <?= $this->formLabel(t('Timezone'), 'timezone') ?> + <?= $this->formSelect('timezone', $timezones, $values, $errors) ?><br/> + + <?= $this->formLabel(t('Language'), 'language') ?> + <?= $this->formSelect('language', $languages, $values, $errors) ?><br/> + <?php if ($this->userSession->isAdmin()): ?> <?= $this->formCheckbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1 ? true : false) ?><br/> <?php endif ?> diff --git a/app/Template/user/new.php b/app/Template/user/new.php index a720d1a1..1413bd3d 100644 --- a/app/Template/user/new.php +++ b/app/Template/user/new.php @@ -27,6 +27,12 @@ <?= $this->formLabel(t('Default project'), 'default_project_id') ?> <?= $this->formSelect('default_project_id', $projects, $values, $errors) ?><br/> + <?= $this->formLabel(t('Timezone'), 'timezone') ?> + <?= $this->formSelect('timezone', $timezones, $values, $errors) ?><br/> + + <?= $this->formLabel(t('Language'), 'language') ?> + <?= $this->formSelect('language', $languages, $values, $errors) ?><br/> + <?= $this->formCheckbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1 ? true : false) ?> <div class="form-actions"> diff --git a/app/Template/user/show.php b/app/Template/user/show.php index f65be260..490d8fb3 100644 --- a/app/Template/user/show.php +++ b/app/Template/user/show.php @@ -3,9 +3,11 @@ </div> <ul class="listing"> <li><?= t('Username:') ?> <strong><?= $this->e($user['username']) ?></strong></li> - <li><?= t('Name:') ?> <strong><?= $this->e($user['name']) ?></strong></li> - <li><?= t('Email:') ?> <strong><?= $this->e($user['email']) ?></strong></li> - <li><?= t('Default project:') ?> <strong><?= (isset($user['default_project_id']) && isset($projects[$user['default_project_id']])) ? $this->e($projects[$user['default_project_id']]) : t('None'); ?></strong></li> + <li><?= t('Name:') ?> <strong><?= $this->e($user['name']) ?: t('None') ?></strong></li> + <li><?= t('Email:') ?> <strong><?= $this->e($user['email']) ?: t('None') ?></strong></li> + <li><?= t('Default project:') ?> <strong><?= (isset($user['default_project_id']) && isset($projects[$user['default_project_id']])) ? $this->e($projects[$user['default_project_id']]) : t('None') ?></strong></li> + <li><?= t('Timezone:') ?> <strong><?= $this->inList($user['timezone'], $timezones) ?></strong></li> + <li><?= t('Language:') ?> <strong><?= $this->inList($user['language'], $languages) ?></strong></li> <li><?= t('Notifications:') ?> <strong><?= $user['notifications_enabled'] == 1 ? t('Enabled') : t('Disabled') ?></strong></li> <li><?= t('Group:') ?> <strong><?= $user['is_admin'] ? t('Administrator') : t('Regular user') ?></strong></li> <li><?= t('Account type:') ?> <strong><?= $user['is_ldap_user'] ? t('Remote') : t('Local') ?></strong></li> |