From 1f75cfe2d8d4e88d9de64e6bd9a3d3f570a033b6 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Sat, 19 Aug 2023 11:04:52 -0600 Subject: [PATCH] Updated to simplify building bridge statement --- app/bridges/bridge_edit.php | 269 +++++++++++++++++++++++++++++++++++- 1 file changed, 262 insertions(+), 7 deletions(-) diff --git a/app/bridges/bridge_edit.php b/app/bridges/bridge_edit.php index 9dc0c6ac5a..b69ffd3b64 100644 --- a/app/bridges/bridge_edit.php +++ b/app/bridges/bridge_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2018 - 2019 + Portions created by the Initial Developer are Copyright (C) 2018 - 2023 the Initial Developer. All Rights Reserved. */ @@ -54,8 +54,12 @@ //get http post variables and set them to php variables if (!empty($_POST)) { - $bridge_uuid = $_POST["bridge_uuid"] ?? null; + $bridge_uuid = $_POST["bridge_uuid"]; $bridge_name = $_POST["bridge_name"]; + $bridge_action = $_POST["bridge_action"]; + $bridge_variables = $_POST["bridge_variables"]; + $bridge_gateways = $_POST["bridge_gateways"]; + $destination_number = $_POST["destination_number"]; $bridge_destination = $_POST["bridge_destination"]; $bridge_enabled = $_POST["bridge_enabled"] ?? 'false'; $bridge_description = $_POST["bridge_description"]; @@ -95,7 +99,7 @@ //check for all required data $msg = ''; if (empty($bridge_name)) { $msg .= $text['message-required']." ".$text['label-bridge_name']."
\n"; } - if (empty($bridge_destination)) { $msg .= $text['message-required']." ".$text['label-bridge_destination']."
\n"; } + //if (empty($bridge_destination)) { $msg .= $text['message-required']." ".$text['label-bridge_destination']."
\n"; } if (empty($bridge_enabled)) { $msg .= $text['message-required']." ".$text['label-bridge_enabled']."
\n"; } if (!empty($msg) && empty($_POST["persistformvar"])) { require_once "resources/header.php"; @@ -115,6 +119,33 @@ $bridge_uuid = uuid(); } + //create the main bridge statement + $bridge_base = ''; + if (!empty($bridge_gateways)) { + foreach($bridge_gateways as $gateway) { + if (!empty($gateway)) { + $gateway_array = explode(':', $gateway); + $bridge_base .= ',sofia/gateway/'.$gateway_array[0].'/'.$destination_number; + } + } + if (!empty($bridge_base)) { + $bridge_destination = trim($bridge_base, ','); + } + } + + //add the variables back into the bridg_destination value + if (!empty($bridge_variables)) { + $variables = ''; + foreach($bridge_variables as $key => $value) { + if (!empty($value)) { + $variables .= ','.$key.'='.$value; + } + } + if (!empty($variables)) { + $bridge_destination = '{'.trim($variables, ',').'}'.$bridge_destination; + } + } + //prepare the array $array['bridges'][0]['bridge_uuid'] = $bridge_uuid; $array['bridges'][0]['domain_uuid'] = $_SESSION["domain_uuid"]; @@ -165,6 +196,111 @@ unset($sql, $parameters, $row); } +//build the bridge_actions array from the session actions + $i = 0; + foreach($_SESSION['bridge']['action'] as $variable) { + $bridge_actions[$i]['action'] = $variable; + $bridge_actions[$i]['label'] = ucwords($variable); + $i++; + } + +//initialize the bridge_variables array from session bridge variables + $session_variables = []; $i = 0; + foreach($_SESSION['bridge']['variable'] as $variable) { + $variable = explode("=", $variable); + $session_variables[$i]['name'] = $variable[0]; + $session_variables[$i]['value'] = $variable[1] ?? ''; + $session_variables[$i]['label'] = ucwords(str_replace('_', ' ', $variable[0])); + $session_variables[$i]['label'] = str_replace('Effective Caller Id', 'Caller ID', $session_variables[$i]['label']); + $i++; + } + +//get the bridge variables from the database bridge_destination value + $database_variables = []; $x = 0; + if (!empty($bridge_destination)) { + //get the variables from inside the { and } brackets + preg_match('/\{([^}]+)\}/', $bridge_destination, $matches); + + //create a variables array from the comma delimitted string + $variables = explode(",", $matches[1]); + + //strip the variables from the $bridge_destination variable + $bridge_destination = str_replace("{$matches[0]}", '', $bridge_destination); + + //build a bridge variables data set + $x = 0; + foreach($variables as $variable) { + $pairs = explode("=", $variable); + $database_variables[$x]['name'] = $pairs[0]; + $database_variables[$x]['value'] = $pairs[1]; + $database_variables[$x]['label'] = ucwords(str_replace('_', ' ', $pairs[0])); + $database_variables[$x]['label'] = str_replace('Effective Caller Id', 'Caller ID', $database_variables[$x]['label']); + $x++; + } + } + +//merge the session and database bridge arrays together + $bridge_variables = $session_variables; + foreach($database_variables as $row) { + $found = false; + $i = 0; + foreach($bridge_variables as $field) { + if ($row['name'] == $field['name']) { + //matching row found + $found = true; + + //override session value with the value from the database + if (!empty($row['value'])) { + $bridge_variables[$i]['value'] = $row['value']; + } + } + $i++; + } + if (!$found) { + $bridge_variables[] = $row; + } + } + +//get the gateways + $actions = explode(',', $bridge_destination); + foreach($actions as $action) { + $action_array = explode('/',$action); + if ($action_array[1] == 'gateway') { + $bridge_gateways[] = $action_array[2]; + $destination_number = $action_array[3]; + } + } + +//get the gateways + $sql = "select * from v_gateways "; + $sql .= "where enabled = 'true' "; + if (permission_exists('outbound_route_any_gateway')) { + $sql .= "order by domain_uuid = :domain_uuid DESC, gateway "; + } + else { + $sql .= "and domain_uuid = :domain_uuid "; + } + $parameters['domain_uuid'] = $_SESION['domain_uuid']; + $database = new database; + $gateways = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); + +//get the domains + $sql = "select * from v_domains "; + $sql .= "where domain_enabled = 'true' "; + $database = new database; + $domains = $database->select($sql, null, 'all'); + unset($sql); + +//get the sip profiles + $sql = "select sip_profile_name "; + $sql .= "from v_sip_profiles "; + $sql .= "where sip_profile_enabled = 'true' "; + $sql .= "order by sip_profile_name asc "; + $database = new database; + $sip_profiles = $database->select($sql, null, 'all'); + unset($sql); + //set the defaults if (empty($bridge_enabled)) { $bridge_enabled = 'true'; } @@ -208,12 +344,131 @@ echo "\n"; echo "\n"; + echo "\n"; + echo "\n"; + echo " ".$text['label-bridge_action']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-bridge_action']."\n"; + echo "\n"; + echo "\n"; + + $i = 0; + foreach($bridge_variables as $row) { + echo "\n"; + echo "\n"; + echo " ".$row['label']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-bridge_variables']."\n"; + echo "\n"; + echo "\n"; + $i++; + } + + echo "\n"; + echo "\n"; + echo " ".$text['label-profile']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-profile']."\n"; + echo "\n"; + echo "\n"; + + for ($x = 0; $x <= 2; $x++) { + echo "\n"; + echo "\n"; + echo " ".$text['label-bridge_gateways']."\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo $text['description-bridge_gateways']."\n"; + echo "\n"; + echo "\n"; + } + + echo "\n"; + echo "\n"; + echo " ".$text['label-destination_number']."\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-destination_number']."\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo " ".$text['label-bridge_destination']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-bridge_destination']."\n"; echo "\n"; @@ -252,10 +507,10 @@ echo "\n"; echo "\n"; - echo ""; - echo "

"; + echo "\n"; + echo "

\n"; - if ($action == "update") { + if (!empty($bridge_uuid)) { echo "\n"; } echo "\n";