Default Settings: Preserve query string parameters across list and edit pages (#7912)

* Default Settings: Preserve query string parameters across list and edit pages

* Update default_settings_reload.php

* Update default_setting_toggle.php

* Update default_setting_edit.php
This commit is contained in:
Alex
2026-04-23 16:45:14 +00:00
committed by GitHub
parent fd4d2d6662
commit fd6bd83bc5
4 changed files with 121 additions and 50 deletions
+27 -21
View File
@@ -46,7 +46,6 @@
$default_setting_order = '';
$default_setting_enabled = true;
$default_setting_description = '';
$search = '';
//action add or update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
@@ -57,11 +56,6 @@
$action = "add";
}
//get the search variable
if (!empty($_REQUEST['search'])) {
$search = $_REQUEST['search'] ?? '';
}
//get http post variables and set them to php variables
if (!empty($_REQUEST)) {
$default_setting_category = strtolower($_REQUEST["default_setting_category"] ?? '');
@@ -73,23 +67,35 @@
$default_setting_description = $_POST["default_setting_description"] ?? '';
}
//sanitize the variables
if (!empty($search)) {
$search = preg_replace('#[^a-zA-Z0-9_\-\. ]#', '', $search);
}
if (!empty($domain_setting_category)) {
$default_setting_category = preg_replace('#[^a-zA-Z0-9_\-\. ]#', '', $default_setting_category);
}
// Set variables from http GET parameters
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'default_setting_category'));
$order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc';
$search = $_GET['search'] ?? '';
$show = $_GET['show'] ?? '';
$default_setting_category = $_GET['default_setting_category'] ?? '';
//build the query string
$query_string = '';
//sanitize the variables
$search = preg_replace('#[^a-zA-Z0-9_\-\. ]#', '', $search);
$default_setting_category = preg_replace('#[^a-zA-Z0-9_\-\.]#', '', $default_setting_category);
// Build the query string
$param = [];
if (!empty($_GET['order_by'])) {
$param['order_by'] = $order_by;
}
if (!empty($_GET['order'])) {
$param['order'] = $order;
}
if (!empty($search)) {
$query_string .= 'search='.urlencode($search);
$param['search'] = $search;
}
if ($default_setting_category != '') {
if ($query_string == '') { $query_string = ''; } else { $query_string .= '&'; }
$query_string .= 'default_setting_category='.urlencode($default_setting_category);
if (!empty($show) && $show == 'all' && permission_exists('stream_all')) {
$param['show'] = $show;
}
if (!empty($default_setting_category)) {
$param['default_setting_category'] = $default_setting_category;
}
$query_string = http_build_query($param);
//process the http post
if (!empty($_POST) && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) {
@@ -106,7 +112,7 @@
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: default_settings.php?'.$query_string);
header('Location: default_settings.php'.($query_string ? '?'.$query_string : ''));
exit;
}
@@ -283,7 +289,7 @@
}
echo " </div>\n";
echo " <div class='actions'>\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'=>'default_settings.php?'.$query_string]);
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'default_settings.php'.($query_string ? '?'.$query_string : '')]);
echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','onclick'=>'submit_form();']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
@@ -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-2021
Portions created by the Initial Developer are Copyright (C) 2008-2026
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -39,9 +39,34 @@
$text = $language->get();
//get submitted variables
$search = $_REQUEST['search'] ?? '';
$default_setting_uuids = $_REQUEST["id"];
// Set variables from http GET parameters
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'default_setting_category'));
$order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc';
$search = $_GET['search'] ?? '';
$show = $_GET['show'] ?? '';
$default_setting_category = $_GET['default_setting_category'] ?? '';
// Build the query string
$param = [];
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('stream_all')) {
$param['show'] = $show;
}
if (!empty($default_setting_category)) {
$param['default_setting_category'] = $default_setting_category;
}
$query_string = http_build_query($param);
//toggle the setting
$toggled = 0;
if (is_array($default_setting_uuids) && sizeof($default_setting_uuids) > 0) {
@@ -72,7 +97,6 @@
}
//redirect the user
$search = preg_replace('#[^a-zA-Z0-9_\-\.]# ', '', $search);
header("Location: default_settings.php".($search != '' ? '?search='.$search : null));
header("Location: default_settings.php".($query_string ? '?'.$query_string : ''));
?>
+38 -21
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 - 2024
Portions created by the Initial Developer are Copyright (C) 2008 - 2026
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -48,9 +48,6 @@
$text = $language->get();
//set the variables
$search = $_REQUEST['search'] ?? '';
$show = $_REQUEST['show'] ?? '';
$default_setting_category = $_REQUEST['default_setting_category'] ?? '';
if (!empty($_POST['default_settings'])) {
$action = $_POST['action'];
$domain_uuid = $_POST['domain_uuid'];
@@ -61,6 +58,13 @@
$default_settings = '';
}
// Set variables from http GET parameters
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'default_setting_category'));
$order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc';
$search = $_GET['search'] ?? '';
$show = $_GET['show'] ?? '';
$default_setting_category = $_GET['default_setting_category'] ?? '';
//sanitize the variables
$action = preg_replace('#[^a-zA-Z0-9_\-\.]#', '', $action);
$search = preg_replace('#[^a-zA-Z0-9_\-\. ]#', '', $search);
@@ -78,15 +82,24 @@
//set from session variables
$list_row_edit_button = $settings->get('theme', 'list_row_edit_button', false);
//build the query string
$query_string = '';
// Build the query string
$param = [];
if (!empty($_GET['order_by'])) {
$param['order_by'] = $order_by;
}
if (!empty($_GET['order'])) {
$param['order'] = $order;
}
if (!empty($search)) {
$query_string .= 'search='.urlencode($search);
$param['search'] = $search;
}
if (!empty($show) && $show == 'all' && permission_exists('stream_all')) {
$param['show'] = $show;
}
if (!empty($default_setting_category)) {
if ($query_string == '') { $query_string = ''; } else { $query_string .= '&'; }
$query_string .= 'default_setting_category='.urlencode($default_setting_category);
$param['default_setting_category'] = $default_setting_category;
}
$query_string = http_build_query($param);
//process the http post data by action
if (!empty($action) && !empty($default_settings)) {
@@ -111,7 +124,7 @@
}
break;
}
header('Location: default_settings.php?'.(!empty($query_string) ? $query_string : null));
header('Location: default_settings.php'.($query_string ? '?'.$query_string : ''));
exit;
}
@@ -293,9 +306,9 @@
echo " <div class='heading'><b>".$text['title-default_settings']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['label-domain'],'icon'=>$settings->get('theme', 'button_icon_domain'),'style'=>'','link'=>PROJECT_PATH.'/core/domain_settings/domain_settings.php?id='.$domain_uuid]);
echo button::create(['label'=>$text['button-reload'],'icon'=>$settings->get('theme', 'button_icon_reload'),'type'=>'button','id'=>'button_reload','link'=>'default_settings_reload.php'.(!empty($search) ? '?search='.urlencode($search) : ''),'style'=>'margin-right: 15px;']);
echo button::create(['label'=>$text['button-reload'],'icon'=>$settings->get('theme', 'button_icon_reload'),'type'=>'button','id'=>'button_reload','link'=>'default_settings_reload.php'.($query_string ? '?'.$query_string : ''),'style'=>'margin-right: 15px;']);
if ($permission['default_setting_add']) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','link'=>'default_setting_edit.php?'.$query_string]);
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','link'=>'default_setting_edit.php'.($query_string ? '?'.$query_string : '')]);
}
if ($permission['default_setting_add'] && !empty($default_settings)) {
if ($permission['domain_select'] && $permission['domain_setting_add']) {
@@ -317,7 +330,12 @@
if ($permission['default_setting_delete'] && $default_settings) {
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 "<form id='form_search' class='inline' method='get'>\n";
echo " <form id='form_search' class='inline' method='get'>\n";
foreach ($param as $key => $value) {
if ($key !== 'search' && $key !== 'page') {
echo " <input type='hidden' name='".escape($key)."' value='".escape($value)."'>\n";
}
}
if (!empty($categories)) {
echo "<select name='default_setting_category' class='formfld' style='width: auto; margin-left: 15px;' id='select_category' onchange='this.form.submit();'>\n";
echo " <option value=''>".$text['label-category']."...</option>\n";
@@ -331,7 +349,7 @@
echo " <option value=''>".$text['label-all']."</option>\n";
echo " </select>";
}
echo "<input type='text' class='txt list-search' name='search' id='search' style='margin-left: 0 !important;' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
echo " <input type='text' class='txt list-search' name='search' id='search' style='margin-left: 0 !important;' 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'=>'default_settings.php','style'=>($search == '' ? 'display: none;' : null)]);
//if (!empty($paging_controls_mini)) {
@@ -354,7 +372,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 "<input type='hidden' name='domain_uuid' id='domain_uuid'>";
if (!empty($default_settings)) {
@@ -442,12 +459,12 @@
echo " </th>\n";
}
if ($show == 'all' && $permission['default_setting_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('default_setting_subcategory', $text['label-subcategory'], $order_by, $order, null, "class='pct-35'");
echo th_order_by('default_setting_name', $text['label-type'], $order_by, $order, null, "class='pct-10 hide-sm-dn'");
echo th_order_by('default_setting_value', $text['label-value'], $order_by, $order, null, "class='pct-30'");
echo th_order_by('default_setting_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('default_setting_subcategory', $text['label-subcategory'], $order_by, $order, null, "class='pct-35'", $query_string);
echo th_order_by('default_setting_name', $text['label-type'], $order_by, $order, null, "class='pct-10 hide-sm-dn'", $query_string);
echo th_order_by('default_setting_value', $text['label-value'], $order_by, $order, null, "class='pct-30'", $query_string);
echo th_order_by('default_setting_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'", $query_string);
echo " <th class='pct-25 hide-sm-dn'>".$text['label-description']."</th>\n";
if ($permission['default_setting_edit'] && $list_row_edit_button) {
echo " <td class='action-button'>&nbsp;</td>\n";
@@ -455,7 +472,7 @@
echo "</tr>\n";
}
if ($permission['default_setting_edit']) {
$list_row_url = "default_setting_edit.php?id=".urlencode($row['default_setting_uuid']).'&'.$query_string;
$list_row_url = "default_setting_edit.php?id=".urlencode($row['default_setting_uuid']).($query_string ? '&'.$query_string : '');
}
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if ($permission['default_setting_add'] || $permission['default_setting_edit'] || $permission['default_setting_delete']) {
@@ -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-2023
Portions created by the Initial Developer are Copyright (C) 2008-2026
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -39,9 +39,34 @@ $language = new text;
$text = $language->get();
//set the variables
$search = $_REQUEST['search'] ?? '';
$domain_uuid = $_GET['id'] ?? null;
// Set variables from http GET parameters
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'default_setting_category'));
$order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc';
$search = $_GET['search'] ?? '';
$show = $_GET['show'] ?? '';
$default_setting_category = $_GET['default_setting_category'] ?? '';
// Build the query string
$param = [];
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('stream_all')) {
$param['show'] = $show;
}
if (!empty($default_setting_category)) {
$param['default_setting_category'] = $default_setting_category;
}
$query_string = http_build_query($param);
//reload autoloader
$autoload->update();
@@ -66,8 +91,7 @@ if (is_uuid($domain_uuid)) {
$location = PROJECT_PATH.'/core/domains/domain_edit.php?id='.$domain_uuid;
}
else {
$search = preg_replace('#[^a-zA-Z0-9_\-\.]# ', '', $search);
$location = 'default_settings.php'.($search != '' ? "?search=".$search : null);
$location = 'default_settings.php'.($query_string ? '?'.$query_string : '');
}
header("Location: ".$location);