diff --git a/public/index.php b/public/index.php index 7ee1f24..e0edb5f 100644 --- a/public/index.php +++ b/public/index.php @@ -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']); diff --git a/src/Models/Payment.php b/src/Models/Payment.php new file mode 100644 index 0000000..b34d2c3 --- /dev/null +++ b/src/Models/Payment.php @@ -0,0 +1,44 @@ +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]); + } + } +} diff --git a/src/Views/admin/users.php b/src/Views/admin/users.php index 02f2966..5e6989b 100644 --- a/src/Views/admin/users.php +++ b/src/Views/admin/users.php @@ -42,6 +42,14 @@ require __DIR__ . '/../partials/header.php'; > + + +