From 2d6e40bcf63f618875eae733f19f82399d3a0ef1 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Wed, 14 Oct 2026 15:14:11 -0400 Subject: [PATCH] Racks makeover: rack page with to-scale front/rear elevation (click an empty U to add), front/rear mounting and full/half depth, non-asset items (patch panel, cable management, shelf, PDU, UPS, KVM, blanking panel), item edit/move, U and power capacity with largest free gap, front/rear photos, U1 top/bottom numbering, print view, Not racked yet list, rack cards with mini elevation and usage, Racks under All Client Docs, rack position on asset views. Fixes model wiped on every rack save, archive denied for non-admins, item edits taking the rack from the form instead of the item, no bounds check on positions, orphaned rack items on asset delete/transfer and orphaned racks on client delete. DB 2.8.0 --- admin/database_updates/2.8.0.php | 55 ++ admin/post/demo_data_model.php | 59 ++- agent/asset.php | 11 + agent/includes/client_overview_side_nav.php | 16 + agent/includes/client_side_nav.php | 3 +- agent/includes/rack_elevation.php | 136 +++++ agent/modals/asset/asset.php | 11 + agent/modals/rack/rack_add.php | 143 +---- agent/modals/rack/rack_device_add.php | 81 ++- agent/modals/rack/rack_device_edit.php | 65 +++ agent/modals/rack/rack_device_form.php | 256 +++++++++ agent/modals/rack/rack_edit.php | 148 +----- agent/modals/rack/rack_form.php | 166 ++++++ agent/post/asset.php | 6 + agent/post/client.php | 3 + agent/post/rack.php | 391 +++++++------- agent/rack.php | 451 ++++++++++++++++ agent/racks.php | 560 ++++++++++---------- api/v1/assets/delete.php | 3 + api/v1/clients/delete.php | 1 + css/itflow_custom.css | 392 ++++++++++++++ db.sql | 9 + functions.php | 1 + functions/rack.php | 335 ++++++++++++ 24 files changed, 2506 insertions(+), 796 deletions(-) create mode 100644 admin/database_updates/2.8.0.php create mode 100644 agent/includes/rack_elevation.php create mode 100644 agent/modals/rack/rack_device_edit.php create mode 100644 agent/modals/rack/rack_device_form.php create mode 100644 agent/modals/rack/rack_form.php create mode 100644 agent/rack.php create mode 100644 functions/rack.php diff --git a/admin/database_updates/2.8.0.php b/admin/database_updates/2.8.0.php new file mode 100644 index 000000000..e2c7b49b1 --- /dev/null +++ b/admin/database_updates/2.8.0.php @@ -0,0 +1,55 @@ + '%patch%panel%', + 'Cable Management' => '%cable%manage%', + 'Blanking Panel' => '%blank%', + 'Shelf' => '%shelf%', + ]; + foreach ($rack_unit_type_guesses as $rack_unit_type => $rack_unit_pattern) { + mysqli_query($mysqli, "UPDATE `rack_units` SET `unit_type` = '$rack_unit_type' + WHERE `unit_type` IS NULL AND `unit_asset_id` IS NULL AND `unit_device` LIKE '$rack_unit_pattern' + "); + } + mysqli_query($mysqli, "UPDATE `rack_units` SET `unit_type` = 'Device' WHERE `unit_type` IS NULL AND `unit_asset_id` IS NULL"); diff --git a/admin/post/demo_data_model.php b/admin/post/demo_data_model.php index 911c7622f..45ce9c6ad 100644 --- a/admin/post/demo_data_model.php +++ b/admin/post/demo_data_model.php @@ -1678,46 +1678,59 @@ function demoBuildRack($mysqli, $profile, $client_id, $location_id, $assets, $mo $rack_id = starterInsert($mysqli, 'racks', [ 'rack_name' => $profile['abbreviation'] . '-RACK-01', 'rack_description' => 'Main comms rack', - 'rack_model' => 'StarTech 12U Wall Mount', - 'rack_depth' => 'Full', - 'rack_type' => 'Wall Mount', + 'rack_model' => 'StarTech 12U Wall Mount Enclosure', + 'rack_depth' => '18 in', + 'rack_type' => 'Wall-Mount Enclosed', 'rack_units' => 12, + 'rack_power_capacity' => 1000, 'rack_physical_location' => 'Server room', - 'rack_notes' => 'Keyed alike with the comms cupboard. Spare key is held by the onsite point of contact.', + 'rack_notes' => 'Keyed alike with the comms cupboard. Spare key is held by the onsite point of contact. Fed from the 1500VA UPS at the bottom of the rack.', 'rack_location_id' => $location_id, 'rack_client_id' => $client_id, 'rack_created_at' => demoMonthDateTime($months, 6, 15, 0), ]); $counts['documentation']++; - // Patch panel at the top, then the kit under it - $unit = 12; - starterInsert($mysqli, 'rack_units', [ - 'unit_start_number' => $unit, - 'unit_end_number' => $unit, - 'unit_device' => 'Patch panel - 24 port', - 'unit_rack_id' => $rack_id, - 'unit_created_at' => demoMonthDateTime($months, 6, 15, 5), - ]); + $racked_at = demoMonthDateTime($months, 6, 15, 5); + $rack_item = function ($start, $end, $fields) use ($mysqli, $rack_id, $racked_at) { + starterInsert($mysqli, 'rack_units', $fields + [ + 'unit_start_number' => $start, + 'unit_end_number' => $end, + 'unit_face' => 'front', + 'unit_full_depth' => 1, + 'unit_rack_id' => $rack_id, + 'unit_created_at' => $racked_at, + ]); + }; + // Patching at the top, front only - the PDU shares those units at the back + $rack_item(12, 12, ['unit_device' => 'Patch panel - 24 port Cat6', 'unit_type' => 'Patch Panel', 'unit_full_depth' => 0]); + $rack_item(11, 11, ['unit_device' => 'Horizontal cable manager', 'unit_type' => 'Cable Management', 'unit_full_depth' => 0]); + $rack_item(11, 12, ['unit_device' => 'Switched PDU - 8 outlet', 'unit_type' => 'PDU', 'unit_face' => 'rear', 'unit_full_depth' => 0]); + + // Then the kit, top down. Firewalls and switches are short-depth; servers are not. + $unit = 11; foreach ($rackable as $asset) { - $unit--; - if ($unit < 1) { + $height = $asset['type'] === 'Server' ? 2 : 1; + $end = $unit - 1; + $start = $end - ($height - 1); + if ($start < 3) { break; } - $height = $asset['type'] === 'Server' ? 2 : 1; - $start = max(1, $unit - ($height - 1)); - starterInsert($mysqli, 'rack_units', [ - 'unit_start_number' => $start, - 'unit_end_number' => $unit, - 'unit_device' => $asset['name'] . ' - ' . $asset['make'] . ' ' . $asset['model'], + $is_server = $asset['type'] === 'Server'; + $is_poe = stripos($asset['model'], 'poe') !== false; + $rack_item($start, $end, [ + 'unit_device' => '', 'unit_asset_id' => $asset['id'], - 'unit_rack_id' => $rack_id, - 'unit_created_at' => demoMonthDateTime($months, 6, 15, 5), + 'unit_full_depth' => $is_server ? 1 : 0, + 'unit_power_watts' => $is_server ? 220 : ($is_poe ? 150 : 35), ]); $unit = $start; } + // The UPS everything runs on, at the bottom where the weight belongs + $rack_item(1, 2, ['unit_device' => 'APC Smart-UPS 1500VA 2U', 'unit_type' => 'UPS', 'unit_notes' => 'Battery replaced at install']); + } // ------------------------------ diff --git a/agent/asset.php b/agent/asset.php index 1ba5498b8..b42b91178 100644 --- a/agent/asset.php +++ b/agent/asset.php @@ -101,6 +101,14 @@ if (isset($_GET['asset_id'])) { $location_name_display = $location_name; } + // The rack it sits in, if any + $asset_rack = rackPositionForAsset($asset_id); + if ($asset_rack) { + $asset_rack_id = intval($asset_rack['rack_id']); + $asset_rack_name = escapeHtml($asset_rack['rack_name']); + $asset_rack_position = rackPositionLabel($asset_rack['unit_start_number'], $asset_rack['unit_end_number']) . ', ' . ($asset_rack['unit_face'] === 'rear' ? 'rear' : 'front'); + } + // Override Tab Title // No Sanitizing needed as this var will opnly be used in the tab title $page_title = $row['asset_name']; @@ -365,6 +373,9 @@ if (isset($_GET['asset_id'])) {
+
·
+
+ +