Refactor PHP code (#7574)

* Use settings-get method
- get default, domain and user settings
- Replace _SESSION

* Simplify get domain paging

* Change isset using empty

* Fix token name and hash

* Add new default settings category: contact, name: default_sort_column, and default_sort_order

* Update app_config.php

* Update footer.php

* Fix require.php and core/dashboard/index.php (#7563)

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Fix require.php and core/dashboard/index.php

* Update destinations.php

* Update permission.php

* Update require.php

---------

Co-authored-by: FusionPBX <markjcrane@gmail.com>
Co-authored-by: FusionPBX <mark@fusionpbx.com>

* Update header.php

* Use settings get classes (#7567)

* access_control

* azure

* azure

* basic_operator_panel

* bridges

* call_block

* call_broadcast

* call_center

* call_flows

* call_forward

* call_recordings

* do_not_disturb

* feature_event_notify

* follow_me

* remove unused object properties

* fix esl command

* fix esl command

* conference_centers

* conference_centers - remove whitespace

* conference_controls

* conference_profiles

* conference_profiles

* Delete core/websockets/resources/classes/socket_exception.php.original~

* Delete core/websockets/resources/classes/websocket_server.php.original~

* conferences

* destinations

* device

* dialplan

* email_queue

* event_guard

* extension_settings

* extension

* fax

* fax_queue

* fifo

* gateways

* ivr_menu

* modules

* switch_music_on_hold

* number_translations

* phrases

* pin_numbers

* provision

* switch_recordings

* registrations

* ring_groups

* sip_profiles

* sofia_global_settings

* streams

* presence

* switch_files

* time_conditions

* vars

* voicemail_greetings

* voicemail

* ringbacks

* contacts

* xml_cdr

* authentication

* dashboard

* default_settings

* domain_settings

* email_templates

* permission

* user_logs

* user_settings

* users

* button

* cache

* captcha

* remove cli_option

* remove directory.php for switch_directory class

* email

* file

* groups

* event_socket use config object

* Use intval to give an integer port

* switch_settings

* tones

* fix object used before initialization

* menu

* fix copy paste error for switch_files.php

* always include require.php for framework files

* Fix missing properties

* set the action

* Use the $database object

* Add missing class properties

* Fix the domain_name

* Use public scope for domain_uuid and domain_name

* Add missing parameters

* Correct the user_uuid parameter

* Add json_validate and use it in the dashboard
update indentation on functions.php

* Intialize the active_registrations variable

* Define the $parameters

* Set a default value for user_setting_enabled

* Add condition domain_uuid not empty

* Add not empty condition for domain_uuid

* Declare the global variables

* Update how the defaults are set use ??

* Use ?? to set the default values

* Update call_center_queue_edit.php

* Prevent an error

* Add domain_name property

* Fix the null coalescing operator

* Removed domain_uuid from the URL

* Change condition to check sip_profile_domain_name

* Refactor domain_uuid declaration and comments

Removed redundant domain_uuid declaration and updated comments.

* Account for an empty value

* Refactor constructor to use settings array

Updated constructor to accept settings array for domain UUID and database initialization.

* Refactor xml_cdr.php to improve variable organization

Removed duplicate domain_uuid declaration and reorganized private variables for better structure.

* Enhance transcription button logic and icon display

Updated transcription button visibility conditions and improved application icon handling in the call flow summary.

* Refactor settings initialization in domains.php

Updated settings initialization to include domain_uuid and user_uuid.

* Modify domain change condition in require.php

Updated condition to check if 'domain_change' is not empty before proceeding.

* Set default_setting_enabled to true by default

* Enhance domain UUID check in access controls

* Enhance domain UUID check in settings list

* Refactor category display logic in vars.php

* Simplify list row URL generation

Removed domain UUID check from list row URL construction.

* Refactor module category display logic

* Fix SQL query by removing parameters variable

* Initialize result_count variable for call recordings

* Refactor leg variable usage in xml_cdr_details.php

* Update conference_room_edit.php

* Change GET to REQUEST for order and search variables

* Set timezone and SQL time format in recordings.php

Added timezone and SQL time format settings.

* Set default for ring group greeting

* Improve domain UUID check in stream listing

* Handle null voicemail_option_param safely

* Add file existence check for greeting files

Check if greeting file exists before getting size and date.

* Improve domain UUID check in email templates

* Update FIFO strategy dropdown and description text

* Add multilingual agent descriptions

Added multilingual descriptions for agents in the app_languages.php file.

* Add music on hold descriptions

* Add the chime list description

Updated copyright year from 2024 to 2025.

* Fix domain UUID check and handle email subject decoding

* Add null coalescing for $value in email_test.php

Ensure $value is not null by providing a default empty string.

* Handle undefined dialplan_uuid in input field

* Add translations for 'Status' label in multiple languages

* Fix typo in config instance check

---------

Co-authored-by: frytimo <tim@fusionpbx.com>
This commit is contained in:
FusionPBX
2025-10-15 21:24:59 -06:00
committed by GitHub
parent e4ca0bf47d
commit dda18481ec
249 changed files with 5180 additions and 4798 deletions

View File

@@ -29,8 +29,10 @@
public static $collapse = 'hide-md-dn';
static function create($array) {
$button_icons = !empty($_SESSION['theme']['button_icons']['text']) ? $_SESSION['theme']['button_icons']['text'] : 'auto';
public static function create($array) {
global $settings;
$button_icons = $settings->get('theme', 'button_icons', 'auto');
//parse styles into array
if (!empty($array['style'])) {
$tmp = explode(';',$array['style']);

View File

@@ -24,15 +24,9 @@ class cache {
$this->method = $this->setting('method');
$this->syslog = $this->setting('syslog');
$this->location = $this->setting('location');
if (empty($this->method)) {
$this->method = 'file';
}
if (empty($this->syslog)) {
$this->syslog = 'false';
}
if (empty($this->location)) {
$this->location = '/var/cache/fusionpbx';
}
$this->method = 'file';
$this->syslog = 'false';
$this->location = '/var/cache/fusionpbx';
}
private function setting($subcategory) {

View File

@@ -49,15 +49,6 @@ class captcha {
*/
public function image_captcha() {
//includes files
require dirname(__DIR__, 2) . "/resources/require.php";
//includes files
require_once "resources/functions.php";
//start the session
if (!isset($_SESSION)) { session_start(); }
//$_SESSION["captcha"] = substr(md5(uuid()), 0, 6);
//$text = $_SESSION["captcha"];
$text = $this->code;

View File

@@ -1,241 +0,0 @@
<?php
/*
* FusionPBX
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FusionPBX
*
* 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
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark J Crane <markjcrane@fusionpbx.com>
* Tim Fry <tim@fusionpbx.com>
*/
/**
* Container object for creating command line options when creating a service
* @author Tim Fry <tim@fusionpbx.com>
*/
class cli_option {
private $short_option;
private $long_option;
private $description;
private $short_description;
private $long_description;
private $functions;
/**
* Constructs an empty cli_option
*/
public function __construct() {
$this->short_option = '';
$this->long_option = '';
$this->description = '';
$this->short_description = '';
$this->long_description = '';
$this->functions = [];
}
/**
* A factory method to create a new cli_option
* @param type $options
* @return cli_option
*/
public static function new(...$options): cli_option {
$obj = new cli_option();
//automatically assign properties to the object that were passed in key/value pairs
self::parse_options($obj, $options);
//return the cli_option with all properties filled in that were passed
return $obj;
}
// used to parse object values when created
private static function parse_options($obj, $options) {
foreach ($options as $key => $value) {
if (is_array($value)) {
self::parse_options($obj, $value);
}
//call the method with the name of $key and pass it $value
if (method_exists($obj, $key)) {
$obj->{$key}($value);
} elseif (property_exists($obj, $key)) {
$obj->{$key} = $value;
}
}
}
/**
* Sets or returns the short option value
* @param string|null $short_option
* @return $this
*/
public function short_option(?string $short_option = null) {
if (!empty($short_option)) {
$this->short_option = $short_option;
return $this;
}
return $this->short_option;
}
/**
* Sets or returns the long option value
* @param string|null $long_option
* @return $this
*/
public function long_option(?string $long_option = null) {
if (!empty($long_option)) {
$this->long_option = $long_option;
return $this;
}
return $this->long_option;
}
/**
* Set the general description
* @param string|null $description
* @return $this
*/
public function description(?string $description = null) {
if (!empty($description)) {
$this->description = $description;
return $this;
}
return $this->description;
}
/**
* Sets or returns the short_description. If short_description is empty then the short_option is used as a default.
* @param string|null $short_description When parameter is null, it returns the currently set value. When not null the short description is set to the passed value.
* @return $this
*/
public function short_description(?string $short_description = null) {
if (!empty($short_description)) {
$this->short_description = $short_description;
return $this;
}
if (empty($this->short_description)) {
if (str_ends_with($this->short_option, ':')) {
$short = rtrim($this->short_option, ':');
$short_description = "-$short <value>";
} else {
$short_description = '-' . $this->short_option;
}
} else {
$short_description = $this->short_description;
}
return $short_description;
}
/**
* Sets or returns the long_description. If long_description is empty then the long_option is used as a default.
* @param string|null $long_description When parameter is null, it returns the currently set value. When not null the long description is set to the passed value.
* @return $this
*/
public function long_description(?string $long_description = null) {
if ($long_description !== null) {
$this->long_description = $long_description;
return $this;
}
if (empty($this->long_description)) {
if (str_ends_with($this->long_option, ':')) {
$long = rtrim($this->long_option, ':');
$long_description = "--$long <value>";
} else {
$long_description = '--' . $this->long_option;
}
} else {
$long_description = $this->long_description;
}
return $long_description;
}
/**
* Adds an array of callback functions replacing the existing callback functions
* @param array|null $functions
* @return $this
*/
public function functions(?array $functions = null) {
if ($functions !== null) {
$this->functions = $functions;
return $this;
}
return $this->functions;
}
/**
* Appends the callback function to the array of existing callback functions
* @param string|null $function When function param is set, the callback function will be appended to the list of functions. When called without a param, the array will be returned of current callbacks.
* @return $this|array Returns the array of callbacks if no parameters passed or this object when appending a callback
*/
public function callback(?string $function = null) {
if ($function !== null) {
$this->functions += [$function];
return $this;
}
return $this->functions;
}
/**
* Appends the callback function to the array of existing callback functions
* @param string|null $function
* @return $this
*/
public function function_append(?string $function = null) {
if ($function !== null) {
$this->functions += [$function];
return $this;
}
return $this->functions;
}
/**
* Returns the array structure required for service
* @return array
*/
public function to_array(): array {
$arr['short_option'] = $this->short_option();
$arr['long_option'] = $this->long_option();
$arr['description'] = $this->description();
$arr['short_description'] = $this->short_description();
$arr['long_description'] = $this->long_description();
$arr['functions'] = $this->functions();
return $arr;
}
}
/* Examples
$cli_option = cli_option::new([
'short_option'=>'m',
'long_option' =>'my-option',
'description' =>'Create an option that uses -m or --my-option command-line parameter'
]);
$cli_option = cli_option::new()
->short_option('m')
->long_option('my-option')
->description('Create an option that uses -m or --my-option command-line parameter');
echo $cli_option->description();
$cli_parsing_array = $cli_option->to_array();
print_r($cli_parsing_array);
//*/

View File

@@ -183,7 +183,7 @@ final class config {
//remove from the global namespace
unset($db_type, $db_host, $db_port, $db_name, $db_username, $db_password, $db_sslmode, $db_secure, $db_cert_authority);
}
}
else {
//save the loaded and parsed conf file to the object
$this->configuration = parse_ini_file($this->file);
@@ -250,11 +250,11 @@ final class config {
/**
* Get a configuration value using a key in the configuration file
* @param string|null $key Match key on the left hand side of the '=' in the config file. If $key is null the default value is returned
* @param string $default_value if no matching key is found, then this value will be returned
* @return string returns a value in the config.conf file or an empty string
* @param string $key Match key on the left hand side of the '=' in the config file. If $key is null the default value is returned
* @param string|null $default_value if no matching key is found, then this value will be returned
* @return string|null returns a value in the config.conf file or an empty string
*/
public function get(string $key, string $default_value = ''): string {
public function get(string $key, ?string $default_value = ''): ?string {
if (!empty($this->__get($key))) {
return $this->__get($key);
}

View File

@@ -1,655 +0,0 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2010
All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//define the directory class
class switch_directory {
/**
* declare public variables
*/
public $domain_uuid;
public $domain_name;
public $db_type;
public $extension;
public $number_alias;
public $password;
public $vm_password;
public $accountcode;
public $effective_caller_id_name;
public $effective_caller_id_number;
public $outbound_caller_id_name;
public $outbound_caller_id_number;
public $limit_max = 5;
public $limit_destination;
public $vm_enabled = 1;
public $vm_mailto;
public $vm_attach_file;
public $vm_keep_local_after_email;
public $user_context;
public $range;
public $autogen_users;
public $toll_allow;
public $call_group;
public $hold_music;
public $auth_acl;
public $cidr;
public $sip_force_contact;
public $sip_force_expires;
public $nibble_account;
public $mwi_account;
public $sip_bypass_media;
public $enabled;
public $description;
/**
* Called when the object is created
*/
public function __construct() {
//connect to the database
if (empty($this->database)) {
$this->database = database::new();
}
}
// get domain_uuid
public function get_domain_uuid() {
return $this->domain_uuid;
}
// set domain_uuid
public function set_domain_uuid($domain_uuid){
$this->domain_uuid = $domain_uuid;
}
// get domain_name
public function get_domain_name() {
return $this->domain_name;
}
// set domain_name
public function set_domain_name($domain_name){
$this->domain_name = $domain_name;
}
// get db_type
public function get_db_type() {
return $this->db_type;
}
// set db_type
public function set_db_type($db_type){
$this->db_type = $db_type;
}
// get extension
public function get_extension() {
return $this->extension;
}
// set extension
public function set_extension($extension){
$this->extension = $extension;
}
public function add() {
$domain_uuid = $this->domain_uuid;
$domain_name = $this->domain_name;
$extension = $this->extension;
$number_alias = $this->number_alias;
$password = $this->password;
$autogen_users = $this->autogen_users;
$provisioning_list = $this->provisioning_list;
$vm_password = $this->vm_password;
$accountcode = $this->accountcode;
$effective_caller_id_name = $this->effective_caller_id_name;
$effective_caller_id_number = $this->effective_caller_id_number;
$outbound_caller_id_name = $this->outbound_caller_id_name;
$outbound_caller_id_number = $this->outbound_caller_id_number;
$limit_max = $this->limit_max;
$limit_destination = $this->limit_destination;
$vm_enabled = $this->vm_enabled;
$vm_mailto = $this->vm_mailto;
$vm_attach_file = $this->vm_attach_file;
$vm_keep_local_after_email = $this->vm_keep_local_after_email;
$user_context = $this->user_context;
$toll_allow = $this->toll_allow;
$call_group = $this->call_group;
$hold_music = $this->hold_music;
$auth_acl = $this->auth_acl;
$cidr = $this->cidr;
$sip_force_contact = $this->sip_force_contact;
$sip_force_expires = $this->sip_force_expires;
$nibble_account = $this->nibble_account;
$mwi_account = $this->mwi_account;
$sip_bypass_media = $this->sip_bypass_media;
$enabled = $this->enabled;
$description = $this->description;
for ($i = 1; $i <= $range; $i++) {
if (extension_exists($extension)) {
//extension exists
}
else {
//extension does not exist, build insert array
$password = generate_password();
$array['extensions'][0]['domain_uuid'] = $domain_uuid;
$array['extensions'][0]['extension_uuid'] = $extension_uuid;
$array['extensions'][0]['extension'] = $extension;
$array['extensions'][0]['number_alias'] = $number_alias;
$array['extensions'][0]['password'] = $password;
$array['extensions'][0]['provisioning_list'] = $provisioning_list;
$array['extensions'][0]['vm_password'] = 'user-choose';
$array['extensions'][0]['accountcode'] = $accountcode;
$array['extensions'][0]['effective_caller_id_name'] = $effective_caller_id_name;
$array['extensions'][0]['effective_caller_id_number'] = $effective_caller_id_number;
$array['extensions'][0]['outbound_caller_id_name'] = $outbound_caller_id_name;
$array['extensions'][0]['outbound_caller_id_number'] = $outbound_caller_id_number;
$array['extensions'][0]['limit_max'] = $limit_max;
$array['extensions'][0]['limit_destination'] = $limit_destination;
$array['extensions'][0]['vm_enabled'] = $vm_enabled;
$array['extensions'][0]['vm_mailto'] = $vm_mailto;
$array['extensions'][0]['vm_attach_file'] = $vm_attach_file;
$array['extensions'][0]['vm_keep_local_after_email'] = $vm_keep_local_after_email;
$array['extensions'][0]['user_context'] = $user_context;
$array['extensions'][0]['toll_allow'] = $toll_allow;
$array['extensions'][0]['call_group'] = $call_group;
$array['extensions'][0]['hold_music'] = $hold_music;
$array['extensions'][0]['auth_acl'] = $auth_acl;
$array['extensions'][0]['cidr'] = $cidr;
$array['extensions'][0]['sip_force_contact'] = $sip_force_contact;
if (!empty($sip_force_expires)) {
$array['extensions'][0]['sip_force_expires'] = $sip_force_expires;
}
if (!empty($nibble_account)) {
$array['extensions'][0]['nibble_account'] = $nibble_account;
}
if (!empty($mwi_account)) {
if (strpos($mwi_account, '@') === false) {
$mwi_account .= count($_SESSION["domains"]) > 1 ? "@".$domain_name : "@\$\${domain}";
}
$array['extensions'][0]['mwi_account'] = $mwi_account;
}
$array['extensions'][0]['sip_bypass_media'] = $sip_bypass_media;
$array['extensions'][0]['enabled'] = $enabled;
$array['extensions'][0]['description'] = $description;
//grant temporary permissions
$p = permissions::new();
$p->add('extension_add', 'temp');
//execute insert
$this->database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('extension_add', 'temp');
}
$extension++;
}
}
public function update() {
$domain_uuid = $this->domain_uuid;
$domain_name = $this->domain_name;
$extension = $this->extension;
$number_alias = $this->number_alias;
$password = $this->password;
$autogen_users = $this->autogen_users;
$provisioning_list = $this->provisioning_list;
$vm_password = $this->vm_password;
$accountcode = $this->accountcode;
$effective_caller_id_name = $this->effective_caller_id_name;
$effective_caller_id_number = $this->effective_caller_id_number;
$outbound_caller_id_name = $this->outbound_caller_id_name;
$outbound_caller_id_number = $this->outbound_caller_id_number;
$limit_max = $this->limit_max;
$limit_destination = $this->limit_destination;
$vm_enabled = $this->vm_enabled;
$vm_mailto = $this->vm_mailto;
$vm_attach_file = $this->vm_attach_file;
$vm_keep_local_after_email = $this->vm_keep_local_after_email;
$user_context = $this->user_context;
$toll_allow = $this->toll_allow;
$call_group = $this->call_group;
$hold_music = $this->hold_music;
$auth_acl = $this->auth_acl;
$cidr = $this->cidr;
$sip_force_contact = $this->sip_force_contact;
$sip_force_expires = $this->sip_force_expires;
$nibble_account = $this->nibble_account;
$mwi_account = $this->mwi_account;
$sip_bypass_media = $this->sip_bypass_media;
$enabled = $this->enabled;
$description = $this->description;
//$user_list_array = explode("|", $user_list);
//foreach($user_list_array as $tmp_user){
// $user_password = generate_password();
// if (!empty($tmp_user)) {
// user_add($tmp_user, $user_password, $user_email);
// }
//}
//unset($tmp_user);
if (empty($password)) {
$password = generate_password();
}
//build update array
$array['extensions'][0]['extension_uuid'] = $extension_uuid;
$array['extensions'][0]['extension'] = $extension;
$array['extensions'][0]['number_alias'] = $number_alias;
$array['extensions'][0]['password'] = $password;
$array['extensions'][0]['provisioning_list'] = $provisioning_list;
$array['extensions'][0]['vm_password'] = !empty($vm_password) ? $vm_password : 'user-choose';
$array['extensions'][0]['accountcode'] = $accountcode;
$array['extensions'][0]['effective_caller_id_name'] = $effective_caller_id_name;
$array['extensions'][0]['effective_caller_id_number'] = $effective_caller_id_number;
$array['extensions'][0]['outbound_caller_id_name'] = $outbound_caller_id_name;
$array['extensions'][0]['outbound_caller_id_number'] = $outbound_caller_id_number;
$array['extensions'][0]['limit_max'] = $limit_max;
$array['extensions'][0]['limit_destination'] = $limit_destination;
$array['extensions'][0]['vm_enabled'] = $vm_enabled;
$array['extensions'][0]['vm_mailto'] = $vm_mailto;
$array['extensions'][0]['vm_attach_file'] = $vm_attach_file;
$array['extensions'][0]['vm_keep_local_after_email'] = $vm_keep_local_after_email;
$array['extensions'][0]['user_context'] = $user_context;
$array['extensions'][0]['toll_allow'] = $toll_allow;
$array['extensions'][0]['call_group'] = $call_group;
$array['extensions'][0]['hold_music'] = $hold_music;
$array['extensions'][0]['auth_acl'] = $auth_acl;
$array['extensions'][0]['cidr'] = $cidr;
$array['extensions'][0]['sip_force_contact'] = $sip_force_contact;
$array['extensions'][0]['sip_force_expires'] = !empty($sip_force_expires) ? $sip_force_expires : null;
$array['extensions'][0]['nibble_account'] = !empty($nibble_account) ? $nibble_account : null;
if (!empty($mwi_account)) {
if (strpos($mwi_account, '@') === false) {
$mwi_account .= count($_SESSION["domains"]) > 1 ? "@".$domain_name : "@\$\${domain}";
}
$array['extensions'][0]['mwi_account'] = $mwi_account;
}
$array['extensions'][0]['sip_bypass_media'] = $sip_bypass_media;
$array['extensions'][0]['enabled'] = $enabled;
$array['extensions'][0]['description'] = $description;
//grant temporary permissions
$p = permissions::new();
$p->add('extension_edit', 'temp');
//execute insert
$this->database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('extension_edit', 'temp');
}
function delete() {
$domain_uuid = $this->domain_uuid;
$extension_uuid = $this->extension_uuid;
if (is_uuid($extension_uuid)) {
//build delete array
$array['extensions'][0]['extension_uuid'] = $extension_uuid;
$array['extensions'][0]['domain_uuid'] = $domain_uuid;
//grant temporary permissions
$p = permissions::new();
$p->add('extension_delete', 'temp');
//execute delete
$this->database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('extension_delete', 'temp');
}
}
function import_sql($data) {
$count = count($data);
$keys = $values = SplFixedArray($count);
$keys = array_keys($data);
$values = array_values($data);
for ($i = 0; $i < $count; $i++) {
$keys[$i] = str_replace("-", "_", $keys[$i]);
$this->{$keys[$i]} = $values[$i];
}
}
function set_bool(&$var, $default = null){
$var = strtolower($var);
if ($var === "true") return;
else if ($var === "false") return;
else if ($var == true) $var = "true";
else if ($var == false) $var = "false";
else if (!is_null($default)) {
$var = $default;
$this->set_bool($var);
}
}
function generate_xml($single = 1) {
//switch_account_code!!
if ($this->enabled== "false" || !$this->enabled) {
return false;
}
$this->vm_password = str_replace("#", "", $this->vm_password); //preserves leading zeros//**Generic Validation!
/*if(!in_array($this->vm_enabled,array("false","true"))) {//**Generic Validation!
$this->vm_enabled = "true";
}
if(!in_array($this->vm_attach_file,array("false","true"))) {//**Generic Validation!
$this->vm_attach_file = "true";
}
if(!in_array($this->vm_keep_local_after_email,array("false","true"))) {//**Generic Validation!
$this->vm_keep_local_after_email = "true";
}
*/
$this->set_bool($this->vm_enabled,1);
$this->set_bool($this->vm_attach_file,1);
$this->set_bool($this->vm_keep_local_after_email,1);
//remove invalid characters from the file names //**Generic Validation!
$this->extension = str_replace(" ", "_", $this->extension);
$this->extension = preg_replace("/[\*\:\\/\<\>\|\'\"\?]/", "", $this->extension);
/*if (!$extension_xml_condensed) { <--- what do I do with this??
$fout = fopen($_SESSION['switch']['extensions']['dir']."/v_".$extension.".xml","w");
$xml .= "<include>\n";
}*/
if (strlen($this->cidr)) {
$this->cidr = " cidr=\"".$this->cidr."\"";
}
if (strlen($this->number_alias)) {
$this->number_alias = " number-alias=\"".$this->number_alias."\"";
}
$xml = $single ? "<include>\n" : "";
$xml .= " <user id=\"".$this->extension."\"".$this->cidr."".$this->number_alias.">\n";
$xml .= " <params>\n";
$xml .= " <param name=\"password\" value=\"".$this->password."\"/>\n";
$xml .= " <param name=\"vm-enabled\" value=\"".$this->vm_enabled."\"/>\n";
if ($this->vm_enabled=="true"){
$xml .= " <param name=\"vm-password\" value=\"".$this->vm_password."\"/>\n";
if(strlen($this->vm_mailto)) {
$xml .= " <param name=\"vm-email-all-messages\" value=\"true\"/>\n";
$xml .= " <param name=\"vm-attach-file\" value=\"".$this->vm_attach_file."\"/>\n";
$xml .= " <param name=\"vm-keep-local-after-email\" value=\"".$this->vm_keep_local_after_email."\"/>\n";
$xml .= " <param name=\"vm-mailto\" value=\"".$this->vm_mailto."\"/>\n";
}
}
if (strlen($this->mwi_account)) {
$xml .= " <param name=\"MWI-Account\" value=\"".$this->mwi_account."\"/>\n";
}
if (strlen($this->auth_acl)) {
$xml .= " <param name=\"auth-acl\" value=\"".$this->auth_acl."\"/>\n";
}
$xml .= " </params>\n";
$xml .= " <variables>\n";
if (strlen($this->hold_music)) {
$xml .= " <variable name=\"hold_music\" value=\"".$this->hold_music."\"/>\n";
}
if (strlen($this->toll_allow)){
$xml .= " <variable name=\"toll_allow\" value=\"".$this->toll_allow."\"/>\n";
}
if (strlen($this->accountcode)){
$xml .= " <variable name=\"accountcode\" value=\"".$this->accountcode."\"/>\n";
}
$xml .= " <variable name=\"user_context\" value=\"".$this->user_context."\"/>\n";
if (strlen($this->effective_caller_id_name)) {
$xml .= " <variable name=\"effective_caller_id_name\" value=\"".$this->effective_caller_id_name."\"/>\n";
}
if (strlen($this->outbound_caller_id_number)) {
$xml .= " <variable name=\"effective_caller_id_number\" value=\"".$this->effective_caller_id_number."\"/>\n";
}
if (strlen($this->outbound_caller_id_name)) {
$xml .= " <variable name=\"outbound_caller_id_name\" value=\"".$this->outbound_caller_id_name."\"/>\n";
}
if (strlen($this->outbound_caller_id_number)) {
$xml .= " <variable name=\"outbound_caller_id_number\" value=\"".$this->outbound_caller_id_number."\"/>\n";
}
if (!strlen($this->limit_max)) {//**validation
$this->limit_max=5;
}
$xml .= " <variable name=\"limit_max\" value=\"".$this->limit_max."\"/>\n";
if (strlen($this->limit_destination)) {
$xml .= " <variable name=\"limit_destination\" value=\"".$this->limit_destination."\"/>\n";
}
if (strlen($this->sip_force_contact)) {
$xml .= " <variable name=\"sip-force-contact\" value=\"".$this->sip_force_contact."\"/>\n";
}
if (strlen($this->sip_force_expires)) {
$xml .= " <variable name=\"sip-force-expires\" value=\"".$this->sip_force_expires."\"/>\n";
}
if (strlen($this->nibble_account)) {
$xml .= " <variable name=\"nibble_account\" value=\"".$this->nibble_account."\"/>\n";
}
switch ($this->sip_bypass_media) {
case "bypass-media":
$xml .= " <variable name=\"bypass_media\" value=\"true\"/>\n";
break;
case "bypass-media-after-bridge":
$xml .= " <variable name=\"bypass_media_after_bridge\" value=\"true\"/>\n";
break;
case "proxy-media":
$xml .= " <variable name=\"proxy_media\" value=\"true\"/>\n";
break;
}
$xml .= " </variables>\n";
$xml .= " </user>\n";
if ($single) { $xml .= "</include>\n"; }
return $xml;
}
function xml_save_all() {
global $config;
$domain_uuid = $this->domain_uuid;
$domain_name = $this->domain_name;
//determine the extensions parent directory
$extension_parent_dir = realpath($_SESSION['switch']['extensions']['dir']."/..");
// delete all old extensions to prepare for new ones
if ($dh = opendir($_SESSION['switch']['extensions']['dir'])) {
$files = array();
while ($file = readdir($dh)) {
if ($file != "." && $file != ".." && $file[0] != '.') {
if (is_dir($dir."/".$file)) {
//this is a directory do nothing
}
else {
//check if file is an extension; verify the file numeric and the extension is xml
if (substr($file,0,2) == 'v_' && substr($file,-4) == '.xml') {
unlink($_SESSION['switch']['extensions']['dir']."/".$file);
}
}
}
}
closedir($dh);
}
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "order by call_group asc ";
$parameters['domain_uuid'] = $domain_uuid;
$rows = $this->database->select($sql, $parameters, 'all');
$i = 0;
$extension_xml_condensed = false;
if ($extension_xml_condensed) {
$fout = fopen($_SESSION['switch']['extensions']['dir']."/v_extensions.xml","w");
$xml = "<include>\n";
}
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$call_group = $row['call_group'];
$call_group = str_replace(";", ",", $call_group);
$tmp_array = explode(",", $call_group);
foreach ($tmp_array as $tmp_call_group) {
if (!empty($tmp_call_group)) {
if (empty($call_group_array[$tmp_call_group])) {
$call_group_array[$tmp_call_group] = $row['extension'];
}
else {
$call_group_array[$tmp_call_group] = $call_group_array[$tmp_call_group].','.$row['extension'];
}
}
$i++;
}
if ($row['enabled'] != "false") {
//$this->import_sql($row);
//if (strlen($switch_account_code)) $this->accountcode=$switch_account_code;
//$xml.=$this->generate_xml(1);
$one_row = new fs_directory;
$one_row->import_sql($row);
if (strlen($switch_account_code)) {
$one_row->accountcode = $switch_account_code;
}
$xml .= $one_row->generate_xml(false);
if (!$extension_xml_condensed) {
$xml .= "</include>\n";
fwrite($fout, $xml);
unset($xml);
fclose($fout);
}
}
}
}
unset($sql, $parameters, $rows, $row);
if ($extension_xml_condensed) {
$xml .= "</include>\n";
fwrite($fout, $xml);
unset($xml);
fclose($fout);
}
//define the group members
$xml = "<!--\n";
$xml .= " NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE\n";
$xml .= "\n";
$xml .= " FreeSWITCH works off the concept of users and domains just like email.\n";
$xml .= " You have users that are in domains for example 1000@domain.com.\n";
$xml .= "\n";
$xml .= " When freeswitch gets a register packet it looks for the user in the directory\n";
$xml .= " based on the from or to domain in the packet depending on how your sofia profile\n";
$xml .= " is configured. Out of the box the default domain will be the IP address of the\n";
$xml .= " machine running FreeSWITCH. This IP can be found by typing \"sofia status\" at the\n";
$xml .= " CLI. You will register your phones to the IP and not the hostname by default.\n";
$xml .= " If you wish to register using the domain please open vars.xml in the root conf\n";
$xml .= " directory and set the default domain to the hostname you desire. Then you would\n";
$xml .= " use the domain name in the client instead of the IP address to register\n";
$xml .= " with FreeSWITCH.\n";
$xml .= "\n";
$xml .= " NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE\n";
$xml .= "-->\n";
$xml .= "\n";
$xml .= "<include>\n";
$xml .= " <!--the domain or ip (the right hand side of the @ in the addr-->\n";
if ($extension_dir_name == "default") {
$xml .= " <domain name=\"\$\${domain}\">\n";
}
else {
$xml .= " <domain name=\"".$extension_dir_name."\">\n";
}
$xml .= " <params>\n";
//$xml .= " <param name=\"dial-string\" value=\"{sip_invite_domain=\${domain_name},presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}\"/>\n";
$xml .= " </params>\n";
$xml .= "\n";
$xml .= " <variables>\n";
$xml .= " <variable name=\"record_stereo\" value=\"true\"/>\n";
$xml .= " <variable name=\"default_gateway\" value=\"\$\${default_provider}\"/>\n";
$xml .= " <variable name=\"default_areacode\" value=\"\$\${default_areacode}\"/>\n";
$xml .= " <variable name=\"transfer_fallback_extension\" value=\"operator\"/>\n";
$xml .= " <variable name=\"export_vars\" value=\"domain_name\"/>\n";
$xml .= " </variables>\n";
$xml .= "\n";
$xml .= " <groups>\n";
$xml .= " <group name=\"".$extension_dir_name."\">\n";
$xml .= " <users>\n";
$xml .= " <X-PRE-PROCESS cmd=\"include\" data=\"".$extension_dir_name."/*.xml\"/>\n";
$xml .= " </users>\n";
$xml .= " </group>\n";
$xml .= "\n";
$previous_call_group = "";
foreach ($call_group_array as $key => $value) {
$call_group = $key;
$extension_list = $value;
if (!empty($call_group)) {
if ($previous_call_group != $call_group) {
$xml .= " <group name=\"$call_group\">\n";
$xml .= " <users>\n";
$xml .= " <!--\n";
$xml .= " type=\"pointer\" is a pointer so you can have the\n";
$xml .= " same user in multiple groups. It basically means\n";
$xml .= " to keep searching for the user in the directory.\n";
$xml .= " -->\n";
$extension_array = explode(",", $extension_list);
foreach ($extension_array as $tmp_extension) {
$xml .= " <user id=\"$tmp_extension\" type=\"pointer\"/>\n";
}
$xml .= " </users>\n";
$xml .= " </group>\n";
$xml .= "\n";
}
$previous_call_group = $call_group;
}
unset($call_group);
}
$xml .= " </groups>\n";
$xml .= "\n";
$xml .= " </domain>\n";
$xml .= "</include>";
//remove invalid characters from the file names
$extension_dir_name = str_replace(" ", "_", $extension_dir_name);
$extension_dir_name = preg_replace("/[\*\:\\/\<\>\|\'\"\?]/", "", $extension_dir_name);
//write the xml file
$fout = fopen($extension_parent_dir."/".$extension_dir_name.".xml","w");
fwrite($fout, $xml);
unset($xml);
fclose($fout);
//syncrhonize the phone directory
sync_directory();
//apply settings reminder
$_SESSION["reload_xml"] = true;
//call reloadxml direct
//$cmd = "api reloadxml";
//event_socket_request_cmd($cmd);
//unset($cmd);
}
}
?>

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-2023
Portions created by the Initial Developer are Copyright (C) 2008-2025
the Initial Developer. All Rights Reserved.
Contributor(s):

View File

@@ -36,10 +36,15 @@
const app_name = 'email';
const app_uuid = '7a4fef67-5bf8-436a-ae25-7e3c03afcf96';
/**
* 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
*/
public $domain_uuid;
/**
* declare public variables
*/
public $domain_uuid;
public $method;
public $recipients;
public $subject;
@@ -53,44 +58,46 @@
public $error;
public $response;
/**
* 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;
/**
* declare private variables
*/
private $name;
private $settings;
/**
* called when the object is created
*/
public function __construct($params = []) {
public function __construct(array $setting_array = []) {
//assign the variables
$this->name = 'email';
$this->priority = 0;
$this->debug_level = 3;
$this->read_confirmation = false;
//set the domain_uuid
$this->domain_uuid = $params['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
if (isset($params['settings'])) {
$this->settings = $params['settings'];
}
//set the database from the settings object if available
if ($this->settings instanceof settings && !isset($this->database)) {
$this->database = $this->settings->database();
}
//ensure we have a valid database object
if (!($this->database instanceof database)) {
$this->database = $params['database'] ?? database::new();
}
//ensure we have a valid settings object
if (!($this->settings) instanceof settings) {
$this->settings = new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid]);
}
//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'] ?? '';
//set the objects
$this->database = $setting_array['database'] ?? database::new();
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
}
/**
@@ -435,13 +442,8 @@
if (!empty($this->settings->get('email','smtp_hostname'))) {
$smtp['hostname'] = $this->settings->get('email','smtp_hostname');
}
$smtp['host'] = (!empty($this->settings->get('email','smtp_host')) ? $this->settings->get('email','smtp_host'): '127.0.0.1');
if (!empty($this->settings->get('email','smtp_port'))) {
$smtp['port'] = (int)$this->settings->get('email','smtp_port');
}
else {
$smtp['port'] = 0;
}
$smtp['host'] = $this->settings->get('email','smtp_host', '127.0.0.1');
$smtp['port'] = (int)$this->settings->get('email','smtp_port', 0);
$smtp['secure'] = $this->settings->get('email','smtp_secure');
$smtp['auth'] = $this->settings->get('email','smtp_auth');
$smtp['username'] = $this->settings->get('email','smtp_username');

View File

@@ -51,14 +51,16 @@ class event_socket {
public $fp;
private static $socket = null;
private $config;
/**
* Create a new connection to the socket
* @param resource|false $fp
*/
public function __construct($fp = false) {
public function __construct($fp = false, ?config $config = null) {
$this->buffer = new buffer;
$this->fp = $fp;
$this->config = $config ?? config::load();
}
/**
@@ -135,14 +137,11 @@ class event_socket {
* @return bool Returns true on success or false if not connected
*/
public function connect($host = null, $port = null, $password = null, $timeout_microseconds = 30000) {
global $conf;
//set the event socket variables in the order of
//param passed to func, conf setting, old conf setting, default
$host = $host ?? $conf['switch.event_socket.host'] ?? $conf['event_socket.ip_address'] ?? '127.0.0.1';
$port = $port ?? $conf['switch.event_socket.port'] ?? $conf['event_socket.port'] ?? '8021';
$password = $password ?? $conf['switch.event_socket.password'] ?? $conf['event_socket.password'] ?? 'ClueCon';
$host = $host ?? $this->config->get('switch.event_socket.host', null) ?? $this->config->get('event_socket.ip_address', null) ?? '127.0.0.1';
$port = intval($port ?? $this->config->get('switch.event_socket.port', null) ?? $this->config->get('event_socket.port', null) ?? '8021');
$password = $password ?? $this->config->get('switch.event_socket.password', null) ?? $this->config->get('event_socket.password', null) ?? 'ClueCon';
//if a socket was provided in the constructor then don't create a new one
if ($this->fp === false) {

View File

@@ -2,8 +2,6 @@
/**
* cache class provides an abstracted cache
*
* @method string glob
*/
class file {
@@ -13,11 +11,41 @@ class file {
public $recursive;
public $files;
/**
* 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() {
//place holder
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
$this->user_uuid = $setting_array['user_uuid'] ?? $_SESSION['user_uuid'] ?? '';
//set objects
$this->database = $setting_array['database'] ?? database::new();
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
}
/**
@@ -66,8 +94,8 @@ class file {
if (!isset($voice)) { $voice = 'callie'; }
//set the variables
if (!empty($_SESSION['switch']['sounds']['dir']) && file_exists($_SESSION['switch']['sounds']['dir'])) {
$dir = $_SESSION['switch']['sounds']['dir'].'/'.$language.'/'.$dialect.'/'.$voice;
if (!empty($this->settings->get('switch', 'sounds')) && file_exists($this->settings->get('switch', 'sounds'))) {
$dir = $this->settings->get('switch', 'sounds').'/'.$language.'/'.$dialect.'/'.$voice;
$rate = '8000';
$files = $this->glob($dir.'/*/'.$rate, true);
}

View File

@@ -61,12 +61,7 @@
public function __construct(database $database = null, $domain_uuid = null, $user_uuid = null) {
//handle the database object
if (isset($database)) {
$this->database = $database;
}
else {
$this->database = database::new();
}
$this->database = $database ?? database::new();
//set the domain_uuid
if (is_uuid($domain_uuid)) {
@@ -79,7 +74,7 @@
}
//get the list of groups the user is a member of
if (!empty($domain_uuid) && !empty($user_uuid)) {
if (!empty($this->domain_uuid) && !empty($this->user_uuid)) {
//get the groups and save them to the groups variable
$this->groups = $this->assigned();
@@ -245,7 +240,7 @@
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ".$this->name."_uuid in (".implode(', ', $uuids).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['domain_uuid'] = $this->domain_uuid;
$rows = $this->database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
@@ -320,7 +315,7 @@
$sql = "select * from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ".$this->name."_uuid in (".implode(', ', $uuids).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['domain_uuid'] = $this->domain_uuid;
$rows = $this->database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
$y = 0;

View File

@@ -36,15 +36,15 @@
const app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
/**
* declare private variables
*/
* declare private variables
*/
public $menu_uuid;
public $menu_language;
public $text;
/**
* declare private variables
*/
* declare private variables
*/
private $name;
private $table;
private $toggle_field;
@@ -69,12 +69,24 @@
*/
private $user_uuid;
/**
* Username 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 $username;
/**
* 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;
/**
* Domain name 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_name;
/**
* called when the object is created
*/
@@ -83,21 +95,15 @@
$this->location = 'menus.php';
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
$this->domain_name = $setting_array['domain_name'] ?? $_SESSION['domain_name'] ?? '';
$this->user_uuid = $setting_array['user_uuid'] ?? $_SESSION['user_uuid'] ?? '';
$this->username = $setting_array['username'] ?? $_SESSION['username'] ?? '';
//open a database connection
if (empty($setting_array['database'])) {
$this->database = database::new();
} else {
$this->database = $setting_array['database'];
}
$this->database = $setting_array['database'] ?? database::new();
//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'];
}
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
//add multi-lingual support
$this->text = (new text)->get();
@@ -303,7 +309,6 @@
//save the changes
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
//save the array
$this->database->save($array);
unset($array);
@@ -681,8 +686,6 @@
$p->add('menu_item_add', 'temp');
$p->add('menu_language_add', 'temp');
//execute insert
$this->database->app_name = 'menu';
$this->database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
$this->database->save($array);
unset($array);
//revoke temporary permissions
@@ -745,8 +748,6 @@
$p = permissions::new();
$p->add('menu_item_group_add', 'temp');
//execute insert
$this->database->app_name = 'menu';
$this->database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
$this->database->save($array);
unset($array);
//revoke temporary permissions
@@ -800,10 +801,7 @@
if ($menu_item_level == 0) {
$menu_html = "<ul class='menu_main'>\n";
$menu_html .= "<li>\n";
if (!isset($_SESSION["username"])) {
$_SESSION["username"] = '';
}
if (empty($_SESSION["username"])) {
if (empty($this->username)) {
$menu_html .= "<a $menu_tags style='padding: 0px 0px; border-style: none; background: none;'><h2 align='center' style=''>".$menu_item_title."</h2></a>\n";
}
else {
@@ -1080,8 +1078,6 @@
$p->add('menu_add', 'temp');
//execute insert
$this->database->app_name = 'menu';
$this->database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
$this->database->save($array);
unset($array);
@@ -1248,7 +1244,7 @@
$html .= " <ul class='navbar-nav ml-auto'>\n";
//current user (latter condition for backward compatibility)
if (
!empty($_SESSION['username']) &&
!empty($this->username) &&
$this->settings->get('theme', 'header_user_visible', 'true') == 'true' && //app_defaults schema data type is 'text' but should be boolean here
$this->settings->get('theme', 'user_visible', 'true') == 'true' //app_defaults schema data type is 'text' but should be boolean here
) {
@@ -1260,22 +1256,22 @@
$user_graphic = "<span style=\"display: inline-block; vertical-align: middle; width: 15px; height: 15px; border-radius: 50%; margin-top: -2px; background-image: url('".PROJECT_PATH."/core/contacts/contact_attachment.php?id=".$_SESSION['user']['contact_image']."&action=download&sid=".session_id()."'); background-repeat: no-repeat; background-size: cover; background-position: center;\"></span>";
}
$html .= " <li class='nav-item'>\n";
$html .= " <a class='nav-link header_user d-block d-sm-none' href='show:usermenu' title=\"".$_SESSION['username']."\" style='border-top: 1px solid ".($this->settings->get('theme', 'menu_sub_background_color') ?? 'rgba(0,0,0,0.90)')."' data-toggle='collapse' data-target='#main_navbar' onclick=\"event.preventDefault(); $('#body_header_user_menu').toggleFadeSlide();\">".($user_graphic ?? null)."<span style='margin-left: 7px;'>".escape($_SESSION['username'])."</span></a>";
$html .= " <a class='nav-link header_user d-none d-sm-block' href='show:usermenu' title=\"".$_SESSION['username']."\" onclick=\"event.preventDefault(); $('#body_header_user_menu').toggleFadeSlide();\">".($user_graphic ?? null)."<span class='d-none d-md-inline' style='margin-left: 7px;'>".escape($_SESSION['username'])."</span></a>";
$html .= " <a class='nav-link header_user d-block d-sm-none' href='show:usermenu' title=\"".$this->username."\" style='border-top: 1px solid ".($this->settings->get('theme', 'menu_sub_background_color') ?? 'rgba(0,0,0,0.90)')."' data-toggle='collapse' data-target='#main_navbar' onclick=\"event.preventDefault(); $('#body_header_user_menu').toggleFadeSlide();\">".($user_graphic ?? null)."<span style='margin-left: 7px;'>".escape($this->username)."</span></a>";
$html .= " <a class='nav-link header_user d-none d-sm-block' href='show:usermenu' title=\"".$this->username."\" onclick=\"event.preventDefault(); $('#body_header_user_menu').toggleFadeSlide();\">".($user_graphic ?? null)."<span class='d-none d-md-inline' style='margin-left: 7px;'>".escape($this->username)."</span></a>";
$html .= " </li>\n";
}
//domain name/selector
if (permission_exists('domain_select') && $this->settings->get('theme', 'domain_visible', 'true') == 'true' && !empty($_SESSION['username']) && !empty($_SESSION['domains']) && count($_SESSION['domains']) > 1) {
if (permission_exists('domain_select') && $this->settings->get('theme', 'domain_visible', 'true') == 'true' && !empty($this->username) && !empty($_SESSION['domains']) && count($_SESSION['domains']) > 1) {
$html .= " <li class='nav-item'>\n";
$html .= " <a class='nav-link header_domain header_domain_selector_domain d-block d-sm-none' href='select:domain' onclick='event.preventDefault();' data-toggle='collapse' data-target='#main_navbar' title='".$this->text['theme-label-open_selector']."'><span class='".$this->settings->get('theme', 'body_header_icon_domain', 'fa-solid fa-earth-americas')."'></span><span style='margin-left: 7px;'>".escape($_SESSION['domain_name'])."</span></a>";
$html .= " <a class='nav-link header_domain header_domain_selector_domain d-none d-sm-block' href='select:domain' onclick='event.preventDefault();' title='".$this->text['theme-label-open_selector']."'><span class='".$this->settings->get('theme', 'body_header_icon_domain', 'fa-solid fa-earth-americas')."'></span><span class='d-none d-md-inline' style='margin-left: 7px;'>".escape($_SESSION['domain_name'])."</span></a>";
$html .= " <a class='nav-link header_domain header_domain_selector_domain d-block d-sm-none' href='select:domain' onclick='event.preventDefault();' data-toggle='collapse' data-target='#main_navbar' title='".$this->text['theme-label-open_selector']."'><span class='".$this->settings->get('theme', 'body_header_icon_domain', 'fa-solid fa-earth-americas')."'></span><span style='margin-left: 7px;'>".escape($this->domain_name)."</span></a>";
$html .= " <a class='nav-link header_domain header_domain_selector_domain d-none d-sm-block' href='select:domain' onclick='event.preventDefault();' title='".$this->text['theme-label-open_selector']."'><span class='".$this->settings->get('theme', 'body_header_icon_domain', 'fa-solid fa-earth-americas')."'></span><span class='d-none d-md-inline' style='margin-left: 7px;'>".escape($this->domain_name)."</span></a>";
$html .= " </li>\n";
}
//logout icon
if (!empty($_SESSION['username']) && isset($_SESSION['theme']['logout_icon_visible']) && $this->settings->get('theme', 'logout_icon_visible', 'false') == "true") {
$username_full = $_SESSION['username'].((count($_SESSION['domains']) > 1) ? "@".$_SESSION["user_context"] : null);
if (!empty($this->username) && $this->settings->get('theme', 'logout_icon_visible', 'false') == "true") {
$username_full = $this->username.((count($_SESSION['domains']) > 1) ? "@".$_SESSION["user_context"] : null);
$html .= " <li class='nav-item'>\n";
$html .= " <a class='logout_icon' href='#' title=\"".$this->text['theme-label-logout']."\" onclick=\"modal_open('modal-logout','btn_logout');\"><span class='fa-solid fa-right-from-bracket'></span></a>";
$html .= " </li>\n";
@@ -1328,7 +1324,7 @@
$html .= "</div>";
//modal for logout icon (above)
if (!empty($_SESSION['username']) && isset($_SESSION['theme']['logout_icon_visible']) && $this->settings->get('theme', 'logout_icon_visible', 'false') == "true") {
if (!empty($this->username) && $this->settings->get('theme', 'logout_icon_visible', 'false') == "true") {
$html .= modal::create(['id'=>'modal-logout','type'=>'general','message'=>$this->text['theme-confirm-logout'],'actions'=>button::create(['type'=>'button','label'=>$this->text['theme-label-logout'],'icon'=>'fa-solid fa-right-from-bracket','id'=>'btn_logout','style'=>'float: right; margin-left: 15px;','collapse'=>'never','link'=>PROJECT_PATH.'/logout.php','onclick'=>"modal_close();"])]);
}
@@ -1488,23 +1484,23 @@
$user_graphic = "<span style=\"display: inline-block; vertical-align: middle; width: ".$user_graphic_size."px; height: ".$user_graphic_size."px; border-radius: 50%; margin-right: 7px; margin-top: ".($user_graphic_size > 18 ? '-'.(ceil(($user_graphic_size - 18) / 2) - 4) : '-4')."px; background-image: url('".PROJECT_PATH."/core/contacts/contact_attachment.php?id=".$_SESSION['user']['contact_image']."&action=download&sid=".session_id()."'); background-repeat: no-repeat; background-size: cover; background-position: center;\"></span>";
}
$html .= "<span style='display: inline-block; padding-right: 20px; font-size: 90%;'>\n";
$html .= " <a href='show:usermenu' title=\"".$_SESSION['username']."\" onclick=\"event.preventDefault(); $('#body_header_user_menu').toggleFadeSlide();\">".($user_graphic ?? null)."<span class='d-none d-sm-inline'>".escape($_SESSION['username'])."</span></a>";
$html .= " <a href='show:usermenu' title=\"".$this->username."\" onclick=\"event.preventDefault(); $('#body_header_user_menu').toggleFadeSlide();\">".($user_graphic ?? null)."<span class='d-none d-sm-inline'>".escape($this->username)."</span></a>";
$html .= "</span>\n";
//domain name/selector (sm+)
if (!empty($_SESSION['username']) && permission_exists('domain_select') && count($_SESSION['domains']) > 1 && $this->settings->get('theme', 'domain_visible') == 'true') {
if (!empty($this->username) && permission_exists('domain_select') && count($_SESSION['domains']) > 1 && $this->settings->get('theme', 'domain_visible') == 'true') {
$html .= "<span style='display: inline-block; padding-right: 10px; font-size: 90%;'>\n";
$html .= " <a href='select:domain' onclick='event.preventDefault();' title='".$this->text['theme-label-open_selector']."' class='header_domain_selector_domain'><i class='".$this->settings->get('theme', 'body_header_icon_domain', 'fa-solid fa-earth-americas')." fa-fw' style='vertical-align: middle; font-size: ".($user_graphic_size - 1)."px; margin-top: ".($user_graphic_size > 18 ? '-'.(ceil(($user_graphic_size - 18) / 2) - 4) : '-3')."px; margin-right: 3px; line-height: 40%;'></i><span class='d-none d-sm-inline'>".escape($_SESSION['domain_name'])."</span></a>";
$html .= " <a href='select:domain' onclick='event.preventDefault();' title='".$this->text['theme-label-open_selector']."' class='header_domain_selector_domain'><i class='".$this->settings->get('theme', 'body_header_icon_domain', 'fa-solid fa-earth-americas')." fa-fw' style='vertical-align: middle; font-size: ".($user_graphic_size - 1)."px; margin-top: ".($user_graphic_size > 18 ? '-'.(ceil(($user_graphic_size - 18) / 2) - 4) : '-3')."px; margin-right: 3px; line-height: 40%;'></i><span class='d-none d-sm-inline'>".escape($this->domain_name)."</span></a>";
$html .= "</span>\n";
}
//logout icon
if (!empty($_SESSION['username']) && $this->settings->get('theme', 'logout_icon_visible') == "true") {
if (!empty($this->username) && $this->settings->get('theme', 'logout_icon_visible') == "true") {
$html .= "<a id='header_logout_icon' href='#' title=\"".$this->text['theme-label-logout']."\" onclick=\"modal_open('modal-logout','btn_logout');\"><span class='fa-solid fa-right-from-bracket'></span></a>";
}
$html .= "</div>";
$html .= " </div>\n";
//modal for logout icon (above)
if (!empty($_SESSION['username']) && $this->settings->get('theme', 'logout_icon_visible') == "true") {
if (!empty($this->username) && $this->settings->get('theme', 'logout_icon_visible') == "true") {
$html .= modal::create(['id'=>'modal-logout','type'=>'general','message'=>$this->text['theme-confirm-logout'],'actions'=>button::create(['type'=>'button','label'=>$this->text['theme-label-logout'],'icon'=>'fa-solid fa-right-from-bracket','id'=>'btn_logout','style'=>'float: right; margin-left: 15px;','collapse'=>'never','link'=>PROJECT_PATH.'/logout.php','onclick'=>"modal_close();"])]);
}

View File

@@ -8,20 +8,32 @@
class sounds {
/**
* Called when the object is created
*/
* 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
*/
public $domain_uuid;
/**
* Additional public variables
*/
public $sound_types;
public $full_path;
/**
* Set in the constructor. Must be a database object and cannot be null.
* @var database Database Object
*/
private $database;
/**
* Called when the object is created
*/
public function __construct() {
//connect to the database
if (empty($this->database)) {
$this->database = database::new();
}
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
//set objects
$this->database = $setting_array['database'] ?? database::new();
}
/**
@@ -97,4 +109,4 @@ class sounds {
}
?>
?>

View File

@@ -11,14 +11,56 @@
public $event_socket_port;
public $event_socket_password;
/**
* 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;
/**
* Username 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 $username;
/**
* 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;
/**
* Domain name 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_name;
/**
* called when the object is created
*/
public function __construct() {
//connect to the database
if (empty($this->database)) {
$this->database = database::new();
}
public function __construct(array $setting_array = []) {
//set domain and user UUIDs
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
$this->domain_name = $setting_array['domain_name'] ?? $_SESSION['domain_name'] ?? '';
$this->user_uuid = $setting_array['user_uuid'] ?? $_SESSION['user_uuid'] ?? '';
$this->username = $setting_array['username'] ?? $_SESSION['username'] ?? '';
//set objects
$this->database = $setting_array['database'] ?? database::new();
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
}
/**
@@ -26,35 +68,9 @@
*/
public function settings() {
//define the variables
if (!isset($this->event_socket_ip_address)) {
if (!empty($_SESSION['event_socket_ip_address'])) {
$this->event_socket_ip_address = $_SESSION['event_socket_ip_address'];
}
else {
$this->event_socket_ip_address = '127.0.0.1';
}
}
if (!isset($this->event_socket_port)) {
if (!empty($_SESSION['event_socket_port'])) {
$this->event_socket_port = $_SESSION['event_socket_port'];
}
else {
$this->event_socket_port = '8021';
}
}
if (!isset($this->event_socket_password)) {
if (!empty($_SESSION['event_socket_password'])) {
$this->event_socket_password = $_SESSION['event_socket_password'];
}
else {
$this->event_socket_password = 'ClueCon';
}
}
//connect to event socket
$esl = event_socket::create($this->event_socket_ip_address, $this->event_socket_port, $this->event_socket_password);
//run the api command
$result = $esl->request('api global_getvar');
@@ -81,7 +97,7 @@
//set the bin directory
if ($vars['base_dir'] == "/usr/local/freeswitch") {
$bin = '/usr/local/freeswitch/bin';
$bin = '/usr/local/freeswitch/bin';
}
else {
$bin = '';
@@ -255,6 +271,9 @@
//execute insert
$this->database->save($array);
//clear the apcu cache
settings::clear_cache();
//revoke temporary permissions
$p->delete('default_setting_add', 'temp');
}

View File

@@ -33,20 +33,18 @@
private $music_list;
private $recordings_list;
private $default_tone_label;
private $database;
/**
/**
* called when the object is created
*/
public function __construct() {
public function __construct(array $setting_array = []) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//connect to the database
if (empty($this->database)) {
$this->database = database::new();
}
$this->database = $setting_array['database'] ?? database::new();
}
public function tones_list() {