diff --git a/app/call_block/call_block.php b/app/call_block/call_block.php index 681fe317b..8d0faf827 100644 --- a/app/call_block/call_block.php +++ b/app/call_block/call_block.php @@ -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,14 +249,14 @@ 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 "