Time Conditions: Preserve query string parameters across list and edit pages (#7905)

* Time Conditions: Preserve query string parameters across list and edit pages

* Update time_condition_edit.php
This commit is contained in:
Alex
2026-04-22 20:59:58 +00:00
committed by GitHub
parent 6cc6622187
commit 580c786e77
2 changed files with 80 additions and 45 deletions
+30 -4
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):
@@ -54,6 +54,32 @@
}
unset($preset_region);
// 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'] ?? 'dialplan_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('time_condition_all')) {
$param['show'] = $show;
}
$query_string = http_build_query($param);
//set the action as an add or an update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
@@ -91,7 +117,7 @@
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: time_conditions.php');
header('Location: time_conditions.php'.($query_string ? '?'.$query_string : ''));
exit;
}
@@ -601,7 +627,7 @@
}
//redirect the browser
header("Location: time_condition_edit.php?id=".$dialplan_uuid.(!empty($app_uuid) && is_uuid($app_uuid) ? "&app_uuid=".$app_uuid : null));
header("Location: time_condition_edit.php?id=".$dialplan_uuid.(!empty($app_uuid) && is_uuid($app_uuid) ? "&app_uuid=".$app_uuid : null).($query_string ? '&'.$query_string : ''));
exit;
}
@@ -1047,7 +1073,7 @@ echo "<form method='post' name='frm' id='frm' onsubmit=\"return check_submit();\
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-time_condition']."</b></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'=>PROJECT_PATH.'/app/time_conditions/time_conditions.php?app_uuid=4b821450-926b-175a-af93-a03c441818b1']);
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>PROJECT_PATH.'/app/time_conditions/time_conditions.php?app_uuid=4b821450-926b-175a-af93-a03c441818b1'.($query_string ? '&'.$query_string : '')]);
if ($action == 'update' && permission_exists('dialplan_edit')) {
echo button::create(['type'=>'button','label'=>$text['button-dialplan'],'icon'=>'list','style'=>'margin-right: 15px;','link'=>PROJECT_PATH.'/app/dialplans/dialplan_edit.php?id='.urlencode($dialplan_uuid).'&app_uuid=4b821450-926b-175a-af93-a03c441818b1']);
}
+50 -41
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):
@@ -39,10 +39,36 @@
$language = new text;
$text = $language->get();
// 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'] ?? 'dialplan_name'));
$order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc';
$sort = $order_by == 'dialplan_number' ? 'natural' : null;
$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('time_condition_all')) {
$param['show'] = $show;
}
$query_string = http_build_query($param);
//get the http post data
if (!empty($_POST['time_conditions']) && is_array($_POST['time_conditions'])) {
$action = $_POST['action'];
$search = $_POST['search'] ?? '';
$time_conditions = $_POST['time_conditions'];
}
@@ -69,19 +95,10 @@
break;
}
header('Location: time_conditions.php'.($search != '' ? '?search='.urlencode($search) : ''));
header('Location: time_conditions.php'.($query_string ? '?'.$query_string : ''));
exit;
}
//get order and order by
$order_by = $_GET["order_by"] ?? 'dialplan_name';
$order = $_GET["order"] ?? 'asc';
$sort = $order_by == 'dialplan_number' ? 'natural' : null;
//add the search variable
$search = $_GET["search"] ?? '';
$show = $_GET["show"] ?? '';
//get the number of rows in the dialplan
$sql = "select count(dialplan_uuid) from v_dialplans ";
if ($show == "all" && permission_exists('time_condition_all')) {
@@ -92,28 +109,21 @@
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
}
if (!empty($search)) {
$search = strtolower($search);
$sql .= "and (";
$sql .= " lower(dialplan_context) like :search ";
$sql .= " or lower(dialplan_name) like :search ";
$sql .= " or lower(dialplan_number) like :search ";
$sql .= " or lower(dialplan_description) like :search ";
$sql .= ") ";
$parameters['search'] = '%'.$search.'%';
$parameters['search'] = '%'.lower_case($search).'%';
}
$sql .= "and app_uuid = '4b821450-926b-175a-af93-a03c441818b1' ";
$sql .= $sql_search ?? null;
$num_rows = $database->select($sql, $parameters ?? null, 'column');
//prepare to page data
$rows_per_page = $settings->get('domain', 'paging', 50);
$param = $search ? "&search=".urlencode($search) : null;
if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('time_condition_all')) {
$param .= "&show=all";
}
$page = !empty($_GET['page']) && is_numeric($_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 data
@@ -136,7 +146,7 @@
echo " <div class='heading'><b>".$text['header-time_conditions']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
echo " <div class='actions'>\n";
if (permission_exists('time_condition_add')) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','link'=>'time_condition_edit.php']);
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','link'=>'time_condition_edit.php'.($query_string ? '?'.$query_string : '')]);
}
if (permission_exists('time_condition_add') && $dialplans) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$settings->get('theme', 'button_icon_copy'),'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
@@ -147,20 +157,20 @@
if (permission_exists('time_condition_delete') && $dialplans) {
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";
if (permission_exists('time_condition_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'=>'?type=&show=all'.($search != '' ? "&search=".urlencode($search) : null)]);
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";
}
}
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
if ($show !== 'all' && permission_exists('time_condition_all')) {
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$settings->get('theme', 'button_icon_all'),'link'=>'?show=all']);
}
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'=>'time_conditions.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($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";
@@ -182,7 +192,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";
@@ -193,16 +202,16 @@
echo " </th>\n";
}
if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('time_condition_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param, "class='shrink'");
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, null, "class='shrink'", $query_string);
}
echo th_order_by('dialplan_name', $text['label-name'], $order_by, $order, null, null, ($search != '' ? "search=".$search : null));
echo th_order_by('dialplan_number', $text['label-number'], $order_by, $order, null, null, ($search != '' ? "search=".$search : null));
echo th_order_by('dialplan_name', $text['label-name'], $order_by, $order, null, null, $query_string);
echo th_order_by('dialplan_number', $text['label-number'], $order_by, $order, null, null, $query_string);
if (permission_exists('time_condition_context')) {
echo th_order_by('dialplan_context', $text['label-context'], $order_by, $order, null, null, ($search != '' ? "search=".$search : null));
echo th_order_by('dialplan_context', $text['label-context'], $order_by, $order, null, null, $query_string);
}
echo th_order_by('dialplan_order', $text['label-order'], $order_by, $order, null, "class='center'", ($search != '' ? "search=".$search : null));
echo th_order_by('dialplan_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'", ($search != '' ? "search=".$search : null));
echo th_order_by('dialplan_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'", ($search != '' ? "search=".$search : null));
echo th_order_by('dialplan_order', $text['label-order'], $order_by, $order, null, "class='center'", $query_string);
echo th_order_by('dialplan_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'", $query_string);
echo th_order_by('dialplan_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'", $query_string);
if (permission_exists('time_condition_edit') && $settings->get('theme', 'list_row_edit_button', false)) {
echo " <td class='action-button'>&nbsp;</td>\n";
}
@@ -213,7 +222,7 @@
foreach ($dialplans as $row) {
$list_row_url = '';
if (permission_exists('time_condition_edit')) {
$list_row_url = "time_condition_edit.php?id=".urlencode($row['dialplan_uuid']);
$list_row_url = "time_condition_edit.php?id=".urlencode($row['dialplan_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';
}