From 9dbdbc1ce32a48a9fa67b91d63ff1ddfbaedd650 Mon Sep 17 00:00:00 2001 From: Alex <40072887+alexdcrane@users.noreply.github.com> Date: Wed, 22 Apr 2026 21:00:42 +0000 Subject: [PATCH] Queues: Preserve query string parameters across list and edit pages (#7901) * Queues: Preserve query string parameters across list and edit pages * Update fifo_edit.php * Update fifo.php --- app/fifo/fifo.php | 99 ++++++++++++++++++++++-------------------- app/fifo/fifo_edit.php | 36 ++++++++++++--- 2 files changed, 83 insertions(+), 52 deletions(-) diff --git a/app/fifo/fifo.php b/app/fifo/fifo.php index 6e41a2de7..e4268b41f 100644 --- a/app/fifo/fifo.php +++ b/app/fifo/fifo.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. */ @@ -42,10 +42,35 @@ //set from session variables $list_row_edit_button = $settings->get('theme', 'list_row_edit_button', 'false'); +// Set variables from http GET parameters + $page = is_numeric($_GET['page'] ?? '') ? $_GET['page'] : 0; + $order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'fifo_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('fifo_all')) { + $param['show'] = $show; + } + $query_string = http_build_query($param); + //get the http post data if (!empty($_POST['fifo']) && is_array($_POST['fifo'])) { $action = $_POST['action']; - $search = $_POST['search'] ?? ''; $fifo = $_POST['fifo']; } @@ -56,7 +81,7 @@ $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); - header('Location: fifo.php'); + header('Location: fifo.php'.($query_string ? '?'.$query_string : '')); exit; } @@ -83,29 +108,13 @@ } //redirect the user - header('Location: fifo.php'.($search != '' ? '?search='.urlencode($search) : '')); + header('Location: fifo.php'.($query_string ? '?'.$query_string : '')); exit; } -//get order and order by - $order_by = $_GET["order_by"] ?? null; - $order = $_GET["order"] ?? null; - //define the variables - $search = ''; - $show = ''; $list_row_url = ''; -//add the search variable - if (!empty($_GET["search"])) { - $search = strtolower($_GET["search"]); - } - -//add the show variable - if (!empty($_GET["show"])) { - $show = $_GET["show"]; - } - //get the count $sql = "select count(fifo_uuid) "; $sql .= "from v_fifo "; @@ -122,18 +131,15 @@ $sql .= " or lower(fifo_extension) like :search "; $sql .= " or lower(fifo_description) like :search "; $sql .= ") "; - $parameters['search'] = '%'.$search.'%'; + $parameters['search'] = '%'.lower_case($search).'%'; } $num_rows = $database->select($sql, $parameters ?? null, 'column'); unset($sql, $parameters); //prepare to page the results $rows_per_page = $settings->get('domain', 'paging', 50); - $param = !empty($search) ? "&search=".$search : null; - $param .= (!empty($_GET['page']) && $show == 'all' && permission_exists('fifo_all')) ? "&show=all" : null; - $page = !empty($_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 @@ -163,7 +169,7 @@ $sql .= " or lower(fifo_extension) like :search "; $sql .= " or lower(fifo_description) like :search "; $sql .= ") "; - $parameters['search'] = '%'.$search.'%'; + $parameters['search'] = '%'.lower_case($search).'%'; } $sql .= "and u.domain_uuid = d.domain_uuid "; $sql .= order_by($order_by, $order, '', ''); @@ -184,7 +190,7 @@ echo "
".$text['title-fifos']."
".number_format($num_rows)."
\n"; echo "
\n"; if (permission_exists('fifo_add')) { - echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','name'=>'btn_add','link'=>'fifo_edit.php']); + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','name'=>'btn_add','link'=>'fifo_edit.php'.($query_string ? '?'.$query_string : '')]); } // if (permission_exists('fifo_add') && $fifo) { // 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');"]); @@ -195,19 +201,19 @@ if (permission_exists('fifo_delete') && $fifo) { 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"; @@ -229,7 +235,6 @@ echo "
\n"; echo "\n"; - echo "\n"; echo "
\n"; echo "\n"; @@ -240,14 +245,14 @@ echo " \n"; } if ($show == 'all' && permission_exists('fifo_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, $query_string); } - echo th_order_by('fifo_name', $text['label-fifo_name'], $order_by, $order); - echo th_order_by('fifo_extension', $text['label-fifo_extension'], $order_by, $order); - echo th_order_by('fifo_agent_status', $text['label-fifo_agent_status'], $order_by, $order); - echo th_order_by('fifo_agent_queue', $text['label-fifo_agent_queue'], $order_by, $order); - echo th_order_by('fifo_order', $text['label-fifo_order'], $order_by, $order); - echo th_order_by('fifo_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'"); + echo th_order_by('fifo_name', $text['label-fifo_name'], $order_by, $order, null, null, $query_string); + echo th_order_by('fifo_extension', $text['label-fifo_extension'], $order_by, $order, null, null, $query_string); + echo th_order_by('fifo_agent_status', $text['label-fifo_agent_status'], $order_by, $order, null, null, $query_string); + echo th_order_by('fifo_agent_queue', $text['label-fifo_agent_queue'], $order_by, $order, null, null, $query_string); + echo th_order_by('fifo_order', $text['label-fifo_order'], $order_by, $order, null, null, $query_string); + echo th_order_by('fifo_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'", $query_string); echo " \n"; if (permission_exists('fifo_edit') && $list_row_edit_button == 'true') { echo " \n"; @@ -258,7 +263,7 @@ $x = 0; foreach ($fifo as $row) { if (permission_exists('fifo_edit')) { - $list_row_url = "fifo_edit.php?id=".urlencode($row['fifo_uuid']); + $list_row_url = "fifo_edit.php?id=".urlencode($row['fifo_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'; } @@ -317,4 +322,4 @@ //include the footer require_once "resources/footer.php"; -?> \ No newline at end of file +?> diff --git a/app/fifo/fifo_edit.php b/app/fifo/fifo_edit.php index 37a5877d9..223589833 100644 --- a/app/fifo/fifo_edit.php +++ b/app/fifo/fifo_edit.php @@ -18,7 +18,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2024-2025 + Portions created by the Initial Developer are Copyright (C) 2024-2026 the Initial Developer. All Rights Reserved. */ @@ -54,6 +54,32 @@ $button_icon_save = $settings->get('theme', 'button_icon_save', ''); $input_toggle_style = $settings->get('theme', 'input_toggle_style', 'switch round'); +// Set variables from http GET parameters + $page = is_numeric($_GET['page'] ?? '') ? $_GET['page'] : 0; + $order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'fifo_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('fifo_all')) { + $param['show'] = $show; + } + $query_string = http_build_query($param); + //action add or update if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $action = "update"; @@ -90,7 +116,7 @@ $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); - header('Location: fifo.php'); + header('Location: fifo.php'.($query_string ? '?'.$query_string : '')); exit; } @@ -130,7 +156,7 @@ //redirect the user if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) { - header('Location: fifo_edit.php?id='.$id); + header('Location: fifo_edit.php?id='.$id.($query_string ? '&'.$query_string : '')); exit; } } @@ -376,7 +402,7 @@ } //header('Location: fifo.php'); - header('Location: fifo_edit.php?id='.urlencode($fifo_uuid)); + header('Location: fifo_edit.php?id='.urlencode($fifo_uuid).($query_string ? '&'.$query_string : '')); return; } } @@ -510,7 +536,7 @@ echo "
\n"; echo "
".$text['title-fifo']."
\n"; echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$button_icon_back,'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'fifo.php']); + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$button_icon_back,'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'fifo.php'.($query_string ? '?'.$query_string : '')]); if ($action == 'update') { if (permission_exists('fifo_member_delete')) { echo button::create(['type'=>'submit','label'=>$text['button-delete'],'icon'=>$button_icon_delete,'id'=>'btn_delete','name'=>'action','value'=>'delete','style'=>'display: none; margin-right: 15px;']);
".$text['label-fifo_description']."