Domains: Preserve query string parameters across list and edit pages (#7916)

* Domains: Preserve query string parameters across list and edit pages

* Update domain_edit.php

* Update domain_json.php

* Update domains.php

* Update domain_edit.php
This commit is contained in:
Alex
2026-04-25 21:19:52 +00:00
committed by GitHub
parent b946e5631d
commit 0ddb7c1164
3 changed files with 90 additions and 47 deletions
+34 -8
View File
@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
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):
@@ -66,6 +66,32 @@
$domain_description = $_POST["domain_description"];
}
// 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'] ?? 'domain_name'));
$order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc';
$search = $_GET['search'] ?? '';
$show = $_GET['show'] ?? '';
// Build the query string
$url_params = [];
if (!empty($page)) {
$url_params['page'] = $page;
}
if (!empty($_GET['order_by'])) {
$url_params['order_by'] = $order_by;
}
if (!empty($_GET['order'])) {
$url_params['order'] = $order;
}
if (!empty($search)) {
$url_params['search'] = $search;
}
if (!empty($show) && $show == 'all' && permission_exists('domain_all')) {
$url_params['show'] = $show;
}
$query_string = http_build_query($url_params);
//process the data
if (!empty($_POST) && empty($_POST["persistformvar"])) {
@@ -89,7 +115,7 @@
$cache->flush();
//redirect
header('Location: domains.php');
header('Location: domains.php'.($query_string ? '?'.$query_string : ''));
exit;
}
@@ -97,7 +123,7 @@
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: domains.php');
header('Location: domains.php'.($query_string ? '?'.$query_string : ''));
exit;
}
@@ -193,7 +219,7 @@
}
else {
message::add($text['message-domain_exists'],'negative');
header("Location: domains.php");
header("Location: domains.php".($query_string ? '?'.$query_string : ''));
exit;
}
}
@@ -514,15 +540,15 @@
if ($action == "update") {
message::add($text['message-update']);
if (!permission_exists('domain_add')) { //admin, updating own domain
header("Location: domain_edit.php");
header("Location: domain_edit.php".($query_string ? '?'.$query_string : ''));
}
else {
header("Location: domains.php"); //superadmin
header("Location: domains.php".($query_string ? '?'.$query_string : '')); //superadmin
}
}
if ($action == "add") {
message::add($text['message-add']);
header("Location: domains.php");
header("Location: domains.php".($query_string ? '?'.$query_string : ''));
}
exit;
}
@@ -619,7 +645,7 @@
echo " <div class='actions'>\n";
if (permission_exists('domain_add')) {
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'domains.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'=>'domains.php'.($query_string ? '?'.$query_string : '')]);
}
if ($action == "update" && permission_exists('domain_setting_view')) {
echo button::create(['type'=>'button','label'=>$text['button-settings'],'icon'=>$settings->get('theme', 'button_icon_settings'),'id'=>'btn_back','style'=>'margin-right: 2px;','link'=>PROJECT_PATH.'/core/domain_settings/domain_settings.php?id='.urlencode($domain_uuid)]);
+2 -2
View File
@@ -41,10 +41,10 @@
//add the search term
if (!empty($_GET["search"])) {
$search = strtolower($_GET["search"]);
$search = lower_case($_GET["search"]);
}
//validate the token
//validate the token
//$token = new token;
//if (!$token->validate($_SERVER['PHP_SELF'])) {
// message::add($text['message-invalid_token'],'negative');
+54 -37
View File
@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
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.
Contributor(s):
@@ -112,10 +112,35 @@
//get the http post data
if (!empty($_POST['domains'])) {
$action = $_POST['action'] ?? '';
$search = $_POST['search'] ?? '';
$domains = $_POST['domains'] ?? '';
}
// 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'] ?? 'domain_name'));
$order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc';
$search = $_GET['search'] ?? '';
$show = $_GET['show'] ?? '';
// Build the query string
$url_params = [];
if (!empty($page)) {
$url_params['page'] = $page;
}
if (!empty($_GET['order_by'])) {
$url_params['order_by'] = $order_by;
}
if (!empty($_GET['order'])) {
$url_params['order'] = $order;
}
if (!empty($search)) {
$url_params['search'] = $search;
}
if (!empty($show) && $show == 'all' && permission_exists('domain_all')) {
$url_params['show'] = $show;
}
$query_string = http_build_query($url_params);
//process the http post data by action
if (!empty($action) && !empty($domains)) {
switch ($action) {
@@ -139,51 +164,39 @@
break;
}
header('Location: domains.php'.(!empty($search) ? '?search='.urlencode($search) : ''));
header('Location: domains.php'.($query_string ? '?'.$query_string : ''));
exit;
}
//get order and order by and sanitize the values
$order_by = $_GET["order_by"] ?? '';
$order = $_GET["order"] ?? '';
//set additional variables
$search = $_GET["search"] ?? '';
$show = $_GET["show"] ?? '';
//set from session variables
$list_row_edit_button = $settings->get('theme', 'list_row_edit_button', false);
//add the search string
if (!empty($search)) {
$search = strtolower($_GET["search"]);
$sql_search = " (";
$sql_search .= " lower(domain_name) like :search ";
$sql_search .= " or lower(domain_description) like :search ";
$sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
}
//get the count
$sql = "select count(domain_uuid) from v_domains ";
if (!empty($sql_search)) {
$sql .= "where ".$sql_search;
if (!empty($search)) {
$sql .= "where (";
$sql .= " lower(domain_name) like :search ";
$sql .= " or lower(domain_description) like :search ";
$sql .= ") ";
$parameters['search'] = '%'.lower_case($search).'%';
}
$num_rows = $database->select($sql, $parameters ?? null, 'column');
//prepare to page the results
$rows_per_page = $settings->get('domain', 'paging', 50);
$param = $search ? "&search=".$search : null;
$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 domain_uuid, domain_name, cast(domain_enabled as text), domain_description ";
$sql .= "from v_domains ";
if (!empty($sql_search)) {
$sql .= "where ".$sql_search;
if (!empty($search)) {
$sql .= "where (";
$sql .= " lower(domain_name) like :search ";
$sql .= " or lower(domain_description) like :search ";
$sql .= ") ";
$parameters['search'] = '%'.lower_case($search).'%';
}
$sql .= order_by($order_by, $order, 'domain_name', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
@@ -211,12 +224,17 @@
if (permission_exists('domain_delete') && $domains) {
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_display_selected('modal-delete'); modal_open('modal-delete','btn_delete_domain');"]);
}
echo "<form id='form_search' class='inline' method='get'>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
echo " <form id='form_search' class='inline' method='get'>\n";
foreach ($url_params as $key => $value) {
if ($key !== 'search' && $key !== 'page') {
echo " <input type='hidden' name='".escape($key)."' value='".escape($value)."'>\n";
}
}
echo " <input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
echo button::create(['label'=>$text['button-search'],'icon'=>$settings->get('theme', 'button_icon_search'),'type'=>'submit','id'=>'btn_search']);
//echo button::create(['label'=>$text['button-reset'],'icon'=>$settings->get('theme', 'button_icon_reset'),'type'=>'button','id'=>'btn_reset','link'=>'domains.php','style'=>($search == '' ? 'display: none;' : null)]);
if (!empty($paging_controls_mini)) {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
echo " <span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
}
echo " </form>\n";
echo " </div>\n";
@@ -235,7 +253,6 @@
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<div class='card'>\n";
echo "<table class='list'>\n";
@@ -246,11 +263,11 @@
echo " </th>\n";
}
if ($show == 'all' && permission_exists('domain_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('domain_name', $text['label-domain_name'], $order_by, $order);
echo th_order_by('domain_name', $text['label-domain_name'], $order_by, $order, null, null, $query_string);
echo "<th class='center'>".$text['label-tools']."</th>";
echo th_order_by('domain_enabled', $text['label-domain_enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('domain_enabled', $text['label-domain_enabled'], $order_by, $order, null, "class='center'", $query_string);
echo " <th class='hide-sm-dn'>".$text['label-domain_description']."</th>\n";
if (permission_exists('domain_edit') && $list_row_edit_button) {
echo " <td class='action-button'>&nbsp;</td>\n";
@@ -262,7 +279,7 @@
foreach ($domains as $row) {
$list_row_url = '';
if (permission_exists('domain_edit')) {
$list_row_url = "domain_edit.php?id=".urlencode($row['domain_uuid']);
$list_row_url = "domain_edit.php?id=".urlencode($row['domain_uuid']).($query_string ? '&'.$query_string : '');
}
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('domain_edit') || permission_exists('domain_delete')) {