Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions webroot/admin/user-mgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<!-- <input type="text" id="tableSearch" placeholder="Search..."> -->

<table class="searchable longTable sortable filterable">
<table class="searchable longTable sortable filterable column-toggle" id="user-table">
<tr>
<input
type="text"
Expand All @@ -39,10 +39,16 @@ class="filterSearch"
>
<th id="name"><span class="filter">⫧ </span>Name</th>
<th id="uid"><span class="filter">⫧ </span>UID</th>
<th id="org"><span class="filter">⫧ </span>Org</th>
<th id="org" class="hidden-by-default"><span class="filter">⫧ </span>Org</th>
<th id="mail"><span class="filter">⫧ </span>Mail</th>
<th id="groups"><span class="filter">⫧ </span>Groups</th>
<th>Actions</th>
<?php
foreach (UserFlag::cases() as $flag) {
$val = $flag->value;
echo "<th id='$val' class='hidden-by-default'><span class='filter'>⫧ </span>$val</th>";
}
?>
</tr>

<?php
Expand All @@ -56,6 +62,10 @@ class="filterSearch"
]
);
$csrf_token = htmlspecialchars(CSRFToken::generate());
$users_with_flags = [];
foreach (UserFlag::cases() as $flag) {
$users_with_flags[$flag->value] = $LDAP->userFlagGroups[$flag->value]->getMemberUIDs();
}
usort($user_attributes, fn ($a, $b) => strcmp($a["uid"][0], $b["uid"][0]));
foreach ($user_attributes as $attributes) {
$uid = $attributes["uid"][0];
Expand All @@ -73,8 +83,8 @@ class="filterSearch"
</td>
";
echo "<td>";
if (count($UID2PIGIDs[$uid] ?? []) > 0) {
echo "<table style='margin: 0 0 0 0;'>";
if (array_key_exists($uid, $UID2PIGIDs) && count($UID2PIGIDs[$uid] ?? []) > 0) {
echo "<table>";
foreach ($UID2PIGIDs[$uid] as $gid) {
echo "<tr><td>$gid</td></tr>";
}
Expand All @@ -90,6 +100,13 @@ class="filterSearch"
<input type='submit' name='action' value='Access'>
</form>";
echo "</td>";
foreach (UserFlag::cases() as $flag) {
echo "<td>";
if (in_array($uid, $users_with_flags[$flag->value])) {
echo $flag->value;
}
echo "</td>";
}
echo "</tr>";
}
?>
Expand Down
34 changes: 34 additions & 0 deletions webroot/js/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,37 @@ $("#tableSearch").keyup(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});

function setColumnVisibility(table_id, column_index, is_visible) {
$(`#${table_id} tr > :nth-child(${column_index})`).toggle(is_visible);
}

$("table.column-toggle").each(function () {
const table = $(this);
const id = $(this).attr("id");
if (typeof id === "undefined") {
console.log("error: table does not have id attribute");
return;
}
const checkboxTable = $(`<table style="margin-bottom: 10px;"></table>`);
const checkboxTableRow = $("<tr></tr>");
table.find('th').each((index, th) => {
const checkboxTableCell = $("<td></td>");
const checkboxLabel = $(`<label>${th.textContent.replace('⫧', '').trim()}</label>`);
const checkbox = $('<input type="checkbox">');
if (th.classList.contains("hidden-by-default")) {
setColumnVisibility(id, index + 1, false);
checkbox.prop("checked", false);
} else {
checkbox.prop("checked", true);
}
checkbox.on('change', function () {
setColumnVisibility(id, index + 1, this.checked);
});
checkboxLabel.append(checkbox);
checkboxTableCell.append(checkboxLabel);
checkboxTableRow.append(checkboxTableCell);
});
checkboxTable.append(checkboxTableRow);
table.before(checkboxTable);
});