From e3dce560cfe0c00a32576bff9138114a01662707 Mon Sep 17 00:00:00 2001 From: fusionate Date: Thu, 25 May 2023 17:46:27 +0000 Subject: [PATCH] Device Profile - Edit: Updates for PHP 8.1 --- app/devices/device_profile_edit.php | 66 +++++++++++++++-------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/app/devices/device_profile_edit.php b/app/devices/device_profile_edit.php index 8d6f1a680e..72b12f8308 100644 --- a/app/devices/device_profile_edit.php +++ b/app/devices/device_profile_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Copyright (C) 2020 - 2022 All Rights Reserved. + Copyright (C) 2020-2023 All Rights Reserved. Contributor(s): Mark J Crane @@ -58,7 +58,7 @@ if (count($_POST) > 0 && empty($_POST["persistformvar"])) { //process the http post data by submitted action - if ($_POST['action'] != '' && is_uuid($_POST['device_profile_uuid'])) { + if (!empty($_POST['action']) && is_uuid($_POST['device_profile_uuid'])) { $array[0]['checked'] = 'true'; $array[0]['uuid'] = $_POST['device_profile_uuid']; @@ -80,10 +80,10 @@ $device_profile_name = $_POST["device_profile_name"]; $device_profile_keys = $_POST["device_profile_keys"]; $device_profile_settings = $_POST["device_profile_settings"]; - $device_profile_enabled = $_POST["device_profile_enabled"] ?: 'false'; + $device_profile_enabled = $_POST["device_profile_enabled"] ?? 'false'; $device_profile_description = $_POST["device_profile_description"]; - $device_profile_keys_delete = $_POST["device_profile_keys_delete"]; - $device_profile_settings_delete = $_POST["device_profile_settings_delete"]; + $device_profile_keys_delete = $_POST["device_profile_keys_delete"] ?? null; + $device_profile_settings_delete = $_POST["device_profile_settings_delete"] ?? null; //set the domain_uuid for users that do not have the permission if (permission_exists('device_profile_domain')) { @@ -159,10 +159,10 @@ } $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_line"] = $row["profile_key_line"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_value"] = $row["profile_key_value"]; - $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_extension"] = $row["profile_key_extension"]; + $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_extension"] = $row["profile_key_extension"] ?? null; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_protected"] = $row["profile_key_protected"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_label"] = $row["profile_key_label"]; - $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_icon"] = $row["profile_key_icon"]; + $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_icon"] = $row["profile_key_icon"] ?? null; $y++; } } @@ -225,7 +225,7 @@ } //pre-populate the form - if (is_array($_GET) && $_POST["persistformvar"] != "true") { + if (!empty($_GET) && is_array($_GET) && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) { $device_profile_uuid = $_GET["id"]; $sql = "select * from v_device_profiles "; $sql .= "where device_profile_uuid = :device_profile_uuid "; @@ -237,8 +237,8 @@ foreach ($result as &$row) { $domain_uuid = $row["domain_uuid"]; $device_profile_name = $row["device_profile_name"]; - $device_profile_keys = $row["device_profile_keys"]; - $device_profile_settings = $row["device_profile_settings"]; + $device_profile_keys = $row["device_profile_keys"] ?? null; + $device_profile_settings = $row["device_profile_settings"] ?? null; $device_profile_enabled = $row["device_profile_enabled"]; $device_profile_description = $row["device_profile_description"]; } @@ -276,7 +276,8 @@ //get the vendor count $vendor_count = 0; - if (is_array($device_profile_keys) && @sizeof($device_profile_keys) != 0) { + if (!empty($device_profile_keys) && is_array($device_profile_keys) && @sizeof($device_profile_keys) != 0) { + $previous_vendor = ''; foreach($device_profile_keys as $row) { if ($previous_vendor != $row['profile_key_vendor']) { $previous_vendor = $row['profile_key_vendor']; @@ -287,7 +288,7 @@ //determine whether to show the key_subtype $show_key_subtype = false; - if (is_array($device_profile_keys) && @sizeof($device_profile_keys) != 0) { + if (!empty($device_profile_keys) && is_array($device_profile_keys) && @sizeof($device_profile_keys) != 0) { foreach($device_profile_keys as $row) { if ($row['profile_key_vendor'] == 'fanvil') { $show_key_subtype = true; @@ -321,17 +322,17 @@ } //add an empty row - if (!is_array($device_profile_keys) || count($device_profile_keys) == 0) { + if (empty($device_profile_keys) || !is_array($device_profile_keys) || count($device_profile_keys) == 0) { $rows = $_SESSION['devices']['profile_key_add_rows']['numeric']; $id = 0; } - if (is_array($device_profile_keys) && count($device_profile_keys) > 0) { + if (!empty($device_profile_keys) && is_array($device_profile_keys) && count($device_profile_keys) > 0) { $rows = $_SESSION['devices']['profile_key_edit_rows']['numeric']; $id = count($device_profile_keys)+1; } for ($x = 0; $x < $rows; $x++) { $device_profile_keys[$id]['domain_uuid'] = $domain_uuid; - $device_profile_keys[$id]['device_profile_uuid'] = $device_profile_uuid; + $device_profile_keys[$id]['device_profile_uuid'] = $device_profile_uuid ?? null; $device_profile_keys[$id]['device_profile_key_uuid'] = ''; $device_profile_keys[$id]['profile_key_category'] = ''; $device_profile_keys[$id]['profile_key_id'] = ''; @@ -366,9 +367,9 @@ } //add an empty row - $x = is_array($device_profile_settings) ? count($device_profile_settings) : 0; + $x = !empty($device_profile_settings) && is_array($device_profile_settings) ? count($device_profile_settings) : 0; $device_profile_settings[$x]['domain_uuid'] = $domain_uuid; - $device_profile_settings[$x]['device_profile_uuid'] = $device_profile_uuid; + $device_profile_settings[$x]['device_profile_uuid'] = $device_profile_uuid ?? null; $device_profile_settings[$x]['device_profile_setting_uuid'] = ''; $device_profile_settings[$x]['profile_setting_name'] = ''; $device_profile_settings[$x]['profile_setting_value'] = ''; @@ -376,7 +377,7 @@ $device_profile_settings[$x]['profile_setting_description'] = ''; //filter the uuid - if (!is_uuid($device_profile_uuid)) { + if (empty($device_profile_uuid) || !is_uuid($device_profile_uuid)) { $device_profile_uuid = null; } @@ -398,7 +399,7 @@ if ($action == 'update') { $button_margin = 'margin-left: 15px;'; if (permission_exists('device_profile_add')) { - echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'name'=>'btn_copy','style'=>$button_margin,'onclick'=>"modal_open('modal-copy','btn_copy');"]); + echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'name'=>'btn_copy','style'=>($button_margin ?? null),'onclick'=>"modal_open('modal-copy','btn_copy');"]); unset($button_margin); } if ( @@ -406,7 +407,7 @@ permission_exists('device_profile_key_delete') || permission_exists('device_profile_setting_delete') ) { - echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>$button_margin,'onclick'=>"modal_open('modal-delete','btn_delete');"]); + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>($button_margin ?? null),'onclick'=>"modal_open('modal-delete','btn_delete');"]); unset($button_margin); } } @@ -437,9 +438,9 @@ echo " ".$text['label-device_profile_name']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; - echo $text['description-device_profile_name']."\n"; + echo ($text['description-device_profile_name'] ?? '')."\n"; echo "\n"; echo "\n"; @@ -493,6 +494,7 @@ $device_vendor = str_replace(' ', '_', $row['profile_key_vendor']); //set the column names + $previous_profile_key_vendor = null; if ($previous_profile_key_vendor != $row['profile_key_vendor']) { echo " \n"; echo " ".$text['label-device_key_category']."\n"; @@ -514,7 +516,7 @@ if (permission_exists('device_key_icon')) { echo " ".$text['label-device_key_icon']."\n"; } - if (is_array($device_profile_keys) && @sizeof($device_profile_keys) > 1 && is_uuid($row["device_profile_key_uuid"]) && permission_exists('device_profile_key_delete')) { + if (!empty($device_profile_keys) && is_array($device_profile_keys) && @sizeof($device_profile_keys) > 1 && is_uuid($row["device_profile_key_uuid"]) && permission_exists('device_profile_key_delete')) { echo " \n"; echo " ".$text['label-delete']."\n"; echo " \n"; @@ -600,10 +602,10 @@ $selected = "selected='selected'"; } if (empty($row['profile_key_vendor'])) { - echo " \n"; + echo " \n"; } if (!empty($row['profile_key_vendor']) && $row['profile_key_vendor'] == $function['vendor_name']) { - echo " \n"; + echo " \n"; } $previous_vendor = $function['vendor_name']; $i++; @@ -674,7 +676,7 @@ } echo " \n"; echo "
\n"; - echo $text['description-profile_key_icon']."\n"; + echo ($text['description-profile_key_icon'] ?? '')."\n"; echo "\n"; echo "\n"; @@ -734,7 +736,7 @@ } echo " \n"; echo "
\n"; - echo $text['description-profile_setting_description']."\n"; + echo ($text['description-profile_setting_description'] ?? '')."\n"; echo "\n"; echo "\n"; } @@ -752,7 +754,7 @@ } echo " \n"; echo "
\n"; - echo $text['description-domain_uuid']."\n"; + echo ($text['description-domain_uuid'] ?? '')."\n"; echo "\n"; echo "\n"; } @@ -775,7 +777,7 @@ echo " \n"; } echo "
\n"; - echo $text['description-device_profile_enabled']."\n"; + echo ($text['description-device_profile_enabled'] ?? '')."\n"; echo "\n"; echo "\n"; @@ -784,9 +786,9 @@ echo " ".$text['label-device_profile_description']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; - echo $text['description-device_profile_description']."\n"; + echo ($text['description-device_profile_description'] ?? '')."\n"; echo "\n"; echo "\n"; @@ -801,4 +803,4 @@ //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file