Call Block: Preserve query string parameters across list and edit pages (#7876)
* Call Block: Preserve query string parameters across list and edit pages * Update call_block_edit.php
This commit is contained in:
@@ -42,9 +42,31 @@
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
//set additional variables
|
||||
$search = $_GET["search"] ?? '';
|
||||
$show = $_GET["show"] ?? '';
|
||||
// Set variables from GET parameters
|
||||
$page = is_numeric($_GET['page'] ?? '') ? $_GET['page'] : 0;
|
||||
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'call_block_number'));
|
||||
$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('call_block_all')) {
|
||||
$param['show'] = $show;
|
||||
}
|
||||
$query_string = http_build_query($param);
|
||||
|
||||
//set from session variables
|
||||
$list_row_edit_button = $settings->get('theme', 'list_row_edit_button', false);
|
||||
@@ -52,7 +74,6 @@
|
||||
//get posted data
|
||||
if (!empty($_POST['call_blocks'])) {
|
||||
$action = $_POST['action'];
|
||||
$search = $_POST['search'] ?? '';
|
||||
$call_blocks = $_POST['call_blocks'];
|
||||
}
|
||||
|
||||
@@ -79,14 +100,10 @@
|
||||
break;
|
||||
}
|
||||
|
||||
header('Location: call_block.php'.($search != '' ? '?search='.urlencode($search) : ''));
|
||||
header('Location: call_block.php'.($query_string ? '?'.$query_string : ''));
|
||||
exit;
|
||||
}
|
||||
|
||||
//get variables used to control the order
|
||||
$order_by = $_GET["order_by"] ?? '';
|
||||
$order = $_GET["order"] ?? '';
|
||||
|
||||
//add the search term
|
||||
if (!empty($_GET["search"])) {
|
||||
$search = strtolower($_GET["search"]);
|
||||
@@ -134,14 +151,8 @@
|
||||
|
||||
//prepare to page the results
|
||||
$rows_per_page = $settings->get('domain', 'paging', 50);
|
||||
$param = "&search=".$search;
|
||||
if ($show == "all" && permission_exists('call_block_all')) {
|
||||
$param .= "&show=all";
|
||||
}
|
||||
$page = $_GET['page'] ?? '';
|
||||
if (empty($page)) { $page = 0; $_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;
|
||||
|
||||
//set the time zone
|
||||
@@ -197,7 +208,7 @@
|
||||
$sql .= " or lower(call_block_data) like :search ";
|
||||
$sql .= " or lower(call_block_description) like :search ";
|
||||
$sql .= ") ";
|
||||
$parameters['search'] = '%'.$search.'%';
|
||||
$parameters['search'] = '%'.strtolower($search).'%';
|
||||
}
|
||||
$sql .= order_by($order_by, $order, ['domain_uuid','call_block_country_code','call_block_number']);
|
||||
$sql .= limit_offset($rows_per_page, $offset);
|
||||
@@ -238,13 +249,13 @@
|
||||
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('call_block_all')) {
|
||||
if ($show == 'all') {
|
||||
echo " <input type='hidden' name='show' value='all'>";
|
||||
foreach ($param as $key => $value) {
|
||||
if ($key !== 'search') {
|
||||
echo " <input type='hidden' name='".escape($key)."' value='".escape($value)."'>\n";
|
||||
}
|
||||
else {
|
||||
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$settings->get('theme', 'button_icon_all'),'link'=>'?type='.urlencode($destination_type ?? '').'&show=all'.($search != '' ? "&search=".urlencode($search ?? '') : null)]);
|
||||
}
|
||||
if (permission_exists('call_block_all') && (!isset($show) || $show != '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']);
|
||||
@@ -272,7 +283,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";
|
||||
@@ -283,20 +293,20 @@
|
||||
echo " </th>\n";
|
||||
}
|
||||
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, $param);
|
||||
}
|
||||
else if (permission_exists('call_block_domain') && $global_call_blocks) {
|
||||
echo th_order_by('domain_uuid', $text['label-domain'], $order_by, $order, null, "style='width: 1%;' class='center'");
|
||||
echo th_order_by('domain_uuid', $text['label-domain'], $order_by, $order, null, "style='width: 1%;' class='center'", $param);
|
||||
}
|
||||
echo th_order_by('call_block_direction', $text['label-direction'], $order_by, $order, null, "style='width: 1%;' class='center'");
|
||||
echo th_order_by('extension', $text['label-extension'], $order_by, $order, null, "class='center'");
|
||||
echo th_order_by('call_block_name', $text['label-caller_id_name'], $order_by, $order);
|
||||
echo th_order_by('call_block_country_code', $text['label-country_code'], $order_by, $order);
|
||||
echo th_order_by('call_block_number', $text['label-number'], $order_by, $order);
|
||||
echo th_order_by('call_block_count', $text['label-count'], $order_by, $order, '', "class='center hide-sm-dn'");
|
||||
echo th_order_by('call_block_action', $text['label-action'], $order_by, $order);
|
||||
echo th_order_by('call_block_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
|
||||
echo th_order_by('insert_date', $text['label-date-added'], $order_by, $order, null, "class='shrink no-wrap'");
|
||||
echo th_order_by('call_block_direction', $text['label-direction'], $order_by, $order, null, "style='width: 1%;' class='center'", $param);
|
||||
echo th_order_by('extension', $text['label-extension'], $order_by, $order, null, "class='center'", $param);
|
||||
echo th_order_by('call_block_name', $text['label-caller_id_name'], $order_by, $order, null, null, $param);
|
||||
echo th_order_by('call_block_country_code', $text['label-country_code'], $order_by, $order, null, null, $param);
|
||||
echo th_order_by('call_block_number', $text['label-number'], $order_by, $order, null, null, $param);
|
||||
echo th_order_by('call_block_count', $text['label-count'], $order_by, $order, '', "class='center hide-sm-dn'", $param);
|
||||
echo th_order_by('call_block_action', $text['label-action'], $order_by, $order, null, null, $param);
|
||||
echo th_order_by('call_block_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'", $param);
|
||||
echo th_order_by('insert_date', $text['label-date-added'], $order_by, $order, null, "class='shrink no-wrap'", $param);
|
||||
echo "<th class='hide-md-dn pct-20'>".$text['label-description']."</th>\n";
|
||||
if (permission_exists('call_block_edit') && $list_row_edit_button) {
|
||||
echo " <td class='action-button'> </td>\n";
|
||||
@@ -308,7 +318,7 @@
|
||||
foreach ($result as $row) {
|
||||
$list_row_url = '';
|
||||
if (permission_exists('call_block_edit')) {
|
||||
$list_row_url = "call_block_edit.php?id=".urlencode($row['call_block_uuid']);
|
||||
$list_row_url = "call_block_edit.php?id=".urlencode($row['call_block_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';
|
||||
}
|
||||
|
||||
@@ -47,6 +47,32 @@
|
||||
$call_block_number = '';
|
||||
$call_block_description = '';
|
||||
|
||||
// Set variables from GET parameters
|
||||
$page = is_numeric($_GET['page'] ?? '') ? $_GET['page'] : 0;
|
||||
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'call_block_number'));
|
||||
$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('call_block_all')) {
|
||||
$param['show'] = $show;
|
||||
}
|
||||
$query_string = http_build_query($param);
|
||||
|
||||
//set the time zone
|
||||
$time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
|
||||
date_default_timezone_set($time_zone);
|
||||
@@ -124,7 +150,7 @@
|
||||
break;
|
||||
}
|
||||
|
||||
header('Location: call_block.php');
|
||||
header('Location: call_block.php'.($query_string ? '?'.$query_string : ''));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -132,7 +158,7 @@
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: call_block.php');
|
||||
header('Location: call_block.php'.($query_string ? '?'.$query_string : ''));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -211,7 +237,7 @@
|
||||
unset($array);
|
||||
|
||||
message::add($text['label-add-complete']);
|
||||
header("Location: call_block.php");
|
||||
header("Location: call_block.php".($query_string ? '?'.$query_string : ''));
|
||||
return;
|
||||
}
|
||||
if ($action == "update") {
|
||||
@@ -258,14 +284,14 @@
|
||||
unset($array);
|
||||
|
||||
message::add($text['label-update-complete']);
|
||||
header("Location: call_block.php");
|
||||
header("Location: call_block.php".($query_string ? '?'.$query_string : ''));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//pre-populate the form
|
||||
if (!empty($_GET) && empty($_POST["persistformvar"])) {
|
||||
if (!empty($_GET["id"]) && empty($_POST["persistformvar"])) {
|
||||
$call_block_uuid = $_GET["id"];
|
||||
$sql = "select * from v_call_block ";
|
||||
$sql .= "where ( ";
|
||||
@@ -443,7 +469,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','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'call_block.php']);
|
||||
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'call_block.php'.($query_string ? '?'.$query_string : '')]);
|
||||
if ($action == 'update' && permission_exists('call_block_delete')) {
|
||||
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('theme', 'button_icon_delete'),'name'=>'btn_delete','collapse'=>'hide-xs','style'=>'margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
|
||||
}
|
||||
@@ -636,7 +662,7 @@
|
||||
echo " </select>\n";
|
||||
echo " </div>\n";
|
||||
echo " <div class='actions'>\n";
|
||||
echo button::create(['type'=>'button','id'=>'action_bar_sub_button_back','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'collapse'=>'hide-xs','style'=>'display: none;','link'=>'call_block.php']);
|
||||
echo button::create(['type'=>'button','id'=>'action_bar_sub_button_back','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'collapse'=>'hide-xs','style'=>'display: none;','link'=>'call_block.php'.($query_string ? '?'.$query_string : '')]);
|
||||
if ($recent_calls) {
|
||||
$select_margin = 'margin-left: 15px;';
|
||||
if (permission_exists('call_block_extension')) {
|
||||
|
||||
Reference in New Issue
Block a user