From 66c11988bec0ff90aa0c4948b8239d69f3447e8b Mon Sep 17 00:00:00 2001 From: Alex <40072887+alexdcrane@users.noreply.github.com> Date: Wed, 15 Apr 2026 21:01:26 +0000 Subject: [PATCH] Bridges: Preserve query string parameters across list and edit pages (#7875) * Bridges: Preserve query string parameters across list and edit page * Update bridge_edit.php --- app/bridges/bridge_edit.php | 40 +++++++++++++++---- app/bridges/bridges.php | 78 +++++++++++++++++++++---------------- 2 files changed, 78 insertions(+), 40 deletions(-) diff --git a/app/bridges/bridge_edit.php b/app/bridges/bridge_edit.php index a96c05be4..3cd906354 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-2025 + Portions created by the Initial Developer are Copyright (C) 2018-2026 the Initial Developer. All Rights Reserved. */ @@ -35,6 +35,32 @@ $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"; @@ -78,7 +104,7 @@ $obj = new bridges; $obj->delete($array); //redirect - header('Location: bridges.php'); + header('Location: bridges.php'.($query_string ? '?'.$query_string : '')); exit; } } @@ -92,7 +118,7 @@ $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); - header('Location: bridges.php'); + header('Location: bridges.php'.($query_string ? '?'.$query_string : '')); exit; } @@ -182,14 +208,14 @@ if ($action == "update") { $_SESSION["message"] = $text['message-update']; } - header('Location: bridges.php'); + header('Location: bridges.php'.($query_string ? '?'.$query_string : '')); return; } } //pre-populate the form - if (!empty($_GET) && is_array($_GET) && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) { - $bridge_uuid = $_GET["id"]; + if (!empty($_GET['id']) && is_uuid($_GET['id']) && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) { + $bridge_uuid = $_GET['id']; $sql = "select * from v_bridges "; $sql .= "where bridge_uuid = :bridge_uuid "; $parameters['bridge_uuid'] = $bridge_uuid; @@ -399,7 +425,7 @@ echo "
\n"; echo "
".$text['title-bridge']."
\n"; echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'bridges.php']); + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'bridges.php'.($query_string ? '?'.$query_string : '')]); if ($action == 'update' && permission_exists('bridge_delete')) { echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('theme', 'button_icon_delete'),'name'=>'btn_delete','style'=>'margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } diff --git a/app/bridges/bridges.php b/app/bridges/bridges.php index 85a455386..30d941b44 100644 --- a/app/bridges/bridges.php +++ b/app/bridges/bridges.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-2024 + Portions created by the Initial Developer are Copyright (C) 2018-2026 the Initial Developer. All Rights Reserved. Contributor(s): @@ -39,9 +39,31 @@ $language = new text; $text = $language->get(); -//set additional variables - $search = $_GET["search"] ?? ''; - $show = $_GET["show"] ?? ''; +// 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); //set from session variables $list_row_edit_button = $settings->get('theme', 'list_row_edit_button', false); @@ -49,7 +71,6 @@ //get the http post data if (!empty($_POST['bridges'])) { $action = $_POST['action']; - $search = $_POST['search'] ?? ''; $bridges = $_POST['bridges']; } @@ -76,23 +97,18 @@ break; } - header('Location: bridges.php'.(!empty($search) ? '?search='.urlencode($search) : '')); + header('Location: bridges.php'.($query_string ? '?'.$query_string : '')); exit; } -//get order and order by - $order_by = $_GET["order_by"] ?? ''; - $order = $_GET["order"] ?? ''; - //add the search string if (!empty($search)) { - $search = strtolower($_GET["search"]); $sql_search = " ("; $sql_search .= " lower(bridge_name) like :search "; $sql_search .= " or lower(bridge_destination) like :search "; $sql_search .= " or lower(bridge_description) like :search "; $sql_search .= ") "; - $parameters['search'] = '%'.$search.'%'; + $parameters['search'] = '%'.strtolower($search).'%'; } //get the count @@ -113,11 +129,8 @@ //prepare to page the results $rows_per_page = $settings->get('domain', 'paging', 50); - $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); + list($paging_controls, $rows_per_page) = paging($num_rows, $query_string, $rows_per_page); + list($paging_controls_mini, $rows_per_page) = paging($num_rows, $query_string, $rows_per_page, true); $offset = $rows_per_page * $page; //get the list @@ -157,7 +170,7 @@ echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$settings->get('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'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','link'=>'bridge_edit.php']); + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','link'=>'bridge_edit.php'.($query_string ? '?'.$query_string : '')]); } if (permission_exists('bridge_add') && $bridges) { echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$settings->get('theme', 'button_icon_copy'),'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); @@ -168,20 +181,20 @@ if (permission_exists('bridge_delete') && $bridges) { echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('theme', 'button_icon_delete'),'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } - echo "\n"; echo "
\n"; @@ -204,7 +217,6 @@ echo "
\n"; echo "
\n"; echo "\n"; - echo "\n"; echo "\n"; echo "\n"; @@ -214,11 +226,11 @@ echo " \n"; } if (!empty($show) && $show == 'all' && permission_exists('bridge_all')) { - echo th_order_by('domain_name', $text['label-domain'], $order_by, $order); + echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, null, null, $param); } - echo th_order_by('bridge_name', $text['label-bridge_name'], $order_by, $order); - echo th_order_by('bridge_destination', $text['label-bridge_destination'], $order_by, $order); - echo th_order_by('bridge_enabled', $text['label-bridge_enabled'], $order_by, $order, null, "class='center'"); + echo th_order_by('bridge_name', $text['label-bridge_name'], $order_by, $order, null, null, $param); + echo th_order_by('bridge_destination', $text['label-bridge_destination'], $order_by, $order, null, null, $param); + echo th_order_by('bridge_enabled', $text['label-bridge_enabled'], $order_by, $order, null, "class='center'", $param); echo " \n"; if (permission_exists('bridge_edit') && $list_row_edit_button) { echo " \n"; @@ -230,7 +242,7 @@ foreach ($bridges as $row) { $list_row_url = ''; if (permission_exists('bridge_edit')) { - $list_row_url = "bridge_edit.php?id=".urlencode($row['bridge_uuid']); + $list_row_url = "bridge_edit.php?id=".urlencode($row['bridge_uuid']).($query_string ? '&'.$query_string : ''); if ($row['domain_uuid'] != $_SESSION['domain_uuid'] && permission_exists('domain_select')) { $list_row_url .= '&domain_uuid='.urlencode($row['domain_uuid']).'&domain_change=true'; }
".$text['label-bridge_description']."