Extensions: Preserve query string parameters across list and edit pages (#7921)

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

* Update extension_edit.php

* Update extension_copy.php
This commit is contained in:
Alex
2026-04-25 21:18:24 +00:00
committed by GitHub
parent 99d40eb831
commit 6cd23ac9e5
3 changed files with 120 additions and 91 deletions
+29 -9
View File
@@ -39,12 +39,6 @@
$language = new text;
$text = $language->get();
//get order and order by, page
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_REQUEST["order_by"] ?? 'extension'));
$order = $_REQUEST["order"] ?? 'asc';
$page = isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) ? $_REQUEST['page'] : 0;
$search = $_REQUEST['search'] ?? null;
//set the http get/post variable(s) to a php variable
if (is_uuid($_REQUEST["id"]) && $_REQUEST["ext"] != '') {
$extension_uuid = $_REQUEST["id"];
@@ -55,11 +49,37 @@
$page = $_REQUEST['page'];
}
// 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'] ?? 'extension'));
$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('extension_all')) {
$url_params['show'] = $show;
}
$query_string = http_build_query($url_params);
// skip the copy if the domain extension already exists
$extension = new extension;
if ($extension->exists($_SESSION['domain_uuid'], $extension_new)) {
message::add($text['message-duplicate'], 'negative');
header("Location: extensions.php?".(!empty($order_by) ? '&order_by='.$order_by.'&order='.$order : null).(is_numeric($page) ? '&page='.$page : null).(!empty($search) ? '&search='.urlencode($search) : null));
header("Location: extensions.php".($query_string ? '?'.$query_string : ''));
exit;
}
@@ -231,7 +251,7 @@
//redirect the user
message::add($text['message-copy']);
header("Location: extensions.php?".(!empty($order_by) ? '&order_by='.$order_by.'&order='.$order : null).(is_numeric($page) ? '&page='.$page : null).(!empty($search) ? '&search='.urlencode($search) : null));
header("Location: extensions.php".($query_string ? '?'.$query_string : ''));
exit;
?>
?>
+37 -17
View File
@@ -44,12 +44,6 @@ $user_uuid = $_SESSION['user_uuid'] ?? '';
$language = new text;
$text = $language->get();
//get order and order by, page
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_REQUEST["order_by"] ?? 'extension'));
$order = $_REQUEST["order"] ?? 'asc';
$page = isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) ? $_REQUEST['page'] : 0;
$search = $_REQUEST['search'] ?? null;
/**
* Returns the first item of a given value.
*
@@ -114,6 +108,32 @@ if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "add";
}
// 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'] ?? 'extension'));
$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('extension_all')) {
$url_params['show'] = $show;
}
$query_string = http_build_query($url_params);
//get total extension count from the database, check limit, if defined
if ($action == 'add' && $limit_extensions != '') {
$sql = "select count(extension_uuid) ";
@@ -125,7 +145,7 @@ if ($action == 'add' && $limit_extensions != '') {
if ($total_extensions >= $limit_extensions) {
message::add($text['message-maximum_extensions'] . ' ' . $limit_extensions, 'negative');
header('Location: extensions.php?' . (!empty($order_by) ? '&order_by=' . $order_by . '&order=' . $order : null) . (isset($page) && is_numeric($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null));
header('Location: extensions.php'.($query_string ? '?'.$query_string : ''));
exit;
}
}
@@ -323,7 +343,7 @@ if (!empty($_REQUEST["delete_type"]) && $_REQUEST["delete_type"] == "user" && is
$p->delete('extension_user_delete', 'temp');
//redirect
header("Location: extension_edit.php?id=" . $extension_uuid . (!empty($order_by) ? '&order_by=' . $order_by . '&order=' . $order : null) . (isset($page) && is_numeric($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null));
header("Location: extension_edit.php?id=".$extension_uuid.($query_string ? '&'.$query_string : ''));
exit;
}
@@ -348,7 +368,7 @@ if (is_dir(dirname(__DIR__, 2) . '/app/devices')) {
$p->delete('device_line_delete', 'temp');
//redirect
header("Location: extension_edit.php?id=" . $extension_uuid . (!empty($order_by) ? '&order_by=' . $order_by . '&order=' . $order : null) . (isset($page) && is_numeric($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null));
header("Location: extension_edit.php?id=".$extension_uuid.($query_string ? '&'.$query_string : ''));
exit;
}
}
@@ -365,7 +385,7 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) {
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'], 'negative');
header('Location: extensions.php?' . (!empty($order_by) ? '&order_by=' . $order_by . '&order=' . $order : null) . (isset($page) && is_numeric($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null));
header('Location: extensions.php'.($query_string ? '?'.$query_string : ''));
exit;
}
@@ -410,7 +430,7 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) {
message::add($text['message-required'] . implode(', ', $invalid), 'negative', 7500);
}
persistent_form_values('store', $_POST);
header("Location: extension_edit.php?" . (permission_exists('extension_edit') && $action != 'add' ? "&id=" . urlencode($extension_uuid) : null) . (!empty($order_by) ? '&order_by=' . $order_by : null) . (!empty($order) ? '&order=' . $order : null) . (!empty($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null));
header("Location: extension_edit.php?" . (permission_exists('extension_edit') && $action != 'add' ? "&id=" . urlencode($extension_uuid) : null) . ($query_string ? '&'.$query_string : ''));
exit;
} else {
persistent_form_values('clear');
@@ -908,9 +928,9 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) {
message::add($text['message-update']);
}
if ($range > 1) {
header("Location: extensions.php?" . (!empty($order_by) ? '&order_by=' . $order_by . '&order=' . $order : null) . (isset($page) && is_numeric($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null));
header("Location: extensions.php".($query_string ? '?'.$query_string : ''));
} else {
header("Location: extension_edit.php?id=" . $extension_uuid . (!empty($order_by) ? '&order_by=' . $order_by . '&order=' . $order : null) . (isset($page) && is_numeric($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null));
header("Location: extension_edit.php?id=".$extension_uuid.($query_string ? '&'.$query_string : ''));
}
exit;
}
@@ -1206,13 +1226,13 @@ echo "function copy_extension() {\n";
echo " var new_ext = prompt('" . $text['message-extension'] . "');\n";
echo " if (new_ext != null) {\n";
echo " if (!isNaN(new_ext)) {\n";
echo " document.location.href='extension_copy.php?id=" . escape($extension_uuid ?? '') . "&ext=' + new_ext + '" . (!empty($order_by) ? '&order_by=' . $order_by . '&order=' . $order : null) . (!empty($page) && is_numeric($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null) . "';\n";
echo " document.location.href='extension_copy.php?id=" . escape($extension_uuid ?? '') . "&ext=' + new_ext + '" . ($query_string ? '&'.$query_string : '') . "';\n";
echo " }\n";
echo " else {\n";
echo " var new_number_alias = prompt('" . $text['message-number_alias'] . "');\n";
echo " if (new_number_alias != null) {\n";
echo " if (!isNaN(new_number_alias)) {\n";
echo " document.location.href='extension_copy.php?id=" . escape($extension_uuid ?? '') . "&ext=' + new_ext + '&alias=' + new_number_alias + '" . (!empty($order_by) ? '&order_by=' . $order_by . '&order=' . $order : null) . (!empty($page) && is_numeric($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null) . "';\n";
echo " document.location.href='extension_copy.php?id=" . escape($extension_uuid ?? '') . "&ext=' + new_ext + '&alias=' + new_number_alias + '" . ($query_string ? '&'.$query_string : '') . "';\n";
echo " }\n";
echo " }\n";
echo " }\n";
@@ -1232,7 +1252,7 @@ if ($action == "update") {
}
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', 'link' => 'extensions.php?' . (!empty($order_by) ? '&order_by=' . $order_by . '&order=' . $order : null) . (isset($page) && is_numeric($page) ? '&page=' . $page : null) . (!empty($search) ? '&search=' . urlencode($search) : null)]);
echo button::create(['type' => 'button', 'label' => $text['button-back'], 'icon' => $settings->get('theme', 'button_icon_back'), 'id' => 'btn_back', 'link' => 'extensions.php'.($query_string ? '?'.$query_string : '')]);
if ($action == 'update') {
$button_margin = 'margin-left: 15px;';
if (permission_exists('xml_cdr_view')) {
@@ -2411,4 +2431,4 @@ echo "</script>\n";
//include the footer
require_once "resources/footer.php";
?>
?>
+54 -65
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):
@@ -40,19 +40,39 @@
$language = new text;
$text = $language->get();
//get order and order by, page, sort
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_REQUEST["order_by"] ?? 'extension'));
$order = $_REQUEST["order"] ?? 'asc';
$page = isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) ? $_REQUEST['page'] : 0;
$sort = $order_by == 'extension' ? 'natural' : null;
//get posted data
if (!empty($_POST['extensions']) && is_array($_POST['extensions'])) {
$action = $_POST['action'];
$search = $_POST['search'] ?? '';
$extensions = $_POST['extensions'];
}
// 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'] ?? 'extension'));
$order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc';
$sort = $order_by == 'extension' ? 'natural' : null;
$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('extension_all')) {
$url_params['show'] = $show;
}
$query_string = http_build_query($url_params);
//process the http post data by action
if (!empty($action) && !empty($extensions) && is_array($extensions) && @sizeof($extensions) != 0) {
switch ($action) {
@@ -74,7 +94,7 @@
break;
}
header('Location: extensions.php?'.(!empty($order_by) ? '&order_by='.$order_by.'&order='.$order : null).(is_numeric($page) ? '&page='.urlencode($page) : null).($search != '' ? '&search='.urlencode($search) : ''));
header('Location: extensions.php'.($query_string ? '?'.$query_string : ''));
exit;
}
@@ -87,22 +107,10 @@
unset($sql, $parameters);
}
//add the search term
$search = strtolower($_GET["search"] ?? '');
//build the query string
$query_string = '';
if (!empty($search)) {
$query_string .= '&search='.urlencode($search);
}
if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('extension_all')) {
$query_string .= "&show=all";
}
//get total extension count
$sql = "select count(*) from v_extensions ";
$sql .= "where true ";
if (!(!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('extension_all'))) {
if (!($show == "all" && permission_exists('extension_all'))) {
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
}
@@ -125,19 +133,14 @@
$sql .= " or lower(enabled::text) like :search ";
$sql .= " or lower(description) like :search ";
$sql .= ") ";
$parameters['search'] = '%'.$search.'%';
$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 = '';
if (!empty($order) && !empty($order_by)) {
$param .= "&order=".$order;
$param .= "&order_by=".$order_by;
}
list($paging_controls, $rows_per_page) = paging($num_rows, $param.$query_string, $rows_per_page); //bottom
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param.$query_string, $rows_per_page, true); //top
list($paging_controls, $rows_per_page) = paging($num_rows, $query_string, $rows_per_page); //bottom
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $query_string, $rows_per_page, true); //top
$offset = $rows_per_page * $page;
//get the extensions
@@ -235,7 +238,7 @@
$sql .= "true as true ";
$sql .= "from v_extensions as e ";
$sql .= "where true ";
if (!(!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('extension_all'))) {
if (!($show == "all" && permission_exists('extension_all'))) {
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
}
@@ -258,7 +261,7 @@
$sql .= " or lower(enabled::text) like :search ";
$sql .= " or lower(description) like :search ";
$sql .= ") ";
$parameters['search'] = '%'.$search.'%';
$parameters['search'] = '%'.lower_case($search).'%';
}
$sql .= order_by($order_by, $order, null, null, $sort);
$sql .= limit_offset($rows_per_page, $offset);
@@ -268,7 +271,7 @@
//get the registrations
if (permission_exists('extension_registered')) {
$obj = new registrations;
if (!empty($_GET['show']) && $_GET['show'] == 'all') {
if ($show == 'all') {
$obj->show = 'all';
}
$registrations = $obj->get('all');
@@ -310,26 +313,20 @@
}
unset($margin_left);
}
echo "<form id='form_search' class='inline' method='get'>\n";
if (permission_exists('extension_all')) {
if (!empty($_GET['show']) && $_GET['show'] == 'all') {
echo " <input type='hidden' name='show' value='all'>";
}
else {
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$settings->get('theme', 'button_icon_all'),'link'=>'?show=all']);
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";
}
}
if (!empty($order)) {
echo " <input type='hidden' name='order' value='".$order."'>";
if ($show !== 'all' && permission_exists('extension_all')) {
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$settings->get('theme', 'button_icon_all'),'link'=>'?show=all']);
}
if (!empty($order_by)) {
echo " <input type='hidden' name='order_by' value='".$order_by."'>";
}
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
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'=>'extensions.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
echo " <span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
}
echo " </form>\n";
echo " </div>\n";
@@ -361,14 +358,6 @@
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
if (!empty($order_by)) {
echo "<input type='hidden' name='order_by' value='".$order_by."'>\n";
echo "<input type='hidden' name='order' value='".$order."'>\n";
}
if (isset($page) && is_numeric($page)) {
echo "<input type='hidden' name='page' value='".$page."'>\n";
}
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<div class='card'>\n";
echo "<table class='list'>\n";
@@ -385,28 +374,28 @@
if (permission_exists('extension_registered')) {
echo "<th>&nbsp;</th>\n";
}
echo th_order_by('extension', $text['label-extension'], $order_by, $order, $query_string);
echo th_order_by('effective_caller_id_name', $text['label-effective_cid_name'], $order_by, $order, $query_string, "class='hide-xs'");
echo th_order_by('extension', $text['label-extension'], $order_by, $order, null, null, $query_string);
echo th_order_by('effective_caller_id_name', $text['label-effective_cid_name'], $order_by, $order, null, "class='hide-xs'", $query_string);
if (permission_exists("outbound_caller_id_name")) {
echo th_order_by('outbound_caller_id_name', $text['label-outbound_cid_name'], $order_by, $order, $query_string, "class='hide-sm-dn'");
echo th_order_by('outbound_caller_id_name', $text['label-outbound_cid_name'], $order_by, $order, null, "class='hide-sm-dn'", $query_string);
}
if (permission_exists("outbound_caller_id_number")) {
echo th_order_by('outbound_caller_id_number', $text['label-outbound_cid_number'], $order_by, $order, $query_string, "class='hide-md-dn'");
echo th_order_by('outbound_caller_id_number', $text['label-outbound_cid_number'], $order_by, $order, null, "class='hide-md-dn'", $query_string);
}
if (permission_exists("extension_call_group")) {
echo th_order_by('call_group', $text['label-call_group'], $order_by, $order, $query_string);
echo th_order_by('call_group', $text['label-call_group'], $order_by, $order, null, null, $query_string);
}
if (permission_exists("extension_device_address")) {
echo th_order_by('device_address', $text['label-device_address'], $order_by, $order, $query_string, "class='hide-md-dn'");
echo th_order_by('device_address', $text['label-device_address'], $order_by, $order, null, "class='hide-md-dn'", $query_string);
}
if (permission_exists("extension_device_template")) {
echo th_order_by('device_template', $text['label-device_template'], $order_by, $order, $query_string, "class='hide-md-dn'");
echo th_order_by('device_template', $text['label-device_template'], $order_by, $order, null, "class='hide-md-dn'", $query_string);
}
if (permission_exists("extension_user_context")) {
echo th_order_by('user_context', $text['label-user_context'], $order_by, $order);
}
echo th_order_by('enabled', $text['label-enabled'], $order_by, $order, $query_string, "class='center'");
echo th_order_by('description', $text['label-description'], $order_by, $order, $query_string, "class='hide-sm-dn'");
echo th_order_by('enabled', $text['label-enabled'], $order_by, $order, null, "class='center'", $query_string);
echo th_order_by('description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'", $query_string);
if (permission_exists('extension_edit') && $settings->get('theme', 'list_row_edit_button', false)) {
echo " <td class='action-button'>&nbsp;</td>\n";
}
@@ -417,7 +406,7 @@
foreach($extensions as $row) {
$list_row_url = '';
if (permission_exists('extension_edit')) {
$list_row_url = "extension_edit.php?id=".urlencode($row['extension_uuid']).(!empty($order_by) ? '&order_by='.$order_by.'&order='.$order : null).(is_numeric($page) ? '&page='.urlencode($page) : null).(!empty($search) ? '&search='.urlencode($search) : null);
$list_row_url = "extension_edit.php?id=".urlencode($row['extension_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';
}