From f6a48235d2ffb28f44c2845db5204f2a72bce067 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Fri, 12 May 2023 23:42:41 -0600 Subject: [PATCH] Update domains for 8.1 support --- core/domains/domains.php | 64 ++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/core/domains/domains.php b/core/domains/domains.php index 443638a1c6..623235506a 100644 --- a/core/domains/domains.php +++ b/core/domains/domains.php @@ -40,14 +40,14 @@ } //change the domain - if (is_uuid($_GET["domain_uuid"]) && $_GET["domain_change"] == "true") { + if (!empty($_GET["domain_uuid"]) && is_uuid($_GET["domain_uuid"]) && $_GET["domain_change"] == "true") { if (permission_exists('domain_select')) { //get the domain_uuid $sql = "select * from v_domains "; $sql .= "order by domain_name asc "; $database = new database; $result = $database->select($sql, null, 'all'); - if (is_array($result) && sizeof($result) != 0) { + if (!empty($result)) { foreach($result as $row) { if (count($result) == 0) { $_SESSION["domain_uuid"] = $row["domain_uuid"]; @@ -79,7 +79,7 @@ $domain->set(); //redirect the user - if ($_SESSION["login"]["destination"] != '') { + if (!empty($_SESSION["login"]["destination"])) { // to default, or domain specific, login destination header("Location: ".PROJECT_PATH.$_SESSION["login"]["destination"]["url"]); } @@ -104,14 +104,14 @@ $text = $language->get(); //get the http post data - if (is_array($_POST['domains'])) { - $action = $_POST['action']; - $search = $_POST['search']; - $domains = $_POST['domains']; + if (!empty($_POST['domains'])) { + $action = $_POST['action'] ?? ''; + $search = $_POST['search'] ?? ''; + $domains = $_POST['domains'] ?? ''; } //process the http post data by action - if ($action != '' && is_array($domains) && @sizeof($domains) != 0) { + if (!empty($action) && !empty($domains)) { switch ($action) { case 'copy': if (permission_exists('domain_add')) { @@ -133,16 +133,23 @@ break; } - header('Location: domains.php'.($search != '' ? '?search='.urlencode($search) : null)); + header('Location: domains.php'.(!empty($search) ? '?search='.urlencode($search) : null)); exit; } -//get order and order by - $order_by = $_GET["order_by"]; - $order = $_GET["order"]; +//get order and order by and sanitize the values + $order_by = $_GET["order_by"] ?? ''; + $order = $_GET["order"] ?? ''; + +//set additional variables + $search = $_GET["search"] ?? ''; + $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'; //add the search string - if (isset($_GET["search"])) { + if (!empty($search)) { $search = strtolower($_GET["search"]); $sql_search = " ("; $sql_search .= " lower(domain_name) like :search "; @@ -153,16 +160,16 @@ //get the count $sql = "select count(domain_uuid) from v_domains "; - if (isset($sql_search)) { + if (!empty($sql_search)) { $sql .= "where ".$sql_search; } $database = new database; - $num_rows = $database->select($sql, $parameters, 'column'); + $num_rows = $database->select($sql, $parameters ?? null, '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=".$search : 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 * $page; @@ -170,13 +177,13 @@ //get the list $sql = "select domain_uuid, domain_name, cast(domain_enabled as text), domain_description "; $sql .= "from v_domains "; - if (isset($sql_search)) { + if (!empty($sql_search)) { $sql .= "where ".$sql_search; } $sql .= order_by($order_by, $order, 'domain_name', 'asc'); $sql .= limit_offset($rows_per_page, $offset); $database = new database; - $domains = $database->select($sql, $parameters, 'all'); + $domains = $database->select($sql, $parameters ?? null, 'all'); unset($sql, $parameters); //create token @@ -204,7 +211,7 @@ echo ""; 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'=>'domains.php','style'=>($search == '' ? 'display: none;' : null)]); - if ($paging_controls_mini != '') { + if (!empty($paging_controls_mini)) { echo "".$paging_controls_mini."\n"; } echo " \n"; @@ -212,10 +219,10 @@ echo "
\n"; echo "\n"; - if (permission_exists('domain_edit') && $domains) { + if (permission_exists('domain_edit') && !empty($domains)) { echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]); } - if (permission_exists('domain_delete') && $domains) { + if (permission_exists('domain_delete') && !empty($domains)) { echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); } @@ -230,24 +237,25 @@ echo "\n"; if (permission_exists('domain_edit') || permission_exists('domain_delete')) { echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; } - if ($_GET['show'] == 'all' && permission_exists('domain_all')) { + 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_name'], $order_by, $order); echo "".$text['label-tools'].""; echo th_order_by('domain_enabled', $text['label-domain_enabled'], $order_by, $order, null, "class='center'"); echo " ".$text['label-domain_description']."\n"; - if (permission_exists('domain_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + if (permission_exists('domain_edit') && $list_row_edit_button == 'true') { echo "  \n"; } echo "\n"; - if (is_array($domains) && @sizeof($domains) != 0) { + if (!empty($domains)) { $x = 0; foreach ($domains as $row) { + $list_row_url = ''; if (permission_exists('domain_edit')) { $list_row_url = "domain_edit.php?id=".urlencode($row['domain_uuid']); } @@ -258,7 +266,7 @@ echo " \n"; echo " \n"; } - if ($_GET['show'] == 'all' && permission_exists('domain_all')) { + if ($show == 'all' && permission_exists('domain_all')) { echo " ".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."\n"; } echo " \n"; @@ -287,7 +295,7 @@ echo " \n"; } echo " ".escape($row['domain_description'])."\n"; - if (permission_exists('domain_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + if (permission_exists('domain_edit') && $list_row_edit_button == 'true') { echo " \n"; echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); echo " \n";