Remove test.php and enhance null safety and sorting across components

- Deleted `test.php` as it was no longer in use.
- Enhanced null safety checks in `Inventory.php`, `StdOut-detail.php`, `Backups.php`, and `SwitchsSAN.php` to prevent potential warnings.
- Refactored `SwitchsSAN.php` to improve sorting logic for ports based on errors, vFabric, and Port ID.
- Added seasonal snow effect script in `all.php` with toggle functionality for user engagement.
- Updated navigation bar (`navbar.html`) to include a new VIO page link.
- Introduced a new `VIO.php` page to display VIO monitoring details with table export and sorting features.
This commit is contained in:
e025532
2026-02-04 14:52:49 +01:00
parent b0c9cafc46
commit d5b45dbc22
9 changed files with 544 additions and 175 deletions

View File

@@ -14,11 +14,11 @@
<link rel="stylesheet" href="/css/bootstrap-icons/bootstrap-icons.css">
<script src="/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="/css/bootstrap-table.min.css">
<script src="/js/bootstrap-table.min.js"></script>
<script src="/js/bootstrap-table-fr-FR.min.js"></script>
<style>
/* Custom styles to match the previous JS rendering */
.table-danger { background-color: #f8d7da !important; }
.table-success { background-color: #d1e7dd !important; }
/* Ensure text is readable on colored headers */
.card-header a { text-decoration: none; color: white; display: block; width: 100%; }
.card-header a:hover { color: #f0f0f0; }
</style>
@@ -26,13 +26,12 @@
<body class="bg-light text-dark">
<?php
// Include your existing libraries
// Include global configurations
include $_SERVER['DOCUMENT_ROOT'] . "/include/all.php";
// --- PHP LOGIC START ---
// 1. Fetch JSON Data
// Ensure the PostJson function returns a valid JSON string
$jsonString = PostJson("$bdnuss/Storage/BROCADE/PORT/BROCADE_PORT_LIST.php", '');
// 2. Decode to PHP Array
@@ -40,7 +39,7 @@
// Check if decode was successful
if (json_last_error() !== JSON_ERROR_NONE) {
$sanData = []; // Fallback to empty array to avoid errors
$sanData = [];
$errorMessage = "Error decoding JSON: " . json_last_error_msg();
}
?>
@@ -62,77 +61,79 @@
<div id="accordion">
<?php
// 3. Loop through Switches
// Loop through Switches
if (!empty($sanData)) {
$switchIndex = 0; // Iterator for unique IDs
$switchIndex = 0;
foreach ($sanData as $switchName => $ports) {
$switchIndex++;
$collapseId = "collapse_" . $switchIndex; // Unique ID for Bootstrap
$collapseId = "collapse_" . $switchIndex;
// Initialize counters
// Inject PortID into the array content for easier sorting
foreach ($ports as $k => $v) $ports[$k]['_PortID'] = $k;
// Custom Sort: Errors (Desc) > vFabric (Asc) > Port (Natural Asc)
uasort($ports, function ($a, $b) {
// Errors (Descending)
$errA = (int)$a['Errors'];
$errB = (int)$b['Errors'];
if ($errA !== $errB) {
return $errB <=> $errA;
}
// vFabric (Ascending / Case Insensitive)
$vfA = $a['vFabric'] ?? '';
$vfB = $b['vFabric'] ?? '';
$cmpVf = strcasecmp($vfA, $vfB);
if ($cmpVf !== 0) {
return $cmpVf;
}
// Port ID (Natural Sort, e.g. 2 comes before 10)
return strnatcmp($a['_PortID'], $b['_PortID']);
});
// Initialize counters & buffers
$upCount = 0;
$downCount = 0;
$errorCount = 0;
$tableBody = "";
// Arrays to store HTML rows (for sorting logic)
$errorRows = [];
$normalRows = [];
// 4. Loop through Ports to calculate stats and build rows
// Generate HTML Rows based on sorted data
foreach ($ports as $portId => $portData) {
$state = $portData['State'];
$errors = (int)$portData['Errors']; // Cast to int for safety
$errors = (int)$portData['Errors'];
if ($state === 'UP') {
$upCount++;
if ($state === 'UP') $upCount++;
elseif ($state === 'DN') $downCount++;
// Determine row color
$rowClass = "table-success";
if ($errors > 0) {
$errorCount++;
$rowClass = "table-danger";
}
if ($errors > 0 && $state === 'UP') $errorCount++;
// Build the HTML for this row
// Note: Using variables in double quotes for cleaner syntax
$rowHtml = "
<tr class='{$rowClass}'>
<td>{$portId}</td>
<td>{$portData['Status']}</td>
<td>{$portData['State']}</td>
<td>{$portData['Speed']}</td>
<td>{$portData['Nego']}</td>
<td>{$portData['FrameTX']}</td>
<td>{$portData['FrameRX']}</td>
<td><strong>{$portData['Errors']}</strong></td>
</tr>";
// Sort into appropriate array
if ($errors > 0) {
$errorRows[] = $rowHtml;
} else {
$normalRows[] = $rowHtml;
}
} elseif ($state === 'DN') {
$downCount++;
if ($state === 'DN') {
continue;
}
// Determine Row CSS Class
$rowClass = "table-success";
if ($errors > 0) $rowClass = "table-danger";
// Build Row HTML
$tableBody .= "
<tr class='{$rowClass}'>
<td>{$portData['vFabric']}</td>
<td>{$portId}</td>
<td>{$portData['Status']}</td>
<td>{$portData['State']}</td>
<td>{$portData['Speed']}</td>
<td>{$portData['Nego']}</td>
<td>{$portData['FrameTX']}</td>
<td>{$portData['FrameRX']}</td>
<td data-value='{$errors}'><strong>{$portData['Errors']}</strong></td>
</tr>";
}
// 5. Merge rows: Errors first
$finalRows = array_merge($errorRows, $normalRows);
$tableBody = implode("\n", $finalRows);
// 6. Determine Header Style
$headerColor = "green";
$msg = "OK";
if ($errorCount > 0) {
$headerColor = "DarkOrange";
$msg = "<b> --> {$errorCount} issue(s)</b>";
}
// 7. Output the Accordion Item (Card)
// Determine Header Color
$headerColor = ($errorCount > 0) ? "DarkOrange" : "green";
$msg = ($errorCount > 0) ? "<b> {$errorCount} issue(s)</b>" : "OK";
?>
<div class="card" style="background-color:<?php echo $headerColor; ?>;">
@@ -142,20 +143,22 @@
</a>
</h4>
</div>
<div id="<?php echo $collapseId; ?>" class="collapse" data-bs-parent="#accordion">
<div class="card-body bg-white border p-0">
<div class="table-responsive">
<table class="table table-bordered table-hover mb-0 text-center">
<table class="table table-bordered table-hover mb-0 text-center" data-toggle="table">
<thead class="table-light">
<tr>
<th>Port</th>
<th>Status</th>
<th>State</th>
<th>Speed</th>
<th>Nego</th>
<th>FrameTX</th>
<th>FrameRX</th>
<th>Errors</th>
<th data-sortable="true">vFabric</th>
<th data-sortable="true">Port</th>
<th data-sortable="true">Status</th>
<th data-sortable="true">State</th>
<th data-sortable="true">Speed</th>
<th data-sortable="true">Nego</th>
<th data-sortable="true">FrameTX</th>
<th data-sortable="true">FrameRX</th>
<th data-sortable="true">Errors</th>
</tr>
</thead>
<tbody>
@@ -168,14 +171,16 @@
<br>
<?php
} // End foreach Switch
}
} else {
echo "<div class='alert alert-warning'>No data available via API.</div>";
}
?>
</div> </div>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="/js/switch.js"></script>
</html>