Update gateways.php for php 8.1

This commit is contained in:
FusionPBX 2023-05-13 20:23:10 -06:00 committed by GitHub
parent 5755ae3f48
commit a94c465759
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 65 additions and 46 deletions

View File

@ -47,14 +47,14 @@
$text = $language->get();
//get posted data
if (is_array($_POST['gateways'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$gateways = $_POST['gateways'];
if (!empty($_POST['gateways'])) {
$action = $_POST['action'] ?? '';
$search = $_POST['search'] ?? '';
$gateways = $_POST['gateways'] ?? '';
}
//process the http post data by action
if ($action != '' && is_array($gateways) && @sizeof($gateways) != 0) {
if (!empty($action) && !empty($gateways)) {
switch ($action) {
case 'copy':
if (permission_exists('gateway_add')) {
@ -89,7 +89,7 @@
break;
}
header('Location: gateways.php'.($search != '' ? '?search='.urlencode($search) : null));
header('Location: gateways.php'.(!empty($search) ? '?search='.urlencode($search) : null));
exit;
}
@ -114,58 +114,77 @@
}
//get order and order by
$order_by = $_GET["order_by"];
$order = $_GET["order"];
$order_by = $_GET["order_by"] ?? '';
$order = $_GET["order"] ?? '';
//add the search term
$search = strtolower($_GET["search"]);
if (!empty($search)) {
$sql_search = "and (";
$sql_search .= "lower(gateway) like :search ";
$sql_search .= "or lower(username) like :search ";
$sql_search .= "or lower(auth_username) like :search ";
$sql_search .= "or lower(from_user) like :search ";
$sql_search .= "or lower(from_domain) like :search ";
$sql_search .= "or lower(proxy) like :search ";
$sql_search .= "or lower(register_proxy) like :search ";
$sql_search .= "or lower(outbound_proxy) like :search ";
$sql_search .= "or lower(description) like :search ";
$sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
}
//set additional variables
$search = !empty($_GET["search"]) ? $_GET["search"] : '';
$show = !empty($_GET["show"]) ? $_GET["show"] : '';
//set from session variables
$list_row_edit_button = !empty($_SESSION['theme']['list_row_edit_button']['boolean']) ? $_SESSION['theme']['list_row_edit_button']['boolean'] : 'false';
//get total gateway count from the database
$sql = "select count(*) from v_gateways where true ";
if (!($_GET['show'] == "all" && permission_exists('gateway_all'))) {
if (!($show == "all" && permission_exists('gateway_all'))) {
$sql .= "and (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
}
if (!empty($search)) {
$search = strtolower($_GET["search"]);
$sql .= "and (";
$sql .= "lower(gateway) like :search ";
$sql .= "or lower(username) like :search ";
$sql .= "or lower(auth_username) like :search ";
$sql .= "or lower(from_user) like :search ";
$sql .= "or lower(from_domain) like :search ";
$sql .= "or lower(proxy) like :search ";
$sql .= "or lower(register_proxy) like :search ";
$sql .= "or lower(outbound_proxy) like :search ";
$sql .= "or lower(description) like :search ";
$sql .= ") ";
$parameters['search'] = '%'.$search.'%';
}
$database = new database;
$total_gateways = $database->select($sql, $parameters, 'column');
$total_gateways = $database->select($sql, $parameters ?? '', 'column');
$num_rows = $total_gateways;
//prepare to page the results
if ($sql_search) {
$sql .= $sql_search;
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
}
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$rows_per_page = (!empty($_SESSION['domain']['paging']['numeric'])) ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = "&search=".$search;
$param .= $order_by ? "&order_by=".$order_by."&order=".$order : null;
$page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
$page = !empty($_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);
$offset = $rows_per_page * $_GET['page'];
$offset = $rows_per_page * $page;
//get the list
$sql = str_replace('count(*)', '*', $sql);
$sql = "select * from ";
$sql .= "from v_gateways ";
$sql .= "where true ";
if (!($show == "all" && permission_exists('gateway_all'))) {
$sql .= "and (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
}
if (!empty($search)) {
$search = strtolower($_GET["search"]);
$sql .= "and (";
$sql .= "lower(gateway) like :search ";
$sql .= "or lower(username) like :search ";
$sql .= "or lower(auth_username) like :search ";
$sql .= "or lower(from_user) like :search ";
$sql .= "or lower(from_domain) like :search ";
$sql .= "or lower(proxy) like :search ";
$sql .= "or lower(register_proxy) like :search ";
$sql .= "or lower(outbound_proxy) like :search ";
$sql .= "or lower(description) like :search ";
$sql .= ") ";
$parameters['search'] = '%'.$search.'%';
}
$sql .= order_by($order_by, $order, 'gateway', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$gateways = $database->select($sql, $parameters, 'all');
$gateways = $database->select($sql, $parameters ?? '', 'all');
unset($sql, $parameters);
//create token
@ -199,7 +218,7 @@
}
echo "<form id='form_search' class='inline' method='get'>\n";
if (permission_exists('gateway_all')) {
if ($_GET['show'] == 'all') {
if ($show == 'all') {
echo " <input type='hidden' name='show' value='all'>";
}
else {
@ -209,7 +228,7 @@
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'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
//echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'gateways.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
if (!empty($paging_controls_mini)) {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
}
echo " </form>\n";
@ -245,7 +264,7 @@
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".($gateways ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
if ($_GET['show'] == "all" && permission_exists('gateway_all')) {
if ($show == "all" && permission_exists('gateway_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param);
}
echo th_order_by('gateway', $text['label-gateway'], $order_by, $order);
@ -262,12 +281,12 @@
echo th_order_by('hostname', $text['label-hostname'], $order_by, $order, null, "class='hide-sm-dn'");
echo th_order_by('enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'");
if (permission_exists('gateway_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
if (permission_exists('gateway_edit') && $list_row_edit_button == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
echo "</tr>\n";
if (is_array($gateways) && @sizeof($gateways) != 0) {
if (!empty($gateways)) {
$x = 0;
foreach($gateways as $row) {
if (permission_exists('gateway_edit')) {
@ -280,7 +299,7 @@
echo " <input type='hidden' name='gateways[$x][uuid]' value='".escape($row['gateway_uuid'])."' />\n";
echo " </td>\n";
}
if ($_GET['show'] == "all" && permission_exists('gateway_all')) {
if ($show == "all" && permission_exists('gateway_all')) {
echo " <td>";
if (is_uuid($row['domain_uuid'])) {
echo escape($_SESSION['domains'][$row['domain_uuid']]['domain_name']);
@ -351,9 +370,9 @@
}
echo " </td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row["description"])."&nbsp;</td>\n";
if (permission_exists('gateway_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
if (permission_exists('gateway_edit') && $list_row_edit_button == 'true') {
echo " <td class='action-button'>";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$list_row_edit_button,'link'=>$list_row_url]);
echo " </td>\n";
}
echo "</tr>\n";