diff options
author | thomascube <thomas@roundcube.net> | 2008-09-03 16:03:19 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2008-09-03 16:03:19 +0000 |
commit | c8ae2497b7e4c7393210ed186acd672a0040389f (patch) | |
tree | b21442a9fff2d15cee5809db3d532d8ef378da37 /program | |
parent | 7003206d64c83534f29d1eb9dfc53edf993baf5b (diff) |
Auto-detect client language and timezone if desired by config/prefs
Diffstat (limited to 'program')
-rw-r--r-- | program/include/main.inc | 10 | ||||
-rw-r--r-- | program/include/rcmail.php | 19 | ||||
-rw-r--r-- | program/include/rcube_config.php | 4 | ||||
-rw-r--r-- | program/include/rcube_shared.inc | 56 | ||||
-rwxr-xr-x | program/include/rcube_template.php | 2 | ||||
-rw-r--r-- | program/js/app.js | 8 | ||||
-rw-r--r-- | program/localization/en_US/labels.inc | 1 | ||||
-rw-r--r-- | program/steps/settings/func.inc | 7 | ||||
-rw-r--r-- | program/steps/settings/save_prefs.inc | 2 |
9 files changed, 38 insertions, 71 deletions
diff --git a/program/include/main.inc b/program/include/main.inc index 83ed8c02e..469d8441c 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -706,9 +706,13 @@ function format_date($date, $format=NULL) return ''; // get user's timezone - $tz = $CONFIG['timezone']; - if ($CONFIG['dst_active']) - $tz++; + if ($CONFIG['timezone'] == 'auto') + $tz = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : intval(date('O'))/100; + else { + $tz = $CONFIG['timezone']; + if ($CONFIG['dst_active']) + $tz++; + } // convert time to user's timezone $timestamp = $ts - date('Z', $ts) + ($tz * 3600); diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 348a91675..243b6f835 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -15,7 +15,7 @@ | Author: Thomas Bruederli <roundcube@gmail.com> | +-----------------------------------------------------------------------+ - $Id: rcube_browser.php 328 2006-08-30 17:41:21Z thomasb $ + $Id: rcmail.php 328 2006-08-30 17:41:21Z thomasb $ */ @@ -167,7 +167,7 @@ class rcmail $this->config->merge((array)$this->user->get_prefs()); } - $_SESSION['language'] = $this->user->language = $this->language_prop($this->config->get('language')); + $_SESSION['language'] = $this->user->language = $this->language_prop($this->config->get('language', $_SESSION['language'])); // set localization setlocale(LC_ALL, $_SESSION['language'] . '.utf8'); @@ -183,7 +183,13 @@ class rcmail private function language_prop($lang) { static $rcube_languages, $rcube_language_aliases; - + + // user HTTP_ACCEPT_LANGUAGE if no language is specified + if (empty($lang) || $lang == 'auto') { + $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + $lang = str_replace('-', '_', $accept_langs[0]); + } + if (empty($rcube_languages)) { @include(INSTALL_PATH . 'program/localization/index.inc'); } @@ -471,6 +477,9 @@ class rcmail $_SESSION['imap_ssl'] = $imap_ssl; $_SESSION['password'] = $this->encrypt_passwd($pass); $_SESSION['login_time'] = mktime(); + + if ($_REQUEST['_timezone'] != '_default_') + $_SESSION['timezone'] = floatval($_REQUEST['_timezone']); // force reloading complete list of subscribed mailboxes $this->set_imap_prop(); @@ -641,7 +650,7 @@ class rcmail */ public function load_language($lang = null) { - $lang = $lang ? $this->language_prop($lang) : $_SESSION['language']; + $lang = $this->language_prop(($lang ? $lang : $_SESSION['language'])); // load localized texts if (empty($this->texts) || $lang != $_SESSION['language']) { @@ -748,7 +757,7 @@ class rcmail $this->user->save_prefs(array('message_sort_col' => $_SESSION['sort_col'], 'message_sort_order' => $_SESSION['sort_order'])); } - $_SESSION = array('language' => $USER->language, 'auth_time' => time(), 'temp' => true); + $_SESSION = array('language' => $this->user->language, 'auth_time' => time(), 'temp' => true); setcookie('sessauth', '-del-', time() - 60); $this->user->reset(); } diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php index 43f735ba9..98e688d02 100644 --- a/program/include/rcube_config.php +++ b/program/include/rcube_config.php @@ -84,9 +84,9 @@ class rcube_config ini_set('log_errors', 1); if ($this->prop['log_driver'] == 'syslog') { - ini_set('error_log', 'syslog'); + ini_set('error_log', 'syslog'); } else { - ini_set('error_log', $this->prop['log_dir'].'/errors'); + ini_set('error_log', $this->prop['log_dir'].'/errors'); } } if ($this->prop['debug_level'] & 4) { diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc index d82b1fef0..0dd661ec5 100644 --- a/program/include/rcube_shared.inc +++ b/program/include/rcube_shared.inc @@ -28,62 +28,6 @@ /** - * Provide details about the client's browser - * - * @return array Key-value pairs of browser properties - */ -function rcube_browser() -{ - $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; - - $bw['ver'] = 0; - $bw['win'] = stristr($HTTP_USER_AGENT, 'win'); - $bw['mac'] = stristr($HTTP_USER_AGENT, 'mac'); - $bw['linux'] = stristr($HTTP_USER_AGENT, 'linux'); - $bw['unix'] = stristr($HTTP_USER_AGENT, 'unix'); - - $bw['ns4'] = stristr($HTTP_USER_AGENT, 'mozilla/4') && !stristr($HTTP_USER_AGENT, 'msie'); - $bw['ns'] = ($bw['ns4'] || stristr($HTTP_USER_AGENT, 'netscape')); - $bw['ie'] = stristr($HTTP_USER_AGENT, 'msie'); - $bw['mz'] = stristr($HTTP_USER_AGENT, 'mozilla/5'); - $bw['opera'] = stristr($HTTP_USER_AGENT, 'opera'); - $bw['safari'] = stristr($HTTP_USER_AGENT, 'safari'); - - if($bw['ns']) - { - $test = eregi("mozilla\/([0-9\.]+)", $HTTP_USER_AGENT, $regs); - $bw['ver'] = $test ? (float)$regs[1] : 0; - } - if($bw['mz']) - { - $test = ereg("rv:([0-9\.]+)", $HTTP_USER_AGENT, $regs); - $bw['ver'] = $test ? (float)$regs[1] : 0; - } - if($bw['ie']) - { - $test = eregi("msie ([0-9\.]+)", $HTTP_USER_AGENT, $regs); - $bw['ver'] = $test ? (float)$regs[1] : 0; - } - if($bw['opera']) - { - $test = eregi("opera ([0-9\.]+)", $HTTP_USER_AGENT, $regs); - $bw['ver'] = $test ? (float)$regs[1] : 0; - } - - if(eregi(" ([a-z]{2})-([a-z]{2})", $HTTP_USER_AGENT, $regs)) - $bw['lang'] = $regs[1]; - else - $bw['lang'] = 'en'; - - $bw['dom'] = ($bw['mz'] || $bw['safari'] || ($bw['ie'] && $bw['ver']>=5) || ($bw['opera'] && $bw['ver']>=7)); - $bw['pngalpha'] = $bw['mz'] || $bw['safari'] || ($bw['ie'] && $bw['ver']>=5.5) || - ($bw['ie'] && $bw['ver']>=5 && $bw['mac']) || ($bw['opera'] && $bw['ver']>=7) ? TRUE : FALSE; - - return $bw; -} - - -/** * Send HTTP headers to prevent caching this page */ function send_nocacheing_headers() diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php index db2275ed4..847ea0df5 100755 --- a/program/include/rcube_template.php +++ b/program/include/rcube_template.php @@ -922,6 +922,7 @@ class rcube_template extends rcube_html_page $input_user = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser', 'size' => 30) + $attrib); $input_pass = new html_passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'size' => 30) + $attrib); $input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login')); + $input_tzone = new html_hiddenfield(array('name' => '_timezone', 'id' => 'rcmlogintz', 'value' => '_default_')); $input_host = null; if (is_array($default_host)) { @@ -960,6 +961,7 @@ class rcube_template extends rcube_html_page } $out = $input_action->show(); + $out .= $input_tzone->show(); $out .= $table->show(); // surround html output with a form tag diff --git a/program/js/app.js b/program/js/app.js index ff6ff8cf3..7ba8572b3 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -318,13 +318,19 @@ function rcube_webmail() case 'login': var input_user = rcube_find_object('rcmloginuser'); var input_pass = rcube_find_object('rcmloginpwd'); + var input_tz = rcube_find_object('rcmlogintz'); + if (input_user) input_user.onkeyup = function(e){ return rcmail.login_user_keyup(e); }; if (input_user && input_user.value=='') input_user.focus(); else if (input_pass) input_pass.focus(); - + + // detect client timezone + if (input_tz) + input_tz.value = new Date().getTimezoneOffset() / -60; + this.enable_command('login', true); break; diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index b628799b2..ac43c85f9 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -254,6 +254,7 @@ $labels['newitem'] = 'New item'; $labels['edititem'] = 'Edit item'; $labels['setdefault'] = 'Set default'; +$labels['autodetect'] = 'Auto'; $labels['language'] = 'Language'; $labels['timezone'] = 'Time zone'; $labels['pagesize'] = 'Rows per page'; diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index 5b6e11308..ef3c24d26 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -49,14 +49,15 @@ function rcmail_user_prefs_form($attrib) $select_lang->add(array_values($a_lang), array_keys($a_lang)); $table->add('title', html::label($field_id, Q(rcube_label('language')))); - $table->add(null, $select_lang->show($_SESSION['language'])); + $table->add(null, $select_lang->show($config['language'])); } // show page size selection if (!isset($no_override['timezone'])) { $field_id = 'rcmfd_timezone'; - $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id)); + $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id, 'onchange' => "document.getElementById('rcmfd_dst').disabled=this.selectedIndex==0")); + $select_timezone->add(rcube_label('autodetect'), 'auto'); $select_timezone->add('(GMT -11:00) Midway Island, Samoa', '-11'); $select_timezone->add('(GMT -10:00) Hawaii', '-10'); $select_timezone->add('(GMT -9:30) Marquesas Islands', '-9.5'); @@ -104,7 +105,7 @@ function rcmail_user_prefs_form($attrib) // daylight savings if (!isset($no_override['dst_active'])) { $field_id = 'rcmfd_dst'; - $input_dst = new html_checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1)); + $input_dst = new html_checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1, 'disabled' => ($config['timezone'] == 'auto'))); $table->add('title', html::label($field_id, Q(rcube_label('dstactive')))); $table->add(null, $input_dst->show($config['dst_active'])); diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc index 3bccffae2..edd184a52 100644 --- a/program/steps/settings/save_prefs.inc +++ b/program/steps/settings/save_prefs.inc @@ -20,7 +20,7 @@ */ $a_user_prefs = array( - 'timezone' => isset($_POST['_timezone']) ? floatval($_POST['_timezone']) : $CONFIG['timezone'], + 'timezone' => isset($_POST['_timezone']) ? (is_numeric($_POST['_timezone']) ? floatval($_POST['_timezone']) : get_input_value('_timezone', RCUBE_INPUT_POST)) : $CONFIG['timezone'], 'dst_active' => isset($_POST['_dst_active']) ? TRUE : FALSE, 'pagesize' => is_numeric($_POST['_pagesize']) ? max(2, intval($_POST['_pagesize'])) : $CONFIG['pagesize'], 'prettydate' => isset($_POST['_pretty_date']) ? TRUE : FALSE, |