diff --git a/tippspiel/public/css/style.css b/tippspiel/public/css/style.css index 8a20aec..2d376c2 100644 --- a/tippspiel/public/css/style.css +++ b/tippspiel/public/css/style.css @@ -80,6 +80,21 @@ h2 { margin-top: 1.4em; } a { color: var(--link); } +/* Aktuelle Mitteilung auf der Startseite (große Schrift) */ +.announcement { + font-family: var(--font-display); + font-size: 1.6em; + font-weight: 700; + color: var(--pitch-dark); + background: #fffbe6; + border: 2px solid var(--gold); + border-left: 8px solid var(--gold); + border-radius: 8px; + padding: 0.8em 1em; + margin: 0 0 1.5em; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08); +} + /* Sprungziele (#round-…, #playerid_…) nicht unter der fixierten Navigation verstecken */ [id] { scroll-margin-top: 90px; } a:hover { color: var(--pitch-dark); } @@ -126,6 +141,23 @@ a:hover { color: var(--pitch-dark); } .nav-user { margin-left: auto; } +/* Menüpunkt "Fragen": animiertes Leuchten bei neuen Fragen/Antworten */ +@keyframes nav-glow { + 0%, 100% { + box-shadow: 0 0 0 rgba(242, 194, 48, 0); + background-color: rgba(255, 255, 255, 0.12); + color: #fff; + } + 50% { + box-shadow: 0 0 12px 3px rgba(242, 194, 48, 0.9); + background-color: rgba(242, 194, 48, 0.45); + color: #3d2d00; + } +} +.site-nav a.is-glowing { + animation: nav-glow 1.5s ease-in-out infinite; +} + /* Dropdowns in der Navigation (Administration, Info, Spielermenü) */ .nav-dropdown { position: relative; display: inline-block; } .nav-dropdown-content { diff --git a/tippspiel/public/index.php b/tippspiel/public/index.php index e4887bf..6c99c53 100644 --- a/tippspiel/public/index.php +++ b/tippspiel/public/index.php @@ -20,6 +20,7 @@ use App\Models\Quota; use App\Models\Roundmail; use App\Models\Setting; use App\Models\Team; +use App\Models\Question; $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $page = $_GET['page'] ?? null; @@ -49,6 +50,7 @@ if ($page === 'reminder') { $appUrl = getenv('APP_URL') ?: ((!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . ($_SERVER['HTTP_HOST'] ?? 'localhost')); // Aufräumen läuft bei jedem Aufruf, auch wenn keine Erinnerung fällig ist echo Roundmail::deleteOldReminders() . " alte Erinnerungen gelöscht.\n"; + echo Question::deleteOld() . " alte Fragen/Antworten gelöscht.\n"; echo Roundmail::sendReminder($appUrl) . "\n"; } catch (\Throwable $e) { http_response_code(500); @@ -323,6 +325,24 @@ if ($page === 'reminder') { } $moneyRanking = $result ? Ranking::moneyRanking($result, true) : []; require __DIR__ . '/../src/Views/admin/accounts.php'; +} elseif ($page === 'admin_message') { + // Aktuelle Mitteilung für die Startseite (nur Admins) + Auth::requireLogin(); + Auth::requireAdmin(); + + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + Setting::setMessage($_POST['message'] ?? ''); + $_SESSION['admin_message'] = 'Die aktuelle Mitteilung wurde gespeichert.'; + header('Location: /index.php?page=admin_message'); + exit; + } + + $flashMessage = $_SESSION['admin_message'] ?? null; + $error = $_SESSION['admin_error'] ?? null; + unset($_SESSION['admin_message'], $_SESSION['admin_error']); + $currentMessage = Setting::getMessage(); + + require __DIR__ . '/../src/Views/admin/message.php'; } elseif ($page === 'settings') { // Eigene Spielerdaten (Legacy UsersController::useredit / storeUserEdit) Auth::requireLogin(); @@ -848,10 +868,76 @@ if ($page === 'reminder') { http_response_code(500); echo "

Fehler: " . htmlspecialchars($e->getMessage()) . "

"; } +} elseif ($page === 'questions') { + // Fragen an die Admins (Legacy: kein direkter Vorgänger, neu für 2027) + Auth::requireLogin(); + $user = Auth::user(); + $isAdmin = (bool)$user['admin']; + + $message = $_SESSION['questions_message'] ?? null; + $error = $_SESSION['questions_error'] ?? null; + unset($_SESSION['questions_message'], $_SESSION['questions_error']); + + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $action = $_POST['action'] ?? ''; + $redirect = '/index.php?page=questions'; + + if ($action === 'ask') { + $questionText = trim($_POST['question'] ?? ''); + if ($questionText === '') { + $_SESSION['questions_error'] = 'Bitte gib eine Frage ein.'; + } else { + Question::create((int)$user['id'], $questionText); + $_SESSION['questions_message'] = 'Deine Frage wurde an die Admins gesendet.'; + } + } elseif ($action === 'answer') { + if (!$isAdmin) { + header('Location: /'); + exit; + } + $questionId = (int)($_POST['id'] ?? 0); + $answerText = trim($_POST['answer'] ?? ''); + $question = Question::findById($questionId); + if (!$question) { + $_SESSION['questions_error'] = 'Frage nicht gefunden.'; + } elseif ($question['answer'] !== null) { + $_SESSION['questions_error'] = 'Die Frage wurde bereits beantwortet.'; + } elseif ($answerText === '') { + $_SESSION['questions_error'] = 'Bitte gib eine Antwort ein.'; + $redirect .= '&answer_id=' . $questionId; + } else { + Question::answer($questionId, $answerText, (int)$user['id']); + $_SESSION['questions_message'] = 'Antwort wurde gespeichert.'; + } + } + + header('Location: ' . $redirect); + exit; + } + + // Beim Ansehen werden die eigenen Antworten (und für Admins auch die + // offenen Fragen) als gesehen markiert. + Question::markAnswersSeen((int)$user['id']); + if ($isAdmin) { + Question::markQuestionsSeen(); + } + + $questions = $isAdmin ? Question::findAllForAdmin() : Question::findByUser((int)$user['id']); + + $answerQuestion = null; + if ($isAdmin && isset($_GET['answer_id'])) { + $answerQuestion = Question::findById((int)$_GET['answer_id']); + if (!$answerQuestion || $answerQuestion['answer'] !== null) { + $answerQuestion = null; + } + } + + require __DIR__ . '/../src/Views/questions.php'; } elseif ($page === 'home') { Auth::requireLogin(); try { $currentSeason = Season::getCurrent(); + $message = Setting::getMessage(); if ($currentSeason) { $rounds = []; diff --git a/tippspiel/src/Models/Question.php b/tippspiel/src/Models/Question.php new file mode 100644 index 0000000..2c12254 --- /dev/null +++ b/tippspiel/src/Models/Question.php @@ -0,0 +1,174 @@ +prepare( + "INSERT INTO questions (user_id, question, question_date, created_at, updated_at) + VALUES (?, ?, NOW(), NOW(), NOW())" + ); + $stmt->execute([(int)$userId, $question]); + return (int)$db->lastInsertId(); + } + + /** + * Alle Fragen eines Spielers, neueste zuerst. + * + * @param int $userId + * @return array + */ + public static function findByUser($userId) { + $db = Database::getConnection(); + $stmt = $db->prepare( + "SELECT * FROM questions WHERE user_id = ? ORDER BY question_date DESC, id DESC" + ); + $stmt->execute([(int)$userId]); + return $stmt->fetchAll(); + } + + /** + * Alle Fragen für die Admin-Ansicht (offene zuerst), mit Name des Fragestellers. + * + * @return array + */ + public static function findAllForAdmin() { + $db = Database::getConnection(); + $stmt = $db->prepare( + "SELECT q.*, COALESCE(u.name, '?') AS user_name + FROM questions q + LEFT JOIN users u ON u.id = q.user_id + ORDER BY (q.answer IS NULL) DESC, q.question_date DESC, q.id DESC" + ); + $stmt->execute(); + return $stmt->fetchAll(); + } + + /** + * @param int $id + * @return array|false + */ + public static function findById($id) { + $db = Database::getConnection(); + $stmt = $db->prepare( + "SELECT q.*, COALESCE(u.name, '?') AS user_name + FROM questions q + LEFT JOIN users u ON u.id = q.user_id + WHERE q.id = ?" + ); + $stmt->execute([(int)$id]); + return $stmt->fetch(); + } + + /** + * Beantwortet eine Frage und markiert die Antwort für den Spieler als neu. + * + * @param int $id + * @param string $answer + * @param int $adminId + * @return bool + */ + public static function answer($id, $answer, $adminId) { + $db = Database::getConnection(); + $stmt = $db->prepare( + "UPDATE questions + SET answer = ?, answer_date = NOW(), answered_by = ?, answer_seen = 0, updated_at = NOW() + WHERE id = ?" + ); + return $stmt->execute([$answer, (int)$adminId, (int)$id]); + } + + /** + * Gibt es für einen Spieler eine noch nicht angesehene Antwort? + * + * @param int $userId + * @return bool + */ + public static function hasNewAnswer($userId) { + $db = Database::getConnection(); + $stmt = $db->prepare( + "SELECT COUNT(*) FROM questions WHERE user_id = ? AND answer IS NOT NULL AND answer_seen = 0" + ); + $stmt->execute([(int)$userId]); + return (int)$stmt->fetchColumn() > 0; + } + + /** + * Gibt es eine noch nicht von einem Admin angesehene offene Frage? + * + * @return bool + */ + public static function hasNewQuestion() { + $db = Database::getConnection(); + $stmt = $db->prepare( + "SELECT COUNT(*) FROM questions WHERE answer IS NULL AND question_seen = 0" + ); + $stmt->execute(); + return (int)$stmt->fetchColumn() > 0; + } + + /** + * Markiert alle beantworteten Fragen eines Spielers als angesehen. + * + * @param int $userId + * @return int + */ + public static function markAnswersSeen($userId) { + $db = Database::getConnection(); + $stmt = $db->prepare( + "UPDATE questions SET answer_seen = 1, updated_at = NOW() + WHERE user_id = ? AND answer IS NOT NULL AND answer_seen = 0" + ); + $stmt->execute([(int)$userId]); + return $stmt->rowCount(); + } + + /** + * Markiert alle offenen Fragen als von Admins angesehen. + * + * @return int + */ + public static function markQuestionsSeen() { + $db = Database::getConnection(); + $stmt = $db->prepare( + "UPDATE questions SET question_seen = 1, updated_at = NOW() + WHERE answer IS NULL AND question_seen = 0" + ); + $stmt->execute(); + return $stmt->rowCount(); + } + + /** + * Löscht Fragen (und damit ihre Antworten), die älter als RETENTION_YEARS Jahre sind. + * + * @return int Anzahl gelöschter Fragen + */ + public static function deleteOld() { + $db = Database::getConnection(); + $stmt = $db->prepare( + "DELETE FROM questions + WHERE question_date < CURDATE() - INTERVAL " . (int)self::RETENTION_YEARS . " YEAR" + ); + $stmt->execute(); + return $stmt->rowCount(); + } +} diff --git a/tippspiel/src/Models/Setting.php b/tippspiel/src/Models/Setting.php index 67ba090..caf589c 100644 --- a/tippspiel/src/Models/Setting.php +++ b/tippspiel/src/Models/Setting.php @@ -42,4 +42,39 @@ class Setting { $stmt = $db->prepare("UPDATE settings SET registration_open = ?, updated_at = NOW() WHERE id = ?"); return $stmt->execute([$open ? 1 : 0, $settingsId]); } + + /** + * Aktuelle Mitteilung für die Startseite (leer = keine Mitteilung). + * + * @return string + */ + public static function getMessage() { + $db = Database::getConnection(); + $value = $db->query("SELECT message FROM settings ORDER BY id LIMIT 1")->fetchColumn(); + return $value === false ? '' : (string)$value; + } + + /** + * Setzt (oder löscht) die aktuelle Mitteilung für die Startseite. + * + * @param string $message + * @return bool + */ + public static function setMessage($message) { + $db = Database::getConnection(); + $message = trim((string)$message); + $settingsId = $db->query("SELECT id FROM settings ORDER BY id LIMIT 1")->fetchColumn(); + + if ($settingsId === false) { + $current = Season::getCurrent(); + $stmt = $db->prepare( + "INSERT INTO settings (current_season_id, registration_open, message, created_at, updated_at) + VALUES (?, ?, ?, NOW(), NOW())" + ); + return $stmt->execute([$current ? (int)$current['id'] : 0, 1, $message]); + } + + $stmt = $db->prepare("UPDATE settings SET message = ?, updated_at = NOW() WHERE id = ?"); + return $stmt->execute([$message, $settingsId]); + } } diff --git a/tippspiel/src/Views/admin/message.php b/tippspiel/src/Views/admin/message.php new file mode 100644 index 0000000..c349c23 --- /dev/null +++ b/tippspiel/src/Views/admin/message.php @@ -0,0 +1,34 @@ + + +

Aktuelle Mitteilung

+ + +

+ + +

+ + +

Die Mitteilung erscheint in großer Schrift oben auf der Startseite. Leer lassen und speichern entfernt die Mitteilung.

+ +
+
+ + +
+
+ +
+
+ + + + diff --git a/tippspiel/src/Views/home.php b/tippspiel/src/Views/home.php index 80ce488..fd2396a 100644 --- a/tippspiel/src/Views/home.php +++ b/tippspiel/src/Views/home.php @@ -7,6 +7,10 @@ require __DIR__ . '/partials/header.php';

Willkommen bei Tippspiel 2027

+ +
+ +

Abgeschlossene Runden:

Saison:

diff --git a/tippspiel/src/Views/partials/header.php b/tippspiel/src/Views/partials/header.php index b5f8e85..bd20205 100644 --- a/tippspiel/src/Views/partials/header.php +++ b/tippspiel/src/Views/partials/header.php @@ -1,4 +1,16 @@ - + @@ -14,9 +26,10 @@ + +
diff --git a/tippspiel/src/Views/questions.php b/tippspiel/src/Views/questions.php new file mode 100644 index 0000000..850700c --- /dev/null +++ b/tippspiel/src/Views/questions.php @@ -0,0 +1,138 @@ + + +

Fragen

+ + +

+ + +

+ + + + +

Frage beantworten

+
+

+ Von + · +

+

+
+ + + + +
+ + +
+
+ + Abbrechen +
+ + + + + +

Hier siehst du alle Fragen der Spieler. Offene Fragen kannst du direkt beantworten.

+ +

Hier siehst du deine Fragen an die Admins und deren Antworten.

+ + +

Neue Frage stellen

+
+ +
+ + +
+
+ +
+
+ +

+ + +

+ + +
+

+ + Von + + · +

+

+ + +

Noch nicht beantwortet

+ +

Antworten

+ + +
+

Antwort ·

+

+
+ +
+ + + + + + + + diff --git a/tools/schema.sql b/tools/schema.sql index 3944c49..8172fcb 100644 --- a/tools/schema.sql +++ b/tools/schema.sql @@ -102,6 +102,7 @@ CREATE TABLE `settings` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `current_season_id` int(11) NOT NULL, `registration_open` tinyint(1) NOT NULL DEFAULT '1', + `message` text DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) @@ -144,6 +145,23 @@ CREATE TABLE `roundmails` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +DROP TABLE IF EXISTS `questions`; +CREATE TABLE `questions` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `question` text NOT NULL, + `question_date` datetime NOT NULL, + `answer` text DEFAULT NULL, + `answer_date` datetime DEFAULT NULL, + `answered_by` int(11) DEFAULT NULL, + `answer_seen` tinyint(1) NOT NULL DEFAULT '0', + `question_seen` tinyint(1) NOT NULL DEFAULT '0', + `created_at` timestamp NULL DEFAULT NULL, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `questions_user_id_index` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + DROP TABLE IF EXISTS `manual_payouts`; CREATE TABLE `manual_payouts` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT,