From 580c786e77f9fca72b6cf4ca7ef87f4c6259a9ec Mon Sep 17 00:00:00 2001 From: Alex <40072887+alexdcrane@users.noreply.github.com> Date: Wed, 22 Apr 2026 20:59:58 +0000 Subject: [PATCH] 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 --- app/time_conditions/time_condition_edit.php | 34 +++++++- app/time_conditions/time_conditions.php | 91 +++++++++++---------- 2 files changed, 80 insertions(+), 45 deletions(-) diff --git a/app/time_conditions/time_condition_edit.php b/app/time_conditions/time_condition_edit.php index 5e84807ba..d1eb7dff6 100644 --- a/app/time_conditions/time_condition_edit.php +++ b/app/time_conditions/time_condition_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - 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 "
\n"; echo "
".$text['title-time_condition']."
\n"; echo "
\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']); } diff --git a/app/time_conditions/time_conditions.php b/app/time_conditions/time_conditions.php index 8276144c2..cd36fdad1 100644 --- a/app/time_conditions/time_conditions.php +++ b/app/time_conditions/time_conditions.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - 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 "
".$text['header-time_conditions']."
".number_format($num_rows)."
\n"; echo "
\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 "\n"; - if (permission_exists('time_condition_all')) { - if (!empty($_GET['show']) && $_GET['show'] == 'all') { - echo " "; - } - 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 " \n"; + foreach ($param as $key => $value) { + if ($key !== 'search' && $key !== 'page') { + echo " \n"; } } - echo ""; + 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 " "; 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 "".$paging_controls_mini."\n"; + echo " ".$paging_controls_mini."\n"; } echo " \n"; echo "
\n"; @@ -182,7 +192,6 @@ echo "
\n"; echo "\n"; - echo "\n"; echo "
\n"; echo "\n"; @@ -193,16 +202,16 @@ echo " \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 " \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'; }