summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-02-23 11:45:08 +0100
committerAleksander Machniak <alec@alec.pl>2012-02-23 11:45:08 +0100
commit4bf2d1c7d09bd20bccc0b6449486804899e53b91 (patch)
treeaa1c4ce2811ca10ab3e6b8ba3af861d1a89ad7dd /lib
parent9585885a269813009c3c3fb540e306a0be98b9b5 (diff)
downloadwebadmin-4bf2d1c7d09bd20bccc0b6449486804899e53b91.tar.gz
Added system.configure action
Diffstat (limited to 'lib')
-rw-r--r--lib/kolab_api_controller.php49
-rw-r--r--lib/kolab_client_task.php93
2 files changed, 99 insertions, 43 deletions
diff --git a/lib/kolab_api_controller.php b/lib/kolab_api_controller.php
index 87cdbc2..b9885ca 100644
--- a/lib/kolab_api_controller.php
+++ b/lib/kolab_api_controller.php
@@ -256,6 +256,8 @@ class kolab_api_controller
*
* @param array GET request parameters
* @param array POST data
+ *
+ * @param array|false Authentication result
*/
private function authenticate($request, $postdata)
{
@@ -308,7 +310,8 @@ class kolab_api_controller
$domain_name = is_array($domain) ? $domain['associateddomain'] : $domain;
// define our very own capabilities
$actions = array(
- 'system.quit' => array('type' => 'w'),
+ 'system.quit' => array('type' => 'w'),
+ 'system.configure' => array('type' => 'w'),
);
foreach ($this->services as $sname => $handler) {
@@ -350,6 +353,36 @@ class kolab_api_controller
}
}
+ /**
+ * Configure current user session parameters
+ *
+ * @param array $request GET request parameters
+ * @param array $postdata POST data
+ *
+ * @return array|false
+ */
+ private function configure($request, $postdata)
+ {
+ if (!$this->session_validate($postdata)) {
+ return false;
+ }
+
+ $result = array();
+
+ foreach ($postdata as $key => $value) {
+ switch ($key) {
+ case 'language':
+ if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $value)) {
+ $_SESSION['language'] = $value;
+ $result[$key] = $value;
+ }
+ break;
+ }
+ }
+
+ return $result;
+ }
+
/* ======== Utility functions ======== */
@@ -358,24 +391,22 @@ class kolab_api_controller
*/
private function locale_init()
{
- // @TODO: read language from logged user data
$lang = 'en_US';
- if ($lang != 'en_US' && file_exists(INSTALL_PATH . "/locale/$lang.api.php")) {
- $language = $lang;
+ // @TODO: read language of logged user in authenticate?
+ if (!empty($_SESSION['language'])) {
+ $lang = $_SESSION['language'];
}
$LANG = array();
@include INSTALL_PATH . '/locale/en_US.api.php';
- if (isset($language)) {
+ if ($lang != 'en_US' && file_exists(INSTALL_PATH . "/locale/$lang.api.php")) {
@include INSTALL_PATH . "/locale/$language.api.php";
- setlocale(LC_ALL, $language . '.utf8', 'en_US.utf8');
- }
- else {
- setlocale(LC_ALL, 'en_US.utf8');
}
+ setlocale(LC_ALL, $lang . '.utf8', 'en_US.utf8');
+
self::$translation = $LANG;
}
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 5f9505d..7cc8863 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -63,48 +63,21 @@ class kolab_client_task
*/
private function locale_init()
{
- $aliases = array(
- 'de' => 'de_DE',
- 'en' => 'en_US',
- 'pl' => 'pl_PL',
- );
-
- // UI language
- $langs = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
- $langs = explode(',', $langs);
+ $language = $this->get_language();
+ $LANG = array();
- if (!empty($_SESSION['user']) && !empty($_SESSION['user']['language'])) {
- array_unshift($langs, $_SESSION['user']['language']);
+ if (!$language) {
+ $language = 'en_US';
}
- while ($lang = array_shift($langs)) {
- $lang = explode(';', $lang);
- $lang = $lang[0];
- $lang = str_replace('-', '_', $lang);
-
- if (file_exists(INSTALL_PATH . "/locale/$lang.php")) {
- $language = $lang;
- break;
- }
- if (isset($aliases[$lang]) && ($alias = $aliases[$lang])
- && file_exists(INSTALL_PATH . "/locale/$alias.php")
- ) {
- $language = $alias;
- break;
- }
- }
-
- $LANG = array();
@include INSTALL_PATH . '/locale/en_US.php';
- if (!empty($language) && $language != 'en_US') {
+ if ($language != 'en_US') {
@include INSTALL_PATH . "/locale/$language.php";
- setlocale(LC_ALL, $language . '.utf8', 'en_US.utf8');
- }
- else {
- setlocale(LC_ALL, 'en_US.utf8');
}
+ setlocale(LC_ALL, $language . '.utf8', 'en_US.utf8');
+
self::$translation = $LANG;
}
@@ -143,6 +116,46 @@ class kolab_client_task
}
/**
+ * Returns system language (locale) setting.
+ *
+ * @return string Language code
+ */
+ private function get_language()
+ {
+ $aliases = array(
+ 'de' => 'de_DE',
+ 'en' => 'en_US',
+ 'pl' => 'pl_PL',
+ );
+
+ // UI language
+ $langs = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
+ $langs = explode(',', $langs);
+
+ if (!empty($_SESSION['user']) && !empty($_SESSION['user']['language'])) {
+ array_unshift($langs, $_SESSION['user']['language']);
+ }
+
+ while ($lang = array_shift($langs)) {
+ $lang = explode(';', $lang);
+ $lang = $lang[0];
+ $lang = str_replace('-', '_', $lang);
+
+ if (file_exists(INSTALL_PATH . "/locale/$lang.php")) {
+ return $lang;
+ }
+
+ if (isset($aliases[$lang]) && ($alias = $aliases[$lang])
+ && file_exists(INSTALL_PATH . "/locale/$alias.php")
+ ) {
+ return $alias;
+ }
+ }
+
+ return null;
+ }
+
+ /**
* User authentication (and authorization).
*/
private function auth()
@@ -171,7 +184,19 @@ class kolab_client_task
$user['fullname'] = $m[1];
}
+ // Save user data
$_SESSION['user'] = $user;
+
+ if (($language = $this->get_language()) && $language != 'en_US') {
+ $_SESSION['user']['language'] = $language;
+ $session_config['language'] = $language;
+ }
+
+ // Configure API session
+ if (!empty($session_config)) {
+ $this->api->post('system.configure', null, $session_config);
+ }
+
header('Location: ?');
die;
}