Portions created by the Initial Developer are Copyright (C) 2018-2026
the Initial Developer. All Rights Reserved.
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (!(permission_exists('bridge_add') || permission_exists('bridge_edit'))) {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
// Set variables from GET parameters
$page = is_numeric($_GET['page'] ?? '') ? $_GET['page'] : 0;
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'bridge_name'));
$order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc';
$search = $_GET['search'] ?? '';
$show = $_GET['show'] ?? '';
// Build the query string
$param = [];
if (!empty($page)) {
$param['page'] = $page;
}
if (!empty($_GET['order_by'])) {
$param['order_by'] = $order_by;
}
if (!empty($_GET['order'])) {
$param['order'] = $order;
}
if (!empty($search)) {
$param['search'] = $search;
}
if (!empty($show) && $show == 'all' && permission_exists('bridge_all')) {
$param['show'] = $show;
}
$query_string = http_build_query($param);
//action add or update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$bridge_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"];
}
else {
$action = "add";
}
//set the defaults
$bridge_uuid = '';
$bridge_name = '';
$bridge_destination = '';
$bridge_description = '';
//get http post variables and set them to php variables
if (!empty($_POST)) {
$bridge_uuid = $_POST["bridge_uuid"] ?? null;
$bridge_name = $_POST["bridge_name"] ?? null;
$bridge_action = $_POST["bridge_action"] ?? null;
$bridge_profile = $_POST["bridge_profile"] ?? null;
$bridge_variables = $_POST["bridge_variables"] ?? null;
$bridge_gateways = $_POST["bridge_gateways"] ?? null;
$destination_number = $_POST["destination_number"] ?? null;
$bridge_destination = $_POST["bridge_destination"] ?? null;
$bridge_enabled = $_POST["bridge_enabled"] ?? null;
$bridge_description = $_POST["bridge_description"] ?? null;
}
//process the user data and save it to the database
if (!empty($_POST) && empty($_POST["persistformvar"])) {
//delete the bridge
if (permission_exists('bridge_delete')) {
if ($_POST['action'] == 'delete' && is_uuid($bridge_uuid)) {
//prepare
$array[0]['checked'] = 'true';
$array[0]['uuid'] = $bridge_uuid;
//delete
$obj = new bridges;
$obj->delete($array);
//redirect
header('Location: bridges.php'.($query_string ? '?'.$query_string : ''));
exit;
}
}
//get the uuid from the POST
if ($action == "update") {
$bridge_uuid = $_POST["bridge_uuid"];
}
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: bridges.php'.($query_string ? '?'.$query_string : ''));
exit;
}
//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_enabled)) { $msg .= $text['message-required']." ".$text['label-bridge_enabled']."
\n"; }
if (!empty($msg) && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
| \n";
echo $msg." "; echo " |