mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Filters UI_columns_filters #953
This commit is contained in:
52
front/php/components/devices_filters.php
Executable file
52
front/php/components/devices_filters.php
Executable file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Check if authenticated
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/security.php';
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/server/db.php';
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/language/lang.php';
|
||||
|
||||
// Function to render a filter dropdown
|
||||
function renderFilterDropdown($headerKey, $columnName, $values) {
|
||||
// Generate dropdown options
|
||||
$optionsHtml = '<option value="" selected>All</option>'; // Default "All" option
|
||||
foreach ($values as $value) {
|
||||
$escapedValue = htmlspecialchars($value);
|
||||
$optionsHtml .= '<option value="' . $escapedValue . '">' . $escapedValue . '</option>';
|
||||
}
|
||||
|
||||
// Generate the dropdown HTML
|
||||
return '
|
||||
<div class="filter-group">
|
||||
<label for="filter_' . htmlspecialchars($columnName) . '">' . lang($headerKey) . '</label>
|
||||
<select id="filter_' . htmlspecialchars($columnName) . '" class="filter-dropdown" data-column="' . htmlspecialchars($columnName) . '">
|
||||
' . $optionsHtml . '
|
||||
</select>
|
||||
</div>';
|
||||
}
|
||||
|
||||
// Get filterObject from POST data
|
||||
$filterObject = isset($_POST['filterObject']) ? json_decode($_POST['filterObject'], true) : [];
|
||||
|
||||
// Validate filterObject structure
|
||||
if (!isset($filterObject['filters']) || !is_array($filterObject['filters'])) {
|
||||
echo '<p class="error">Invalid filter data provided.</p>';
|
||||
exit();
|
||||
}
|
||||
|
||||
// Generate HTML for each filter in the filterObject
|
||||
$html = '';
|
||||
foreach ($filterObject['filters'] as $filter) {
|
||||
if (isset($filter['column'], $filter['headerKey'], $filter['options'])) {
|
||||
$html .= renderFilterDropdown($filter['headerKey'], $filter['column'], $filter['options']);
|
||||
} else {
|
||||
// Skip invalid entries
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Output the generated HTML
|
||||
echo $html;
|
||||
exit();
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user