From 435ef38c8854b3a0f6cea579a4295ebba40f593b Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Fri, 10 Oct 2025 12:01:51 -0600 Subject: [PATCH] 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 --- app/call_block/call_block.php | 7 +- app/call_recordings/call_recordings.php | 7 +- app/click_to_call/click_to_call.php | 2 +- app/email_queue/email_queue.php | 7 +- app/emergency/emergency.php | 7 +- app/event_guard/event_guard_logs.php | 7 +- app/fax/fax_files.php | 7 +- .../resources/dashboard/missed_calls.php | 2 +- .../resources/dashboard/recent_calls.php | 2 +- app/xml_cdr/xml_cdr_inc.php | 9 +-- app/xml_cdr/xml_cdr_statistics_inc.php | 7 +- core/users/user_edit.php | 7 ++ core/users/user_profile.php | 7 ++ resources/check_auth.php | 14 ++-- resources/classes/domains.php | 41 +++++++++--- resources/classes/text.php | 65 ++++++++++++++++--- 16 files changed, 124 insertions(+), 74 deletions(-) diff --git a/app/call_block/call_block.php b/app/call_block/call_block.php index ec7c5dfcc8..b9d98e3826 100644 --- a/app/call_block/call_block.php +++ b/app/call_block/call_block.php @@ -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 "; diff --git a/app/call_recordings/call_recordings.php b/app/call_recordings/call_recordings.php index 2d518c931f..56ef110235 100644 --- a/app/call_recordings/call_recordings.php +++ b/app/call_recordings/call_recordings.php @@ -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 diff --git a/app/click_to_call/click_to_call.php b/app/click_to_call/click_to_call.php index b130461633..debd831c82 100644 --- a/app/click_to_call/click_to_call.php +++ b/app/click_to_call/click_to_call.php @@ -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"; diff --git a/app/email_queue/email_queue.php b/app/email_queue/email_queue.php index 8c9aeb1cae..3fc63eeb7c 100644 --- a/app/email_queue/email_queue.php +++ b/app/email_queue/email_queue.php @@ -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; diff --git a/app/emergency/emergency.php b/app/emergency/emergency.php index eb66e14ef0..9c29a82642 100644 --- a/app/emergency/emergency.php +++ b/app/emergency/emergency.php @@ -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, "; diff --git a/app/event_guard/event_guard_logs.php b/app/event_guard/event_guard_logs.php index 736d6dd57f..e3db39e08f 100644 --- a/app/event_guard/event_guard_logs.php +++ b/app/event_guard/event_guard_logs.php @@ -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 diff --git a/app/fax/fax_files.php b/app/fax/fax_files.php index 9792e2c336..bf6a7cb57b 100644 --- a/app/fax/fax_files.php +++ b/app/fax/fax_files.php @@ -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 diff --git a/app/xml_cdr/resources/dashboard/missed_calls.php b/app/xml_cdr/resources/dashboard/missed_calls.php index b7cba02cac..eb53d51001 100644 --- a/app/xml_cdr/resources/dashboard/missed_calls.php +++ b/app/xml_cdr/resources/dashboard/missed_calls.php @@ -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; diff --git a/app/xml_cdr/resources/dashboard/recent_calls.php b/app/xml_cdr/resources/dashboard/recent_calls.php index 7c766604c0..fd099aff4f 100644 --- a/app/xml_cdr/resources/dashboard/recent_calls.php +++ b/app/xml_cdr/resources/dashboard/recent_calls.php @@ -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; diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index 9ab74f3ac0..8e3683924f 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - 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 diff --git a/app/xml_cdr/xml_cdr_statistics_inc.php b/app/xml_cdr/xml_cdr_statistics_inc.php index 4beea5b7b4..c083e77a28 100644 --- a/app/xml_cdr/xml_cdr_statistics_inc.php +++ b/app/xml_cdr/xml_cdr_statistics_inc.php @@ -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 diff --git a/core/users/user_edit.php b/core/users/user_edit.php index c2037069e8..273c3254b2 100644 --- a/core/users/user_edit.php +++ b/core/users/user_edit.php @@ -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 diff --git a/core/users/user_profile.php b/core/users/user_profile.php index b8cdefce7f..fd8947336a 100644 --- a/core/users/user_profile.php +++ b/core/users/user_profile.php @@ -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 diff --git a/resources/check_auth.php b/resources/check_auth.php index 18405cafd4..dac2f89674 100644 --- a/resources/check_auth.php +++ b/resources/check_auth.php @@ -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"])) { diff --git a/resources/classes/domains.php b/resources/classes/domains.php index 4777a82954..7c0ad04fb7 100644 --- a/resources/classes/domains.php +++ b/resources/classes/domains.php @@ -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"])) { diff --git a/resources/classes/text.php b/resources/classes/text.php index 0c560d20d2..957a6179ec 100644 --- a/resources/classes/text.php +++ b/resources/classes/text.php @@ -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; }