190 lines
7.1 KiB
PHP
190 lines
7.1 KiB
PHP
<?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 editing a user -->
|
|
<?php if ($editUser): ?>
|
|
<h2>Benutzer bearbeiten</h2>
|
|
<form action="/index.php?page=admin_users" method="post">
|
|
<input type="hidden" name="action" value="update">
|
|
<input type="hidden" name="id" value="<?php echo htmlspecialchars($editUser['id']); ?>">
|
|
|
|
<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="mobile">Handynummer:</label>
|
|
<input type="tel" id="mobile" name="mobile" value="<?php echo htmlspecialchars((string)$editUser['mobile']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="iban">IBAN:</label>
|
|
<input type="text" id="iban" name="iban" maxlength="34" value="<?php echo htmlspecialchars((string)$editUser['iban']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="paypal">PayPal:</label>
|
|
<input type="text" id="paypal" name="paypal" maxlength="255" placeholder="E-Mail oder PayPal.Me-Link" value="<?php echo htmlspecialchars((string)$editUser['paypal']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="change_password">Passwort ändern:</label>
|
|
<input type="checkbox" id="change_password" name="change_password" value="1">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Neues Passwort:</label>
|
|
<input type="password" id="password" name="password" autocomplete="new-password"
|
|
placeholder="Nur ausfüllen, wenn das Passwort geändert werden soll" disabled>
|
|
</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 (!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">Speichern</button>
|
|
<a href="/index.php?page=admin_users">Abbrechen</a>
|
|
</div>
|
|
</form>
|
|
|
|
<hr>
|
|
<?php endif; ?>
|
|
|
|
<!-- 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; ?>
|
|
<?php if ($tippableRound): ?>
|
|
<th>Tipps (<?php echo htmlspecialchars($tippableRound['name']); ?>)</th>
|
|
<th>Joker (<?php echo htmlspecialchars($tippableRound['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; ?>
|
|
<?php if ($tippableRound): ?>
|
|
<td class="text-center">
|
|
<?php if (isset($missingTipps[$user['id']])): ?>
|
|
<span class="status-no" title="Tipps fehlen" aria-label="Tipps fehlen">✘</span>
|
|
<?php else: ?>
|
|
<span class="status-yes" title="Runde komplett getippt" aria-label="Runde komplett getippt">✔</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="text-center">
|
|
<?php if (isset($missingJoker[$user['id']])): ?>
|
|
<span class="status-no" title="Joker fehlt" aria-label="Joker fehlt">✘</span>
|
|
<?php else: ?>
|
|
<span class="status-yes" title="Joker gesetzt" aria-label="Joker gesetzt">✔</span>
|
|
<?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: var(--link);
|
|
cursor: pointer;
|
|
padding: 0;
|
|
font-size: inherit;
|
|
text-decoration: underline;
|
|
font-family: inherit;
|
|
}
|
|
.status-yes,
|
|
.status-no {
|
|
font-weight: 900;
|
|
font-size: 1.35em;
|
|
line-height: 1;
|
|
}
|
|
.status-yes { color: var(--pitch); }
|
|
.status-no { color: var(--col-joker-exact); }
|
|
</style>
|
|
|
|
<script>
|
|
(function () {
|
|
var checkbox = document.getElementById('change_password');
|
|
var password = document.getElementById('password');
|
|
if (!checkbox || !password) {
|
|
return;
|
|
}
|
|
function syncPasswordField() {
|
|
password.disabled = !checkbox.checked;
|
|
if (!checkbox.checked) {
|
|
password.value = '';
|
|
}
|
|
}
|
|
checkbox.addEventListener('change', syncPasswordField);
|
|
syncPasswordField();
|
|
})();
|
|
</script>
|
|
|
|
<?php require __DIR__ . '/../partials/footer.php'; ?>
|