Files
fusionpbx/core/domains/domain_edit.php
FusionPBX dda18481ec 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>
2025-10-15 21:24:59 -06:00

701 lines
30 KiB
PHP

<?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-2025
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('domain_all') && permission_exists('domain_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//set the defaults
$domain_name = '';
$domain_description = '';
//action add or update
if (!permission_exists('domain_add') || (file_exists(dirname(__DIR__, 2)."/app/domains/") && !permission_exists('domain_all'))) {
//admin editing own domain/settings
$domain_uuid = $_SESSION['domain_uuid'];
$action = "update";
}
else {
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$domain_uuid = $_REQUEST["id"];
}
else {
$action = "add";
}
}
//get http post variables and set them to php variables
if (!empty($_POST)) {
$domain_name = strtolower($_POST["domain_name"]);
$domain_enabled = $_POST["domain_enabled"];
$domain_description = $_POST["domain_description"];
}
//process the data
if (!empty($_POST) && empty($_POST["persistformvar"])) {
//get the domain_uuid
if ($action == "update" && !empty($_POST["domain_uuid"]) && is_uuid($_POST["domain_uuid"])) {
$domain_uuid = $_POST["domain_uuid"];
}
//delete the domain
if (permission_exists('domain_delete') && !empty($_POST['action']) && $_POST['action'] == 'delete' && is_uuid($domain_uuid)) {
//prepare
$array[0]['checked'] = 'true';
$array[0]['uuid'] = $domain_uuid;
//delete
$obj = new domains;
$obj->delete($array);
//redirect
header('Location: domains.php');
exit;
}
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: domains.php');
exit;
}
//check for all required data
$msg = '';
if (empty($domain_name)) { $msg .= $text['message-required'].$text['label-name']."<br>\n"; }
//if (empty($domain_description)) { $msg .= $text['message-required'].$text['label-description']."<br>\n"; }
if (!empty($msg) && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "<div align='center'>\n";
echo "<table><tr><td>\n";
echo $msg."<br />";
echo "</td></tr></table>\n";
persistformvar($_POST);
echo "</div>\n";
require_once "resources/footer.php";
return;
}
//add or update the database
if (empty($_POST["persistformvar"])) {
//add a domain to the database
if ($action == "add" && permission_exists('domain_add')) {
$sql = "select count(*) from v_domains ";
$sql .= "where lower(domain_name) = :domain_name ";
$parameters['domain_name'] = $domain_name;
$num_rows = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
if ($num_rows == 0) {
//add the domain uuid
$domain_uuid = uuid();
//build the domain array
$array['domains'][0]['domain_uuid'] = $domain_uuid;
$array['domains'][0]['domain_name'] = $domain_name;
$array['domains'][0]['domain_enabled'] = $domain_enabled;
$array['domains'][0]['domain_description'] = $domain_description;
//create a copy of the domain array as the database save method empties the array that we still need.
$domain_array = $array;
//add the new domain
$database->save($array);
//add dialplans to the domain
if (file_exists(dirname(__DIR__, 2)."/app/dialplans/app_config.php")) {
//import the dialplans
$dialplan = new dialplan;
$dialplan->import($domain_array['domains']);
unset($array);
//add xml for each dialplan where the dialplan xml is empty
$dialplans = new dialplan;
$dialplans->source = "details";
$dialplans->destination = "database";
$dialplans->context = $domain_name;
$dialplans->is_empty = "dialplan_xml";
$array = $dialplans->xml();
}
//create the recordings directory for the new domain.
if (!empty($settings->get('switch', 'recordings')) && !empty($settings->get('switch', 'recordings'))) {
if (!file_exists($settings->get('switch', 'recordings')."/".$domain_name)) {
mkdir($settings->get('switch', 'recordings')."/".$domain_name, 0770);
}
}
//create the voicemail directory for the new domain.
if (!empty($settings->get('switch', 'voicemail')) && !empty($settings->get('switch', 'voicemail'))) {
if (!file_exists($settings->get('switch', 'voicemail')."/default/".$domain_name)) {
mkdir($settings->get('switch', 'voicemail')."/default/".$domain_name, 0770);
}
}
}
else {
message::add($text['message-domain_exists'],'negative');
header("Location: domains.php");
exit;
}
}
//update the domain
if ($action == "update" && permission_exists('domain_edit')) {
//get original domain name
$sql = "select domain_name from v_domains ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
$original_domain_name = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
//update domain name, description
$array['domains'][0]['domain_uuid'] = $domain_uuid;
$array['domains'][0]['domain_name'] = $domain_name;
$array['domains'][0]['domain_enabled'] = $domain_enabled;
$array['domains'][0]['domain_description'] = $domain_description;
$database->save($array);
//add dialplans to the domain
if (file_exists(dirname(__DIR__, 2)."/app/dialplans/app_config.php")) {
//import the dialplans
$dialplan = new dialplan;
$dialplan->import($array['domains'] ?? null);
unset($array);
//add xml for each dialplan where the dialplan xml is empty
$dialplans = new dialplan;
$dialplans->source = "details";
$dialplans->destination = "database";
$dialplans->context = $domain_name;
$dialplans->is_empty = "dialplan_xml";
$array = $dialplans->xml();
}
if ($original_domain_name != $domain_name) {
//update dialplans
if (file_exists(dirname(__DIR__, 2)."/app/dialplans/app_config.php")) {
$sql = "update v_dialplans set ";
$sql .= "dialplan_context = replace(dialplan_context, :domain_name_old, :domain_name_new), ";
$sql .= "dialplan_xml = replace(dialplan_xml, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
$sql = "update v_dialplan_details set ";
$sql .= "dialplan_detail_data = replace(dialplan_detail_data, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update destinations
if (file_exists(dirname(__DIR__, 2)."/app/destinations/app_config.php")) {
$sql = "update v_destinations set ";
$sql .= "destination_data = replace(destination_data, :destination_data_old, :destination_data_new), ";
$sql .= "destination_conditions = replace(destination_conditions::text, :destination_data_old, :destination_data_new)::json, ";
$sql .= "destination_actions = replace(destination_actions::text, :destination_data_old, :destination_data_new)::json ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['destination_data_old'] = $original_domain_name;
$parameters['destination_data_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update extensions (accountcode, user_context, dial_domain)
if (file_exists(dirname(__DIR__, 2)."/app/extensions/app_config.php")) {
$sql = "update v_extensions set ";
$sql .= "user_context = replace(user_context, :domain_name_old, :domain_name_new), ";
$sql .= "accountcode = replace(accountcode, :domain_name_old, :domain_name_new), ";
$sql .= "dial_domain = replace(dial_domain, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update ivr_menus (ivr_menu_context, ivr_menu_greet_long, ivr_menu_greet_short) and ivr_menu_options (ivr_menu_option_param)
if (file_exists(dirname(__DIR__, 2)."/app/ivr_menus/app_config.php")) {
$sql = "update v_ivr_menus set ";
$sql .= "ivr_menu_context = replace(ivr_menu_context, :domain_name_old, :domain_name_new), ";
$sql .= "ivr_menu_greet_long = replace(ivr_menu_greet_long, :domain_name_old, :domain_name_new), ";
$sql .= "ivr_menu_greet_short = replace(ivr_menu_greet_short, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
$sql = "update v_ivr_menu_options set ";
$sql .= "ivr_menu_option_param = replace(ivr_menu_option_param, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update ring_groups (ring_group_context, ring_group_forward_destination, ring_group_timeout_data)
if (file_exists(dirname(__DIR__, 2)."/app/ring_groups/app_config.php")) {
$sql = "update v_ring_groups set ";
$sql .= "ring_group_context = replace(ring_group_context, :domain_name_old, :domain_name_new), ";
$sql .= "ring_group_forward_destination = replace(ring_group_forward_destination, :domain_name_old, :domain_name_new), ";
$sql .= "ring_group_timeout_data = replace(ring_group_timeout_data, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update cdr records (domain_name, context)
if (file_exists(dirname(__DIR__, 2)."/app/xml_cdr/app_config.php")){
$sql = "update v_xml_cdr set ";
$sql .= "domain_name = :domain_name_new ";
$sql .= "where domain_name = :domain_name_old ";
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
$sql = "update v_xml_cdr set ";
$sql .= "context = replace(user_context, :context_old, :context_new), ";
$sql .= "where context = :context_old ";
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['context_old'] = $original_domain_name;
$parameters['context_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update conference session recording paths
if (file_exists(dirname(__DIR__, 2)."/app/conference_centers/app_config.php")) {
$sql = "update v_conference_sessions set ";
$sql .= "recording = replace(recording, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update conference center greetings
if (file_exists(dirname(__DIR__, 2)."/app/conference_centers/app_config.php")) {
$sql = "update v_conference_centers set ";
$sql .= "conference_center_greeting = replace(conference_center_greeting, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update call center queue record templates
if (file_exists(dirname(__DIR__, 2)."/app/call_centers/app_config.php")) {
$sql = "update v_call_center_queues set ";
$sql .= "queue_record_template = replace(queue_record_template, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update call center agent contacts
if (file_exists(dirname(__DIR__, 2)."/app/call_centers/app_config.php")) {
$sql = "update v_call_center_agents set ";
$sql .= "agent_contact = replace(agent_contact, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update call flows data, alternate-data and contexts
if (file_exists(dirname(__DIR__, 2)."/app/call_flows/app_config.php")) {
$sql = "update v_call_flows set ";
$sql .= "call_flow_data = replace(call_flow_data, :domain_name_old, :domain_name_new), ";
$sql .= "call_flow_alternate_data = replace(call_flow_alternate_data, :domain_name_old, :domain_name_new), ";
$sql .= "call_flow_context = replace(call_flow_context, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//update device lines server_address, server_address_primary, server_address_secondary, outbound_proxy_primary, outbound_proxy_secondary
if (file_exists(dirname(__DIR__, 2)."/app/devices/app_config.php")) {
$sql = "update v_device_lines set ";
$sql .= "server_address = replace(server_address, :domain_name_old, :domain_name_new), ";
$sql .= "server_address_primary = replace(server_address_primary, :domain_name_old, :domain_name_new), ";
$sql .= "server_address_secondary = replace(server_address_secondary, :domain_name_old, :domain_name_new), ";
$sql .= "outbound_proxy_primary = replace(outbound_proxy_primary, :domain_name_old, :domain_name_new), ";
$sql .= "outbound_proxy_secondary = replace(outbound_proxy_secondary, :domain_name_old, :domain_name_new) ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_name_old'] = $original_domain_name;
$parameters['domain_name_new'] = $domain_name;
$parameters['domain_uuid'] = $domain_uuid;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
//rename switch/storage/voicemail/default/[domain] (folder)
if (!empty($settings->get('switch', 'voicemail')) && file_exists($settings->get('switch', 'voicemail')."/default/".$original_domain_name)) {
@rename($settings->get('switch', 'voicemail')."/default/".$original_domain_name, $settings->get('switch', 'voicemail')."/default/".$domain_name); // folder
}
//rename switch/storage/fax/[domain] (folder)
if (!empty($settings->get('switch', 'storage')) && file_exists($settings->get('switch', 'storage')."/fax/".$original_domain_name)) {
@rename($settings->get('switch', 'storage')."/fax/".$original_domain_name, $settings->get('switch', 'storage')."/fax/".$domain_name); // folder
}
//rename switch/conf/dialplan/[domain] (folder/file)
if (!empty($settings->get('switch', 'dialplan'))) {
if (file_exists($settings->get('switch', 'dialplan')."/".$original_domain_name)) {
@rename($settings->get('switch', 'dialplan')."/".$original_domain_name, $settings->get('switch', 'dialplan')."/".$domain_name); // folder
}
if (file_exists($settings->get('switch', 'dialplan')."/".$original_domain_name.".xml")) {
@rename($settings->get('switch', 'dialplan')."/".$original_domain_name.".xml", $settings->get('switch', 'dialplan')."/".$domain_name.".xml"); // file
}
}
//rename switch/conf/dialplan/public/[domain] (folder/file)
if (!empty($settings->get('switch', 'dialplan'))) {
if (file_exists($settings->get('switch', 'dialplan')."/public/".$original_domain_name)) {
@rename($settings->get('switch', 'dialplan')."/public/".$original_domain_name, $settings->get('switch', 'dialplan')."/public/".$domain_name); // folder
}
if (file_exists($settings->get('switch', 'dialplan')."/public/".$original_domain_name.".xml")) {
@rename($settings->get('switch', 'dialplan')."/public/".$original_domain_name.".xml", $settings->get('switch', 'dialplan')."/public/".$domain_name.".xml"); // file
}
}
//rename switch/conf/directory/[domain] (folder/file)
if (!empty($settings->get('switch', 'extensions'))) {
if (file_exists($settings->get('switch', 'extensions')."/".$original_domain_name)) {
@rename($settings->get('switch', 'extensions')."/".$original_domain_name, $settings->get('switch', 'extensions')."/".$domain_name); // folder
}
if (file_exists($settings->get('switch', 'extensions')."/".$original_domain_name.".xml")) {
@rename($settings->get('switch', 'extensions')."/".$original_domain_name.".xml", $settings->get('switch', 'extensions')."/".$domain_name.".xml"); // file
}
}
//rename switch/recordings/[domain] (folder)
if (file_exists($settings->get('switch', 'recordings')."/".$_SESSION['domain_name'])) {
$switch_recordings_dir = str_replace("/".$_SESSION["domain_name"], "", $settings->get('switch', 'recordings')."/".$_SESSION['domain_name']);
if (file_exists($switch_recordings_dir."/".$original_domain_name)) {
@rename($switch_recordings_dir."/".$original_domain_name, $switch_recordings_dir."/".$domain_name); // folder
}
}
//update dialplan, dialplan/public xml files
$dialplan_xml = file_get_contents($settings->get('switch', 'dialplan')."/".$domain_name.".xml");
$dialplan_xml = str_replace($original_domain_name, $domain_name, $dialplan_xml);
file_put_contents($settings->get('switch', 'dialplan')."/".$domain_name.".xml", $dialplan_xml);
unset($dialplan_xml);
$dialplan_public_xml = file_get_contents($settings->get('switch', 'dialplan')."/public/".$domain_name.".xml");
$dialplan_public_xml = str_replace($original_domain_name, $domain_name, $dialplan_public_xml);
file_put_contents($settings->get('switch', 'dialplan')."/public/".$domain_name.".xml", $dialplan_public_xml);
unset($dialplan_public_xml);
//update session domain name
$_SESSION['domains'][$domain_uuid]['domain_name'] = $domain_name;
//recreate dialplan and extension xml files
if (is_readable($settings->get('switch', 'extensions'))) {
$extension = new extension;
$extension->xml();
}
//if single-tenant and variables exist, update variables > domain value to match new domain
if (count($_SESSION['domains']) == 1 && file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/vars/")) {
$sql = "update v_vars set ";
$sql .= "var_value = :var_value ";
$sql .= "where var_name = 'domain' ";
$parameters['var_value'] = $domain_name;
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
}
}
//clear the cache
$cache = new cache;
$response = $cache->flush();
//clear the domains session array to update it
unset($_SESSION["domains"]);
unset($_SESSION['domain']);
unset($_SESSION['switch']);
//redirect the browser
if ($action == "update") {
message::add($text['message-update']);
if (!permission_exists('domain_add')) { //admin, updating own domain
header("Location: domain_edit.php");
}
else {
header("Location: domains.php"); //superadmin
}
}
if ($action == "add") {
message::add($text['message-add']);
header("Location: domains.php");
}
exit;
}
}
//pre-populate the form (admin won't have domain_add permissions, but domain_uuid will already be set above)
if ((!empty($_GET) || (!permission_exists('domain_add') && !empty($domain_uuid))) && empty($_POST["persistformvar"])) {
$sql = "select ";
$sql .= "domain_uuid, ";
$sql .= "domain_name, ";
$sql .= "domain_enabled, ";
$sql .= "domain_description ";
$sql .= "from v_domains ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && sizeof($row) != 0) {
$domain_name = strtolower($row["domain_name"]);
$domain_enabled = $row["domain_enabled"];
$domain_description = $row["domain_description"];
}
unset($sql, $parameters, $row);
}
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//show the header
require_once "resources/header.php";
if ($action == "update") {
$document['title'] = $text['title-domain-edit'];
}
if ($action == "add") {
$document['title'] = $text['title-domain-add'];
}
//copy settings javascript
if (permission_exists("domain_select") && permission_exists("domain_setting_add") && !empty($_SESSION['domains']) && count($_SESSION['domains']) > 1) {
echo "<script language='javascript' type='text/javascript'>\n";
echo " var fade_speed = 400;\n";
echo " function show_domains() {\n";
echo " document.getElementById('action').value = 'copy';\n";
echo " $('#button_copy').fadeOut(fade_speed, function() {\n";
echo " $('#button_back').fadeIn(fade_speed);\n";
echo " $('#target_domain_uuid').fadeIn(fade_speed);\n";
echo " $('#button_paste').fadeIn(fade_speed);\n";
echo " });";
echo " }";
echo " function hide_domains() {\n";
echo " document.getElementById('action').value = '';\n";
echo " $('#button_back').fadeOut(fade_speed);\n";
echo " $('#target_domain_uuid').fadeOut(fade_speed);\n";
echo " $('#button_paste').fadeOut(fade_speed, function() {\n";
echo " $('#button_copy').fadeIn(fade_speed);\n";
echo " document.getElementById('target_domain_uuid').selectedIndex = 0;\n";
echo " });\n";
echo " }\n";
echo "\n";
echo " $(document).ready(function() {\n";
echo " $('#domain_setting_search').trigger('focus');\n";
if (!empty($search)) {
echo " // scroll to previous category\n";
echo " var category_span_id;\n";
echo " var url = document.location.href;\n";
echo " var hashindex = url.indexOf('#');\n";
echo " if (hashindex == -1) { }\n";
echo " else {\n";
echo " category_span_id = url.substr(hashindex + 1);\n";
echo " }\n";
echo " if (category_span_id) {\n";
echo " $('#page').animate({scrollTop: $('#anchor_'+category_span_id).offset().top - 200}, 'slow');\n";
echo " }\n";
}
echo " });\n";
echo "</script>";
}
//show the content
echo "<form method='post' name='frm' id='frm'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'>";
if ($action == "update") {
echo "<b>".$text['header-domain']."</b>";
}
if ($action == "add") {
echo "<b>".$text['header-domain-add']."</b>";
}
echo " </div>\n";
echo " <div class='actions'>\n";
if (permission_exists('domain_add')) {
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'domains.php']);
}
if ($action == "update" && permission_exists('domain_setting_view')) {
echo button::create(['type'=>'button','label'=>$text['button-settings'],'icon'=>$settings->get('theme', 'button_icon_settings'),'id'=>'btn_back','style'=>'margin-right: 2px;','link'=>PROJECT_PATH.'/core/domain_settings/domain_settings.php?id='.urlencode($domain_uuid)]);
}
if (permission_exists('domain_delete') && is_array($_SESSION['domains']) && @sizeof($_SESSION['domains']) > 1 && $domain_uuid != $_SESSION['domain_uuid']) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('theme', 'button_icon_delete'),'onclick'=>"modal_open('modal-delete-domain','btn_delete_domain');"]);
}
if (permission_exists("domain_select") && is_array($_SESSION['domains']) && @sizeof($_SESSION['domains']) > 1) {
echo "<select id='domains' class='formfld' style='width: auto;' onchange=\"window.location.href='?id=' + document.getElementById('domains').options[document.getElementById('domains').selectedIndex].value;\">\n";
foreach ($_SESSION['domains'] as $domain) {
$selected = $domain["domain_uuid"] == $domain_uuid ? "selected='selected'" : null;
echo " <option value='".escape($domain["domain_uuid"])."' ".$selected.">".escape($domain["domain_name"])."</option>\n";
}
echo "</select>";
}
if (permission_exists('domain_export')) {
echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$settings->get('theme', 'button_icon_export'),'link'=>PROJECT_PATH."/app/domain_export/index.php?id=".urlencode($domain_uuid)]);
}
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','style'=>'margin-left: 3px;']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
if (permission_exists('domain_delete') && is_array($_SESSION['domains']) && @sizeof($_SESSION['domains']) > 1 && $domain_uuid != $_SESSION['domain_uuid']) {
echo modal::create(['id'=>'modal-delete-domain','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete_domain','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]);
}
if ($action == "update") {
echo $text['description-domain-edit']."\n";
}
if ($action == "add") {
echo $text['description-domain-add']."\n";
}
echo "<br /><br />\n";
echo "<div class='card'>\n";
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-name']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='domain_name' maxlength='255' value=\"".escape($domain_name)."\">\n";
echo "<br />\n";
echo $text['description-name']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
if ($input_toggle_style_switch) {
echo " <span class='switch'>\n";
}
echo " <select class='formfld' id='domain_enabled' name='domain_enabled'>\n";
echo " <option value='true' ".($domain_enabled === true ? "selected='selected'" : null).">".$text['option-true']."</option>\n";
echo " <option value='false' ".($domain_enabled === false ? "selected='selected'" : null).">".$text['option-false']."</option>\n";
echo " </select>\n";
if ($input_toggle_style_switch) {
echo " <span class='slider'></span>\n";
echo " </span>\n";
}
echo "<br />\n";
echo $text['description-domain_enabled']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-description']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='domain_description' maxlength='255' value=\"".escape($domain_description)."\">\n";
echo "<br />\n";
echo $text['description-description']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "</div>";
echo "<br /><br />";
if ($action == "update") {
echo "<input type='hidden' name='domain_uuid' value='".escape($domain_uuid)."'>\n";
}
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>";
//include the footer
require_once "resources/footer.php";
?>