Files
fusionpbx/app/bridges/bridges.php
T

295 lines
12 KiB
PHP
Raw Normal View History

2018-03-18 20:59:24 -06:00
<?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>
2024-09-05 16:10:04 -07:00
Portions created by the Initial Developer are Copyright (C) 2018-2024
2018-03-18 20:59:24 -06:00
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
2022-10-10 16:35:14 -06:00
//includes files
2023-06-15 14:28:23 -03:00
require_once dirname(__DIR__, 2) . "/resources/require.php";
2018-03-18 20:59:24 -06:00
require_once "resources/check_auth.php";
2019-04-23 10:02:54 -06:00
require_once "resources/paging.php";
2018-03-18 20:59:24 -06:00
//check permissions
if (permission_exists('bridge_view')) {
//access granted
}
else {
echo "access denied";
exit;
2018-03-18 20:59:24 -06:00
}
//add multi-lingual support
$language = new text;
$text = $language->get();
2023-05-26 11:48:39 -06:00
//set additional variables
$search = $_GET["search"] ?? '';
$show = $_GET["show"] ?? '';
//set from session variables
2025-03-04 14:25:47 -04:00
$list_row_edit_button = filter_var($_SESSION['theme']['list_row_edit_button']['boolean'] ?? false, FILTER_VALIDATE_BOOL);
2023-05-26 11:48:39 -06:00
2019-11-30 12:04:42 -07:00
//get the http post data
2023-05-26 11:48:39 -06:00
if (!empty($_POST['bridges'])) {
$action = $_POST['action'];
2019-10-19 16:57:41 -06:00
$search = $_POST['search'];
$bridges = $_POST['bridges'];
}
2019-11-30 12:04:42 -07:00
//process the http post data by action
2023-05-26 11:48:39 -06:00
if (!empty($action) && !empty($bridges)) {
2019-11-30 11:12:41 -07:00
switch ($action) {
case 'copy':
if (permission_exists('bridge_add')) {
2019-11-30 12:04:42 -07:00
$obj = new bridges;
2019-11-30 11:12:41 -07:00
$obj->copy($bridges);
}
break;
case 'toggle':
if (permission_exists('bridge_edit')) {
2019-11-30 12:04:42 -07:00
$obj = new bridges;
2019-11-30 11:12:41 -07:00
$obj->toggle($bridges);
}
break;
case 'delete':
if (permission_exists('bridge_delete')) {
2019-11-30 12:04:42 -07:00
$obj = new bridges;
2019-11-30 11:12:41 -07:00
$obj->delete($bridges);
}
break;
}
2018-03-18 20:59:24 -06:00
2023-05-26 11:48:39 -06:00
header('Location: bridges.php'.(!empty($search) ? '?search='.urlencode($search) : null));
2019-11-30 11:12:41 -07:00
exit;
2018-03-18 20:59:24 -06:00
}
2019-11-18 13:31:06 -07:00
//get order and order by
2023-05-09 22:52:32 +00:00
$order_by = $_GET["order_by"] ?? '';
$order = $_GET["order"] ?? '';
2019-05-27 20:22:00 -06:00
2019-11-30 15:56:06 -07:00
//add the search string
2023-05-26 11:48:39 -06:00
if (!empty($search)) {
2020-05-11 10:30:14 -06:00
$search = strtolower($_GET["search"]);
2018-03-18 20:59:24 -06:00
$sql_search = " (";
2019-11-30 15:56:06 -07:00
$sql_search .= " lower(bridge_name) like :search ";
$sql_search .= " or lower(bridge_destination) like :search ";
$sql_search .= " or lower(bridge_enabled) like :search ";
$sql_search .= " or lower(bridge_description) like :search ";
2018-03-18 20:59:24 -06:00
$sql_search .= ") ";
2019-04-23 10:02:54 -06:00
$parameters['search'] = '%'.$search.'%';
}
2018-03-18 20:59:24 -06:00
2019-11-30 15:56:06 -07:00
//get the count
$sql = "select count(bridge_uuid) from v_bridges ";
2023-05-26 11:48:39 -06:00
if (!empty($show) && $show == "all" && permission_exists('bridge_all')) {
2018-03-18 20:59:24 -06:00
if (isset($sql_search)) {
$sql .= "where ".$sql_search;
}
2019-04-23 10:02:54 -06:00
}
else {
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
2018-03-18 20:59:24 -06:00
if (isset($sql_search)) {
$sql .= "and ".$sql_search;
}
$parameters['domain_uuid'] = $domain_uuid;
2018-03-18 20:59:24 -06:00
}
2019-04-23 10:02:54 -06:00
$database = new database;
2023-05-19 23:47:47 +00:00
$num_rows = $database->select($sql, $parameters ?? null, 'column');
2018-03-18 20:59:24 -06:00
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
2023-05-09 22:52:32 +00:00
$param = !empty($search) ? "&search=".$search : null;
$param = (isset($_GET['show']) && $_GET['show'] == 'all' && permission_exists('bridge_all')) ? "&show=all" : null;
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 0;
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
2018-03-18 20:59:24 -06:00
$offset = $rows_per_page * $page;
//get the list
$sql = "select d.domain_uuid, b.bridge_uuid, d.domain_name, b.bridge_name, b.bridge_destination, bridge_enabled, bridge_description ";
2024-02-26 09:28:17 -07:00
$sql .= "from v_bridges as b, v_domains as d ";
$sql .= "where b.domain_uuid = d.domain_uuid ";
if (!empty($show) && $show == "all" && permission_exists('bridge_all')) {
if (isset($sql_search)) {
$sql .= "and ".$sql_search;
}
}
else {
$sql .= "and (b.domain_uuid = :domain_uuid or b.domain_uuid is null) ";
if (isset($sql_search)) {
$sql .= "and ".$sql_search;
}
$parameters['domain_uuid'] = $domain_uuid;
}
$sql .= order_by($order_by, $order, 'bridge_name', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
2019-04-23 10:02:54 -06:00
$database = new database;
2023-05-19 23:47:47 +00:00
$bridges = $database->select($sql, $parameters ?? null, 'all');
2019-10-19 16:57:41 -06:00
unset($sql, $parameters);
2018-03-18 20:59:24 -06:00
2019-09-19 08:49:34 -06:00
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
2019-04-23 10:02:54 -06:00
//include the header
2020-01-06 10:27:53 -07:00
$document['title'] = $text['title-bridges'];
2019-04-23 10:02:54 -06:00
require_once "resources/header.php";
2018-03-18 20:59:24 -06:00
//show the content
2019-10-17 14:24:34 -06:00
echo "<div class='action_bar' id='action_bar'>\n";
2024-09-06 15:43:42 -07:00
echo " <div class='heading'><b>".$text['title-bridges']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
2019-10-24 16:31:14 -06:00
echo " <div class='actions'>\n";
2023-10-27 21:01:23 -06:00
if (permission_exists('bridge_import')) {
echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'style'=>'margin-right: 15px;','link'=>'bridge_imports.php']);
}
if (permission_exists('bridge_add')) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'bridge_edit.php']);
}
if (permission_exists('bridge_add') && $bridges) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
}
if (permission_exists('bridge_edit') && $bridges) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display: none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
}
if (permission_exists('bridge_delete') && $bridges) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
}
echo "<form id='form_search' class='inline' method='get'>\n";
2018-03-18 20:59:24 -06:00
if (permission_exists('bridge_all')) {
2023-05-26 11:48:39 -06:00
if (isset($show) && $show == 'all') {
2019-11-30 15:56:06 -07:00
echo " <input type='hidden' name='show' value='all'>\n";
2018-03-18 20:59:24 -06:00
}
else {
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
2018-03-18 20:59:24 -06:00
}
}
2023-05-26 11:48:39 -06:00
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
2022-01-12 16:00:01 -07:00
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
//echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'bridges.php','style'=>($search == '' ? 'display: none;' : null)]);
2019-10-19 16:57:41 -06:00
if ($paging_controls_mini != '') {
2019-11-30 15:56:06 -07:00
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
2019-10-19 16:57:41 -06:00
}
2019-10-24 16:28:09 -06:00
echo " </form>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
2018-03-18 20:59:24 -06:00
2020-03-25 19:32:26 -06:00
if (permission_exists('bridge_add') && $bridges) {
echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]);
}
if (permission_exists('bridge_edit') && $bridges) {
echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]);
}
if (permission_exists('bridge_delete') && $bridges) {
echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
}
echo $text['title_description-bridge']."\n";
echo "<br /><br />\n";
2024-09-05 16:10:04 -07:00
echo "<div class='card'>\n";
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
2023-05-26 11:48:39 -06:00
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
2018-03-18 20:59:24 -06:00
2019-10-19 16:57:41 -06:00
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
if (permission_exists('bridge_add') || permission_exists('bridge_edit') || permission_exists('bridge_delete')) {
echo " <th class='checkbox'>\n";
2023-05-19 23:47:47 +00:00
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(empty($bridges) ? "style='visibility: hidden;'" : null).">\n";
echo " </th>\n";
}
2023-05-26 11:48:39 -06:00
if (!empty($show) && $show == 'all' && permission_exists('bridge_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
}
2018-03-18 22:37:36 -06:00
echo th_order_by('bridge_name', $text['label-bridge_name'], $order_by, $order);
2018-03-18 23:35:41 -06:00
echo th_order_by('bridge_destination', $text['label-bridge_destination'], $order_by, $order);
2019-10-19 19:13:15 -06:00
echo th_order_by('bridge_enabled', $text['label-bridge_enabled'], $order_by, $order, null, "class='center'");
2019-11-30 15:56:06 -07:00
echo " <th class='hide-sm-dn'>".$text['label-bridge_description']."</th>\n";
2025-03-04 14:25:47 -04:00
if (permission_exists('bridge_edit') && $list_row_edit_button) {
2019-10-19 16:57:41 -06:00
echo " <td class='action-button'>&nbsp;</td>\n";
}
echo "</tr>\n";
2018-03-18 20:59:24 -06:00
2023-05-26 11:48:39 -06:00
if (!empty($bridges)) {
2018-03-18 20:59:24 -06:00
$x = 0;
2019-11-07 21:15:11 -07:00
foreach ($bridges as $row) {
$list_row_url = '';
2018-03-18 20:59:24 -06:00
if (permission_exists('bridge_edit')) {
$list_row_url = "bridge_edit.php?id=".urlencode($row['bridge_uuid']);
if ($row['domain_uuid'] != $_SESSION['domain_uuid'] && permission_exists('domain_select')) {
$list_row_url .= '&domain_uuid='.urlencode($row['domain_uuid']).'&domain_change=true';
}
2018-03-18 20:59:24 -06:00
}
2019-10-19 16:57:41 -06:00
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('bridge_add') || permission_exists('bridge_edit') || permission_exists('bridge_delete')) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='bridges[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='bridges[$x][uuid]' value='".escape($row['bridge_uuid'])."' />\n";
echo " </td>\n";
}
2023-05-19 23:47:47 +00:00
if (!empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('bridge_all')) {
2024-02-26 09:28:17 -07:00
echo " <td>".escape($row['domain_name'])."</td>\n";
}
2019-11-30 15:56:06 -07:00
echo " <td>\n";
if (permission_exists('bridge_edit')) {
2019-11-30 15:56:06 -07:00
echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['bridge_name'])."</a>\n";
}
else {
2019-11-30 15:56:06 -07:00
echo " ".escape($row['bridge_name']);
}
echo " </td>\n";
2019-10-19 16:57:41 -06:00
echo " <td>".escape($row['bridge_destination'])."</td>\n";
if (permission_exists('bridge_edit')) {
2019-11-30 15:56:06 -07:00
echo " <td class='no-link center'>\n";
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['bridge_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
}
else {
2019-11-30 15:56:06 -07:00
echo " <td class='center'>\n";
echo $text['label-'.$row['bridge_enabled']];
}
echo " </td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row['bridge_description'])."</td>\n";
2025-03-04 14:25:47 -04:00
if (permission_exists('bridge_edit') && $list_row_edit_button) {
2019-11-30 15:56:06 -07:00
echo " <td class='action-button'>\n";
2019-10-19 16:57:41 -06:00
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";
2018-03-18 20:59:24 -06:00
}
echo "</tr>\n";
$x++;
}
2019-10-19 16:57:41 -06:00
unset($bridges);
}
2018-03-18 20:59:24 -06:00
echo "</table>\n";
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
2019-09-19 08:49:34 -06:00
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
2018-03-18 20:59:24 -06:00
echo "</form>\n";
2024-09-05 16:10:04 -07:00
echo "</div>\n";
2018-03-18 20:59:24 -06:00
//include the footer
require_once "resources/footer.php";
2019-11-30 12:04:42 -07:00
?>