tippspiel2027/src/Views/admin/users.php

132 lines
4.7 KiB
PHP
Raw Normal View History

<?php
$pageTitle = 'Benutzer verwalten';
require __DIR__ . '/../partials/header.php';
?>
<h1>Benutzer verwalten</h1>
<?php if (!empty($message)): ?>
<p style="color: green;"><?php echo htmlspecialchars($message); ?></p>
<?php endif; ?>
<?php if (!empty($error)): ?>
<p style="color: red;"><?php echo htmlspecialchars($error); ?></p>
<?php endif; ?>
<!-- Form for creating/editing a user -->
<h2><?php echo $editUser ? 'Benutzer bearbeiten' : 'Neuen Benutzer anlegen'; ?></h2>
<form action="/index.php?page=admin_users" method="post">
<?php if ($editUser): ?>
<input type="hidden" name="action" value="update">
<input type="hidden" name="id" value="<?php echo htmlspecialchars($editUser['id']); ?>">
<?php else: ?>
<input type="hidden" name="action" value="create">
<?php endif; ?>
<div class="form-group">
<label for="firstname">Vorname:</label>
<input type="text" id="firstname" name="firstname" value="<?php echo htmlspecialchars($editUser['firstname'] ?? ''); ?>" required>
</div>
<div class="form-group">
<label for="lastname">Nachname:</label>
<input type="text" id="lastname" name="lastname" value="<?php echo htmlspecialchars($editUser['lastname'] ?? ''); ?>" required>
</div>
<div class="form-group">
<label for="email">E-Mail:</label>
<input type="email" id="email" name="email" value="<?php echo htmlspecialchars($editUser['email'] ?? ''); ?>" required>
</div>
<div class="form-group">
<label for="password">Passwort:</label>
<input type="password" id="password" name="password" placeholder="<?php echo $editUser ? 'Leer lassen, um nicht zu ändern' : ''; ?>">
</div>
<div class="form-group">
<label for="admin">Admin:</label>
<input type="checkbox" id="admin" name="admin" value="1" <?php echo !empty($editUser['admin']) ? 'checked' : ''; ?>>
</div>
<?php if ($editUser && !empty($currentSeason)): ?>
<div class="form-group">
<label for="has_paid">Bezahlt (<?php echo htmlspecialchars($currentSeason['name']); ?>):</label>
<input type="checkbox" id="has_paid" name="has_paid" value="1" <?php echo isset($payments[$editUser['id']]) ? 'checked' : ''; ?>>
</div>
<?php endif; ?>
<div class="form-group">
<button type="submit"><?php echo $editUser ? 'Speichern' : 'Anlegen'; ?></button>
<?php if ($editUser): ?>
<a href="/index.php?page=admin_users">Abbrechen</a>
<?php endif; ?>
</div>
</form>
<hr>
<!-- User List -->
<h2>Benutzerliste</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>E-Mail</th>
<th>Admin</th>
<?php if (!empty($currentSeason)): ?>
<th>Bezahlt (<?php echo htmlspecialchars($currentSeason['name']); ?>)</th>
<?php endif; ?>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo htmlspecialchars($user['name']); ?></td>
<td><?php echo htmlspecialchars($user['email']); ?></td>
<td><?php echo $user['admin'] ? 'Ja' : 'Nein'; ?></td>
<?php if (!empty($currentSeason)): ?>
<td>
<?php if (isset($payments[$user['id']])): ?>
Ja (<?php echo date('d.m.Y', strtotime($payments[$user['id']])); ?>)
<?php else: ?>
Nein
<?php endif; ?>
</td>
<?php endif; ?>
<td>
<a href="/index.php?page=admin_users&edit_id=<?php echo $user['id']; ?>">Bearbeiten</a>
<form action="/index.php?page=admin_users" method="post" style="display: inline;" onsubmit="return confirm('Sicher, dass du diesen Benutzer löschen willst?');">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?php echo $user['id']; ?>">
<button type="submit" class="link-button">Löschen</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<style>
/* From login.php, for consistency */
.form-group {
margin-bottom: 1rem;
}
.form-group label {
display: inline-block;
width: 150px;
text-align: right;
margin-right: 10px;
}
.form-group button, .form-group a {
margin-left: calc(150px + 10px);
}
.link-button {
background: none;
border: none;
color: #007bff;
cursor: pointer;
padding: 0;
font-size: inherit;
text-decoration: underline;
font-family: inherit;
}
</style>
<?php require __DIR__ . '/../partials/footer.php'; ?>