Skip to content

Commit 7b61014

Browse files
committed
add user flags to user-mgmt.php
1 parent 36910ed commit 7b61014

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

webroot/admin/user-mgmt.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

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

31-
<table class="searchable longTable sortable filterable">
31+
<table class="searchable longTable sortable filterable column-toggle" id="user-table">
3232
<tr>
3333
<input
3434
type="text"
@@ -39,10 +39,16 @@ class="filterSearch"
3939
>
4040
<th id="name"><span class="filter">⫧ </span>Name</th>
4141
<th id="uid"><span class="filter">⫧ </span>UID</th>
42-
<th id="org"><span class="filter">⫧ </span>Org</th>
42+
<th id="org" class="hidden-by-default"><span class="filter">⫧ </span>Org</th>
4343
<th id="mail"><span class="filter">⫧ </span>Mail</th>
4444
<th id="groups"><span class="filter">⫧ </span>Groups</th>
4545
<th>Actions</th>
46+
<?php
47+
foreach (UserFlag::cases() as $flag) {
48+
$val = $flag->value;
49+
echo "<th id='$val' class='hidden-by-default'><span class='filter'>⫧ </span>$val</th>";
50+
}
51+
?>
4652
</tr>
4753

4854
<?php
@@ -56,6 +62,10 @@ class="filterSearch"
5662
]
5763
);
5864
$csrf_token = htmlspecialchars(CSRFToken::generate());
65+
$users_with_flags = [];
66+
foreach (UserFlag::cases() as $flag) {
67+
$users_with_flags[$flag->value] = $LDAP->userFlagGroups[$flag->value]->getMemberUIDs();
68+
}
5969
usort($user_attributes, fn ($a, $b) => strcmp($a["uid"][0], $b["uid"][0]));
6070
foreach ($user_attributes as $attributes) {
6171
$uid = $attributes["uid"][0];
@@ -73,8 +83,8 @@ class="filterSearch"
7383
</td>
7484
";
7585
echo "<td>";
76-
if (count($UID2PIGIDs[$uid] ?? []) > 0) {
77-
echo "<table style='margin: 0 0 0 0;'>";
86+
if (array_key_exists($uid, $UID2PIGIDs) && count($UID2PIGIDs[$uid] ?? []) > 0) {
87+
echo "<table>";
7888
foreach ($UID2PIGIDs[$uid] as $gid) {
7989
echo "<tr><td>$gid</td></tr>";
8090
}
@@ -90,6 +100,13 @@ class="filterSearch"
90100
<input type='submit' name='action' value='Access'>
91101
</form>";
92102
echo "</td>";
103+
foreach (UserFlag::cases() as $flag) {
104+
echo "<td>";
105+
if (in_array($uid, $users_with_flags[$flag->value])) {
106+
echo $flag->value;
107+
}
108+
echo "</td>";
109+
}
93110
echo "</tr>";
94111
}
95112
?>

webroot/js/tables.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,37 @@ $("#tableSearch").keyup(function () {
5353
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
5454
});
5555
});
56+
57+
function setColumnVisibility(table_id, column_index, is_visible) {
58+
$(`#${table_id} tr > :nth-child(${column_index})`).toggle(is_visible);
59+
}
60+
61+
$("table.column-toggle").each(function () {
62+
const table = $(this);
63+
const id = $(this).attr("id");
64+
if (typeof id === "undefined") {
65+
console.log("error: table does not have id attribute");
66+
return;
67+
}
68+
const checkboxTable = $(`<table style="margin-bottom: 10px;"></table>`);
69+
const checkboxTableRow = $("<tr></tr>");
70+
table.find('th').each((index, th) => {
71+
const checkboxTableCell = $("<td></td>");
72+
const checkboxLabel = $(`<label>${th.textContent.replace('⫧', '').trim()}</label>`);
73+
const checkbox = $('<input type="checkbox">');
74+
if (th.classList.contains("hidden-by-default")) {
75+
setColumnVisibility(id, index + 1, false);
76+
checkbox.prop("checked", false);
77+
} else {
78+
checkbox.prop("checked", true);
79+
}
80+
checkbox.on('change', function () {
81+
setColumnVisibility(id, index + 1, this.checked);
82+
});
83+
checkboxLabel.append(checkbox);
84+
checkboxTableCell.append(checkboxLabel);
85+
checkboxTableRow.append(checkboxTableCell);
86+
});
87+
checkboxTable.append(checkboxTableRow);
88+
table.before(checkboxTable);
89+
});

0 commit comments

Comments
 (0)