From ea6a02d5f033f1d2e1e5feb80b2ae8919d2803e1 Mon Sep 17 00:00:00 2001 From: Alex <40072887+alexdcrane@users.noreply.github.com> Date: Thu, 16 Apr 2026 22:55:52 +0000 Subject: [PATCH] Call Centers: Preserve query string parameters across list and edit pages (#7879) * Call Centers: Preserve query string parameters across list and edit pages * Update call_center_queue_edit.php * Update call_center_agents.php --- app/call_centers/call_center_agent_edit.php | 34 +++++- app/call_centers/call_center_agents.php | 129 +++++++++++--------- app/call_centers/call_center_queue_edit.php | 35 +++++- app/call_centers/call_center_queues.php | 111 +++++++++-------- 4 files changed, 189 insertions(+), 120 deletions(-) diff --git a/app/call_centers/call_center_agent_edit.php b/app/call_centers/call_center_agent_edit.php index 7dce3b92a..1fa8f8306 100644 --- a/app/call_centers/call_center_agent_edit.php +++ b/app/call_centers/call_center_agent_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) 2008-2025 + Portions created by the Initial Developer are Copyright (C) 2008-2026 the Initial Developer. All Rights Reserved. Contributor(s): @@ -44,6 +44,32 @@ $agent_name = ''; $agent_password = ''; +// Set variables from GET parameters + $page = is_numeric($_GET['page'] ?? '') ? $_GET['page'] : 0; + $order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'agent_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('call_center_all')) { + $param['show'] = $show; + } + $query_string = http_build_query($param); + //action add or update if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $action = "update"; @@ -88,7 +114,7 @@ $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); - header('Location: call_center_agents.php'); + header('Location: call_center_agents.php'.($query_string ? '?'.$query_string : '')); exit; } @@ -247,7 +273,7 @@ if ($action == "update") { message::add($text['message-update']); } - header("Location: call_center_agents.php"); + header("Location: call_center_agents.php".($query_string ? '?'.$query_string : '')); return; } } //(is_array($_POST) && empty($_POST["persistformvar"])) @@ -339,7 +365,7 @@ } echo "\n"; echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','link'=>'call_center_agents.php']); + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','link'=>'call_center_agents.php'.($query_string ? '?'.$query_string : '')]); echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','style'=>'margin-left: 15px;']); echo "
\n"; echo "
\n"; diff --git a/app/call_centers/call_center_agents.php b/app/call_centers/call_center_agents.php index f19137c4a..f84c687b2 100644 --- a/app/call_centers/call_center_agents.php +++ b/app/call_centers/call_center_agents.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) 2008-2024 + Portions created by the Initial Developer are Copyright (C) 2008-2026 the Initial Developer. All Rights Reserved. Contributor(s): @@ -39,13 +39,38 @@ $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'] ?? 'agent_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('call_center_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); //get posted data if (!empty($_POST['call_center_agents'])) { $action = $_POST['action']; - $search = $_POST['search'] ?? ''; $call_center_agents = $_POST['call_center_agents']; } @@ -60,63 +85,47 @@ break; } - header('Location: call_center_agents.php'.($search != '' ? '?search='.urlencode($search) : '')); + header('Location: call_center_agents.php'.($query_string ? '?'.$query_string : '')); exit; } -//get http variables and set them to php variables - $order_by = $_GET["order_by"] ?? ''; - $order = $_GET["order"] ?? ''; - -//add the search and show variables - $search = $_GET["search"] ?? ''; - $show = $_GET["show"] ?? ''; +//add the search term + if (!empty($search)) { + $sql_search = " ("; + $sql_search .= " lower(agent_name) like :search "; + $sql_search .= " or lower(agent_id) like :search "; + $sql_search .= ") "; + $parameters['search'] = '%'.lower_case($search).'%'; + } //get total call center agent count from the database $sql = "select count(*) from v_call_center_agents "; - if ($show == "all" && permission_exists('call_center_all')) { - $sql .= "where true "; - } - else { - $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; + $sql .= "where true "; + if ($show != "all" || !permission_exists('call_center_all')) { + $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } - if (!empty($search)) { - $sql .= "and ("; - $sql .= " lower(agent_name) like :search "; - $sql .= " or lower(agent_id) like :search "; - $sql .= ") "; - $parameters['search'] = '%'.strtolower($search).'%'; + if (!empty($sql_search)) { + $sql .= "and ".$sql_search; } $num_rows = $database->select($sql, $parameters ?? null, 'column'); //prepare to page the results $rows_per_page = $settings->get('domain', 'paging', 50); - $param = "&search=".urlencode($search); - if ($show == "all" && permission_exists('call_center_all')) { - $param .= "&show=all"; - } - $page = !empty($_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 $sql = "select * "; $sql .= "from v_call_center_agents "; - if ($show == "all" && permission_exists('call_center_all')) { - $sql .= "where true "; + $sql .= "where true "; + if ($show != "all" || !permission_exists('call_center_all')) { + $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; + $parameters['domain_uuid'] = $domain_uuid; } - else { - $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - } - if (!empty($search)) { - $sql .= "and ("; - $sql .= " lower(agent_name) like :search "; - $sql .= " or lower(agent_id) like :search "; - $sql .= ") "; - $parameters['search'] = '%'.strtolower($search).'%'; + if (!empty($sql_search)) { + $sql .= "and ".$sql_search; } $sql .= order_by($order_by, $order, 'agent_name', 'asc'); $sql .= limit_offset($rows_per_page, $offset); @@ -149,14 +158,14 @@ 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 "