Add search functionality for users in admin panel and improve email display
This commit is contained in:
parent
c693574575
commit
cb4df57993
@ -69,15 +69,31 @@ if ($rolesQuery) {
|
||||
}
|
||||
}
|
||||
|
||||
// 3) Alle Benutzer laden
|
||||
$usersResult = $conn->query("
|
||||
// 3) Alle Benutzer laden (mit Suche)
|
||||
$searchQuery = isset($_GET['search']) ? trim($_GET['search']) : '';
|
||||
$searchParam = '%' . $searchQuery . '%';
|
||||
|
||||
$sql = "
|
||||
SELECT u.userID, u.email, u.displayname, u.profilePicture, u.isActive,
|
||||
GROUP_CONCAT(ur.roleID) as roleIDs
|
||||
FROM users u
|
||||
LEFT JOIN userRoles ur ON u.userID = ur.userID
|
||||
GROUP BY u.userID
|
||||
ORDER BY u.userID ASC
|
||||
");
|
||||
";
|
||||
|
||||
if ($searchQuery !== '') {
|
||||
$sql .= " WHERE u.displayname LIKE ? OR u.email LIKE ?";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY u.userID ORDER BY u.userID ASC";
|
||||
|
||||
$stmtUsers = $conn->prepare($sql);
|
||||
if ($searchQuery !== '') {
|
||||
$stmtUsers->bind_param("ss", $searchParam, $searchParam);
|
||||
}
|
||||
$stmtUsers->execute();
|
||||
$usersResult = $stmtUsers->get_result();
|
||||
|
||||
$formActionUrl = "admin_users.php" . ($searchQuery !== '' ? "?search=" . urlencode($searchQuery) : "");
|
||||
|
||||
?>
|
||||
|
||||
@ -98,7 +114,15 @@ $usersResult = $conn->query("
|
||||
<div class="auth__message auth__message--error" style="color: #f87171; background: #7f1d1d; padding: 10px; border-radius: 4px; margin-bottom: 15px; text-align: center;"><?= htmlspecialchars($errorMsg) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="admin_users.php">
|
||||
<form method="get" action="admin_users.php" style="margin-bottom: 20px; display: flex; gap: 10px; align-items: center;">
|
||||
<input type="text" name="search" placeholder="Suche nach Name oder E-Mail..." value="<?= htmlspecialchars($searchQuery) ?>" style="flex: 1; background: #0f172a; color: #f8fafc; border: 1px solid #334155; padding: 10px; border-radius: 4px; font-size: 0.95rem;">
|
||||
<button type="submit" class="auth__submit" style="width: auto; padding: 10px 16px; margin: 0; background-color: #3b82f6;">Suchen</button>
|
||||
<?php if ($searchQuery !== ''): ?>
|
||||
<a href="admin_users.php" style="color: #94a3b8; text-decoration: none; padding: 10px; font-size: 0.9rem;">Zurücksetzen</a>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
|
||||
<form method="post" action="<?= htmlspecialchars($formActionUrl) ?>">
|
||||
<div style="display: flex; justify-content: flex-end; margin-top: 10px;">
|
||||
<button type="submit" name="update_all_roles" value="1" style="background-color: #3b82f6; color: white; border: none; padding: 10px 16px; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 0.9rem;">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align: middle; margin-right: 5px;">
|
||||
@ -136,7 +160,7 @@ $usersResult = $conn->query("
|
||||
alt="Profil" style="width: 40px; height: 40px; border-radius: 50%; object-fit: cover; display: block;">
|
||||
</td>
|
||||
<td style="padding: 12px 10px;"><?= htmlspecialchars($user['displayname']) ?></td>
|
||||
<td style="padding: 12px 10px; word-break: break-all;"><?= htmlspecialchars($user['email']) ?></td>
|
||||
<td style="padding: 12px 10px; white-space: nowrap;"><?= htmlspecialchars($user['email']) ?></td>
|
||||
|
||||
<td style="padding: 12px 10px;">
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 5px;">
|
||||
@ -155,7 +179,6 @@ $usersResult = $conn->query("
|
||||
<?php if (!$isSelf): ?>
|
||||
<input type="hidden" name="submitted_users[]" value="<?= $user['userID'] ?>">
|
||||
<select name="user_roles[<?= $user['userID'] ?>]" style="background: #0f172a; color: #f8fafc; border: 1px solid #334155; padding: 5px; border-radius: 4px; font-size: 0.85rem; width: 100%;">
|
||||
<option value="">Keine</option>
|
||||
<?php foreach ($allRoles as $role): ?>
|
||||
<option value="<?= $role['roleID'] ?>" <?= in_array($role['roleID'], $userRoles) ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($role['name']) ?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user