Some improvements and fixes for webgui
This commit is contained in:
+40
-9
@@ -56,6 +56,9 @@ $g_scriptname = basename($_SERVER['SCRIPT_NAME']);
|
||||
require 'config.inc';
|
||||
|
||||
// Localization
|
||||
|
||||
$lang = get_browser_lang(['de', 'en']);
|
||||
|
||||
setlocale(LC_ALL, $g_locale);
|
||||
$g_lconv = localeconv();
|
||||
$g_lang = substr($g_locale, 0, 2); // short language identifier
|
||||
@@ -244,6 +247,7 @@ class User {
|
||||
public $datefmt;
|
||||
public $rows_pp;
|
||||
public $menu;
|
||||
public $language;
|
||||
|
||||
private function __construct() {
|
||||
global $g_rows_pp;
|
||||
@@ -255,6 +259,7 @@ class User {
|
||||
$this->datefmt = 'Y-m-d';
|
||||
$this->rows_pp = $g_rows_pp;
|
||||
$this->menu = [1, 2, 3, 4, 5, 6];
|
||||
$this->language = 'en';
|
||||
}
|
||||
|
||||
public static function getInstance() {
|
||||
@@ -317,13 +322,14 @@ class User {
|
||||
}
|
||||
|
||||
$this->id = $_SESSION['userid'];
|
||||
$sql = "SELECT displayname, role FROM user WHERE userid=?";
|
||||
$sql = "SELECT displayname, role, language FROM user WHERE userid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$this->id]);
|
||||
$row = $sth->fetch();
|
||||
if ($row) {
|
||||
$this->displayname = $row['displayname'];
|
||||
$this->role = $row['role'];
|
||||
$this->language = $row['language'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1251,15 +1257,16 @@ function format_currency($val) {
|
||||
}
|
||||
|
||||
function format_date($date) {
|
||||
// date is string in ISO format
|
||||
global $user;
|
||||
// $user->datefmt;
|
||||
/*'Y-m-d' => _('YYYY-MM-DD'). $curdate->format(' - Y-m-d'),
|
||||
'Y/m/d' => _('YYYY/MM/DD'). $curdate->format(' - Y/m/d'),
|
||||
'd.m.Y' => _('DD.MM.YYYY'). $curdate->format(' - d.m.Y'),
|
||||
'd/m/Y' => _('DD/MM/YYYY'). $curdate->format(' - d/m/Y'),
|
||||
'm-d-Y' => _('MM/DD/YYYY'). $curdate->format(' - m-d-Y') */
|
||||
|
||||
return '';
|
||||
if (empty($date)) {
|
||||
return '';
|
||||
}
|
||||
$timestamp = strtotime($date);
|
||||
if ($timestamp === false) {
|
||||
return '';
|
||||
}
|
||||
return date($user->datefmt, $timestamp);
|
||||
}
|
||||
|
||||
function format_color($color) {
|
||||
@@ -1345,6 +1352,30 @@ function header_location($location, $message=NULL) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function get_browser_lang($allowed, $default='en') {
|
||||
$h = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '';
|
||||
if (!$h) {
|
||||
return $def;
|
||||
}
|
||||
$langs = [];
|
||||
foreach (explode(',', $h) as $p) {
|
||||
$p = explode(';q=', trim($p));
|
||||
$l = strtolower($p[0]);
|
||||
$q = isset($p[1]) ? (float) $p[1] : 1.0;
|
||||
$langs[$l] = $q;
|
||||
}
|
||||
arsort($langs);
|
||||
foreach ($langs as $bl => $q) {
|
||||
foreach ($allowed as $l) {
|
||||
$l = strtolower($l);
|
||||
if ($bl === $l || str_starts_with($bl, $l . '-')) {
|
||||
return $l;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
function pgettext($context, $msgid) {
|
||||
// implement missing function
|
||||
global $g_textdomain;
|
||||
|
||||
Reference in New Issue
Block a user