Fix the user settings

- When language is changed, update the menu and translations immediately
- When time zone is changed, update it immediately
- Flush the settings apcu cache if enabled
This commit is contained in:
FusionPBX
2025-10-10 12:01:51 -06:00
committed by GitHub
parent ec852b10f8
commit 435ef38c88
16 changed files with 124 additions and 74 deletions

View File

@@ -92,12 +92,7 @@
}
//set the time zone
if (isset($_SESSION['domain']['time_zone']['name'])) {
$time_zone = $_SESSION['domain']['time_zone']['name'];
}
else {
$time_zone = date_default_timezone_get();
}
$time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
//prepare to page the results
$sql = "select count(*) from view_call_block ";

View File

@@ -96,12 +96,7 @@
}
//set the time zone
if (!empty($_SESSION['domain']['time_zone']['name'])) {
$time_zone = $_SESSION['domain']['time_zone']['name'];
}
else {
$time_zone = date_default_timezone_get();
}
$time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
$parameters['time_zone'] = $time_zone;
//prepare some of the paging values

View File

@@ -210,7 +210,7 @@
//$uuid = substr($result, 4);
if ($rec == "true") {
//use the server's time zone to ensure it matches the time zone used by freeswitch
date_default_timezone_set($_SESSION['time_zone']['system']);
date_default_timezone_set(date_default_timezone_get());
//create the api record command and send it over event socket
if (is_uuid($origination_uuid) && file_exists($record_path)) {
$switch_cmd = "uuid_record $origination_uuid start $record_path/$record_name";

View File

@@ -95,12 +95,7 @@
}
//set the time zone
if (isset($_SESSION['domain']['time_zone']['name'])) {
$time_zone = $_SESSION['domain']['time_zone']['name'];
}
else {
$time_zone = date_default_timezone_get();
}
$time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
//get order and order by
$order_by = $_GET["order_by"] ?? null;

View File

@@ -110,12 +110,7 @@ list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_pe
$offset = $rows_per_page * $page;
//set the time zone
if (isset($_SESSION['domain']['time_zone']['name'])) {
$time_zone = $_SESSION['domain']['time_zone']['name'];
}
else {
$time_zone = date_default_timezone_get();
}
$time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
//get the list
$sql = "select e.emergency_log_uuid, ";

View File

@@ -117,12 +117,7 @@
$offset = $rows_per_page * $page;
//set the time zone
if (isset($_SESSION['domain']['time_zone']['name'])) {
$time_zone = $_SESSION['domain']['time_zone']['name'];
}
else {
$time_zone = date_default_timezone_get();
}
$time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
$parameters['time_zone'] = $time_zone;
//get the list

View File

@@ -246,12 +246,7 @@
$offset = $rows_per_page * $page;
//set the time zone
if (isset($_SESSION['domain']['time_zone']['name'])) {
$time_zone = $_SESSION['domain']['time_zone']['name'];
}
else {
$time_zone = date_default_timezone_get();
}
$time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
$parameters['time_zone'] = $time_zone;
//set the time format options: 12h, 24h

View File

@@ -76,7 +76,7 @@
$sql .= "start_epoch desc \n";
$sql .= "limit :missed_limit \n";
$parameters['missed_limit'] = $missed_limit;
$parameters['time_zone'] = isset($_SESSION['domain']['time_zone']['name']) ? $_SESSION['domain']['time_zone']['name'] : date_default_timezone_get();
$parameters['time_zone'] = $settings->get('domain', 'time_zone', date_default_timezone_get());
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$result = $database->select($sql, $parameters, 'all');
$num_rows = !empty($result) ? sizeof($result) : 0;

View File

@@ -73,7 +73,7 @@
$sql .= "order by start_epoch desc ";
$sql .= "limit :recent_limit ";
$parameters['recent_limit'] = $recent_limit;
$parameters['time_zone'] = isset($_SESSION['domain']['time_zone']['name']) ? $_SESSION['domain']['time_zone']['name'] : date_default_timezone_get();
$parameters['time_zone'] = $settings->get('domain', 'time_zone', date_default_timezone_get());
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$result = $database->select($sql, $parameters, 'all');
$num_rows = !empty($result) ? sizeof($result) : 0;

View File

@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2024
Portions created by the Initial Developer are Copyright (C) 2008-2025
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -298,12 +298,7 @@
$offset = $rows_per_page * $page;
//set the time zone
if (isset($_SESSION['domain']['time_zone']['name'])) {
$time_zone = $_SESSION['domain']['time_zone']['name'];
}
else {
$time_zone = date_default_timezone_get();
}
$time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
$parameters['time_zone'] = $time_zone;
//set the sql time format

View File

@@ -357,12 +357,7 @@
$seconds_month = $seconds_day * 30;
//set the time zone
if (isset($_SESSION['domain']['time_zone']['name'])) {
$time_zone = $_SESSION['domain']['time_zone']['name'];
}
else {
$time_zone = date_default_timezone_get();
}
$time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
$parameters['time_zone'] = $time_zone;
//build the sql query for xml cdr statistics

View File

@@ -570,6 +570,13 @@
$p->delete("user_edit", "temp");
$p->delete('user_group_add', 'temp');
//clear the menu
unset($_SESSION["menu"]);
//get settings based on the user
$settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]);
settings::clear_cache();
//if call center installed
if ($action == 'edit' && permission_exists('user_edit') && file_exists($_SERVER["PROJECT_ROOT"]."/app/call_centers/app_config.php")) {
//get the call center agent uuid

View File

@@ -438,6 +438,13 @@
$p->delete("contact_attachment_edit", "temp");
$p->delete("contact_attachment_delete", "temp");
//clear the menu
unset($_SESSION["menu"]);
//get settings based on the user
$settings = new settings(['database' => $database, 'domain_uuid' => $_SESSION['domain_uuid'], 'user_uuid' => $_SESSION['user_uuid']]);
settings::clear_cache();
//if call center installed
if ($action == 'edit' && permission_exists('user_edit') && file_exists($_SERVER["PROJECT_ROOT"]."/app/call_centers/app_config.php")) {
//get the call center agent uuid

View File

@@ -51,7 +51,7 @@
//if session created is not set then set the time
if (!isset($_SESSION['session']['created'])) {
$_SESSION['session']['created'] = time();
}
}
//check the elapsed time if exceeds limit then rotate the session
if (time() - $_SESSION['session']['created'] > 900) {
@@ -114,11 +114,8 @@
//if the session is not authorized then verify the identity
if (!$_SESSION['authorized']) {
//clear the menu
unset($_SESSION["menu"]);
//clear the template only if the template has not been assigned by the superadmin
if (empty($_SESSION['domain']['template']['name'])) {
if (empty($settings->get('domain', 'template'))) {
$_SESSION["template_content"] = '';
}
@@ -140,6 +137,13 @@
exit;
}
//clear the menu
unset($_SESSION["menu"]);
//get settings based on the user
$settings = new settings(['database' => $database, 'domain_uuid' => $_SESSION['domain_uuid'], 'user_uuid' => $_SESSION['user_uuid']]);
settings::clear_cache();
//if logged in, redirect to login destination
if (!isset($_REQUEST["key"])) {

View File

@@ -52,6 +52,24 @@
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* @var string
*/
private $domain_uuid;
/**
* called when the object is created
*/
@@ -63,12 +81,24 @@
$this->toggle_values = ['true','false'];
$this->location = 'domains.php';
//set the domain and user uuids
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
$this->user_uuid = $setting_array['user_uuid'] ?? $_SESSION['user_uuid'] ?? '';
//open a database connection
if (empty($setting_array['database'])) {
$this->database = database::new();
} else {
$this->database = $setting_array['database'];
}
//load the settings
if (empty($setting_array['settings'])) {
$this->settings = new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
} else {
$this->settings = $setting_array['settings'];
}
}
/**
@@ -573,15 +603,8 @@
}
}
//set the values from the session variables
if (!empty($_SESSION['domain']['time_zone']['name'])) {
//server time zone
$_SESSION['time_zone']['system'] = date_default_timezone_get();
//domain time zone set in system settings
$_SESSION['time_zone']['domain'] = $_SESSION['domain']['time_zone']['name'];
//set the domain time zone as the default time zone
date_default_timezone_set($_SESSION['domain']['time_zone']['name']);
}
//set the domain time zone as the default time zone
date_default_timezone_set($this->settings->get('domain', 'time_zone', date_default_timezone_get()));
//set the context
if (!empty($_SESSION["domain_name"])) {

View File

@@ -5,7 +5,17 @@
*
*/
class text {
/**
* Contains the list of supported languages
* @var array
*/
public $languages;
/**
* Legacy older list of supported languages
* @var array
*/
public $legacy_map = array(
'he' => 'he-il',
'pl' => 'pl-pl',
@@ -22,13 +32,55 @@ class text {
'pt' => 'pt-pt',
);
/**
* Set in the constructor. Must be a database object and cannot be null.
* @var database Database Object
*/
private $database;
/**
* Settings object set in the constructor. Must be a settings object and cannot be null.
* @var settings Settings Object
*/
private $settings;
/**
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* @var string
*/
private $user_uuid;
/**
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
* @var string
*/
private $domain_uuid;
/**
* Called when the object is created
*/
public function __construct() {
public function __construct($setting_array = []) {
//define the text array
$text = array();
//set the domain and user uuids
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
$this->user_uuid = $setting_array['user_uuid'] ?? $_SESSION['user_uuid'] ?? '';
//open a database connection
if (empty($setting_array['database'])) {
$this->database = database::new();
} else {
$this->database = $setting_array['database'];
}
//load the settings
if (empty($setting_array['settings'])) {
$this->settings = new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
} else {
$this->settings = $setting_array['settings'];
}
//get the global app_languages.php so we can get the list of languages
if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/app_languages.php")) {
include $_SERVER["PROJECT_ROOT"]."/resources/app_languages.php";
@@ -81,11 +133,8 @@ class text {
//}
//check the session language
if (isset($_SESSION['domain']) and $language_code == null) {
$language_code = $_SESSION['domain']['language']['code'];
}
elseif ($language_code == null) {
$language_code = 'en-us';
if ($language_code == null) {
$language_code = $this->settings->get('domain', 'language', 'en-us');
}
//check the language code
@@ -338,7 +387,7 @@ class text {
include $file . "/app_config.php";
$x++;
}
//check every tag
foreach($apps as $app) {
$language_totals['app_descriptions']['total']++;
@@ -355,7 +404,7 @@ class text {
}
}
}
return $language_totals;
}