feat: Benutzerverwaltung um Zahlungsstatus für aktuelle Saison erweitern
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
parent
9767767b13
commit
fd20fab5b4
3 changed files with 73 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ use App\Models\User;
|
|||
use App\Models\Round;
|
||||
use App\Models\Season;
|
||||
use App\Models\Ranking;
|
||||
use App\Models\Payment;
|
||||
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
$page = $_GET['page'] ?? null;
|
||||
|
|
@ -57,6 +58,7 @@ if ($page === 'login') {
|
|||
Auth::requireLogin();
|
||||
Auth::requireAdmin();
|
||||
|
||||
$currentSeason = Season::getCurrent();
|
||||
$message = null;
|
||||
$error = null;
|
||||
|
||||
|
|
@ -83,6 +85,9 @@ if ($page === 'login') {
|
|||
$_SESSION['admin_message'] = "Benutzer erfolgreich erstellt.";
|
||||
} elseif ($userId) {
|
||||
User::update($userId, $data);
|
||||
if ($currentSeason) {
|
||||
Payment::setPaidStatus($userId, $currentSeason['id'], isset($_POST['has_paid']));
|
||||
}
|
||||
$_SESSION['admin_message'] = "Benutzer erfolgreich aktualisiert.";
|
||||
}
|
||||
} elseif ($action === 'delete' && $userId) {
|
||||
|
|
@ -110,6 +115,10 @@ if ($page === 'login') {
|
|||
}
|
||||
|
||||
$users = User::getAll();
|
||||
$payments = [];
|
||||
if ($currentSeason) {
|
||||
$payments = Payment::getPaymentsBySeason($currentSeason['id']);
|
||||
}
|
||||
$editUser = null;
|
||||
if (isset($_GET['edit_id'])) {
|
||||
$editUser = User::findById((int)$_GET['edit_id']);
|
||||
|
|
|
|||
44
src/Models/Payment.php
Normal file
44
src/Models/Payment.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
class Payment {
|
||||
/**
|
||||
* Holt alle Zahlungen für eine gegebene Saison, als Map von user_id zu paid_date.
|
||||
*
|
||||
* @param int $seasonId
|
||||
* @return array
|
||||
*/
|
||||
public static function getPaymentsBySeason($seasonId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT user_id, paid_date FROM payments WHERE season_id = ?");
|
||||
$stmt->execute([$seasonId]);
|
||||
return $stmt->fetchAll(\PDO::FETCH_KEY_PAIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Bezahlstatus für einen Benutzer in einer Saison.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $seasonId
|
||||
* @param bool $hasPaid
|
||||
* @return bool
|
||||
*/
|
||||
public static function setPaidStatus($userId, $seasonId, $hasPaid) {
|
||||
$db = Database::getConnection();
|
||||
|
||||
if ($hasPaid) {
|
||||
// Zahlung einfügen oder ignorieren, wenn sie bereits existiert
|
||||
$stmt = $db->prepare(
|
||||
"INSERT IGNORE INTO payments (user_id, season_id, paid_date, created_at, updated_at) VALUES (?, ?, NOW(), NOW(), NOW())"
|
||||
);
|
||||
return $stmt->execute([$userId, $seasonId]);
|
||||
} else {
|
||||
// Zahlung löschen
|
||||
$stmt = $db->prepare("DELETE FROM payments WHERE user_id = ? AND season_id = ?");
|
||||
return $stmt->execute([$userId, $seasonId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,14 @@ require __DIR__ . '/../partials/header.php';
|
|||
<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): ?>
|
||||
|
|
@ -60,6 +68,9 @@ require __DIR__ . '/../partials/header.php';
|
|||
<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>
|
||||
|
|
@ -69,6 +80,15 @@ require __DIR__ . '/../partials/header.php';
|
|||
<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?');">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue