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:
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
The Initial Developer of the Original Code is
|
The Initial Developer of the Original Code is
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
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.
|
the Initial Developer. All Rights Reserved.
|
||||||
|
|
||||||
Contributor(s):
|
Contributor(s):
|
||||||
@@ -66,6 +66,32 @@
|
|||||||
$domain_description = $_POST["domain_description"];
|
$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
|
//process the data
|
||||||
if (!empty($_POST) && empty($_POST["persistformvar"])) {
|
if (!empty($_POST) && empty($_POST["persistformvar"])) {
|
||||||
|
|
||||||
@@ -89,7 +115,7 @@
|
|||||||
$cache->flush();
|
$cache->flush();
|
||||||
|
|
||||||
//redirect
|
//redirect
|
||||||
header('Location: domains.php');
|
header('Location: domains.php'.($query_string ? '?'.$query_string : ''));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +123,7 @@
|
|||||||
$token = new token;
|
$token = new token;
|
||||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||||
message::add($text['message-invalid_token'],'negative');
|
message::add($text['message-invalid_token'],'negative');
|
||||||
header('Location: domains.php');
|
header('Location: domains.php'.($query_string ? '?'.$query_string : ''));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +219,7 @@
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
message::add($text['message-domain_exists'],'negative');
|
message::add($text['message-domain_exists'],'negative');
|
||||||
header("Location: domains.php");
|
header("Location: domains.php".($query_string ? '?'.$query_string : ''));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -514,15 +540,15 @@
|
|||||||
if ($action == "update") {
|
if ($action == "update") {
|
||||||
message::add($text['message-update']);
|
message::add($text['message-update']);
|
||||||
if (!permission_exists('domain_add')) { //admin, updating own domain
|
if (!permission_exists('domain_add')) { //admin, updating own domain
|
||||||
header("Location: domain_edit.php");
|
header("Location: domain_edit.php".($query_string ? '?'.$query_string : ''));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
header("Location: domains.php"); //superadmin
|
header("Location: domains.php".($query_string ? '?'.$query_string : '')); //superadmin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($action == "add") {
|
if ($action == "add") {
|
||||||
message::add($text['message-add']);
|
message::add($text['message-add']);
|
||||||
header("Location: domains.php");
|
header("Location: domains.php".($query_string ? '?'.$query_string : ''));
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -619,7 +645,7 @@
|
|||||||
echo " <div class='actions'>\n";
|
echo " <div class='actions'>\n";
|
||||||
|
|
||||||
if (permission_exists('domain_add')) {
|
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')) {
|
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)]);
|
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)]);
|
||||||
|
|||||||
@@ -41,10 +41,10 @@
|
|||||||
|
|
||||||
//add the search term
|
//add the search term
|
||||||
if (!empty($_GET["search"])) {
|
if (!empty($_GET["search"])) {
|
||||||
$search = strtolower($_GET["search"]);
|
$search = lower_case($_GET["search"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//validate the token
|
//validate the token
|
||||||
//$token = new token;
|
//$token = new token;
|
||||||
//if (!$token->validate($_SERVER['PHP_SELF'])) {
|
//if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||||
// message::add($text['message-invalid_token'],'negative');
|
// message::add($text['message-invalid_token'],'negative');
|
||||||
|
|||||||
+54
-37
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
The Initial Developer of the Original Code is
|
The Initial Developer of the Original Code is
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
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.
|
the Initial Developer. All Rights Reserved.
|
||||||
|
|
||||||
Contributor(s):
|
Contributor(s):
|
||||||
@@ -112,10 +112,35 @@
|
|||||||
//get the http post data
|
//get the http post data
|
||||||
if (!empty($_POST['domains'])) {
|
if (!empty($_POST['domains'])) {
|
||||||
$action = $_POST['action'] ?? '';
|
$action = $_POST['action'] ?? '';
|
||||||
$search = $_POST['search'] ?? '';
|
|
||||||
$domains = $_POST['domains'] ?? '';
|
$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
|
//process the http post data by action
|
||||||
if (!empty($action) && !empty($domains)) {
|
if (!empty($action) && !empty($domains)) {
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
@@ -139,51 +164,39 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
header('Location: domains.php'.(!empty($search) ? '?search='.urlencode($search) : ''));
|
header('Location: domains.php'.($query_string ? '?'.$query_string : ''));
|
||||||
exit;
|
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
|
//set from session variables
|
||||||
$list_row_edit_button = $settings->get('theme', 'list_row_edit_button', false);
|
$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
|
//get the count
|
||||||
$sql = "select count(domain_uuid) from v_domains ";
|
$sql = "select count(domain_uuid) from v_domains ";
|
||||||
if (!empty($sql_search)) {
|
if (!empty($search)) {
|
||||||
$sql .= "where ".$sql_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');
|
$num_rows = $database->select($sql, $parameters ?? null, 'column');
|
||||||
|
|
||||||
//prepare to page the results
|
//prepare to page the results
|
||||||
$rows_per_page = $settings->get('domain', 'paging', 50);
|
$rows_per_page = $settings->get('domain', 'paging', 50);
|
||||||
$param = $search ? "&search=".$search : null;
|
list($paging_controls, $rows_per_page) = paging($num_rows, $query_string, $rows_per_page);
|
||||||
$page = !empty($_GET['page']) ? $_GET['page'] : 0;
|
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $query_string, $rows_per_page, true);
|
||||||
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);
|
|
||||||
$offset = $rows_per_page * $page;
|
$offset = $rows_per_page * $page;
|
||||||
|
|
||||||
//get the list
|
//get the list
|
||||||
$sql = "select domain_uuid, domain_name, cast(domain_enabled as text), domain_description ";
|
$sql = "select domain_uuid, domain_name, cast(domain_enabled as text), domain_description ";
|
||||||
$sql .= "from v_domains ";
|
$sql .= "from v_domains ";
|
||||||
if (!empty($sql_search)) {
|
if (!empty($search)) {
|
||||||
$sql .= "where ".$sql_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 .= order_by($order_by, $order, 'domain_name', 'asc');
|
||||||
$sql .= limit_offset($rows_per_page, $offset);
|
$sql .= limit_offset($rows_per_page, $offset);
|
||||||
@@ -211,12 +224,17 @@
|
|||||||
if (permission_exists('domain_delete') && $domains) {
|
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 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 " <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=''>";
|
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-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)]);
|
//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)) {
|
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 " </form>\n";
|
||||||
echo " </div>\n";
|
echo " </div>\n";
|
||||||
@@ -235,7 +253,6 @@
|
|||||||
|
|
||||||
echo "<form id='form_list' method='post'>\n";
|
echo "<form id='form_list' method='post'>\n";
|
||||||
echo "<input type='hidden' id='action' name='action' value=''>\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 "<div class='card'>\n";
|
||||||
echo "<table class='list'>\n";
|
echo "<table class='list'>\n";
|
||||||
@@ -246,11 +263,11 @@
|
|||||||
echo " </th>\n";
|
echo " </th>\n";
|
||||||
}
|
}
|
||||||
if ($show == 'all' && permission_exists('domain_all')) {
|
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 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";
|
echo " <th class='hide-sm-dn'>".$text['label-domain_description']."</th>\n";
|
||||||
if (permission_exists('domain_edit') && $list_row_edit_button) {
|
if (permission_exists('domain_edit') && $list_row_edit_button) {
|
||||||
echo " <td class='action-button'> </td>\n";
|
echo " <td class='action-button'> </td>\n";
|
||||||
@@ -262,7 +279,7 @@
|
|||||||
foreach ($domains as $row) {
|
foreach ($domains as $row) {
|
||||||
$list_row_url = '';
|
$list_row_url = '';
|
||||||
if (permission_exists('domain_edit')) {
|
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";
|
echo "<tr class='list-row' href='".$list_row_url."'>\n";
|
||||||
if (permission_exists('domain_edit') || permission_exists('domain_delete')) {
|
if (permission_exists('domain_edit') || permission_exists('domain_delete')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user