2023-09-13 17:46:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-31 19:19:03 +02:00
|
|
|
* settings class is used to load settings using hierarchical overriding
|
|
|
|
|
*
|
|
|
|
|
* The settings are loaded from the database tables default_settings, domain_settings, and user_settings in that order with
|
|
|
|
|
* each setting overriding the setting from the previous table.
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
* @author Mark Crane <mark@fusionpbx.com>
|
2023-09-13 17:46:52 +02:00
|
|
|
*/
|
2025-03-15 16:13:36 +01:00
|
|
|
class settings implements clear_cache {
|
2023-09-13 17:46:52 +02:00
|
|
|
|
2024-05-31 19:19:03 +02:00
|
|
|
/**
|
|
|
|
|
* Set in the constructor. String used to load a specific domain. Must be a value domain UUID before sending to the constructor.
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
private $domain_uuid;
|
2024-05-31 19:19:03 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set in the constructor. String used to load a specific user. Must be a valid user UUID before sending to the constructor.
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
private $user_uuid;
|
2024-05-31 19:19:03 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set in the constructor. String used for loading a specific device UUID
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
private $device_uuid;
|
2024-05-31 19:19:03 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set in the constructor. String used for loading device profile
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
private $device_profile_uuid;
|
2024-05-31 19:19:03 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set in the constructor. Current category set to load
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
private $category;
|
2024-05-31 19:19:03 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Internal array structure that is populated from the database
|
|
|
|
|
* @var array Array of settings loaded from Default Settings
|
|
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
private $settings;
|
2024-05-31 19:19:03 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set in the constructor. Must be a database object and cannot be null.
|
|
|
|
|
* @var database Database Object
|
|
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
private $database;
|
|
|
|
|
|
2025-02-26 01:21:41 +01:00
|
|
|
/**
|
|
|
|
|
* Tracks if the APCu extension is loaded for database queries
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
private $apcu_enabled;
|
|
|
|
|
|
2023-09-13 17:46:52 +02:00
|
|
|
/**
|
2024-05-31 19:19:03 +02:00
|
|
|
* Create a settings object using key/value pairs in the $setting_array.
|
|
|
|
|
*
|
|
|
|
|
* Valid values are: database, domain_uuid, user_uuid, device_uuid, device_profile_uuid, and category.
|
2023-09-14 20:28:38 +02:00
|
|
|
* @param array setting_array
|
|
|
|
|
* @depends database::new()
|
2024-05-31 19:19:03 +02:00
|
|
|
* @access public
|
2023-09-13 17:46:52 +02:00
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
public function __construct($setting_array = []) {
|
|
|
|
|
|
2025-02-26 01:21:41 +01:00
|
|
|
//try to use RAM cache by default
|
|
|
|
|
if (!isset($setting_array['allow_caching'])) {
|
|
|
|
|
$setting_array['allow_caching'] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//track ram caching
|
|
|
|
|
if ($setting_array['allow_caching']) {
|
|
|
|
|
$this->apcu_enabled = function_exists('apcu_enabled') && apcu_enabled();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 20:28:38 +02:00
|
|
|
//open a database connection
|
2024-05-31 19:19:03 +02:00
|
|
|
if (empty($setting_array['database'])) {
|
|
|
|
|
$this->database = database::new();
|
|
|
|
|
} else {
|
|
|
|
|
$this->database = $setting_array['database'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//trap passing a PDO object instead of the required database object
|
|
|
|
|
if (!($this->database instanceof database)) {
|
|
|
|
|
//should never happen but will trap it here just-in-case
|
|
|
|
|
throw new \InvalidArgumentException("Database object passed in settings class constructor is not a valid database object");
|
|
|
|
|
}
|
2023-09-14 20:28:38 +02:00
|
|
|
|
|
|
|
|
//set the values from the array
|
|
|
|
|
$this->domain_uuid = $setting_array['domain_uuid'] ?? null;
|
|
|
|
|
$this->user_uuid = $setting_array['user_uuid'] ?? null;
|
|
|
|
|
$this->device_profile_uuid = $setting_array['device_profile_uuid'] ?? null;
|
2024-05-31 19:19:03 +02:00
|
|
|
$this->device_uuid = $setting_array['device_uuid'] ?? null;
|
2023-09-14 20:28:38 +02:00
|
|
|
$this->category = $setting_array['category'] ?? null;
|
|
|
|
|
|
2024-05-31 19:19:03 +02:00
|
|
|
$this->reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the database object used in the settings
|
|
|
|
|
* @return database Object
|
|
|
|
|
*/
|
|
|
|
|
public function database(): database {
|
|
|
|
|
return $this->database;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reloads the settings from the database
|
|
|
|
|
*/
|
|
|
|
|
public function reload() {
|
|
|
|
|
$this->settings = [];
|
|
|
|
|
|
2023-09-14 20:28:38 +02:00
|
|
|
//set the default settings
|
|
|
|
|
$this->default_settings();
|
|
|
|
|
|
|
|
|
|
//set the domain settings
|
|
|
|
|
if (!empty($this->domain_uuid)) {
|
|
|
|
|
$this->domain_settings();
|
|
|
|
|
|
2024-05-31 19:19:03 +02:00
|
|
|
//set the user settings only when the domain_uuid was set
|
|
|
|
|
if (!empty($this->user_uuid)) {
|
|
|
|
|
$this->user_settings();
|
|
|
|
|
}
|
2023-09-14 20:28:38 +02:00
|
|
|
|
2024-05-31 19:19:03 +02:00
|
|
|
//set the device profile settings
|
|
|
|
|
if (!empty($this->device_profile_uuid)) {
|
|
|
|
|
$this->device_profile_settings();
|
|
|
|
|
}
|
2023-09-14 20:28:38 +02:00
|
|
|
|
2024-05-31 19:19:03 +02:00
|
|
|
//set the device settings
|
|
|
|
|
if (!empty($this->device_uuid)) {
|
|
|
|
|
$this->device_settings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-31 19:19:03 +02:00
|
|
|
* Get the value utilizing the hierarchical overriding technique
|
|
|
|
|
* @param string $category Returns all settings when empty or the default value if the settings array is null
|
|
|
|
|
* @param string $subcategory Returns the array of category items when empty or the default value if the category array is null
|
|
|
|
|
* @param mixed $default_value allows default value returned if category and subcategory not found
|
2023-09-13 17:46:52 +02:00
|
|
|
*/
|
2024-03-04 17:35:17 +01:00
|
|
|
public function get(string $category = null, string $subcategory = null, $default_value = null) {
|
2023-09-14 20:28:38 +02:00
|
|
|
|
2024-05-31 19:19:03 +02:00
|
|
|
//incremental refinement from all settings to a single setting
|
2023-09-14 20:28:38 +02:00
|
|
|
if (empty($category)) {
|
2024-05-31 19:19:03 +02:00
|
|
|
return $this->settings ?? $default_value;
|
2023-09-14 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
elseif (empty($subcategory)) {
|
2024-05-31 19:19:03 +02:00
|
|
|
return $this->settings[$category] ?? $default_value;
|
2023-09-14 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2024-03-01 18:26:51 +01:00
|
|
|
return $this->settings[$category][$subcategory] ?? $default_value;
|
2023-09-14 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-13 17:46:52 +02:00
|
|
|
|
2025-03-13 21:32:51 +01:00
|
|
|
/**
|
|
|
|
|
* Returns the domain_uuid in this object used to load the settings
|
|
|
|
|
* @return string UUID of the domain used to load the object or an empty string
|
|
|
|
|
*/
|
|
|
|
|
public function get_domain_uuid(): string {
|
|
|
|
|
if (!empty($this->domain_uuid)) {
|
|
|
|
|
return $this->domain_uuid;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the user_uuid in this object used to load the settings
|
|
|
|
|
* @return string UUID of the user used to load the object or an empty string
|
|
|
|
|
*/
|
|
|
|
|
public function get_user_uuid(): string {
|
|
|
|
|
if (!empty($this->user_uuid)) {
|
|
|
|
|
return $this->user_uuid;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 23:43:52 +02:00
|
|
|
/**
|
|
|
|
|
* set the default, domain, user, device or device profile settings
|
2023-09-21 01:59:37 +02:00
|
|
|
* @param string $table_prefix prefix for the table.
|
|
|
|
|
* @param string $uuid uuid of the setting if available. If set to an empty string then a new uuid will be created.
|
|
|
|
|
* @param string $category Category of the setting.
|
|
|
|
|
* @param string $subcategory Subcategory of the setting.
|
|
|
|
|
* @param string $value (optional) Value to set. Default is empty string.
|
2025-03-04 19:25:47 +01:00
|
|
|
* @param string $type Type of the setting (array, numeric, text, etc)
|
2023-09-21 01:59:37 +02:00
|
|
|
* @param bool $enabled (optional) True or False. Default is True.
|
|
|
|
|
* @param string $description (optional) Description. Default is empty string.
|
2023-09-14 23:43:52 +02:00
|
|
|
*/
|
2025-02-26 01:21:41 +01:00
|
|
|
public function set(string $table_prefix, string $uuid, string $category, string $subcategory, string $value = "", string $type = 'text', bool $enabled = true, string $description = "") {
|
2024-05-31 19:19:03 +02:00
|
|
|
|
2023-09-21 01:59:37 +02:00
|
|
|
//set the table name
|
|
|
|
|
$table_name = $table_prefix.'_settings';
|
|
|
|
|
|
|
|
|
|
//init record as an array
|
|
|
|
|
$record = [];
|
|
|
|
|
if(!empty($this->domain_uuid)) {
|
|
|
|
|
$record[$table_name][0]['domain_uuid'] = $this->domain_uuid;
|
|
|
|
|
}
|
|
|
|
|
if(!empty($this->user_uuid)) {
|
|
|
|
|
$record[$table_name][0]['user_uuid'] = $this->user_uuid;
|
|
|
|
|
}
|
|
|
|
|
if(!empty($this->device_uuid)) {
|
|
|
|
|
$record[$table_name][0]['device_uuid'] = $this->device_uuid;
|
|
|
|
|
}
|
|
|
|
|
if(!empty($this->device_profile_uuid)) {
|
|
|
|
|
$record[$table_name][0]['device_profile_uuid'] = $this->device_profile_uuid;
|
|
|
|
|
}
|
|
|
|
|
if(!is_uuid($uuid)) {
|
|
|
|
|
$uuid = uuid();
|
|
|
|
|
}
|
2024-05-31 19:19:03 +02:00
|
|
|
|
2023-09-14 23:43:52 +02:00
|
|
|
//build the array
|
2023-09-21 01:59:37 +02:00
|
|
|
$record[$table_name][0][$table_prefix.'_setting_uuid' ] = $uuid;
|
|
|
|
|
$record[$table_name][0][$table_prefix.'_setting_category' ] = $category;
|
|
|
|
|
$record[$table_name][0][$table_prefix.'_setting_subcategory'] = $subcategory;
|
|
|
|
|
$record[$table_name][0][$table_prefix.'_setting_name' ] = $type;
|
|
|
|
|
$record[$table_name][0][$table_prefix.'_setting_value' ] = $value;
|
|
|
|
|
$record[$table_name][0][$table_prefix.'_setting_enabled' ] = $enabled;
|
|
|
|
|
$record[$table_name][0][$table_prefix.'_setting_description'] = $description;
|
|
|
|
|
|
2023-09-14 23:43:52 +02:00
|
|
|
//grant temporary permissions
|
2024-11-29 21:57:01 +01:00
|
|
|
$p = permissions::new();
|
2023-09-21 01:59:37 +02:00
|
|
|
$p->add($table_prefix.'_setting_add', 'temp');
|
|
|
|
|
$p->add($table_prefix.'_setting_edit', 'temp');
|
2023-09-14 23:43:52 +02:00
|
|
|
|
|
|
|
|
//execute insert
|
2023-09-21 01:59:37 +02:00
|
|
|
$this->database->app_name = $table_name;
|
|
|
|
|
$this->database->save($record);
|
2023-09-14 23:43:52 +02:00
|
|
|
|
|
|
|
|
//revoke temporary permissions
|
2023-09-21 01:59:37 +02:00
|
|
|
$p->delete($table_prefix.'_setting_add', 'temp');
|
|
|
|
|
$p->delete($table_prefix.'_setting_edit', 'temp');
|
2023-09-14 23:43:52 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-14 20:28:38 +02:00
|
|
|
/**
|
2024-05-31 19:19:03 +02:00
|
|
|
* Update the internal settings array with the default settings from the database
|
|
|
|
|
* @access private
|
2023-09-14 20:28:38 +02:00
|
|
|
*/
|
|
|
|
|
private function default_settings() {
|
2023-09-13 17:46:52 +02:00
|
|
|
|
2025-02-26 01:21:41 +01:00
|
|
|
//set the key for global defaults
|
|
|
|
|
$key = 'settings_global_' . $this->category;
|
|
|
|
|
|
|
|
|
|
//if the apcu extension is loaded get the already parsed array
|
|
|
|
|
if ($this->apcu_enabled && apcu_exists($key)) {
|
|
|
|
|
$this->settings = apcu_fetch($key);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 17:46:52 +02:00
|
|
|
//get the default settings
|
|
|
|
|
$sql = "select * from v_default_settings ";
|
|
|
|
|
$sql .= "where default_setting_enabled = 'true' ";
|
2023-09-14 20:28:38 +02:00
|
|
|
if (!empty($this->category)) {
|
2023-09-13 17:46:52 +02:00
|
|
|
$sql .= "and default_setting_category = :default_setting_category ";
|
2023-09-14 20:28:38 +02:00
|
|
|
$parameters['default_setting_category'] = $this->category;
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
$sql .= "order by default_setting_order asc ";
|
2023-09-14 20:28:38 +02:00
|
|
|
$result = $this->database->select($sql, $parameters ?? null, 'all');
|
|
|
|
|
if (!empty($result)) {
|
2023-09-13 17:46:52 +02:00
|
|
|
foreach ($result as $row) {
|
|
|
|
|
$name = $row['default_setting_name'];
|
|
|
|
|
$category = $row['default_setting_category'];
|
|
|
|
|
$subcategory = $row['default_setting_subcategory'];
|
2024-10-27 18:08:37 +01:00
|
|
|
if (isset($row['default_setting_value']) && $row['default_setting_value'] !== '') {
|
2024-10-23 02:15:35 +02:00
|
|
|
if ($name == "boolean") {
|
2025-03-04 19:25:47 +01:00
|
|
|
$this->settings[$category][$subcategory] = filter_var($row['default_setting_value'], FILTER_VALIDATE_BOOLEAN);
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
2024-10-23 02:15:35 +02:00
|
|
|
elseif ($name == "array") {
|
2024-01-10 23:25:41 +01:00
|
|
|
if (!isset($this->settings[$category][$subcategory]) || !is_array($this->settings[$category][$subcategory])) {
|
|
|
|
|
$this->settings[$category][$subcategory] = array();
|
|
|
|
|
}
|
2023-09-14 20:28:38 +02:00
|
|
|
$this->settings[$category][$subcategory][] = $row['default_setting_value'];
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2023-09-14 20:28:38 +02:00
|
|
|
$this->settings[$category][$subcategory] = $row['default_setting_value'];
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-26 01:21:41 +01:00
|
|
|
|
|
|
|
|
//if the apcu extension is loaded store the result
|
|
|
|
|
if ($this->apcu_enabled) {
|
|
|
|
|
apcu_store($key, $this->settings);
|
|
|
|
|
}
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-31 19:19:03 +02:00
|
|
|
* Update the internal settings array with the domain settings from the database
|
|
|
|
|
* @access private
|
2023-09-13 17:46:52 +02:00
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
private function domain_settings() {
|
2025-02-26 01:21:41 +01:00
|
|
|
$key = 'settings_domain_'.$this->domain_uuid;
|
|
|
|
|
$result = '';
|
|
|
|
|
//if the apcu extension is loaded get the cached database result
|
|
|
|
|
if ($this->apcu_enabled && apcu_exists($key)) {
|
|
|
|
|
$result = apcu_fetch($key);
|
|
|
|
|
} else {
|
|
|
|
|
$sql = "select * from v_domain_settings ";
|
|
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$sql .= "and domain_setting_enabled = 'true' ";
|
|
|
|
|
$parameters['domain_uuid'] = $this->domain_uuid;
|
|
|
|
|
$result = $this->database->select($sql, $parameters, 'all');
|
|
|
|
|
//if the apcu extension is loaded store the result
|
|
|
|
|
if ($this->apcu_enabled) {
|
|
|
|
|
apcu_store($key, $result);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-14 20:28:38 +02:00
|
|
|
if (!empty($result)) {
|
2024-07-05 02:05:37 +02:00
|
|
|
//domain setting array types override the default settings set as type array
|
|
|
|
|
foreach ($result as $row) {
|
|
|
|
|
$name = $row['domain_setting_name'];
|
|
|
|
|
$category = $row['domain_setting_category'];
|
|
|
|
|
$subcategory = $row['domain_setting_subcategory'];
|
|
|
|
|
if ($name == "array") {
|
|
|
|
|
$this->settings[$category][$subcategory] = array();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add the domain settings to the $this->settings array
|
2023-09-13 17:46:52 +02:00
|
|
|
foreach ($result as $row) {
|
|
|
|
|
$name = $row['domain_setting_name'];
|
|
|
|
|
$category = $row['domain_setting_category'];
|
|
|
|
|
$subcategory = $row['domain_setting_subcategory'];
|
2024-10-27 18:08:37 +01:00
|
|
|
if (isset($row['domain_setting_value']) && $row['domain_setting_value'] !== '') {
|
2024-10-23 02:15:35 +02:00
|
|
|
if ($name == "boolean") {
|
2025-03-04 19:25:47 +01:00
|
|
|
$this->settings[$category][$subcategory] = filter_var($row['domain_setting_value'], FILTER_VALIDATE_BOOLEAN);
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
if ($name == "array") {
|
2024-01-10 23:08:20 +01:00
|
|
|
if (!isset($this->settings[$category][$subcategory]) || !is_array($this->settings[$category][$subcategory])) {
|
2024-07-05 02:05:37 +02:00
|
|
|
$this->settings[$category][$subcategory] = array();
|
2024-01-10 23:08:20 +01:00
|
|
|
}
|
2023-09-14 20:28:38 +02:00
|
|
|
$this->settings[$category][$subcategory][] = $row['domain_setting_value'];
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2023-09-14 20:28:38 +02:00
|
|
|
$this->settings[$category][$subcategory] = $row['domain_setting_value'];
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-10-23 02:15:35 +02:00
|
|
|
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-31 19:19:03 +02:00
|
|
|
* Update the internal settings array with the user settings from the database
|
|
|
|
|
* @access private
|
|
|
|
|
* @depends $this->domain_uuid
|
2023-09-13 17:46:52 +02:00
|
|
|
*/
|
2023-09-14 20:28:38 +02:00
|
|
|
private function user_settings() {
|
2025-02-26 01:21:41 +01:00
|
|
|
$key = 'settings_user_'.$this->user_uuid;
|
|
|
|
|
$result = '';
|
|
|
|
|
//if the apcu extension is loaded get the cached database result
|
|
|
|
|
if ($this->apcu_enabled && apcu_exists($key)) {
|
|
|
|
|
$result = apcu_fetch($key);
|
|
|
|
|
} else {
|
|
|
|
|
$sql = "select * from v_user_settings ";
|
|
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$sql .= "and user_uuid = :user_uuid ";
|
|
|
|
|
$sql .= " order by user_setting_order asc ";
|
|
|
|
|
$parameters['domain_uuid'] = $this->domain_uuid;
|
|
|
|
|
$parameters['user_uuid'] = $this->user_uuid;
|
|
|
|
|
$result = $this->database->select($sql, $parameters, 'all');
|
|
|
|
|
//if the apcu extension is loaded store the result
|
|
|
|
|
if ($this->apcu_enabled) {
|
|
|
|
|
apcu_store($key, $result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!empty($result)) {
|
2023-09-13 17:46:52 +02:00
|
|
|
foreach ($result as $row) {
|
|
|
|
|
if ($row['user_setting_enabled'] == 'true') {
|
|
|
|
|
$name = $row['user_setting_name'];
|
|
|
|
|
$category = $row['user_setting_category'];
|
|
|
|
|
$subcategory = $row['user_setting_subcategory'];
|
2024-10-27 18:08:37 +01:00
|
|
|
if (isset($row['user_setting_value']) && $row['user_setting_value'] !== '') {
|
2024-10-23 02:15:35 +02:00
|
|
|
if ($name == "boolean") {
|
2025-03-04 19:25:47 +01:00
|
|
|
$this->settings[$category][$subcategory] = filter_var($row['user_setting_value'], FILTER_VALIDATE_BOOLEAN);
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
2024-10-23 02:15:35 +02:00
|
|
|
elseif ($name == "array") {
|
|
|
|
|
$this->settings[$category][$subcategory][] = $row['user_setting_value'];
|
|
|
|
|
}
|
2023-09-13 17:46:52 +02:00
|
|
|
else {
|
2024-10-23 02:15:35 +02:00
|
|
|
$this->settings[$category][$subcategory] = $row['user_setting_value'];
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
2024-10-23 02:15:35 +02:00
|
|
|
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-31 19:19:03 +02:00
|
|
|
}
|
2023-09-13 17:46:52 +02:00
|
|
|
|
2024-05-31 19:19:03 +02:00
|
|
|
/**
|
|
|
|
|
* Update the internal settings array with the device profile settings from the database
|
|
|
|
|
* @access private
|
|
|
|
|
* @depends $this->domain_uuid
|
|
|
|
|
*/
|
|
|
|
|
private function device_profile_settings() {
|
|
|
|
|
|
|
|
|
|
//get the device profile settings
|
|
|
|
|
$sql = "select profile_setting_name, profile_setting_value from v_device_profile_settings"
|
|
|
|
|
. " where device_profile_uuid = :device_profile_uuid"
|
|
|
|
|
. " and domain_uuid = :domain_uuid"
|
|
|
|
|
. " and profile_setting_enabled = 'true'"
|
|
|
|
|
;
|
|
|
|
|
$params = [];
|
|
|
|
|
$params['device_profile_uuid'] = $this->device_profile_uuid;
|
|
|
|
|
$params['domain_uuid'] = $this->domain_uuid;
|
|
|
|
|
$result = $this->database->select($sql, $params, 'all');
|
|
|
|
|
if (!empty($result)) {
|
|
|
|
|
foreach ($result as $row) {
|
|
|
|
|
$name = $row['profile_setting_name'];
|
|
|
|
|
$value = $row['profile_setting_value'];
|
|
|
|
|
$this->settings[$name] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-31 19:19:03 +02:00
|
|
|
/**
|
|
|
|
|
* Update the internal settings array with the device settings from the database
|
|
|
|
|
* @access private
|
|
|
|
|
* @depends $this->domain_uuid
|
|
|
|
|
*/
|
|
|
|
|
private function device_settings() {
|
|
|
|
|
|
|
|
|
|
//get the device settings
|
|
|
|
|
$sql = "select device_setting_subcategory, device_setting_value from v_device_settings"
|
|
|
|
|
. " where device_setting_uuid = :device_uuid"
|
|
|
|
|
. " and domain_uuid = :domain_uuid"
|
|
|
|
|
. " and device_setting_enabled = 'true'"
|
|
|
|
|
;
|
|
|
|
|
$params = [];
|
|
|
|
|
$params['device_uuid'] = $this->device_uuid;
|
|
|
|
|
$params['domain_uuid'] = $this->domain_uuid;
|
|
|
|
|
$result = $this->database->select($sql, $params, 'all');
|
|
|
|
|
if (!empty($result)) {
|
|
|
|
|
foreach ($result as $row) {
|
|
|
|
|
$name = $row['device_setting_subcategory'];
|
|
|
|
|
$value = $row['device_setting_value'] ?? null;
|
|
|
|
|
$this->settings[$name] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-26 01:21:41 +01:00
|
|
|
|
2025-03-15 16:13:36 +01:00
|
|
|
public static function clear_cache() {
|
2025-03-17 21:58:36 +01:00
|
|
|
if (function_exists('apcu_enabled') && apcu_enabled()) {
|
|
|
|
|
$cache = apcu_cache_info(false);
|
|
|
|
|
if (!empty($cache['cache_list'])) {
|
2025-03-31 18:04:33 +02:00
|
|
|
//clear apcu cache
|
2025-03-17 21:58:36 +01:00
|
|
|
foreach ($cache['cache_list'] as $entry) {
|
|
|
|
|
$key = $entry['info'];
|
|
|
|
|
if (str_starts_with($key, 'settings_')) {
|
|
|
|
|
apcu_delete($key);
|
|
|
|
|
}
|
2025-02-26 01:21:41 +01:00
|
|
|
}
|
2025-03-31 18:04:33 +02:00
|
|
|
global $settings;
|
|
|
|
|
//check there is a settings object
|
|
|
|
|
if (!empty($settings) && ($settings instanceof settings)) {
|
|
|
|
|
$database = $settings->database();
|
|
|
|
|
$domain_uuid = $settings->get_domain_uuid();
|
|
|
|
|
$user_uuid = $settings->get_user_uuid();
|
|
|
|
|
//recreate the settings object to reload all settings from database
|
|
|
|
|
$settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]);
|
|
|
|
|
}
|
2025-02-26 01:21:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-13 17:46:52 +02:00
|
|
|
}
|