Erster Durchstich mit updates
This commit is contained in:
parent
d3fd60b548
commit
3331f08091
60 changed files with 693 additions and 195 deletions
112
tippspiel/src/Core/Auth.php
Normal file
112
tippspiel/src/Core/Auth.php
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class Auth {
|
||||
private static $user = null;
|
||||
|
||||
/**
|
||||
* Startet die Session, falls noch nicht geschehen.
|
||||
*/
|
||||
public static function start() {
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Versucht, den Benutzer anzumelden.
|
||||
*
|
||||
* @param string $firstname
|
||||
* @param string $lastname
|
||||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
public static function login($firstname, $lastname, $password) {
|
||||
$user = User::findByFirstAndLastName($firstname, $lastname);
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Meldet den Benutzer ab.
|
||||
*/
|
||||
public static function logout() {
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
unset($_SESSION['user_id']);
|
||||
}
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob ein Benutzer angemeldet ist.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function check() {
|
||||
return isset($_SESSION['user_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die ID des aktuell angemeldeten Benutzers zurück.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public static function id() {
|
||||
return $_SESSION['user_id'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den aktuell angemeldeten Benutzer zurück.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function user() {
|
||||
if (!self::check()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (self::$user === null) {
|
||||
self::$user = User::findById(self::id());
|
||||
}
|
||||
|
||||
return self::$user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob der angemeldete Benutzer ein Admin ist.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAdmin() {
|
||||
$user = self::user();
|
||||
return $user && $user['admin'] == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Leitet zur Login-Seite weiter, wenn der Benutzer nicht angemeldet ist.
|
||||
*/
|
||||
public static function requireLogin() {
|
||||
if (!self::check()) {
|
||||
header('Location: /index.php?page=login');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Leitet zur Startseite, wenn der Benutzer kein Admin ist.
|
||||
*/
|
||||
public static function requireAdmin() {
|
||||
if (!self::isAdmin()) {
|
||||
header('Location: /index.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
tippspiel/src/Core/Database.php
Normal file
39
tippspiel/src/Core/Database.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
class Database {
|
||||
private static $instance = null;
|
||||
private $pdo;
|
||||
|
||||
private function __construct() {
|
||||
$host = getenv('DB_HOST') ?: '127.0.0.1';
|
||||
$user = getenv('DB_USER') ?: 'root';
|
||||
$pass = getenv('DB_PASS') ?: '';
|
||||
$dbName = getenv('DB_NEW_NAME') ?: 'tippspiel2027';
|
||||
|
||||
$dsn = "mysql:host=$host;dbname=$dbName;charset=utf8mb4";
|
||||
|
||||
try {
|
||||
$this->pdo = new PDO($dsn, $user, $pass);
|
||||
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
die("Datenbankverbindung fehlgeschlagen: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function getInstance() {
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public static function getConnection() {
|
||||
return self::getInstance()->pdo;
|
||||
}
|
||||
}
|
||||
133
tippspiel/src/Core/Mailer.php
Normal file
133
tippspiel/src/Core/Mailer.php
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core;
|
||||
|
||||
/**
|
||||
* Minimaler SMTP-Client ohne externe Abhängigkeiten.
|
||||
*
|
||||
* Konfiguration über Umgebungsvariablen:
|
||||
* SMTP_HOST, SMTP_PORT (Default 587), SMTP_USER, SMTP_PASS,
|
||||
* SMTP_ENCRYPTION (tls = STARTTLS, ssl = SMTPS, none), MAIL_FROM, MAIL_FROM_NAME
|
||||
*/
|
||||
class Mailer {
|
||||
|
||||
private $socket;
|
||||
|
||||
/**
|
||||
* Versendet eine HTML-Mail einzeln an jeden Empfänger (Empfänger sehen sich gegenseitig nicht).
|
||||
*
|
||||
* @param string[] $recipients
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param string|null $replyTo
|
||||
* @return string[] Empfänger, an die nicht versendet werden konnte
|
||||
* @throws \Exception bei Verbindungs- oder Anmeldefehlern
|
||||
*/
|
||||
public static function send(array $recipients, $subject, $html, $replyTo = null) {
|
||||
$mailer = new self();
|
||||
$mailer->connect();
|
||||
|
||||
$failed = [];
|
||||
try {
|
||||
foreach ($recipients as $to) {
|
||||
try {
|
||||
$mailer->sendOne($to, $subject, $html, $replyTo);
|
||||
} catch (\Exception $e) {
|
||||
$failed[] = $to;
|
||||
$mailer->command('RSET', [250]);
|
||||
}
|
||||
}
|
||||
$mailer->command('QUIT', [221]);
|
||||
} finally {
|
||||
fclose($mailer->socket);
|
||||
}
|
||||
return $failed;
|
||||
}
|
||||
|
||||
private function connect() {
|
||||
$host = getenv('SMTP_HOST');
|
||||
if (!$host) {
|
||||
throw new \Exception('Kein Mailserver konfiguriert (SMTP_HOST fehlt).');
|
||||
}
|
||||
$port = (int)(getenv('SMTP_PORT') ?: 587);
|
||||
$encryption = getenv('SMTP_ENCRYPTION') ?: 'tls';
|
||||
|
||||
$address = ($encryption === 'ssl' ? 'ssl://' : 'tcp://') . $host . ':' . $port;
|
||||
$this->socket = @stream_socket_client($address, $errno, $errstr, 15);
|
||||
if (!$this->socket) {
|
||||
throw new \Exception("Verbindung zum Mailserver fehlgeschlagen: $errstr");
|
||||
}
|
||||
stream_set_timeout($this->socket, 30);
|
||||
|
||||
$this->expect([220]);
|
||||
$hostname = gethostname() ?: 'localhost';
|
||||
$this->command("EHLO $hostname", [250]);
|
||||
|
||||
if ($encryption === 'tls') {
|
||||
$this->command('STARTTLS', [220]);
|
||||
if (!stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
|
||||
throw new \Exception('STARTTLS fehlgeschlagen.');
|
||||
}
|
||||
$this->command("EHLO $hostname", [250]);
|
||||
}
|
||||
|
||||
$user = getenv('SMTP_USER');
|
||||
if ($user) {
|
||||
$this->command('AUTH LOGIN', [334]);
|
||||
$this->command(base64_encode($user), [334]);
|
||||
$this->command(base64_encode((string)getenv('SMTP_PASS')), [235]);
|
||||
}
|
||||
}
|
||||
|
||||
private function sendOne($to, $subject, $html, $replyTo) {
|
||||
$from = getenv('MAIL_FROM') ?: 'noreply@localhost';
|
||||
$fromName = getenv('MAIL_FROM_NAME') ?: 'Tippspiel';
|
||||
|
||||
$this->command('MAIL FROM:<' . $from . '>', [250]);
|
||||
$this->command('RCPT TO:<' . $to . '>', [250, 251]);
|
||||
$this->command('DATA', [354]);
|
||||
|
||||
$headers = [
|
||||
'Date: ' . date('r'),
|
||||
'From: ' . self::encodeHeader($fromName) . ' <' . $from . '>',
|
||||
'To: <' . $to . '>',
|
||||
'Subject: ' . self::encodeHeader($subject),
|
||||
'MIME-Version: 1.0',
|
||||
'Content-Type: text/html; charset=UTF-8',
|
||||
'Content-Transfer-Encoding: base64',
|
||||
];
|
||||
if ($replyTo) {
|
||||
$headers[] = 'Reply-To: <' . $replyTo . '>';
|
||||
}
|
||||
|
||||
$body = chunk_split(base64_encode($html), 76, "\r\n");
|
||||
// base64 enthält keine Zeilen, die mit "." beginnen – kein Dot-Stuffing nötig
|
||||
fwrite($this->socket, implode("\r\n", $headers) . "\r\n\r\n" . $body . ".\r\n");
|
||||
$this->expect([250]);
|
||||
}
|
||||
|
||||
private function command($line, array $expectedCodes) {
|
||||
fwrite($this->socket, $line . "\r\n");
|
||||
return $this->expect($expectedCodes);
|
||||
}
|
||||
|
||||
private function expect(array $expectedCodes) {
|
||||
$response = '';
|
||||
while (($line = fgets($this->socket, 515)) !== false) {
|
||||
$response .= $line;
|
||||
// Mehrzeilige Antworten: "250-..." – letzte Zeile hat ein Leerzeichen nach dem Code
|
||||
if (strlen($line) < 4 || $line[3] === ' ') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$code = (int)substr($response, 0, 3);
|
||||
if (!in_array($code, $expectedCodes, true)) {
|
||||
throw new \Exception('SMTP-Fehler: ' . trim($response));
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
private static function encodeHeader($text) {
|
||||
return preg_match('/[^\x20-\x7E]/', $text) ? '=?UTF-8?B?' . base64_encode($text) . '?=' : $text;
|
||||
}
|
||||
}
|
||||
93
tippspiel/src/Models/Game.php
Normal file
93
tippspiel/src/Models/Game.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
use DateTime;
|
||||
use DateInterval;
|
||||
|
||||
class Game {
|
||||
|
||||
/**
|
||||
* Prüft ob ein Spiel bereits gelockt (Anpfiff steht kurz bevor) ist.
|
||||
* Portiert aus dem Laravel Game Modell: Lock war 1 Minute vor Anpfiff.
|
||||
*/
|
||||
public static function isLocked($kickoffTime) {
|
||||
$now = new DateTime();
|
||||
$kickoff = new DateTime($kickoffTime);
|
||||
|
||||
// 1 Minute vor Anpfiff wird gelockt
|
||||
$kickoff->sub(new DateInterval('PT1M'));
|
||||
|
||||
return $now >= $kickoff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt einen formatierten String für das Ergebnis eines Spiels zurück
|
||||
*/
|
||||
public static function getResultString($score1, $score2, $kickoffTime) {
|
||||
if ($score1 > -1 && $score2 > -1) {
|
||||
return "$score1 : $score2";
|
||||
}
|
||||
|
||||
$now = new DateTime();
|
||||
$start = new DateTime($kickoffTime);
|
||||
$end = (clone $start)->add(new DateInterval('PT2H')); // ca. 2 Stunden nach Anpfiff
|
||||
|
||||
if ($start > $now) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
if ($now > $start && $now < $end) {
|
||||
return "Läuft";
|
||||
}
|
||||
|
||||
return "(Eingeben)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Spiele einer Runde aus der Datenbank
|
||||
*/
|
||||
public static function getGamesByRound($roundId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM games WHERE round_id = ? ORDER BY kickoff ASC, id ASC");
|
||||
$stmt->execute([$roundId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt ein Spiel anhand der ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array|false
|
||||
*/
|
||||
public static function getById($id) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM games WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert Paarung, Anstoß und Ergebnis eines Spiels (Legacy GamesController::store).
|
||||
* Ein fehlendes Ergebnis wird als -1:-1 gespeichert.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data ['team1', 'team2', 'kickoff' (Y-m-d H:i:s), 'score1', 'score2']
|
||||
* @return bool
|
||||
*/
|
||||
public static function update($id, array $data) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"UPDATE games SET team1 = ?, team2 = ?, kickoff = ?, score1 = ?, score2 = ?, updated_at = NOW() WHERE id = ?"
|
||||
);
|
||||
return $stmt->execute([
|
||||
$data['team1'],
|
||||
$data['team2'],
|
||||
$data['kickoff'],
|
||||
(int)$data['score1'],
|
||||
(int)$data['score2'],
|
||||
$id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
44
tippspiel/src/Models/Payment.php
Normal file
44
tippspiel/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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
171
tippspiel/src/Models/Quota.php
Normal file
171
tippspiel/src/Models/Quota.php
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
class Quota {
|
||||
|
||||
/** Anzahl der Platzierungen mit Preisgeld (platz1..platz10) */
|
||||
const PLACES = 10;
|
||||
|
||||
/**
|
||||
* Berechnet die Ausschüttungsbeträge einer Saison (portiert aus Legacy Quota::getPayouts).
|
||||
*
|
||||
* - Pott = bezahlte Spieler * Einsatz.
|
||||
* - Tagessieg je Runde: Anteil "tagessieg" / Rundenzahl, auf durch 6 teilbar abgerundet.
|
||||
* Der Rundungsrest fließt in den Platzierungstopf.
|
||||
* - Platz 1..10: Anteil "platzN" des Platzierungstopfs, auf durch 6 teilbar abgerundet.
|
||||
* - Der nicht verteilte Rest des Potts geht an Platz 1.
|
||||
* Grünes Trikot, Pokal und Liga werden nicht mehr berücksichtigt.
|
||||
*
|
||||
* @param int $seasonId
|
||||
* @return array ['tagessieg' => int, 'platz1' => int, ..., 'platz10' => int]
|
||||
*/
|
||||
public static function computePayouts($seasonId) {
|
||||
$quotas = self::getMapBySeason($seasonId);
|
||||
$quota = fn($name) => $quotas[$name] ?? 0.0;
|
||||
|
||||
$roundCount = count(Round::getBySeason($seasonId));
|
||||
$pot = count(User::getPaid($seasonId)) * $quota('einsatz');
|
||||
|
||||
$dayWinSum = (int)($pot * $quota('tagessieg') / 100);
|
||||
$dayWin = $roundCount > 0 ? self::get6Divisor((int)($dayWinSum / $roundCount)) : 0;
|
||||
|
||||
$placementPot = (int)($pot * $quota('platzierung') / 100);
|
||||
$placementPot += $dayWinSum - $dayWin * $roundCount;
|
||||
|
||||
$payouts = ['tagessieg' => $dayWin];
|
||||
$distributed = $dayWin * $roundCount;
|
||||
for ($place = 1; $place <= self::PLACES; $place++) {
|
||||
$amount = self::get6Divisor((int)($placementPot * $quota('platz' . $place) / 100));
|
||||
$payouts['platz' . $place] = $amount;
|
||||
$distributed += $amount;
|
||||
}
|
||||
|
||||
// Nicht verteilter Rest an Platz 1
|
||||
$payouts['platz1'] += (int)$pot - $distributed;
|
||||
|
||||
return $payouts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Senkt die Zahl, bis sie durch 6 teilbar ist (Abrundungsvorgabe für Ausschüttungen).
|
||||
* @param int $number
|
||||
* @return int
|
||||
*/
|
||||
public static function get6Divisor($number) {
|
||||
return max(0, $number - $number % 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Quoten für eine Saison.
|
||||
* @param int $seasonId
|
||||
* @return array
|
||||
*/
|
||||
public static function getBySeason($seasonId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM quotas WHERE season_id = ? ORDER BY `order` ASC, id ASC");
|
||||
$stmt->execute([$seasonId]);
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quoten einer Saison als name => prc.
|
||||
* @param int $seasonId
|
||||
* @return array
|
||||
*/
|
||||
public static function getMapBySeason($seasonId) {
|
||||
$map = [];
|
||||
foreach (self::getBySeason($seasonId) as $quota) {
|
||||
$map[$quota['name']] = (float)$quota['prc'];
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Namen der pflegbaren Quoten (Legacy SeasonsController::store_quota).
|
||||
* @return string[]
|
||||
*/
|
||||
public static function editableNames() {
|
||||
$names = ['einsatz', 'tagessieg', 'platzierung'];
|
||||
for ($place = 1; $place <= self::PLACES; $place++) {
|
||||
$names[] = 'platz' . $place;
|
||||
}
|
||||
return $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standardquoten für eine neue Saison (Legacy Quota::createDefaultQuota
|
||||
* ohne Grünes Trikot, Pokal und Liga).
|
||||
* @return array name => prc
|
||||
*/
|
||||
public static function defaults() {
|
||||
return [
|
||||
'einsatz' => 40, 'tagessieg' => 60, 'platzierung' => 40,
|
||||
'platz1' => 21, 'platz2' => 17, 'platz3' => 13, 'platz4' => 10, 'platz5' => 9,
|
||||
'platz6' => 8, 'platz7' => 7, 'platz8' => 6, 'platz9' => 5, 'platz10' => 4,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft die Quoten: alle Werte >= 0, Tagessieg + Platzierung = 100 %,
|
||||
* Platz 1..10 zusammen = 100 %.
|
||||
* @param array $quotas name => prc
|
||||
* @return string|null Fehlermeldung oder null
|
||||
*/
|
||||
public static function validate(array $quotas) {
|
||||
foreach (self::editableNames() as $name) {
|
||||
if (!isset($quotas[$name]) || !is_numeric($quotas[$name]) || $quotas[$name] < 0) {
|
||||
return "Ungültiger Wert für \"$name\".";
|
||||
}
|
||||
}
|
||||
if (abs($quotas['tagessieg'] + $quotas['platzierung'] - 100) > 0.001) {
|
||||
return 'Tagessieg und Platzierung müssen zusammen 100 % ergeben.';
|
||||
}
|
||||
$placeSum = 0;
|
||||
for ($place = 1; $place <= self::PLACES; $place++) {
|
||||
$placeSum += $quotas['platz' . $place];
|
||||
}
|
||||
if (abs($placeSum - 100) > 0.001) {
|
||||
return 'Die Platzierungsquoten müssen zusammen 100 % ergeben (aktuell ' . round($placeSum, 2) . ' %).';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert die pflegbaren Quoten einer Saison (Upsert je Name wie Legacy Quota::setQuota).
|
||||
* Andere Einträge (z.B. Legacy gshirt, liga) bleiben unverändert.
|
||||
* @param int $seasonId
|
||||
* @param array $quotas name => prc
|
||||
*/
|
||||
public static function saveForSeason($seasonId, array $quotas) {
|
||||
$db = Database::getConnection();
|
||||
$existing = [];
|
||||
foreach (self::getBySeason($seasonId) as $quota) {
|
||||
$existing[$quota['name']] = (int)$quota['id'];
|
||||
}
|
||||
|
||||
$update = $db->prepare("UPDATE quotas SET prc = ?, `order` = ?, updated_at = NOW() WHERE id = ?");
|
||||
$insert = $db->prepare(
|
||||
"INSERT INTO quotas (season_id, name, `order`, prc, created_at, updated_at) VALUES (?, ?, ?, ?, NOW(), NOW())"
|
||||
);
|
||||
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
foreach (self::editableNames() as $name) {
|
||||
$prc = (float)$quotas[$name];
|
||||
$order = str_starts_with($name, 'platz') && $name !== 'platzierung' ? (int)substr($name, 5) : 0;
|
||||
if (isset($existing[$name])) {
|
||||
$update->execute([$prc, $order, $existing[$name]]);
|
||||
} else {
|
||||
$insert->execute([$seasonId, $name, $order, $prc]);
|
||||
}
|
||||
}
|
||||
$db->commit();
|
||||
} catch (\Exception $e) {
|
||||
$db->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
388
tippspiel/src/Models/Ranking.php
Normal file
388
tippspiel/src/Models/Ranking.php
Normal file
|
|
@ -0,0 +1,388 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
/**
|
||||
* Rangliste, Tagessieg und Ausschüttungen einer Saison
|
||||
* (portiert aus Legacy Tipp::getRoundTipps und Quota::getPayoutList).
|
||||
*
|
||||
* Regeln:
|
||||
* - Wertung: nur Spieler mit Zahlung für die Saison.
|
||||
* - Gesamtpunkte: Summe der Rundenpunkte (Tipp::evaluateRound) bis zur gewählten Runde.
|
||||
* - Rang: nach Gesamtpunkten, Gleichstand = geteilter Rang (1, 1, 3).
|
||||
* - Tagessieg (nur abgeschlossene Runden): meiste exakte Treffer, dann höchster Joker-Wert.
|
||||
* Bei mehr als 6 Tagessiegern bleiben nur die mit den meisten Rundenpunkten.
|
||||
* Ohne Tagessieger wandert das Preisgeld in die nächste Runde mit Tagessieger.
|
||||
* - Platzierungsgeld: nur wenn die letzte Runde der Saison angezeigt wird.
|
||||
* Geteilte Ränge teilen sich das Geld; unbesetzte Plätze gehen an die Gruppe darüber.
|
||||
*/
|
||||
class Ranking {
|
||||
|
||||
/** Ab mehr als so vielen Tagessiegern entscheiden die Rundenpunkte */
|
||||
const MAX_DAY_WINNERS = 6;
|
||||
|
||||
/**
|
||||
* Berechnet die komplette Wertung einer Saison bis einschließlich $maxRoundId.
|
||||
*
|
||||
* @param int $seasonId
|
||||
* @param int $maxRoundId
|
||||
* @return array [
|
||||
* 'max_round_id' => int,
|
||||
* 'users' => user_id => Zeile aus `users` (nur bezahlte Spieler),
|
||||
* 'rounds' => round_id => ['round', 'games', 'completed', 'entries' => user_id => Auswertung],
|
||||
* 'ranks' => user_id => Rang (sortiert nach Rang),
|
||||
* 'totals' => user_id => Gesamtpunkte,
|
||||
* 'tipps' => user_id => game_id => Tipp (nur für $maxRoundId),
|
||||
* 'is_final' => bool,
|
||||
* 'ranking_payouts' => user_id => Betrag,
|
||||
* 'payouts' => Ergebnis von Quota::computePayouts,
|
||||
* ]
|
||||
*/
|
||||
public static function compute($seasonId, $maxRoundId) {
|
||||
$maxRoundId = (int)$maxRoundId;
|
||||
$allRounds = Round::getBySeason($seasonId);
|
||||
$gamesByRound = self::loadGames($seasonId, $maxRoundId);
|
||||
$tippsByRound = self::loadTipps($seasonId, $maxRoundId);
|
||||
$payouts = Quota::computePayouts($seasonId);
|
||||
|
||||
$users = [];
|
||||
foreach (User::getPaid($seasonId) as $user) {
|
||||
$users[(int)$user['id']] = $user;
|
||||
}
|
||||
$userIds = array_keys($users);
|
||||
|
||||
$totals = array_fill_keys($userIds, 0);
|
||||
$rounds = [];
|
||||
$dayPrizePot = 0.0;
|
||||
|
||||
foreach ($allRounds as $round) {
|
||||
$roundId = (int)$round['id'];
|
||||
if ($roundId > $maxRoundId) {
|
||||
break;
|
||||
}
|
||||
$games = $gamesByRound[$roundId] ?? [];
|
||||
if (empty($games)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$completed = true;
|
||||
foreach ($games as $game) {
|
||||
if ((int)$game['score1'] < 0 || (int)$game['score2'] < 0) {
|
||||
$completed = false;
|
||||
}
|
||||
}
|
||||
|
||||
$entries = [];
|
||||
foreach ($userIds as $userId) {
|
||||
$entry = Tipp::evaluateRound($games, $tippsByRound[$roundId][$userId] ?? []);
|
||||
$totals[$userId] += $entry['points'];
|
||||
$entry['total'] = $totals[$userId];
|
||||
$entry['is_day_winner'] = false;
|
||||
$entry['payout'] = 0.0;
|
||||
$entries[$userId] = $entry;
|
||||
}
|
||||
|
||||
// Tagessieg: Preisgeld sammelt sich, bis es einen Sieger gibt
|
||||
$dayPrizePot += $payouts['tagessieg'];
|
||||
$winners = $completed ? self::determineDayWinners($entries) : [];
|
||||
if (!empty($winners)) {
|
||||
$perWinner = round($dayPrizePot / count($winners), 2);
|
||||
$dayPrizePot = 0.0;
|
||||
foreach ($winners as $userId) {
|
||||
$entries[$userId]['is_day_winner'] = true;
|
||||
$entries[$userId]['payout'] = $perWinner;
|
||||
}
|
||||
}
|
||||
|
||||
$rounds[$roundId] = [
|
||||
'round' => $round,
|
||||
'games' => $games,
|
||||
'completed' => $completed,
|
||||
'entries' => $entries,
|
||||
];
|
||||
}
|
||||
|
||||
$ranks = self::computeRanks($totals, $users);
|
||||
|
||||
$lastRound = end($allRounds);
|
||||
$isFinal = $lastRound && (int)$lastRound['id'] === $maxRoundId && isset($rounds[$maxRoundId]);
|
||||
|
||||
return [
|
||||
'max_round_id' => $maxRoundId,
|
||||
'users' => $users,
|
||||
'rounds' => $rounds,
|
||||
'ranks' => $ranks,
|
||||
'totals' => $totals,
|
||||
'tipps' => $tippsByRound[$maxRoundId] ?? [],
|
||||
'is_final' => $isFinal,
|
||||
'ranking_payouts' => $isFinal ? self::computeRankingPayouts($ranks, $payouts) : [],
|
||||
'payouts' => $payouts,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeilen der Ranglisten-Tabelle für die gewählte Runde, sortiert nach Rang.
|
||||
*
|
||||
* @param array $result Ergebnis von compute()
|
||||
* @return array
|
||||
*/
|
||||
public static function roundTable(array $result) {
|
||||
$roundId = $result['max_round_id'];
|
||||
if (!isset($result['rounds'][$roundId])) {
|
||||
return [];
|
||||
}
|
||||
$round = $result['rounds'][$roundId];
|
||||
|
||||
$rows = [];
|
||||
foreach ($result['ranks'] as $userId => $rank) {
|
||||
$entry = $round['entries'][$userId];
|
||||
$cells = [];
|
||||
foreach ($round['games'] as $game) {
|
||||
$tipp = $result['tipps'][$userId][$game['id']] ?? null;
|
||||
$tipp1 = $tipp ? (int)$tipp['score1'] : -1;
|
||||
$tipp2 = $tipp ? (int)$tipp['score2'] : -1;
|
||||
$joker = $tipp ? (bool)$tipp['joker'] : false;
|
||||
$cells[$game['id']] = [
|
||||
'text' => ($tipp1 < 0 ? 'x' : $tipp1) . ':' . ($tipp2 < 0 ? 'x' : $tipp2),
|
||||
'joker' => $joker,
|
||||
'points' => Tipp::getScoreLocal((int)$game['score1'], (int)$game['score2'], $tipp1, $tipp2, $joker),
|
||||
'color' => Tipp::getCol((int)$game['score1'], (int)$game['score2'], $tipp1, $tipp2, $joker),
|
||||
];
|
||||
}
|
||||
|
||||
$rows[] = [
|
||||
'user_id' => $userId,
|
||||
'name' => $result['users'][$userId]['name'],
|
||||
'rank' => $rank,
|
||||
'total' => $entry['total'],
|
||||
'points' => $entry['points'],
|
||||
'is_day_winner' => $entry['is_day_winner'],
|
||||
'payout' => $entry['payout'],
|
||||
'ranking_payout' => $result['ranking_payouts'][$userId] ?? 0,
|
||||
'cells' => $cells,
|
||||
];
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Einzelne Ausschüttungen je Spieler (Legacy Quota::getPayoutList).
|
||||
*
|
||||
* @param array $result Ergebnis von compute()
|
||||
* @return array user_id => [['label' => ..., 'amount' => ...], ...]
|
||||
*/
|
||||
public static function payoutItems(array $result) {
|
||||
$items = array_fill_keys(array_keys($result['users']), []);
|
||||
|
||||
foreach ($result['rounds'] as $round) {
|
||||
foreach ($round['entries'] as $userId => $entry) {
|
||||
if ($entry['payout'] > 0) {
|
||||
$items[$userId][] = [
|
||||
'label' => $round['round']['name'] . ' (Tagessieg)',
|
||||
'amount' => $entry['payout'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($result['ranking_payouts'] as $userId => $amount) {
|
||||
if ($amount > 0) {
|
||||
$items[$userId][] = [
|
||||
'label' => 'Platzierungssieg Rang ' . $result['ranks'][$userId],
|
||||
'amount' => $amount,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wertung für Geldrangliste und Kontoliste (Legacy UsersController::money_ranking):
|
||||
* gerechnet wird bis zur letzten gesperrten Runde, angezeigt erst, wenn mindestens
|
||||
* eine Runde abgeschlossen ist.
|
||||
*
|
||||
* @param int $seasonId
|
||||
* @return array ['result' => Ergebnis von compute() oder null, 'season_start' => \DateTime|null]
|
||||
*/
|
||||
public static function computeForMoneyRanking($seasonId) {
|
||||
$lastLockedRoundId = null;
|
||||
$hasCompletedRound = false;
|
||||
$seasonStart = null;
|
||||
foreach (Round::getBySeason($seasonId) as $round) {
|
||||
$games = Game::getGamesByRound($round['id']);
|
||||
if (empty($games)) {
|
||||
continue;
|
||||
}
|
||||
$seasonStart = $seasonStart ?? Round::getLockTime($games);
|
||||
if (Round::isLocked($games)) {
|
||||
$lastLockedRoundId = (int)$round['id'];
|
||||
}
|
||||
if (Round::isCompleted($games)) {
|
||||
$hasCompletedRound = true;
|
||||
}
|
||||
}
|
||||
|
||||
$result = null;
|
||||
if ($hasCompletedRound && $lastLockedRoundId !== null) {
|
||||
$result = self::compute($seasonId, $lastLockedRoundId);
|
||||
}
|
||||
return ['result' => $result, 'season_start' => $seasonStart];
|
||||
}
|
||||
|
||||
/**
|
||||
* Geldrangliste: Summe aller Ausschüttungen je Spieler, absteigend sortiert.
|
||||
*
|
||||
* @param array $result Ergebnis von compute()
|
||||
* @return array Liste von ['user_id', 'name', 'amount', 'iban', 'bankname', 'blz', 'kontonr']
|
||||
*/
|
||||
public static function moneyRanking(array $result) {
|
||||
$list = [];
|
||||
foreach (self::payoutItems($result) as $userId => $items) {
|
||||
$user = $result['users'][$userId];
|
||||
$list[] = [
|
||||
'user_id' => $userId,
|
||||
'name' => $user['name'],
|
||||
'amount' => array_sum(array_column($items, 'amount')),
|
||||
'iban' => $user['iban'],
|
||||
'bankname' => $user['bankname'],
|
||||
'blz' => $user['blz'],
|
||||
'kontonr' => $user['kontonr'],
|
||||
];
|
||||
}
|
||||
|
||||
usort($list, fn($a, $b) => [$b['amount'], $a['name']] <=> [$a['amount'], $b['name']]);
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tagessieger einer Runde.
|
||||
*
|
||||
* @param array $entries user_id => Auswertung (Tipp::evaluateRound)
|
||||
* @return array user_ids
|
||||
*/
|
||||
private static function determineDayWinners(array $entries) {
|
||||
$best = null;
|
||||
foreach ($entries as $entry) {
|
||||
if ($best === null || Tipp::compareDayScore($entry, $best) < 0) {
|
||||
$best = $entry;
|
||||
}
|
||||
}
|
||||
if ($best === null || $best['exact'] === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$winners = array_keys(array_filter(
|
||||
$entries,
|
||||
fn($entry) => Tipp::compareDayScore($entry, $best) === 0
|
||||
));
|
||||
|
||||
if (count($winners) > self::MAX_DAY_WINNERS) {
|
||||
$maxPoints = max(array_map(fn($userId) => $entries[$userId]['points'], $winners));
|
||||
$winners = array_values(array_filter(
|
||||
$winners,
|
||||
fn($userId) => $entries[$userId]['points'] === $maxPoints
|
||||
));
|
||||
}
|
||||
|
||||
return $winners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ränge nach Gesamtpunkten (geteilte Ränge bei Gleichstand), bei Gleichstand nach Name sortiert.
|
||||
*
|
||||
* @return array user_id => Rang, in Ranglisten-Reihenfolge
|
||||
*/
|
||||
private static function computeRanks(array $totals, array $users) {
|
||||
$order = array_keys($totals);
|
||||
usort($order, fn($a, $b) =>
|
||||
[$totals[$b], $users[$a]['name']] <=> [$totals[$a], $users[$b]['name']]
|
||||
);
|
||||
|
||||
$ranks = [];
|
||||
$previousTotal = null;
|
||||
$rank = 0;
|
||||
foreach ($order as $position => $userId) {
|
||||
if ($totals[$userId] !== $previousTotal) {
|
||||
$rank = $position + 1;
|
||||
$previousTotal = $totals[$userId];
|
||||
}
|
||||
$ranks[$userId] = $rank;
|
||||
}
|
||||
return $ranks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verteilt das Platzierungsgeld (Plätze 1..10) auf die Spieler.
|
||||
*
|
||||
* @return array user_id => Betrag
|
||||
*/
|
||||
private static function computeRankingPayouts(array $ranks, array $payouts) {
|
||||
$groups = [];
|
||||
foreach ($ranks as $userId => $rank) {
|
||||
if ($rank <= Quota::PLACES) {
|
||||
$groups[$rank][] = $userId;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [];
|
||||
for ($place = 1; $place <= Quota::PLACES; $place++) {
|
||||
// Unbesetzter Platz (z.B. Platz 2 bei zwei Erstplatzierten) geht an die Gruppe darüber
|
||||
$rank = $place;
|
||||
while ($rank > 0 && !isset($groups[$rank])) {
|
||||
$rank--;
|
||||
}
|
||||
if ($rank === 0) {
|
||||
continue;
|
||||
}
|
||||
$share = $payouts['platz' . $place] / count($groups[$rank]);
|
||||
foreach ($groups[$rank] as $userId) {
|
||||
$result[$userId] = ($result[$userId] ?? 0) + $share;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array round_id => Liste der Spiele
|
||||
*/
|
||||
private static function loadGames($seasonId, $maxRoundId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"SELECT g.* FROM games g
|
||||
JOIN rounds r ON r.id = g.round_id
|
||||
WHERE r.season_id = ? AND r.id <= ?
|
||||
ORDER BY g.round_id, g.kickoff, g.id"
|
||||
);
|
||||
$stmt->execute([$seasonId, $maxRoundId]);
|
||||
|
||||
$result = [];
|
||||
foreach ($stmt->fetchAll() as $game) {
|
||||
$result[(int)$game['round_id']][] = $game;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array round_id => user_id => game_id => Tipp
|
||||
*/
|
||||
private static function loadTipps($seasonId, $maxRoundId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"SELECT g.round_id, t.user_id, t.game_id, t.score1, t.score2, t.joker
|
||||
FROM tipps t
|
||||
JOIN games g ON g.id = t.game_id
|
||||
JOIN rounds r ON r.id = g.round_id
|
||||
WHERE r.season_id = ? AND r.id <= ?"
|
||||
);
|
||||
$stmt->execute([$seasonId, $maxRoundId]);
|
||||
|
||||
$result = [];
|
||||
foreach ($stmt->fetchAll() as $row) {
|
||||
$result[(int)$row['round_id']][(int)$row['user_id']][(int)$row['game_id']] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
126
tippspiel/src/Models/Round.php
Normal file
126
tippspiel/src/Models/Round.php
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
class Round {
|
||||
|
||||
/**
|
||||
* Holt eine Runde anhand der ID
|
||||
*/
|
||||
public static function getById($id) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM rounds WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Runden einer Season
|
||||
*/
|
||||
public static function getBySeason($seasonId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM rounds WHERE season_id = ? ORDER BY id ASC");
|
||||
$stmt->execute([$seasonId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert den Namen einer Runde.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public static function updateName($id, $name) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("UPDATE rounds SET name = ?, updated_at = NOW() WHERE id = ?");
|
||||
return $stmt->execute([$name, $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert den Rundenbericht. Zeilenumbrüche werden wie im Legacy als <br/> gespeichert.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $report Klartext mit Zeilenumbrüchen
|
||||
* @return bool
|
||||
*/
|
||||
public static function updateReport($id, $report) {
|
||||
$report = str_replace(["\r\n", "\r", "\n"], "<br/>", trim($report));
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("UPDATE rounds SET report = ?, updated_at = NOW() WHERE id = ?");
|
||||
return $stmt->execute([$report, $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rundenbericht als Klartext für Formulare (Gegenstück zu updateReport).
|
||||
*
|
||||
* @param string|null $report
|
||||
* @return string
|
||||
*/
|
||||
public static function reportToText($report) {
|
||||
return str_replace(["<br/>", "<br>", "<br />"], "\n", (string)$report);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sperrzeitpunkt der Runde: 1 Minute vor dem frühesten Anstoß (Legacy Round::getLockTime).
|
||||
*
|
||||
* @param array $games Spiele der Runde
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public static function getLockTime(array $games) {
|
||||
if (empty($games)) {
|
||||
return null;
|
||||
}
|
||||
$earliest = min(array_column($games, 'kickoff'));
|
||||
return (new \DateTime($earliest))->modify('-1 minute');
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Runde ist abgeschlossen, wenn alle Spiele ein Ergebnis haben (Legacy Round::isCompleted).
|
||||
*
|
||||
* @param array $games Spiele der Runde
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCompleted(array $games) {
|
||||
foreach ($games as $game) {
|
||||
if ((int)$game['score1'] < 0 || (int)$game['score2'] < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Runde ist gesperrt, sobald eines ihrer Spiele gesperrt ist (Legacy Round::hasLockedGame).
|
||||
*
|
||||
* @param array $games Spiele der Runde
|
||||
* @return bool
|
||||
*/
|
||||
public static function isLocked(array $games) {
|
||||
foreach ($games as $game) {
|
||||
if (Game::isLocked($game['kickoff'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erste Runde der Saison, in der noch kein Spiel gesperrt ist (Legacy Round::getFirstTippableRound).
|
||||
*
|
||||
* @param int $seasonId
|
||||
* @return array|null Runde inkl. 'games'
|
||||
*/
|
||||
public static function getFirstTippable($seasonId) {
|
||||
foreach (self::getBySeason($seasonId) as $round) {
|
||||
$games = Game::getGamesByRound($round['id']);
|
||||
if (!self::isLocked($games)) {
|
||||
$round['games'] = $games;
|
||||
return $round;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
240
tippspiel/src/Models/Roundmail.php
Normal file
240
tippspiel/src/Models/Roundmail.php
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
use App\Core\Mailer;
|
||||
|
||||
/**
|
||||
* Protokoll der versendeten Rundmails (Legacy Roundmail).
|
||||
* user_id = 0 steht für den Automailer.
|
||||
*/
|
||||
class Roundmail {
|
||||
|
||||
/** Erinnerungen werden erst verschickt, wenn die Runde in weniger als so vielen Stunden sperrt */
|
||||
const REMINDER_HOURS = 48;
|
||||
|
||||
/** Betreff der automatischen Erinnerungsmails */
|
||||
const REMINDER_TOPIC = 'Fehlende Tipps/Joker';
|
||||
|
||||
/** Automatische Erinnerungen werden nach so vielen Monaten aus dem Protokoll gelöscht */
|
||||
const REMINDER_RETENTION_MONTHS = 1;
|
||||
|
||||
/**
|
||||
* Anzahl aller protokollierten Mails.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function count() {
|
||||
$db = Database::getConnection();
|
||||
return (int)$db->query("SELECT COUNT(*) FROM roundmails")->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Seite der Mails, neueste zuerst, mit Name des Versenders.
|
||||
*
|
||||
* @param int $limit
|
||||
* @param int $offset
|
||||
* @return array
|
||||
*/
|
||||
public static function getPage($limit, $offset) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"SELECT m.id, m.send_date, m.topic, m.recipients, COALESCE(u.name, 'Automailer') AS sender_name
|
||||
FROM roundmails m
|
||||
LEFT JOIN users u ON u.id = m.user_id
|
||||
ORDER BY m.send_date DESC, m.id DESC
|
||||
LIMIT ? OFFSET ?"
|
||||
);
|
||||
$stmt->bindValue(1, (int)$limit, \PDO::PARAM_INT);
|
||||
$stmt->bindValue(2, (int)$offset, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return array|false
|
||||
*/
|
||||
public static function findById($id) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"SELECT m.*, COALESCE(u.name, 'Automailer') AS sender_name
|
||||
FROM roundmails m
|
||||
LEFT JOIN users u ON u.id = m.user_id
|
||||
WHERE m.id = ?"
|
||||
);
|
||||
$stmt->execute([$id]);
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Protokolliert eine versendete Mail. Die Nachricht wird wie im Legacy mit <br/> gespeichert.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param string[] $recipients
|
||||
* @param string $topic
|
||||
* @param string $messageHtml
|
||||
* @return int ID
|
||||
*/
|
||||
public static function create($userId, array $recipients, $topic, $messageHtml) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO roundmails (user_id, send_date, recipients, topic, message, created_at, updated_at)
|
||||
VALUES (?, CURDATE(), ?, ?, ?, NOW(), NOW())"
|
||||
);
|
||||
$stmt->execute([$userId, implode(',', $recipients), $topic, $messageHtml]);
|
||||
return (int)$db->lastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wandelt den Klartext aus dem Formular in das gespeicherte/versendete HTML um
|
||||
* (HTML wird maskiert, Zeilenumbrüche werden zu <br/>, URLs werden verlinkt).
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public static function textToHtml($text) {
|
||||
$html = htmlspecialchars(trim($text), ENT_QUOTES, 'UTF-8');
|
||||
$html = preg_replace('~https?://[^\s<]+~', '<a href="$0">$0</a>', $html);
|
||||
return str_replace(["\r\n", "\r", "\n"], '<br/>', $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zerlegt eine Empfängerliste (Komma, Semikolon, Leerzeichen oder Zeilenumbruch getrennt).
|
||||
*
|
||||
* @param string $list
|
||||
* @return array ['valid' => [...], 'invalid' => [...]]
|
||||
*/
|
||||
public static function parseRecipients($list) {
|
||||
$result = ['valid' => [], 'invalid' => []];
|
||||
foreach (preg_split('/[\s,;]+/', (string)$list, -1, PREG_SPLIT_NO_EMPTY) as $address) {
|
||||
$key = filter_var($address, FILTER_VALIDATE_EMAIL) ? 'valid' : 'invalid';
|
||||
$result[$key][strtolower($address)] = $address;
|
||||
}
|
||||
$result['valid'] = array_values($result['valid']);
|
||||
$result['invalid'] = array_values($result['invalid']);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empfängergruppen für die Schnellauswahl (Legacy RoundmailController::show).
|
||||
* Fehlende Tipps/Joker beziehen sich auf die erste tippbare Runde und nur auf bezahlte Spieler.
|
||||
*
|
||||
* @param int $seasonId
|
||||
* @param array|null $tippableRound Ergebnis von Round::getFirstTippable
|
||||
* @return array key => ['label' => ..., 'emails' => [...]]
|
||||
*/
|
||||
public static function recipientGroups($seasonId, $tippableRound) {
|
||||
$users = User::getAll();
|
||||
$paidIds = array_flip(array_map('intval', array_column(User::getPaid($seasonId), 'id')));
|
||||
|
||||
$missing = ['tipps' => [], 'joker' => []];
|
||||
if ($tippableRound) {
|
||||
$missing = Tipp::getMissing($tippableRound['id'], array_keys($paidIds));
|
||||
}
|
||||
$missingTipps = array_flip(array_map('intval', $missing['tipps']));
|
||||
$missingJoker = array_flip(array_map('intval', $missing['joker']));
|
||||
|
||||
$groups = [
|
||||
'admins' => ['label' => 'Alle Administratoren', 'emails' => []],
|
||||
'active' => ['label' => 'Alle aktiven Spieler', 'emails' => []],
|
||||
'inactive' => ['label' => 'Alle inaktiven Spieler', 'emails' => []],
|
||||
'missing_tipps' => ['label' => 'Spieler mit fehlenden Tipps', 'emails' => []],
|
||||
'missing_joker' => ['label' => 'Spieler mit fehlendem Joker', 'emails' => []],
|
||||
];
|
||||
foreach ($users as $user) {
|
||||
$id = (int)$user['id'];
|
||||
if (empty($user['email'])) {
|
||||
continue;
|
||||
}
|
||||
if ($user['admin']) {
|
||||
$groups['admins']['emails'][] = $user['email'];
|
||||
}
|
||||
$groups[isset($paidIds[$id]) ? 'active' : 'inactive']['emails'][] = $user['email'];
|
||||
if (isset($missingTipps[$id])) {
|
||||
$groups['missing_tipps']['emails'][] = $user['email'];
|
||||
}
|
||||
if (isset($missingJoker[$id])) {
|
||||
$groups['missing_joker']['emails'][] = $user['email'];
|
||||
}
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erinnerungsmail an alle bezahlten Spieler mit fehlenden Tipps oder Joker in der ersten
|
||||
* tippbaren Runde (Legacy RoundmailController::checkReminder). Verschickt nur, wenn die Runde
|
||||
* in weniger als REMINDER_HOURS Stunden sperrt, und nur an Spieler mit gets_reminders = 1.
|
||||
*
|
||||
* @param string $appUrl Basis-URL für den Link in der Mail
|
||||
* @return string Ergebnis als Text (für das Log des Cron-Jobs)
|
||||
*/
|
||||
public static function sendReminder($appUrl) {
|
||||
$season = Season::getCurrent();
|
||||
if (!$season) {
|
||||
return 'Keine aktive Saison - nichts zu tun.';
|
||||
}
|
||||
$round = Round::getFirstTippable($season['id']);
|
||||
if (!$round) {
|
||||
return 'Keine tippbare Runde - nichts zu tun.';
|
||||
}
|
||||
$lockTime = Round::getLockTime($round['games']);
|
||||
$warnFrom = (clone $lockTime)->modify('-' . self::REMINDER_HOURS . ' hours');
|
||||
if (new \DateTime() < $warnFrom) {
|
||||
return sprintf('%s sperrt am %s, Erinnerung erst ab %s - nichts zu tun.',
|
||||
$round['name'], $lockTime->format('d.m.Y H:i'), $warnFrom->format('d.m.Y H:i'));
|
||||
}
|
||||
|
||||
$paid = [];
|
||||
foreach (User::getPaid($season['id']) as $user) {
|
||||
if ($user['deleted'] === null && $user['gets_reminders'] && !empty($user['email'])) {
|
||||
$paid[(int)$user['id']] = $user['email'];
|
||||
}
|
||||
}
|
||||
$missing = Tipp::getMissing($round['id'], array_keys($paid));
|
||||
$userIds = array_unique(array_merge($missing['tipps'], $missing['joker']));
|
||||
$recipients = [];
|
||||
foreach ($userIds as $userId) {
|
||||
$recipients[] = $paid[(int)$userId];
|
||||
}
|
||||
if (empty($recipients)) {
|
||||
return $round['name'] . ': alle Tipps und Joker vollständig - keine Erinnerung nötig.';
|
||||
}
|
||||
|
||||
$topic = self::REMINDER_TOPIC;
|
||||
$link = htmlspecialchars(rtrim($appUrl, '/') . '/', ENT_QUOTES, 'UTF-8');
|
||||
$html = 'Es fehlen noch Tipps/Joker für: ' . htmlspecialchars($round['name'], ENT_QUOTES, 'UTF-8')
|
||||
. '<br/>Die Runde sperrt sich: ' . $lockTime->format('d.m.Y H:i')
|
||||
. '<br/><br/>Link zum Spiel: <a href="' . $link . '">( Hier klicken )</a>';
|
||||
|
||||
$failed = Mailer::send($recipients, $topic, $html);
|
||||
$sent = array_values(array_diff($recipients, $failed));
|
||||
if (!empty($sent)) {
|
||||
self::create(0, $sent, $topic, $html);
|
||||
}
|
||||
|
||||
$result = sprintf('%s: Erinnerung an %d Empfänger versendet.', $round['name'], count($sent));
|
||||
if (!empty($failed)) {
|
||||
$result .= ' Nicht zustellbar: ' . implode(', ', $failed);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht automatische Erinnerungsmails (Automailer, Betreff REMINDER_TOPIC), die älter als
|
||||
* REMINDER_RETENTION_MONTHS Monate sind. Rundmails von Admins bleiben unberührt.
|
||||
*
|
||||
* @return int Anzahl gelöschter Mails
|
||||
*/
|
||||
public static function deleteOldReminders() {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"DELETE FROM roundmails
|
||||
WHERE user_id = 0 AND topic = ?
|
||||
AND send_date < CURDATE() - INTERVAL " . (int)self::REMINDER_RETENTION_MONTHS . " MONTH"
|
||||
);
|
||||
$stmt->execute([self::REMINDER_TOPIC]);
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
}
|
||||
215
tippspiel/src/Models/Season.php
Normal file
215
tippspiel/src/Models/Season.php
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
class Season {
|
||||
|
||||
/** Legacy-Default für seasons.max_identical_jokertipps */
|
||||
const DEFAULT_MAX_IDENTICAL_JOKERTIPPS = 6;
|
||||
|
||||
/** Jede Runde besteht aus 4 Spielen (Legacy-Konvention) */
|
||||
const GAMES_PER_ROUND = 4;
|
||||
|
||||
/**
|
||||
* Holt die aktuell selektierte Saison (settings.current_season_id).
|
||||
* Fallback: Die Saison mit der höchsten ID.
|
||||
*/
|
||||
public static function getCurrent() {
|
||||
$db = Database::getConnection();
|
||||
|
||||
$stmt = $db->query(
|
||||
"SELECT s.* FROM settings st
|
||||
JOIN seasons s ON s.id = st.current_season_id
|
||||
ORDER BY st.id
|
||||
LIMIT 1"
|
||||
);
|
||||
$season = $stmt->fetch();
|
||||
if ($season) {
|
||||
return $season;
|
||||
}
|
||||
|
||||
$stmt = $db->query("SELECT * FROM seasons ORDER BY id DESC LIMIT 1");
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Saisons.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAll() {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM seasons ORDER BY id DESC");
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt eine Saison anhand der ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array|false
|
||||
*/
|
||||
public static function findById($id) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM seasons WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt eine neue Saison mit Platzhalter-Runden und je 4 Platzhalter-Spielen
|
||||
* (wie im Legacy SeasonsController::store). Die Platzhalter-Spiele liegen 7 Monate
|
||||
* in der Zukunft, damit die Runden nicht gesperrt sind, bis der Admin die echten
|
||||
* Paarungen und Anstoßzeiten einträgt.
|
||||
*
|
||||
* Tipps werden NICHT vorab angelegt - sie entstehen beim ersten Tippen (siehe Tipp::saveRound).
|
||||
*
|
||||
* @param array $data ['name', 'rounds', optional 'max_identical_jokertipps']
|
||||
* @return int|false Die ID der neuen Saison oder false bei einem Fehler.
|
||||
*/
|
||||
public static function create($data) {
|
||||
$db = Database::getConnection();
|
||||
$roundCount = (int)$data['rounds'];
|
||||
$maxJoker = (int)($data['max_identical_jokertipps'] ?? self::DEFAULT_MAX_IDENTICAL_JOKERTIPPS);
|
||||
|
||||
$db->beginTransaction();
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO seasons (name, rounds, max_identical_jokertipps, created_at, updated_at)
|
||||
VALUES (:name, :rounds, :max_joker, NOW(), NOW())"
|
||||
);
|
||||
$stmt->execute([
|
||||
':name' => $data['name'],
|
||||
':rounds' => $roundCount,
|
||||
':max_joker' => $maxJoker,
|
||||
]);
|
||||
$seasonId = (int)$db->lastInsertId();
|
||||
|
||||
$placeholderKickoff = (new \DateTime('+7 months'))->format('Y-m-d H:i:s');
|
||||
|
||||
$stmtRound = $db->prepare(
|
||||
"INSERT INTO rounds (name, season_id, created_at, updated_at) VALUES (?, ?, NOW(), NOW())"
|
||||
);
|
||||
$stmtGame = $db->prepare(
|
||||
"INSERT INTO games (round_id, team1, team2, kickoff, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, NOW(), NOW())"
|
||||
);
|
||||
|
||||
for ($i = 1; $i <= $roundCount; $i++) {
|
||||
$stmtRound->execute([$i . ". Spieltag", $seasonId]);
|
||||
$roundId = (int)$db->lastInsertId();
|
||||
|
||||
for ($g = 1; $g <= self::GAMES_PER_ROUND; $g++) {
|
||||
$stmtGame->execute([
|
||||
$roundId,
|
||||
"Mannschaft " . (2 * $g - 1),
|
||||
"Mannschaft " . (2 * $g),
|
||||
$placeholderKickoff,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$db->commit();
|
||||
return $seasonId;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$db->rollBack();
|
||||
error_log("Season::create fehlgeschlagen: " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert eine Saison.
|
||||
* Hinweis: Eine Änderung von 'rounds' legt keine Runden an oder löscht welche.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data ['name', 'rounds', optional 'max_identical_jokertipps']
|
||||
* @return bool
|
||||
*/
|
||||
public static function update($id, $data) {
|
||||
$db = Database::getConnection();
|
||||
|
||||
$sql = "UPDATE seasons SET name = :name, rounds = :rounds, updated_at = NOW()";
|
||||
$params = [
|
||||
':id' => $id,
|
||||
':name' => $data['name'],
|
||||
':rounds' => (int)$data['rounds'],
|
||||
];
|
||||
|
||||
if (isset($data['max_identical_jokertipps'])) {
|
||||
$sql .= ", max_identical_jokertipps = :max_joker";
|
||||
$params[':max_joker'] = (int)$data['max_identical_jokertipps'];
|
||||
}
|
||||
|
||||
$sql .= " WHERE id = :id";
|
||||
$stmt = $db->prepare($sql);
|
||||
return $stmt->execute($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht eine Saison mit allen abhängigen Daten (Tipps, Spiele, Runden,
|
||||
* Quoten, Zahlungen, manuelle Ausschüttungen). Die aktive Saison kann nicht gelöscht werden.
|
||||
*
|
||||
* @param int $id
|
||||
* @throws \Exception wenn die Saison aktiv ist oder nicht existiert
|
||||
*/
|
||||
public static function delete($id) {
|
||||
$id = (int)$id;
|
||||
if (!self::findById($id)) {
|
||||
throw new \Exception('Saison nicht gefunden.');
|
||||
}
|
||||
$current = self::getCurrent();
|
||||
if ($current && (int)$current['id'] === $id) {
|
||||
throw new \Exception('Die aktive Saison kann nicht gelöscht werden.');
|
||||
}
|
||||
|
||||
$db = Database::getConnection();
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$statements = [
|
||||
"DELETE t FROM tipps t JOIN games g ON g.id = t.game_id JOIN rounds r ON r.id = g.round_id WHERE r.season_id = ?",
|
||||
"DELETE g FROM games g JOIN rounds r ON r.id = g.round_id WHERE r.season_id = ?",
|
||||
"DELETE FROM rounds WHERE season_id = ?",
|
||||
"DELETE FROM quotas WHERE season_id = ?",
|
||||
"DELETE FROM payments WHERE season_id = ?",
|
||||
"DELETE FROM manual_payouts WHERE season_id = ?",
|
||||
"DELETE FROM seasons WHERE id = ?",
|
||||
];
|
||||
foreach ($statements as $sql) {
|
||||
$db->prepare($sql)->execute([$id]);
|
||||
}
|
||||
$db->commit();
|
||||
} catch (\Exception $e) {
|
||||
$db->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die aktive Saison in der `settings`-Tabelle.
|
||||
* Es wird (wie im Legacy-Code) immer die erste Zeile von settings verwendet.
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function setCurrent($id) {
|
||||
$db = Database::getConnection();
|
||||
|
||||
$settingsId = $db->query("SELECT id FROM settings ORDER BY id LIMIT 1")->fetchColumn();
|
||||
|
||||
if ($settingsId === false) {
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO settings (current_season_id, created_at, updated_at) VALUES (?, NOW(), NOW())"
|
||||
);
|
||||
return $stmt->execute([$id]);
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("UPDATE settings SET current_season_id = ?, updated_at = NOW() WHERE id = ?");
|
||||
return $stmt->execute([$id, $settingsId]);
|
||||
}
|
||||
}
|
||||
45
tippspiel/src/Models/Setting.php
Normal file
45
tippspiel/src/Models/Setting.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
/**
|
||||
* Systemeinstellungen aus der `settings`-Tabelle.
|
||||
* Wie im Legacy-Code wird immer die erste Zeile verwendet (siehe Season::setCurrent).
|
||||
*/
|
||||
class Setting {
|
||||
|
||||
/**
|
||||
* Dürfen sich neue Benutzer registrieren? Ohne Settings-Zeile ist die Registrierung offen.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isRegistrationOpen() {
|
||||
$db = Database::getConnection();
|
||||
$value = $db->query("SELECT registration_open FROM settings ORDER BY id LIMIT 1")->fetchColumn();
|
||||
return $value === false || (bool)$value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schaltet die Registrierung neuer Benutzer ein oder aus.
|
||||
*
|
||||
* @param bool $open
|
||||
* @return bool
|
||||
*/
|
||||
public static function setRegistrationOpen($open) {
|
||||
$db = Database::getConnection();
|
||||
$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, created_at, updated_at) VALUES (?, ?, NOW(), NOW())"
|
||||
);
|
||||
return $stmt->execute([$current ? (int)$current['id'] : 0, $open ? 1 : 0]);
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("UPDATE settings SET registration_open = ?, updated_at = NOW() WHERE id = ?");
|
||||
return $stmt->execute([$open ? 1 : 0, $settingsId]);
|
||||
}
|
||||
}
|
||||
472
tippspiel/src/Models/Tipp.php
Normal file
472
tippspiel/src/Models/Tipp.php
Normal file
|
|
@ -0,0 +1,472 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
/**
|
||||
* Tipps und Punktewertung (portiert aus Legacy App\Tipp und TippsController).
|
||||
*
|
||||
* Konvention: Ein fehlender Eintrag in `tipps` bedeutet "nicht getippt"
|
||||
* (gleichwertig zum Legacy-Platzhalter -1:-1). Einträge werden erst beim
|
||||
* Speichern angelegt (Upsert über den Unique-Key user_id/game_id).
|
||||
*/
|
||||
class Tipp {
|
||||
|
||||
/** Bonus, wenn in einer Runde jedes Spiel mindestens Tendenz-Punkte bringt */
|
||||
const ALL_HITS_BONUS = 2;
|
||||
|
||||
/** Maximal erlaubte Toranzahl pro Team bei der Eingabe */
|
||||
const MAX_GOALS = 99;
|
||||
|
||||
/**
|
||||
* Berechnet die Punkte für einen Tipp im Vergleich zum echten Ergebnis.
|
||||
* Portiert aus der alten Laravel-Anwendung.
|
||||
*
|
||||
* - Richtige Tendenz: 1 Punkt
|
||||
* - Exaktes Ergebnis: 2 Punkte + max(0, Gesamttore - 3)
|
||||
* - Joker verdoppelt
|
||||
*
|
||||
* @param int $goals1 Tore Team 1
|
||||
* @param int $goals2 Tore Team 2
|
||||
* @param int $tipp1 Getippte Tore Team 1
|
||||
* @param int $tipp2 Getippte Tore Team 2
|
||||
* @param bool $joker Ob der Joker für diesen Tipp gesetzt wurde
|
||||
* @return int Die erreichten Punkte
|
||||
*/
|
||||
public static function getScoreLocal($goals1, $goals2, $tipp1, $tipp2, $joker) {
|
||||
$score = 0;
|
||||
|
||||
// Wenn noch kein Ergebnis vorliegt (-1 bedeutet in der DB meistens noch nicht gespielt)
|
||||
if ($tipp1 == -1 || $tipp2 == -1 || $goals1 == -1 || $goals2 == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$tippTendenz = $tipp1 - $tipp2;
|
||||
if ($tippTendenz > 0) { $tippTendenz = 1; }
|
||||
if ($tippTendenz < 0) { $tippTendenz = -1; }
|
||||
|
||||
$gameTendenz = $goals1 - $goals2;
|
||||
if ($gameTendenz < 0) { $gameTendenz = -1; }
|
||||
if ($gameTendenz > 0) { $gameTendenz = 1; }
|
||||
|
||||
// Tendenz richtig
|
||||
if ($tippTendenz == $gameTendenz) {
|
||||
$score = 1;
|
||||
}
|
||||
|
||||
// Genaues Ergebnis richtig (gibt 2 Grundpunkte + Bonus)
|
||||
if (($tipp1 == $goals1) && ($tipp2 == $goals2)) {
|
||||
$bonus = max(0, $goals1 + $goals2 - 3);
|
||||
$score = 2 + $bonus;
|
||||
}
|
||||
|
||||
// Joker verdoppelt die Punktzahl
|
||||
if ($joker == true) {
|
||||
$score = $score * 2;
|
||||
}
|
||||
|
||||
return $score;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob ein Tipp das exakte Ergebnis getroffen hat.
|
||||
*/
|
||||
public static function isExact($goals1, $goals2, $tipp1, $tipp2) {
|
||||
if ($tipp1 == -1 || $tipp2 == -1 || $goals1 == -1 || $goals2 == -1) {
|
||||
return false;
|
||||
}
|
||||
return $tipp1 == $goals1 && $tipp2 == $goals2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die CSS-Klasse für die Farbe des Tipps zurück (portiert aus Legacy Tipp::trendCol).
|
||||
*
|
||||
* - "col_tendenz" = richtige Tendenz (grau)
|
||||
* - "col_exact" = richtiges Ergebnis (orange)
|
||||
* - "col_joker_exact" = richtiges Ergebnis mit Joker (rot)
|
||||
* - "" = kein Treffer, nicht getippt oder noch kein Ergebnis
|
||||
*/
|
||||
public static function getCol($goals1, $goals2, $tipp1, $tipp2, $joker) {
|
||||
if ($tipp1 == -1 || $tipp2 == -1 || $goals1 == -1 || $goals2 == -1) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (self::isExact($goals1, $goals2, $tipp1, $tipp2)) {
|
||||
return $joker ? "col_joker_exact" : "col_exact";
|
||||
}
|
||||
|
||||
$tippSign = $tipp1 <=> $tipp2;
|
||||
$gameSign = $goals1 <=> $goals2;
|
||||
|
||||
return $tippSign === $gameSign ? "col_tendenz" : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Wertet die Tipps eines Benutzers für eine Runde aus.
|
||||
*
|
||||
* @param array $games Spiele der Runde (Zeilen aus `games`)
|
||||
* @param array $tippsByGameId Tipps des Benutzers, game_id => Zeile aus `tipps`
|
||||
* @return array [
|
||||
* 'points' => Rundenpunkte inkl. Bonus (+2 wenn alle Spiele punkten),
|
||||
* 'hits' => Anzahl Spiele mit Punkten,
|
||||
* 'exact' => Anzahl exakter Treffer (für Tagessieg),
|
||||
* 'joker_value' => Wert eines exakten Joker-Treffers (für Tagessieg), 0 wenn keiner,
|
||||
* ]
|
||||
*/
|
||||
public static function evaluateRound(array $games, array $tippsByGameId) {
|
||||
$points = 0;
|
||||
$hits = 0;
|
||||
$exact = 0;
|
||||
$jokerValue = 0;
|
||||
|
||||
foreach ($games as $game) {
|
||||
$tipp = $tippsByGameId[$game['id']] ?? null;
|
||||
$goals1 = (int)$game['score1'];
|
||||
$goals2 = (int)$game['score2'];
|
||||
$tipp1 = $tipp ? (int)$tipp['score1'] : -1;
|
||||
$tipp2 = $tipp ? (int)$tipp['score2'] : -1;
|
||||
$joker = $tipp ? (bool)$tipp['joker'] : false;
|
||||
|
||||
$gamePoints = self::getScoreLocal($goals1, $goals2, $tipp1, $tipp2, $joker);
|
||||
$points += $gamePoints;
|
||||
if ($gamePoints > 0) {
|
||||
$hits++;
|
||||
}
|
||||
|
||||
if (self::isExact($goals1, $goals2, $tipp1, $tipp2)) {
|
||||
$exact++;
|
||||
if ($joker) {
|
||||
// Legacy: Jokersieg mit mehr Toren zählt mehr
|
||||
$jokerValue = max($jokerValue, max(0, $goals1 + $goals2 - 3) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($games) > 0 && $hits === count($games)) {
|
||||
$points += self::ALL_HITS_BONUS;
|
||||
}
|
||||
|
||||
return [
|
||||
'points' => $points,
|
||||
'hits' => $hits,
|
||||
'exact' => $exact,
|
||||
'joker_value' => $jokerValue,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Vergleicht zwei Rundenauswertungen nach Tagessieg-Regel (absteigend, für usort):
|
||||
* 1. Anzahl exakter Treffer, 2. Wert des exakten Joker-Treffers.
|
||||
* (Bei mehr als 6 Tagessiegern entscheiden zusätzlich die Rundenpunkte - das
|
||||
* erledigt die Ranglistenberechnung.)
|
||||
*
|
||||
* @return int <0 wenn $a besser ist, >0 wenn $b besser ist, 0 bei Gleichstand
|
||||
*/
|
||||
public static function compareDayScore(array $a, array $b) {
|
||||
return [$b['exact'], $b['joker_value']] <=> [$a['exact'], $a['joker_value']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt die Tipps eines Benutzers für eine Runde.
|
||||
*
|
||||
* @return array game_id => Zeile aus `tipps`
|
||||
*/
|
||||
public static function findByUserAndRound($userId, $roundId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"SELECT t.* FROM tipps t
|
||||
JOIN games g ON g.id = t.game_id
|
||||
WHERE t.user_id = ? AND g.round_id = ?"
|
||||
);
|
||||
$stmt->execute([$userId, $roundId]);
|
||||
|
||||
$result = [];
|
||||
foreach ($stmt->fetchAll() as $row) {
|
||||
$result[$row['game_id']] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Tipps aller Benutzer für eine Runde.
|
||||
*
|
||||
* @return array user_id => [game_id => Zeile aus `tipps`]
|
||||
*/
|
||||
public static function findByRound($roundId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"SELECT t.* FROM tipps t
|
||||
JOIN games g ON g.id = t.game_id
|
||||
WHERE g.round_id = ?"
|
||||
);
|
||||
$stmt->execute([$roundId]);
|
||||
|
||||
$result = [];
|
||||
foreach ($stmt->fetchAll() as $row) {
|
||||
$result[$row['user_id']][$row['game_id']] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zählt, wie oft ein Benutzer in einer Saison welches Ergebnis mit Joker getippt hat.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $seasonId
|
||||
* @param int|null $excludeRoundId Diese Runde nicht mitzählen (beim Speichern der Runde)
|
||||
* @param int|null $upToRoundId Nur Runden bis einschließlich dieser ID (für die Anzeige)
|
||||
* @return array "2:1" => Anzahl, absteigend sortiert
|
||||
*/
|
||||
public static function getJokerUsage($userId, $seasonId, $excludeRoundId = null, $upToRoundId = null) {
|
||||
$db = Database::getConnection();
|
||||
|
||||
$sql = "SELECT CONCAT(t.score1, ':', t.score2) AS result, COUNT(*) AS cnt
|
||||
FROM tipps t
|
||||
JOIN games g ON g.id = t.game_id
|
||||
JOIN rounds r ON r.id = g.round_id
|
||||
WHERE t.user_id = ? AND t.joker = 1 AND r.season_id = ?";
|
||||
$params = [$userId, $seasonId];
|
||||
|
||||
if ($excludeRoundId !== null) {
|
||||
$sql .= " AND r.id <> ?";
|
||||
$params[] = $excludeRoundId;
|
||||
}
|
||||
if ($upToRoundId !== null) {
|
||||
$sql .= " AND r.id <= ?";
|
||||
$params[] = $upToRoundId;
|
||||
}
|
||||
$sql .= " GROUP BY result ORDER BY cnt DESC, result ASC";
|
||||
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
return array_map('intval', $stmt->fetchAll(\PDO::FETCH_KEY_PAIR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert die Joker-Nutzung für die Anzeige, z.B. "3x2:1, 1x1:0".
|
||||
*/
|
||||
public static function formatJokerUsage(array $usage) {
|
||||
$parts = [];
|
||||
foreach ($usage as $result => $count) {
|
||||
$parts[] = $count . 'x' . $result;
|
||||
}
|
||||
return implode(', ', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert alle Tipps eines Benutzers für eine Runde (atomar).
|
||||
*
|
||||
* Regeln (aus dem Legacy-Code):
|
||||
* - Eine Runde ist gesperrt, sobald eines ihrer Spiele gesperrt ist (1 Min. vor Anpfiff).
|
||||
* - Pro Runde genau ein Joker (oder keiner).
|
||||
* - Dasselbe Ergebnis darf pro Saison höchstens max_identical_jokertipps-mal
|
||||
* mit Joker getippt werden (die aktuelle Runde zählt dabei nicht mit).
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $roundId
|
||||
* @param array $scores game_id => ['score1' => .., 'score2' => ..] für alle Spiele der Runde
|
||||
* @param int|null $jokerGameId game_id des Joker-Tipps oder null
|
||||
* @return string|null Fehlermeldung oder null bei Erfolg
|
||||
*/
|
||||
public static function saveRound($userId, $roundId, array $scores, $jokerGameId) {
|
||||
$db = Database::getConnection();
|
||||
|
||||
$stmt = $db->prepare(
|
||||
"SELECT r.season_id, s.max_identical_jokertipps
|
||||
FROM rounds r JOIN seasons s ON s.id = r.season_id
|
||||
WHERE r.id = ?"
|
||||
);
|
||||
$stmt->execute([$roundId]);
|
||||
$round = $stmt->fetch();
|
||||
if (!$round) {
|
||||
return "Runde nicht gefunden.";
|
||||
}
|
||||
|
||||
$games = Game::getGamesByRound($roundId);
|
||||
if (empty($games)) {
|
||||
return "Diese Runde enthält keine Spiele.";
|
||||
}
|
||||
|
||||
foreach ($games as $game) {
|
||||
if (Game::isLocked($game['kickoff'])) {
|
||||
return "Die Runde ist bereits gesperrt, Tipps können nicht mehr geändert werden.";
|
||||
}
|
||||
}
|
||||
|
||||
// Eingaben validieren
|
||||
$validated = [];
|
||||
foreach ($games as $game) {
|
||||
$input = $scores[$game['id']] ?? null;
|
||||
$s1 = filter_var($input['score1'] ?? null, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0, 'max_range' => self::MAX_GOALS]]);
|
||||
$s2 = filter_var($input['score2'] ?? null, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0, 'max_range' => self::MAX_GOALS]]);
|
||||
if ($s1 === false || $s2 === false) {
|
||||
return "Bitte für alle Spiele ein gültiges Ergebnis (0-" . self::MAX_GOALS . ") eintragen: "
|
||||
. $game['team1'] . " - " . $game['team2'];
|
||||
}
|
||||
$validated[$game['id']] = [$s1, $s2];
|
||||
}
|
||||
|
||||
if ($jokerGameId !== null) {
|
||||
$jokerGameId = (int)$jokerGameId;
|
||||
if (!isset($validated[$jokerGameId])) {
|
||||
return "Der Joker muss auf ein Spiel dieser Runde gesetzt werden.";
|
||||
}
|
||||
|
||||
// Joker-Limit pro Ergebnis und Saison
|
||||
$jokerResult = $validated[$jokerGameId][0] . ':' . $validated[$jokerGameId][1];
|
||||
$usage = self::getJokerUsage($userId, $round['season_id'], $roundId);
|
||||
$limit = (int)$round['max_identical_jokertipps'];
|
||||
if (($usage[$jokerResult] ?? 0) >= $limit) {
|
||||
return "Das Ergebnis $jokerResult wurde in dieser Saison bereits "
|
||||
. $usage[$jokerResult] . "-mal mit Joker getippt (Maximum: $limit).";
|
||||
}
|
||||
}
|
||||
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO tipps (user_id, game_id, score1, score2, joker, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
score1 = VALUES(score1),
|
||||
score2 = VALUES(score2),
|
||||
joker = VALUES(joker),
|
||||
updated_at = NOW()"
|
||||
);
|
||||
foreach ($validated as $gameId => [$s1, $s2]) {
|
||||
$stmt->execute([$userId, $gameId, $s1, $s2, $gameId === $jokerGameId ? 1 : 0]);
|
||||
}
|
||||
$db->commit();
|
||||
} catch (\Exception $e) {
|
||||
$db->rollBack();
|
||||
error_log("Tipp::saveRound fehlgeschlagen: " . $e->getMessage());
|
||||
return "Die Tipps konnten nicht gespeichert werden.";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert einen einzelnen Tipp (Legacy TippsController::store).
|
||||
*
|
||||
* Regeln wie bei saveRound(): Runde nicht gesperrt, Joker-Limit pro Ergebnis und Saison.
|
||||
* Wird der Joker gesetzt, wird er von den anderen Tipps der Runde entfernt.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $gameId
|
||||
* @param mixed $score1
|
||||
* @param mixed $score2
|
||||
* @param bool $joker
|
||||
* @return string|null Fehlermeldung oder null bei Erfolg
|
||||
*/
|
||||
public static function saveSingle($userId, $gameId, $score1, $score2, $joker) {
|
||||
$db = Database::getConnection();
|
||||
|
||||
$stmt = $db->prepare(
|
||||
"SELECT g.round_id, r.season_id, s.max_identical_jokertipps
|
||||
FROM games g
|
||||
JOIN rounds r ON r.id = g.round_id
|
||||
JOIN seasons s ON s.id = r.season_id
|
||||
WHERE g.id = ?"
|
||||
);
|
||||
$stmt->execute([$gameId]);
|
||||
$info = $stmt->fetch();
|
||||
if (!$info) {
|
||||
return "Spiel nicht gefunden.";
|
||||
}
|
||||
$roundId = (int)$info['round_id'];
|
||||
|
||||
if (Round::isLocked(Game::getGamesByRound($roundId))) {
|
||||
return "Die Runde ist bereits gesperrt, Tipps können nicht mehr geändert werden.";
|
||||
}
|
||||
|
||||
$options = ['options' => ['min_range' => 0, 'max_range' => self::MAX_GOALS]];
|
||||
$s1 = filter_var($score1, FILTER_VALIDATE_INT, $options);
|
||||
$s2 = filter_var($score2, FILTER_VALIDATE_INT, $options);
|
||||
if ($s1 === false || $s2 === false) {
|
||||
return "Bitte ein gültiges Ergebnis (0-" . self::MAX_GOALS . ") eintragen.";
|
||||
}
|
||||
|
||||
if ($joker) {
|
||||
$jokerResult = $s1 . ':' . $s2;
|
||||
$usage = self::getJokerUsage($userId, $info['season_id'], $roundId);
|
||||
$limit = (int)$info['max_identical_jokertipps'];
|
||||
if (($usage[$jokerResult] ?? 0) >= $limit) {
|
||||
return "Das Ergebnis $jokerResult wurde in dieser Saison bereits "
|
||||
. $usage[$jokerResult] . "-mal mit Joker getippt (Maximum: $limit).";
|
||||
}
|
||||
}
|
||||
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO tipps (user_id, game_id, score1, score2, joker, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
score1 = VALUES(score1),
|
||||
score2 = VALUES(score2),
|
||||
joker = VALUES(joker),
|
||||
updated_at = NOW()"
|
||||
);
|
||||
$stmt->execute([$userId, $gameId, $s1, $s2, $joker ? 1 : 0]);
|
||||
|
||||
if ($joker) {
|
||||
$stmt = $db->prepare(
|
||||
"UPDATE tipps t JOIN games g ON g.id = t.game_id
|
||||
SET t.joker = 0, t.updated_at = NOW()
|
||||
WHERE t.user_id = ? AND g.round_id = ? AND t.game_id <> ? AND t.joker = 1"
|
||||
);
|
||||
$stmt->execute([$userId, $roundId, $gameId]);
|
||||
}
|
||||
$db->commit();
|
||||
} catch (\Exception $e) {
|
||||
$db->rollBack();
|
||||
error_log("Tipp::saveSingle fehlgeschlagen: " . $e->getMessage());
|
||||
return "Der Tipp konnte nicht gespeichert werden.";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ermittelt, welche Benutzer in einer Runde noch Tipps oder den Joker vergessen haben
|
||||
* (für Admin-Benutzerliste, Startseiten-Hinweis, Rundmail-Empfänger und Erinnerungen).
|
||||
*
|
||||
* @param int $roundId
|
||||
* @param array $userIds
|
||||
* @return array ['tipps' => [user_id, ...], 'joker' => [user_id, ...]]
|
||||
*/
|
||||
public static function getMissing($roundId, array $userIds) {
|
||||
$gameCount = count(Game::getGamesByRound($roundId));
|
||||
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"SELECT t.user_id,
|
||||
SUM(t.score1 >= 0 AND t.score2 >= 0) AS tipped,
|
||||
MAX(t.joker) AS has_joker
|
||||
FROM tipps t
|
||||
JOIN games g ON g.id = t.game_id
|
||||
WHERE g.round_id = ?
|
||||
GROUP BY t.user_id"
|
||||
);
|
||||
$stmt->execute([$roundId]);
|
||||
|
||||
$status = [];
|
||||
foreach ($stmt->fetchAll() as $row) {
|
||||
$status[$row['user_id']] = $row;
|
||||
}
|
||||
|
||||
$missing = ['tipps' => [], 'joker' => []];
|
||||
foreach ($userIds as $userId) {
|
||||
$row = $status[$userId] ?? null;
|
||||
if (!$row || (int)$row['tipped'] < $gameCount) {
|
||||
$missing['tipps'][] = $userId;
|
||||
}
|
||||
if (!$row || !(int)$row['has_joker']) {
|
||||
$missing['joker'][] = $userId;
|
||||
}
|
||||
}
|
||||
return $missing;
|
||||
}
|
||||
}
|
||||
315
tippspiel/src/Models/User.php
Normal file
315
tippspiel/src/Models/User.php
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
class User {
|
||||
|
||||
/**
|
||||
* Felder, die ein Admin bzw. der Benutzer selbst optional ändern darf.
|
||||
*/
|
||||
const BANK_FIELDS = ['iban', 'bankname', 'blz', 'kontonr', 'mobile'];
|
||||
|
||||
/**
|
||||
* Findet einen Benutzer anhand seiner E-Mail-Adresse.
|
||||
*
|
||||
* @param string $email
|
||||
* @return array|false
|
||||
*/
|
||||
public static function findByEmail($email) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Findet einen (nicht gelöschten) Benutzer für den Login.
|
||||
*
|
||||
* Wie im Legacy-Code (SessionsController::store) wird über das Feld `name`
|
||||
* gesucht, das aus "Vorname Nachname" besteht. Die Einzelfelder firstname/lastname
|
||||
* sind bei alten Konten nicht zuverlässig befüllt.
|
||||
*
|
||||
* @param string $firstname
|
||||
* @param string $lastname
|
||||
* @return array|false
|
||||
*/
|
||||
public static function findByFirstAndLastName($firstname, $lastname) {
|
||||
$db = Database::getConnection();
|
||||
$name = trim($firstname) . ' ' . trim($lastname);
|
||||
$stmt = $db->prepare("SELECT * FROM users WHERE name = ? AND deleted IS NULL");
|
||||
$stmt->execute([$name]);
|
||||
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Findet einen (nicht gelöschten) Benutzer anhand seiner ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array|false
|
||||
*/
|
||||
public static function findById($id) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM users WHERE id = ? AND deleted IS NULL");
|
||||
$stmt->execute([$id]);
|
||||
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob der Name "Vorname Nachname" bereits vergeben ist (inkl. gelöschter Benutzer,
|
||||
* wie im Legacy RegistrationController).
|
||||
*
|
||||
* @param string $firstname
|
||||
* @param string $lastname
|
||||
* @param int|null $excludeId Eigene ID beim Bearbeiten ausschließen
|
||||
* @return bool
|
||||
*/
|
||||
public static function nameExists($firstname, $lastname, $excludeId = null) {
|
||||
$db = Database::getConnection();
|
||||
$name = trim($firstname) . ' ' . trim($lastname);
|
||||
$stmt = $db->prepare("SELECT COUNT(*) FROM users WHERE name = ? AND id <> ?");
|
||||
$stmt->execute([$name, (int)$excludeId]);
|
||||
return (int)$stmt->fetchColumn() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob die E-Mail-Adresse bereits vergeben ist (inkl. gelöschter Benutzer).
|
||||
*
|
||||
* @param string $email
|
||||
* @param int|null $excludeId Eigene ID beim Bearbeiten ausschließen
|
||||
* @return bool
|
||||
*/
|
||||
public static function emailExists($email, $excludeId = null) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT COUNT(*) FROM users WHERE email = ? AND id <> ?");
|
||||
$stmt->execute([trim($email), (int)$excludeId]);
|
||||
return (int)$stmt->fetchColumn() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anzahl aller Benutzer (inkl. gelöschter). Wird für die Regel
|
||||
* "der erste registrierte Benutzer wird Admin" benötigt.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function countAll() {
|
||||
$db = Database::getConnection();
|
||||
return (int)$db->query("SELECT COUNT(*) FROM users")->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle (nicht gelöschten) Benutzer, sortiert wie im Legacy-Code nach Nachname.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAll() {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM users WHERE deleted IS NULL ORDER BY lastname ASC, firstname ASC, name ASC");
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle gelöschten Benutzer (neueste Löschung zuerst).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getDeleted() {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM users WHERE deleted IS NOT NULL ORDER BY deleted DESC");
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Benutzer, die für die Saison bezahlt haben ("aktive" Spieler im Legacy-Sprachgebrauch).
|
||||
* Gelöschte Benutzer werden bewusst nicht gefiltert: Beim Löschen wird die Zahlung der
|
||||
* aktuellen Saison entfernt, in vergangenen Saisons bleiben sie Teil der Rangliste.
|
||||
*
|
||||
* @param int $seasonId
|
||||
* @return array
|
||||
*/
|
||||
public static function getPaid($seasonId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"SELECT u.* FROM users u
|
||||
JOIN payments p ON p.user_id = u.id
|
||||
WHERE p.season_id = ? AND p.paid_date IS NOT NULL
|
||||
ORDER BY u.lastname ASC, u.firstname ASC, u.name ASC"
|
||||
);
|
||||
$stmt->execute([$seasonId]);
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob ein Benutzer für eine Saison bezahlt hat.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $seasonId
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPaid($userId, $seasonId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"SELECT COUNT(*) FROM payments WHERE user_id = ? AND season_id = ? AND paid_date IS NOT NULL"
|
||||
);
|
||||
$stmt->execute([$userId, $seasonId]);
|
||||
return (int)$stmt->fetchColumn() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert eine Zuordnung user_id => name aller Benutzer (inkl. gelöschter).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getNames() {
|
||||
$db = Database::getConnection();
|
||||
return $db->query("SELECT id, name FROM users")->fetchAll(\PDO::FETCH_KEY_PAIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen neuen Benutzer.
|
||||
*
|
||||
* @param array $data ['firstname', 'lastname', 'email', 'password', optional 'admin']
|
||||
* @return int|false Die ID des neuen Benutzers oder false bei einem Fehler.
|
||||
*/
|
||||
public static function create($data) {
|
||||
$db = Database::getConnection();
|
||||
$firstname = trim($data['firstname'] ?? '');
|
||||
$lastname = trim($data['lastname'] ?? '');
|
||||
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO users (firstname, lastname, name, email, password, admin, created_at, updated_at)
|
||||
VALUES (:firstname, :lastname, :name, :email, :password, :admin, NOW(), NOW())"
|
||||
);
|
||||
|
||||
$ok = $stmt->execute([
|
||||
':firstname' => $firstname,
|
||||
':lastname' => $lastname,
|
||||
':name' => $firstname . ' ' . $lastname,
|
||||
':email' => trim($data['email']),
|
||||
':password' => password_hash($data['password'], PASSWORD_DEFAULT),
|
||||
':admin' => !empty($data['admin']) ? 1 : 0,
|
||||
]);
|
||||
|
||||
return $ok ? (int)$db->lastInsertId() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert einen Benutzer (Admin-Bearbeitung).
|
||||
* Bankdaten/Handy und Passwort werden nur geändert, wenn sie in $data enthalten sind.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public static function update($id, $data) {
|
||||
$db = Database::getConnection();
|
||||
$firstname = trim($data['firstname'] ?? '');
|
||||
$lastname = trim($data['lastname'] ?? '');
|
||||
|
||||
$sql = "UPDATE users SET firstname = :firstname, lastname = :lastname, name = :name,
|
||||
email = :email, admin = :admin, updated_at = NOW()";
|
||||
$params = [
|
||||
':id' => $id,
|
||||
':firstname' => $firstname,
|
||||
':lastname' => $lastname,
|
||||
':name' => $firstname . ' ' . $lastname,
|
||||
':email' => trim($data['email']),
|
||||
':admin' => !empty($data['admin']) ? 1 : 0,
|
||||
];
|
||||
|
||||
foreach (self::BANK_FIELDS as $field) {
|
||||
if (array_key_exists($field, $data)) {
|
||||
$sql .= ", `$field` = :$field";
|
||||
$params[":$field"] = trim((string)$data[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['password'])) {
|
||||
$sql .= ", password = :password";
|
||||
$params[':password'] = password_hash($data['password'], PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
$sql .= " WHERE id = :id";
|
||||
$stmt = $db->prepare($sql);
|
||||
return $stmt->execute($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert die eigenen Einstellungen eines Benutzers
|
||||
* (Legacy: UsersController::storeUserEdit). Name ist dort nicht änderbar.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data ['email', 'iban', 'bankname', 'blz', 'kontonr', 'mobile', 'gets_reminders']
|
||||
* @return bool
|
||||
*/
|
||||
public static function updateProfile($id, $data) {
|
||||
$db = Database::getConnection();
|
||||
|
||||
$sql = "UPDATE users SET email = :email, gets_reminders = :gets_reminders, updated_at = NOW()";
|
||||
$params = [
|
||||
':id' => $id,
|
||||
':email' => trim($data['email']),
|
||||
':gets_reminders' => !empty($data['gets_reminders']) ? 1 : 0,
|
||||
];
|
||||
|
||||
foreach (self::BANK_FIELDS as $field) {
|
||||
if (array_key_exists($field, $data)) {
|
||||
$sql .= ", `$field` = :$field";
|
||||
$params[":$field"] = trim((string)$data[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= " WHERE id = :id";
|
||||
$stmt = $db->prepare($sql);
|
||||
return $stmt->execute($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht einen Benutzer (Soft-Delete). Wie im Legacy-Code wird zusätzlich die
|
||||
* Zahlung für die aktuelle Saison entfernt, damit er nicht mehr als aktiver
|
||||
* Spieler in Rangliste und Ausschüttung zählt.
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function delete($id) {
|
||||
$db = Database::getConnection();
|
||||
$db->beginTransaction();
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("UPDATE users SET deleted = NOW() WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
|
||||
$season = Season::getCurrent();
|
||||
if ($season) {
|
||||
$stmt = $db->prepare(
|
||||
"UPDATE payments SET paid_date = NULL, updated_at = NOW() WHERE user_id = ? AND season_id = ?"
|
||||
);
|
||||
$stmt->execute([$id, $season['id']]);
|
||||
}
|
||||
|
||||
$db->commit();
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$db->rollBack();
|
||||
error_log("User::delete fehlgeschlagen: " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stellt einen gelöschten Benutzer wieder her (Zahlung muss ggf. neu eingetragen werden).
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function restore($id) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("UPDATE users SET deleted = NULL, updated_at = NOW() WHERE id = ?");
|
||||
return $stmt->execute([$id]);
|
||||
}
|
||||
}
|
||||
66
tippspiel/src/Views/admin/accounts.php
Normal file
66
tippspiel/src/Views/admin/accounts.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
$pageTitle = 'Kontoliste';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
|
||||
$euro = fn($amount) => number_format($amount, 2, ',', '.') . ' €';
|
||||
?>
|
||||
|
||||
<h1>Konto- & Ausschüttungsübersicht</h1>
|
||||
|
||||
<?php if (!$currentSeason): ?>
|
||||
<p>Es gibt noch keine Saison.</p>
|
||||
<?php elseif (!$result): ?>
|
||||
<p>Es gibt noch keine abgeschlossene Runde, daher noch keine Ausschüttungen.
|
||||
<?php if ($seasonStart): ?>Die Saison beginnt am <?php echo $seasonStart->format('d.m.Y H:i'); ?>.<?php endif; ?></p>
|
||||
<?php else: ?>
|
||||
<p><?php echo htmlspecialchars($currentSeason['name']); ?>, Stand: <?php echo htmlspecialchars($result['rounds'][$result['max_round_id']]['round']['name']); ?>
|
||||
<?php if (!$result['is_final']): ?>(ohne Platzierungsgeld, das erst nach der letzten Runde feststeht)<?php endif; ?></p>
|
||||
|
||||
<div class="table-container">
|
||||
<table class="accounts-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Ausschüttung</th>
|
||||
<th>Bankname</th>
|
||||
<th>IBAN</th>
|
||||
<th>BLZ</th>
|
||||
<th>Kontonummer</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($moneyRanking as $entry):
|
||||
$missingAccount = $entry['amount'] > 0 && empty($entry['iban']) && empty($entry['kontonr']);
|
||||
?>
|
||||
<tr <?php if ($entry['amount'] <= 0) echo 'class="no-payout"'; ?>>
|
||||
<td><a href="/index.php?page=money_ranking&user_id=<?php echo (int)$entry['user_id']; ?>"><?php echo htmlspecialchars($entry['name']); ?></a></td>
|
||||
<td class="amount"><?php echo $euro($entry['amount']); ?></td>
|
||||
<td><?php echo htmlspecialchars((string)$entry['bankname']); ?></td>
|
||||
<td class="iban <?php if ($missingAccount) echo 'missing'; ?>">
|
||||
<?php echo $missingAccount ? 'fehlt' : htmlspecialchars((string)$entry['iban']); ?>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars((string)$entry['blz']); ?></td>
|
||||
<td><?php echo htmlspecialchars((string)$entry['kontonr']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th>Summe</th>
|
||||
<th class="amount"><?php echo $euro(array_sum(array_column($moneyRanking, 'amount'))); ?></th>
|
||||
<th colspan="4"></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.accounts-table td.amount, .accounts-table th.amount { text-align: right; white-space: nowrap; }
|
||||
.accounts-table td.iban { font-family: monospace; white-space: nowrap; }
|
||||
.accounts-table td.missing { color: #c00; font-family: inherit; font-weight: bold; }
|
||||
.accounts-table tr.no-payout td { color: #999; }
|
||||
.accounts-table tr.no-payout td a { color: #999; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
182
tippspiel/src/Views/admin/roundmails.php
Normal file
182
tippspiel/src/Views/admin/roundmails.php
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
<?php
|
||||
use App\Models\Round;
|
||||
|
||||
$pageTitle = 'Runden-E-Mails versenden';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
?>
|
||||
|
||||
<h1>Runden-E-Mails</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; ?>
|
||||
|
||||
<?php if ($compose): ?>
|
||||
|
||||
<h2>Neue Mail</h2>
|
||||
<?php if (!$mailConfigured): ?>
|
||||
<p style="color: red;">Es ist kein Mailserver konfiguriert (Umgebungsvariable SMTP_HOST). Versand ist nicht möglich.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="/index.php?page=admin_roundmails" class="mail-form">
|
||||
<div class="form-group">
|
||||
<label>Versender:</label>
|
||||
<?php echo htmlspecialchars(App\Core\Auth::user()['name']); ?>
|
||||
<small>(Antworten gehen an <?php echo htmlspecialchars(App\Core\Auth::user()['email']); ?>)</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="topic">Thema:</label>
|
||||
<input type="text" id="topic" name="topic" maxlength="200" required
|
||||
value="<?php echo htmlspecialchars($failedForm['topic'] ?? ''); ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="recipients">Empfänger:</label>
|
||||
<textarea id="recipients" name="recipients" rows="5" required><?php echo htmlspecialchars($failedForm['recipients'] ?? ''); ?></textarea>
|
||||
</div>
|
||||
<div class="form-group buttons">
|
||||
<?php foreach ($recipientGroups as $key => $group): ?>
|
||||
<button type="button" data-recipients="<?php echo htmlspecialchars(implode(', ', $group['emails'])); ?>">
|
||||
<?php echo htmlspecialchars($group['label']); ?> (<?php echo count($group['emails']); ?>)
|
||||
</button>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($tippableRound): ?>
|
||||
<p class="hint">Fehlende Tipps/Joker beziehen sich auf „<?php echo htmlspecialchars($tippableRound['name']); ?>“
|
||||
<?php $lock = Round::getLockTime($tippableRound['games']); if ($lock): ?>
|
||||
(sperrt <?php echo $lock->format('d.m.Y H:i'); ?>)
|
||||
<?php endif; ?>.</p>
|
||||
<?php else: ?>
|
||||
<p class="hint">Aktuell gibt es keine tippbare Runde.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="message">Nachricht:</label>
|
||||
<textarea id="message" name="message" rows="12" required><?php echo htmlspecialchars($failedForm['message'] ?? ''); ?></textarea>
|
||||
</div>
|
||||
<div class="form-group buttons">
|
||||
<button type="button" id="add-tipplink" data-link="<?php echo htmlspecialchars($tippLink); ?>">Tipplink hinzufügen</button>
|
||||
</div>
|
||||
|
||||
<div class="form-group buttons">
|
||||
<button type="submit" onclick="return confirm('Mail jetzt versenden?');" <?php if (!$mailConfigured) echo 'disabled'; ?>>Senden</button>
|
||||
<a href="/index.php?page=admin_roundmails">Abbrechen</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.querySelectorAll('[data-recipients]').forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
document.getElementById('recipients').value = button.dataset.recipients;
|
||||
});
|
||||
});
|
||||
document.getElementById('add-tipplink').addEventListener('click', function () {
|
||||
const message = document.getElementById('message');
|
||||
message.value += (message.value && !message.value.endsWith('\n') ? '\n' : '') + 'Link zur Tippseite: ' + this.dataset.link;
|
||||
message.focus();
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php elseif ($viewMail): ?>
|
||||
|
||||
<h2><?php echo htmlspecialchars($viewMail['topic']); ?></h2>
|
||||
<table class="mail-details">
|
||||
<tr><th>Datum</th><td><?php echo date('d.m.Y', strtotime($viewMail['send_date'])); ?></td></tr>
|
||||
<tr><th>Versender</th><td><?php echo htmlspecialchars($viewMail['sender_name']); ?></td></tr>
|
||||
<tr><th>Empfänger</th><td class="recipients"><?php echo htmlspecialchars(str_replace(',', ', ', $viewMail['recipients'])); ?></td></tr>
|
||||
<tr><th>Nachricht</th><td><?php echo nl2br(htmlspecialchars(html_entity_decode(strip_tags(Round::reportToText($viewMail['message'])), ENT_QUOTES, 'UTF-8'))); ?></td></tr>
|
||||
</table>
|
||||
<?php $backPage = max(1, (int)($_GET['p'] ?? 1)); ?>
|
||||
<p><a href="/index.php?page=admin_roundmails<?php if ($backPage > 1) echo '&p=' . $backPage; ?>">Zurück zur Übersicht</a></p>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<p><a href="/index.php?page=admin_roundmails&new=1">Neue Mail schreiben</a></p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Datum</th>
|
||||
<th>Thema</th>
|
||||
<th>Versender</th>
|
||||
<th>Empfänger</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($mails as $mail): ?>
|
||||
<tr>
|
||||
<td><?php echo date('d.m.Y', strtotime($mail['send_date'])); ?></td>
|
||||
<td><a href="/index.php?page=admin_roundmails&id=<?php echo (int)$mail['id']; ?><?php if ($currentPage > 1) echo '&p=' . $currentPage; ?>"><?php echo htmlspecialchars($mail['topic']); ?></a></td>
|
||||
<td><?php echo htmlspecialchars($mail['sender_name']); ?></td>
|
||||
<td><?php echo $mail['recipients'] === '' ? 0 : count(explode(',', $mail['recipients'])); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php if (empty($mails)): ?>
|
||||
<tr><td colspan="4">Noch keine Mails versendet.</td></tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php if ($totalPages > 1):
|
||||
$pageUrl = fn($n) => '/index.php?page=admin_roundmails' . ($n > 1 ? '&p=' . $n : '');
|
||||
// Angezeigt werden erste und letzte Seite sowie zwei Seiten um die aktuelle herum
|
||||
$shown = array_unique(array_filter(
|
||||
[1, $currentPage - 2, $currentPage - 1, $currentPage, $currentPage + 1, $currentPage + 2, $totalPages],
|
||||
fn($n) => $n >= 1 && $n <= $totalPages
|
||||
));
|
||||
sort($shown);
|
||||
?>
|
||||
<nav class="pagination" aria-label="Seiten">
|
||||
<?php if ($currentPage > 1): ?>
|
||||
<a href="<?php echo $pageUrl($currentPage - 1); ?>">« Zurück</a>
|
||||
<?php else: ?>
|
||||
<span class="disabled">« Zurück</span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $previous = 0; foreach ($shown as $n): ?>
|
||||
<?php if ($n > $previous + 1): ?><span class="gap">…</span><?php endif; ?>
|
||||
<?php if ($n === $currentPage): ?>
|
||||
<span class="current" aria-current="page"><?php echo $n; ?></span>
|
||||
<?php else: ?>
|
||||
<a href="<?php echo $pageUrl($n); ?>"><?php echo $n; ?></a>
|
||||
<?php endif; ?>
|
||||
<?php $previous = $n; endforeach; ?>
|
||||
|
||||
<?php if ($currentPage < $totalPages): ?>
|
||||
<a href="<?php echo $pageUrl($currentPage + 1); ?>">Weiter »</a>
|
||||
<?php else: ?>
|
||||
<span class="disabled">Weiter »</span>
|
||||
<?php endif; ?>
|
||||
</nav>
|
||||
<p class="pagination-info">
|
||||
Einträge <?php echo ($currentPage - 1) * $perPage + 1; ?>–<?php echo min($currentPage * $perPage, $totalMails); ?>
|
||||
von <?php echo $totalMails; ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.mail-form { max-width: 900px; }
|
||||
.mail-form .form-group { margin-bottom: 1rem; }
|
||||
.mail-form label { display: block; font-weight: bold; margin-bottom: 0.3rem; }
|
||||
.mail-form input[type="text"], .mail-form textarea { width: 100%; box-sizing: border-box; }
|
||||
.mail-form .buttons button { margin: 0 0.4em 0.4em 0; }
|
||||
.mail-form .hint { color: #666; font-size: 0.8em; }
|
||||
.pagination { margin-top: 1em; display: flex; flex-wrap: wrap; gap: 0.3em; align-items: center; }
|
||||
.pagination a, .pagination span { padding: 0.2em 0.6em; border: 1px solid #ccc; border-radius: 3px; text-decoration: none; }
|
||||
.pagination a { color: var(--link); }
|
||||
.pagination a:hover { background: #f4f4f4; }
|
||||
.pagination .current { background: var(--link); border-color: var(--link); color: white; font-weight: bold; }
|
||||
.pagination .disabled { color: #aaa; }
|
||||
.pagination .gap { border: none; }
|
||||
.pagination-info { color: #666; font-size: 0.8em; }
|
||||
.mail-details th { width: 150px; vertical-align: top; }
|
||||
.mail-details td.recipients { word-break: break-word; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
136
tippspiel/src/Views/admin/rounds.php
Normal file
136
tippspiel/src/Views/admin/rounds.php
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
use App\Models\Round;
|
||||
|
||||
$pageTitle = 'Spiele & Ergebnisse eintragen';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
|
||||
$failedRoundId = $failedForm ? (int)($failedForm['round_id'] ?? 0) : null;
|
||||
?>
|
||||
|
||||
<h1>Spiele & Ergebnisse eintragen</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 method="get" action="/index.php" class="round-filter">
|
||||
<input type="hidden" name="page" value="admin_rounds">
|
||||
<label for="season_id">Saison:</label>
|
||||
<select id="season_id" name="season_id" onchange="this.form.submit()">
|
||||
<?php foreach ($seasons as $s): ?>
|
||||
<option value="<?php echo (int)$s['id']; ?>" <?php if ((int)$s['id'] === $seasonId) echo 'selected'; ?>>
|
||||
<?php echo htmlspecialchars($s['name']); ?><?php if ($currentSeason && (int)$currentSeason['id'] === (int)$s['id']) echo ' (aktiv)'; ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<noscript><button type="submit">Anzeigen</button></noscript>
|
||||
</form>
|
||||
|
||||
<?php if (!$season): ?>
|
||||
<p>Keine Saison vorhanden. Bitte zuerst unter <a href="/index.php?page=admin_seasons">Saisons verwalten</a> eine Saison anlegen.</p>
|
||||
<?php elseif (empty($rounds)): ?>
|
||||
<p>Diese Saison hat keine Runden.</p>
|
||||
<?php else: ?>
|
||||
|
||||
<p class="round-index">
|
||||
<?php foreach ($rounds as $round): ?>
|
||||
<a href="#round-<?php echo (int)$round['id']; ?>" class="<?php echo $round['completed'] ? 'done' : 'open'; ?>"
|
||||
title="<?php echo $round['completed'] ? 'Abgeschlossen' : 'Offen'; ?>"><?php echo htmlspecialchars($round['name']); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</p>
|
||||
|
||||
<?php foreach ($rounds as $round):
|
||||
$roundId = (int)$round['id'];
|
||||
$form = ($failedRoundId === $roundId) ? $failedForm : null;
|
||||
$isOpen = $failedRoundId === $roundId || ($failedRoundId === null && $roundId === $firstIncompleteRoundId);
|
||||
?>
|
||||
<details id="round-<?php echo $roundId; ?>" class="round-admin" <?php if ($isOpen) echo 'open'; ?>>
|
||||
<summary>
|
||||
<strong><?php echo htmlspecialchars($round['name']); ?></strong>
|
||||
<span class="round-status <?php echo $round['completed'] ? 'done' : 'open'; ?>">
|
||||
<?php echo $round['completed'] ? 'abgeschlossen' : 'offen'; ?>
|
||||
</span>
|
||||
<?php if ($round['lock_time']): ?>
|
||||
<small>sperrt: <?php echo $round['lock_time']->format('d.m.Y H:i'); ?></small>
|
||||
<?php endif; ?>
|
||||
</summary>
|
||||
|
||||
<form method="post" action="/index.php?page=admin_rounds&season_id=<?php echo $seasonId; ?>">
|
||||
<input type="hidden" name="round_id" value="<?php echo $roundId; ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name-<?php echo $roundId; ?>">Rundenname:</label>
|
||||
<input type="text" id="name-<?php echo $roundId; ?>" name="name" maxlength="64" required
|
||||
value="<?php echo htmlspecialchars($form['name'] ?? $round['name']); ?>">
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Heim</th>
|
||||
<th>Gast</th>
|
||||
<th>Anstoß</th>
|
||||
<th>Ergebnis</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($round['games'] as $game):
|
||||
$gameId = (int)$game['id'];
|
||||
$in = $form['games'][$gameId] ?? null;
|
||||
$field = "games[$gameId]";
|
||||
?>
|
||||
<tr>
|
||||
<td><input type="text" name="<?php echo $field; ?>[team1]" maxlength="100" required
|
||||
value="<?php echo htmlspecialchars($in['team1'] ?? $game['team1']); ?>"></td>
|
||||
<td><input type="text" name="<?php echo $field; ?>[team2]" maxlength="100" required
|
||||
value="<?php echo htmlspecialchars($in['team2'] ?? $game['team2']); ?>"></td>
|
||||
<td><input type="datetime-local" name="<?php echo $field; ?>[kickoff]" required
|
||||
value="<?php echo htmlspecialchars($in['kickoff'] ?? date('Y-m-d\TH:i', strtotime($game['kickoff']))); ?>"></td>
|
||||
<td class="score">
|
||||
<input type="number" min="0" name="<?php echo $field; ?>[score1]"
|
||||
value="<?php echo htmlspecialchars($in['score1'] ?? ((int)$game['score1'] < 0 ? '' : $game['score1'])); ?>">
|
||||
:
|
||||
<input type="number" min="0" name="<?php echo $field; ?>[score2]"
|
||||
value="<?php echo htmlspecialchars($in['score2'] ?? ((int)$game['score2'] < 0 ? '' : $game['score2'])); ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="hint">Ergebnis leer lassen, solange das Spiel noch nicht beendet ist.</p>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="report-<?php echo $roundId; ?>">Berichterstattung:</label><br>
|
||||
<textarea id="report-<?php echo $roundId; ?>" name="report" rows="4"><?php
|
||||
echo htmlspecialchars($form['report'] ?? Round::reportToText($round['report']));
|
||||
?></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit">Speichern</button>
|
||||
</form>
|
||||
</details>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.round-index a { margin-right: 0.6em; white-space: nowrap; text-decoration: none; }
|
||||
.round-index a.done { color: #888; }
|
||||
.round-index a.open { color: var(--link); font-weight: bold; }
|
||||
.round-admin { border: 1px solid #ccc; padding: 0.5em 1em; margin-bottom: 1em; max-width: 1000px; }
|
||||
.round-admin summary { cursor: pointer; }
|
||||
.round-admin summary small { color: #666; margin-left: 1em; }
|
||||
.round-status { margin-left: 0.5em; font-size: 0.8em; padding: 0 0.4em; border-radius: 3px; }
|
||||
.round-status.done { background: #d4edda; color: #155724; }
|
||||
.round-status.open { background: #fff3cd; color: #856404; }
|
||||
.round-admin td input[type="text"] { width: 10em; }
|
||||
.round-admin td.score { white-space: nowrap; }
|
||||
.round-admin td.score input { width: 3.5em; }
|
||||
.round-admin textarea { width: 100%; max-width: 800px; }
|
||||
.round-admin .form-group { margin: 0.8em 0; }
|
||||
.round-admin .hint { color: #666; font-size: 0.8em; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
160
tippspiel/src/Views/admin/seasons.php
Normal file
160
tippspiel/src/Views/admin/seasons.php
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
$pageTitle = 'Saisons verwalten';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
?>
|
||||
|
||||
<h1>Saisons 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 season -->
|
||||
<h2><?php echo $editSeason ? 'Saison bearbeiten' : 'Neue Saison anlegen'; ?></h2>
|
||||
<form action="/index.php?page=admin_seasons" method="post">
|
||||
<?php if ($editSeason): ?>
|
||||
<input type="hidden" name="action" value="update">
|
||||
<input type="hidden" name="id" value="<?php echo htmlspecialchars($editSeason['id']); ?>">
|
||||
<?php else: ?>
|
||||
<input type="hidden" name="action" value="create">
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name">Name:</label>
|
||||
<input type="text" id="name" name="name" value="<?php echo htmlspecialchars($formValues['name']); ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="rounds">Runden:</label>
|
||||
<input type="number" min="1" id="rounds" name="rounds" value="<?php echo htmlspecialchars($formValues['rounds']); ?>" required>
|
||||
<?php if ($editSeason): ?>
|
||||
<small>(Runden werden nur beim Anlegen erzeugt; eine Änderung legt keine Runden an oder löscht welche.)</small>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="max_identical_jokertipps">Max. gleiche Joker:</label>
|
||||
<input type="number" min="0" id="max_identical_jokertipps" name="max_identical_jokertipps" value="<?php echo htmlspecialchars($formValues['max_identical_jokertipps']); ?>" required>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$q = $formValues['quotas'];
|
||||
$quotaInput = function ($name, $label, $unit, $amount = null) use ($q) {
|
||||
echo '<div class="form-group">';
|
||||
echo '<label for="quota_' . $name . '">' . htmlspecialchars($label) . ':</label>';
|
||||
echo '<input type="number" step="0.01" min="0" id="quota_' . $name . '" name="quotas[' . $name . ']" value="'
|
||||
. htmlspecialchars((string)($q[$name] ?? '')) . '" style="width: 100px;" required> ' . $unit;
|
||||
if ($amount !== null) {
|
||||
echo ' = ' . number_format($amount, 2, ',', '.') . ' €';
|
||||
}
|
||||
echo '</div>';
|
||||
};
|
||||
?>
|
||||
|
||||
<h2>Spiel-Einsatz</h2>
|
||||
<?php $quotaInput('einsatz', 'Einsatz pro Spieler', '€'); ?>
|
||||
<?php if ($payouts !== null): ?>
|
||||
<p class="hint"><?php echo $paidUserCount; ?> bezahlte Spieler, <?php echo $roundCount; ?> Runden.
|
||||
Beträge berechnet aus den gespeicherten Quoten.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<h2>Spielquoten</h2>
|
||||
<?php
|
||||
$placementSum = 0;
|
||||
if ($payouts !== null) {
|
||||
for ($place = 1; $place <= \App\Models\Quota::PLACES; $place++) {
|
||||
$placementSum += $payouts['platz' . $place];
|
||||
}
|
||||
}
|
||||
$quotaInput('tagessieg', 'Tagessieg', '%', $payouts !== null ? $payouts['tagessieg'] : null);
|
||||
if ($payouts !== null) {
|
||||
echo '<p class="hint">je Runde</p>';
|
||||
}
|
||||
$quotaInput('platzierung', 'Platzierung', '%', $payouts !== null ? $placementSum : null);
|
||||
?>
|
||||
|
||||
<h2>Platzierungsquoten</h2>
|
||||
<?php for ($place = 1; $place <= \App\Models\Quota::PLACES; $place++) {
|
||||
$quotaInput('platz' . $place, 'Platz ' . $place, '%', $payouts !== null ? $payouts['platz' . $place] : null);
|
||||
} ?>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit"><?php echo $editSeason ? 'Speichern' : 'Anlegen'; ?></button>
|
||||
<?php if ($editSeason): ?>
|
||||
<a href="/index.php?page=admin_seasons">Abbrechen</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<!-- Season List -->
|
||||
<h2>Saison-Liste</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Runden</th>
|
||||
<th>Aktiv</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($seasons as $season): ?>
|
||||
<tr <?php if ((int)$currentSeason['id'] === (int)$season['id']) echo 'style="font-weight: bold;"'; ?>>
|
||||
<td><?php echo htmlspecialchars($season['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($season['rounds']); ?></td>
|
||||
<td><?php echo (int)$currentSeason['id'] === (int)$season['id'] ? 'Ja' : 'Nein'; ?></td>
|
||||
<td>
|
||||
<a href="/index.php?page=admin_seasons&edit_id=<?php echo $season['id']; ?>">Bearbeiten</a>
|
||||
<?php if ((int)$currentSeason['id'] !== (int)$season['id']): ?>
|
||||
<form action="/index.php?page=admin_seasons" method="post" style="display: inline;">
|
||||
<input type="hidden" name="action" value="set_current">
|
||||
<input type="hidden" name="id" value="<?php echo $season['id']; ?>">
|
||||
<button type="submit" class="link-button">Als aktiv setzen</button>
|
||||
</form>
|
||||
<form action="/index.php?page=admin_seasons" method="post" style="display: inline;" onsubmit="return confirm(<?php echo htmlspecialchars(json_encode('Saison "' . $season['name'] . '" mit allen Runden, Spielen, Tipps, Zahlungen und Quoten endgültig löschen?'), ENT_QUOTES); ?>);">
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="hidden" name="id" value="<?php echo $season['id']; ?>">
|
||||
<button type="submit" class="link-button">Löschen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<style>
|
||||
/* From users.php, for consistency */
|
||||
.form-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.form-group label {
|
||||
display: inline-block;
|
||||
width: 150px;
|
||||
text-align: right;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.hint {
|
||||
margin-left: calc(150px + 10px);
|
||||
color: #666;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
131
tippspiel/src/Views/admin/users.php
Normal file
131
tippspiel/src/Views/admin/users.php
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
<?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: var(--link);
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
font-size: inherit;
|
||||
text-decoration: underline;
|
||||
font-family: inherit;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
27
tippspiel/src/Views/home.php
Normal file
27
tippspiel/src/Views/home.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
use App\Models\Round;
|
||||
|
||||
$pageTitle = 'Tippspiel 2027 - Startseite';
|
||||
require __DIR__ . '/partials/header.php';
|
||||
?>
|
||||
|
||||
<h1>Willkommen bei Tippspiel 2027</h1>
|
||||
|
||||
<h2>Rundenübersicht</h2>
|
||||
<?php if ($currentSeason): ?>
|
||||
<p>Saison: <strong><?php echo htmlspecialchars($currentSeason['name']); ?></strong></p>
|
||||
<?php if ($rounds): ?>
|
||||
<?php foreach ($rounds as $round): ?>
|
||||
<h3><a href="/index.php?page=round&id=<?php echo htmlspecialchars($round['id']); ?>"><?php echo htmlspecialchars($round['name']); ?></a></h3>
|
||||
<?php if (!empty($round['report'])): ?>
|
||||
<p><?php echo nl2br(htmlspecialchars(Round::reportToText($round['report']))); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<p>Noch keine abgeschlossenen Runden in der aktuellen Saison.</p>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<p>Keine Saison gefunden.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php require __DIR__ . '/partials/footer.php'; ?>
|
||||
171
tippspiel/src/Views/info/guide.php
Normal file
171
tippspiel/src/Views/info/guide.php
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
use App\Models\Quota;
|
||||
use App\Models\Ranking;
|
||||
use App\Models\Tipp;
|
||||
|
||||
$pageTitle = 'Anleitung';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
|
||||
$euro = fn($amount) => number_format($amount, 0, ',', '.') . ' €';
|
||||
|
||||
// Beispielwerte direkt aus der Punkteberechnung, damit die Anleitung immer zum Code passt
|
||||
$exactExamples = ['1:0', '2:1', '2:2', '3:1', '3:2', '4:2', '5:3'];
|
||||
?>
|
||||
|
||||
<div class="guide">
|
||||
|
||||
<h1>Anleitung</h1>
|
||||
<p class="lead">Die wichtigsten Regeln auf einen Blick: wie du tippst, wie Punkte entstehen und wie Rangliste und Gewinne berechnet werden.</p>
|
||||
|
||||
<nav class="guide-toc">
|
||||
<a href="#tippen">Tippen</a>
|
||||
<a href="#joker">Joker</a>
|
||||
<a href="#punkte">Punkte</a>
|
||||
<a href="#rangliste">Rangliste</a>
|
||||
<a href="#tagessieg">Tagessieg</a>
|
||||
<a href="#gewinne">Gewinne</a>
|
||||
<a href="#app">Als App installieren</a>
|
||||
</nav>
|
||||
|
||||
<h2 id="tippen">1. Tippen</h2>
|
||||
<ul>
|
||||
<li>Mitspielen und in der Rangliste erscheinen kannst du, sobald dein <strong>Einsatz für die Saison</strong> als bezahlt eingetragen ist.</li>
|
||||
<li>Eine Saison besteht aus Runden mit mehreren Spielen. Unter <a href="/index.php?page=tipps">Tipps</a> tippst du für jedes Spiel ein Ergebnis, entweder die ganze Runde auf einmal („Runde Tippen“) oder jedes Spiel einzeln.</li>
|
||||
<li>Deine Tipps kannst du beliebig oft ändern, bis die Runde <strong>gesperrt</strong> wird: <strong>1 Minute vor dem Anpfiff des ersten Spiels der Runde</strong>. Ab dann ist die ganze Runde gesperrt, auch für die späteren Spiele. Den Sperrzeitpunkt siehst du bei jeder Runde.</li>
|
||||
<li>Ein fehlender Tipp bringt 0 Punkte.</li>
|
||||
<li>Fehlen dir rund 48 Stunden vor der Sperre noch Tipps oder der Joker, bekommst du eine Erinnerungsmail. Das kannst du unter <em>Einstellungen</em> abschalten.</li>
|
||||
</ul>
|
||||
|
||||
<h2 id="joker">2. Joker</h2>
|
||||
<ul>
|
||||
<li>Pro Runde setzt du <strong>genau einen Joker</strong> auf eines der Spiele. Er <strong>verdoppelt die Punkte</strong> dieses Spiels.</li>
|
||||
<li>Du kannst den Joker bis zur Sperre beliebig auf ein anderes Spiel der Runde verschieben.</li>
|
||||
<li>Dasselbe Ergebnis darfst du pro Saison höchstens <strong><?php echo $maxIdenticalJokertipps; ?>-mal</strong> mit Joker tippen. Wie oft du welches Ergebnis schon „gejokert“ hast, steht bei jeder Runde unter „Bereits verwendete Joker“.</li>
|
||||
<li>Ein exakt getroffener Joker entscheidet außerdem beim <a href="#tagessieg">Tagessieg</a> mit.</li>
|
||||
</ul>
|
||||
|
||||
<h2 id="punkte">3. Punkte</h2>
|
||||
<table class="guide-table">
|
||||
<thead><tr><th>Treffer</th><th>Punkte</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>Falsche Tendenz</td><td>0</td></tr>
|
||||
<tr><td><strong>Richtige Tendenz</strong> (Sieg Heim / Unentschieden / Sieg Gast richtig, Ergebnis falsch)</td><td>1</td></tr>
|
||||
<tr><td><strong>Exaktes Ergebnis</strong></td><td>2 + Torbonus</td></tr>
|
||||
<tr><td>Mit <strong>Joker</strong></td><td>Punkte des Spiels × 2</td></tr>
|
||||
<tr><td><strong>Rundenbonus</strong>: Jedes Spiel der Runde bringt dir mindestens einen Punkt</td><td>+ <?php echo Tipp::ALL_HITS_BONUS; ?> (wird nicht verdoppelt)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p><strong>Torbonus:</strong> Bei einem exakten Treffer gibt es für jedes Tor über drei Tore hinaus einen Extrapunkt.
|
||||
Torreiche Ergebnisse exakt zu treffen lohnt sich also mehr:</p>
|
||||
<table class="guide-table compact">
|
||||
<thead>
|
||||
<tr><th>Exakt getroffen</th><?php foreach ($exactExamples as $ex): ?><th><?php echo $ex; ?></th><?php endforeach; ?></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td>Punkte</td>
|
||||
<?php foreach ($exactExamples as $ex): [$a, $b] = array_map('intval', explode(':', $ex)); ?>
|
||||
<td><?php echo Tipp::getScoreLocal($a, $b, $a, $b, false); ?></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<tr><td>mit Joker</td>
|
||||
<?php foreach ($exactExamples as $ex): [$a, $b] = array_map('intval', explode(':', $ex)); ?>
|
||||
<td><?php echo Tipp::getScoreLocal($a, $b, $a, $b, true); ?></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="example">
|
||||
<strong>Beispiel einer Runde:</strong>
|
||||
<table class="guide-table compact">
|
||||
<thead><tr><th>Ergebnis</th><th>Dein Tipp</th><th>Wertung</th><th>Punkte</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>2:1</td><td>1:0</td><td>Tendenz richtig</td><td><?php echo Tipp::getScoreLocal(2, 1, 1, 0, false); ?></td></tr>
|
||||
<tr><td>1:1</td><td>1:1</td><td>exakt</td><td><?php echo Tipp::getScoreLocal(1, 1, 1, 1, false); ?></td></tr>
|
||||
<tr><td>3:2</td><td>3:2 mit Joker</td><td>exakt: 2 + 2 Torbonus, verdoppelt</td><td><?php echo Tipp::getScoreLocal(3, 2, 3, 2, true); ?></td></tr>
|
||||
<tr><td>0:2</td><td>1:3</td><td>Tendenz richtig</td><td><?php echo Tipp::getScoreLocal(0, 2, 1, 3, false); ?></td></tr>
|
||||
<tr><td colspan="3">Alle Spiele haben gepunktet: Rundenbonus</td><td>+<?php echo Tipp::ALL_HITS_BONUS; ?></td></tr>
|
||||
<tr class="total"><td colspan="3">Rundenpunkte</td>
|
||||
<td><?php echo Tipp::getScoreLocal(2, 1, 1, 0, false) + Tipp::getScoreLocal(1, 1, 1, 1, false)
|
||||
+ Tipp::getScoreLocal(3, 2, 3, 2, true) + Tipp::getScoreLocal(0, 2, 1, 3, false) + Tipp::ALL_HITS_BONUS; ?></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Hätte beim letzten Spiel der Tipp 2:0 gelautet (falsche Tendenz), gäbe es dafür 0 Punkte und keinen Rundenbonus.</p>
|
||||
</div>
|
||||
|
||||
<h2 id="rangliste">4. Rangliste</h2>
|
||||
<ul>
|
||||
<li>Die <a href="/index.php?page=ranking">Rangliste</a> zeigt den Stand nach einer Runde. Oben kannst du jede Runde auswählen, die schon begonnen hat. Die Tipps der anderen siehst du also erst, wenn die Runde gesperrt ist.</li>
|
||||
<li><strong>Platz</strong>: Sortiert wird nach <strong>Punkte (Gesamt)</strong>, der Summe aller Rundenpunkte bis einschließlich der gewählten Runde.</li>
|
||||
<li><strong>Gleichstand</strong>: Spieler mit gleicher Gesamtpunktzahl teilen sich den Platz. Der nächste Platz wird übersprungen (z.B. 1., 1., 3.). Innerhalb eines geteilten Platzes wird alphabetisch sortiert.</li>
|
||||
<li><strong>Punkte (Runde)</strong>: Punkte der gewählten Runde inklusive Rundenbonus.</li>
|
||||
<li>Pro Spiel siehst du die Punkte jedes Spielers. Beim Überfahren mit der Maus erscheint der getippte Tipp. Die Farbe zeigt den Treffer:
|
||||
<span class="swatch" style="background: var(--col-tendenz);"></span> richtige Tendenz,
|
||||
<span class="swatch" style="background: var(--col-exact);"></span> exaktes Ergebnis,
|
||||
<span class="swatch" style="background: var(--col-joker-exact);"></span> exaktes Ergebnis mit Joker.
|
||||
Das Joker-Symbol markiert, wo der Joker gesetzt war.</li>
|
||||
<li>🏆 markiert die Tagessieger der Runde.</li>
|
||||
</ul>
|
||||
|
||||
<h2 id="tagessieg">5. Tagessieg</h2>
|
||||
<ul>
|
||||
<li>Ist eine Runde komplett ausgespielt, wird der Tagessieg vergeben<?php if ($payouts): ?>, derzeit <strong><?php echo $euro($payouts['tagessieg']); ?></strong> pro Runde<?php endif; ?>.</li>
|
||||
<li>Tagessieger ist, wer in der Runde die <strong>meisten exakten Ergebnisse</strong> getroffen hat. Die Rundenpunkte spielen dabei zunächst keine Rolle.</li>
|
||||
<li>Bei Gleichstand entscheidet der <strong>Joker</strong>: Wer seinen Joker exakt getroffen hat, liegt vorn. Haben das mehrere, gewinnt der Joker-Treffer mit dem höheren Torbonus (z.B. schlägt ein 3:2-Joker einen 2:1-Joker; 1:0 und 2:1 zählen gleich).</li>
|
||||
<li>Bleibt es gleich, teilen sich alle Gleichplatzierten den Betrag.</li>
|
||||
<li>Wären es mehr als <?php echo Ranking::MAX_DAY_WINNERS; ?> Tagessieger, gewinnen nur die mit den meisten Rundenpunkten.</li>
|
||||
<li>Hat niemand ein exaktes Ergebnis getroffen, gibt es keinen Tagessieger. Der Betrag <strong>wandert in die nächste Runde</strong>, in der es einen Tagessieger gibt.</li>
|
||||
</ul>
|
||||
|
||||
<h2 id="gewinne">6. Gewinne</h2>
|
||||
<ul>
|
||||
<li>Alle Einsätze bilden den Pott. Ein Teil geht an die Tagessiege, der Rest an die Plätze 1 bis <?php echo Quota::PLACES; ?> der Endabrechnung.
|
||||
Die aktuellen Beträge stehen unter <a href="/index.php?page=info_quotas">Quoten</a>.</li>
|
||||
<li>Das <strong>Platzierungsgeld</strong> wird erst nach der letzten Runde der Saison vergeben, maßgeblich ist die Rangliste nach dieser Runde.</li>
|
||||
<li>Teilen sich mehrere Spieler einen Platz, teilen sie sich das Geld aller Plätze, die sie gemeinsam belegen.
|
||||
Beispiel: Zwei Spieler auf Platz 1 teilen sich das Geld für Platz 1 und Platz 2.</li>
|
||||
<li>Was du bisher gewonnen hast, zeigt die <a href="/index.php?page=money_ranking">Geldrangliste</a>. Damit dein Gewinn überwiesen werden kann, trage deine Bankverbindung unter <em>Einstellungen</em> ein.</li>
|
||||
</ul>
|
||||
|
||||
<h2 id="app">7. Als App installieren</h2>
|
||||
<p>Das Tippspiel kannst du dir wie eine App auf den Startbildschirm deines Smartphones legen. Sie öffnet sich dann im Vollbild mit eigenem Symbol – ohne Adressleiste des Browsers. Der eigentliche Inhalt ist identisch mit der Webseite, und es funktioniert weiterhin nur mit Internetverbindung.</p>
|
||||
|
||||
<h3>Android (Chrome)</h3>
|
||||
<ol>
|
||||
<li>Öffne das Tippspiel in <strong>Chrome</strong>.</li>
|
||||
<li>Tippe auf das Menü <strong>⋮</strong> (drei Punkte) oben rechts.</li>
|
||||
<li>Wähle <strong>„App installieren“</strong> (oder „Zum Startbildschirm hinzufügen“).</li>
|
||||
<li>Bestätige mit <strong>„Installieren“</strong>.</li>
|
||||
<li>Die App erscheint auf dem Startbildschirm und in der App-Übersicht.</li>
|
||||
</ol>
|
||||
|
||||
<h3>iPhone (Safari)</h3>
|
||||
<ol>
|
||||
<li>Öffne das Tippspiel in <strong>Safari</strong>.</li>
|
||||
<li>Tippe unten in der Mitte auf das <strong>Teilen-Symbol</strong> <span style="font-size:1.2em;">⏏</span> (Quadrat mit Pfeil nach oben).</li>
|
||||
<li>Scrolle und wähle <strong>„Zum Home-Bildschirm“</strong>.</li>
|
||||
<li>Bestätige mit <strong>„Hinzufügen“</strong> (oben rechts).</li>
|
||||
<li>Die App erscheint auf dem Home-Bildschirm.</li>
|
||||
</ol>
|
||||
|
||||
<p class="hint">Tipp: Beim ersten Öffnen musst du dich einmal anmelden. Danach bleibst du – wie im Browser – angemeldet.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.guide { max-width: 900px; line-height: 1.5; }
|
||||
.guide .lead { color: #555; }
|
||||
.guide h2 { margin-top: 1.8em; border-bottom: 1px solid #ddd; padding-bottom: 0.2em; scroll-margin-top: 1em; }
|
||||
.guide-toc { background: none; padding: 0; margin: 0 0 1em; }
|
||||
.guide-toc a { margin-right: 1em; font-weight: normal; color: var(--link); }
|
||||
.guide-table { width: auto; margin: 0.8em 0; }
|
||||
.guide-table td:last-child, .guide-table th:last-child { text-align: center; }
|
||||
.guide-table.compact td, .guide-table.compact th { padding: 4px 10px; text-align: center; }
|
||||
.guide-table.compact td:first-child, .guide-table.compact th:first-child { text-align: left; }
|
||||
.guide-table tr.total td { font-weight: bold; border-top: 2px solid #999; }
|
||||
.guide .example { background: #f9f9f9; border: 1px solid #ddd; padding: 0.8em 1em; margin: 1em 0; }
|
||||
.guide .swatch { display: inline-block; width: 0.9em; height: 0.9em; vertical-align: middle; border: 1px solid #999; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
44
tippspiel/src/Views/info/money_ranking.php
Normal file
44
tippspiel/src/Views/info/money_ranking.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
$pageTitle = 'Geldrangliste';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
|
||||
$myId = (int)$user['id'];
|
||||
?>
|
||||
|
||||
<h1>Geldrangliste</h1>
|
||||
|
||||
<table class="money-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Ausschüttung</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($moneyRanking as $entry):
|
||||
$isMe = (int)$entry['user_id'] === $myId;
|
||||
?>
|
||||
<tr id="playerid_<?php echo (int)$entry['user_id']; ?>" <?php if ($isMe) echo 'class="me"'; ?>>
|
||||
<td><a href="/index.php?page=money_ranking&user_id=<?php echo (int)$entry['user_id']; ?>"><?php echo htmlspecialchars($entry['name']); ?></a></td>
|
||||
<td class="amount"><?php echo number_format($entry['amount'], 2, ',', '.'); ?> €</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
// Wie im Legacy (Link auf #playerid_<eigene ID>): ohne Anker zur eigenen Zeile springen
|
||||
if (!location.hash) {
|
||||
const me = document.getElementById('playerid_<?php echo $myId; ?>');
|
||||
if (me) me.scrollIntoView({block: 'center'});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.money-table { width: auto; min-width: 400px; }
|
||||
.money-table td.amount { text-align: right; }
|
||||
.money-table tr.me td { background: #fff3cd; font-weight: bold; }
|
||||
.money-table tr:target td { background: #fff3cd; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
41
tippspiel/src/Views/info/money_ranking_detail.php
Normal file
41
tippspiel/src/Views/info/money_ranking_detail.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
$pageTitle = 'Ausschüttungsübersicht';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
?>
|
||||
|
||||
<h1>Ausschüttungsübersicht <?php echo htmlspecialchars($detailUser['name']); ?></h1>
|
||||
|
||||
<table class="money-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Quoten-Titel</th>
|
||||
<th>Ausschüttung</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($payoutItems as $item): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($item['label']); ?></td>
|
||||
<td class="amount"><?php echo number_format($item['amount'], 2, ',', '.'); ?> €</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php if (empty($payoutItems)): ?>
|
||||
<tr><td colspan="2">Bisher keine Ausschüttungen.</td></tr>
|
||||
<?php else: ?>
|
||||
<tr class="total">
|
||||
<td>Summe</td>
|
||||
<td class="amount"><?php echo number_format(array_sum(array_column($payoutItems, 'amount')), 2, ',', '.'); ?> €</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p><a href="/index.php?page=money_ranking#playerid_<?php echo (int)$detailUser['id']; ?>">Zurück</a></p>
|
||||
|
||||
<style>
|
||||
.money-table { width: auto; min-width: 400px; }
|
||||
.money-table td.amount { text-align: right; }
|
||||
.money-table tr.total td { font-weight: bold; border-top: 2px solid #999; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
14
tippspiel/src/Views/info/no_ranking.php
Normal file
14
tippspiel/src/Views/info/no_ranking.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
$pageTitle = 'Geldrangliste';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
?>
|
||||
|
||||
<p style="color: red;">
|
||||
Es gibt noch keine Tipprunde, die reif für die Anzeige ist.
|
||||
<?php if ($seasonStart): ?>
|
||||
Rangliste / Tippvergleich verfügbar ab <?php echo $seasonStart->format('d.m.Y H:i'); ?>.
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<p><a href="/">Ok</a></p>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
48
tippspiel/src/Views/info/quotas.php
Normal file
48
tippspiel/src/Views/info/quotas.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
use App\Models\Quota;
|
||||
|
||||
$pageTitle = 'Quoten';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
|
||||
$euro = fn($amount) => number_format($amount, 2, ',', '.') . ' €';
|
||||
?>
|
||||
|
||||
<?php if (!$currentSeason): ?>
|
||||
<p>Es gibt noch keine Saison.</p>
|
||||
<?php else: ?>
|
||||
<h1><?php echo htmlspecialchars($currentSeason['name']); ?></h1>
|
||||
<h2>Ausschüttungs-Quoten</h2>
|
||||
|
||||
<div class="quota-section">
|
||||
<h3>Spiel-Einsatz</h3>
|
||||
<table class="info-table">
|
||||
<tr><th>Aktive Spieler</th><td><?php echo $activeUserCount; ?></td></tr>
|
||||
<tr><th>Einsatz pro Spieler</th><td><?php echo $euro($stake); ?></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="quota-section">
|
||||
<h3>Spielquoten</h3>
|
||||
<table class="info-table">
|
||||
<tr><th>Tagessieg</th><td><?php echo $euro($payouts['tagessieg']); ?></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="quota-section">
|
||||
<h3>Platzierungsquoten</h3>
|
||||
<table class="info-table">
|
||||
<?php for ($place = 1; $place <= Quota::PLACES; $place++): ?>
|
||||
<tr><th>Platz <?php echo $place; ?></th><td><?php echo $euro($payouts['platz' . $place]); ?></td></tr>
|
||||
<?php endfor; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.quota-section { text-align: center; }
|
||||
.info-table { width: auto; min-width: 350px; margin-left: auto; margin-right: auto; }
|
||||
.info-table th { width: 200px; font-weight: normal; }
|
||||
.info-table td { text-align: right; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
55
tippspiel/src/Views/login.php
Normal file
55
tippspiel/src/Views/login.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
$pageTitle = 'Login';
|
||||
require __DIR__ . '/partials/header.php';
|
||||
?>
|
||||
|
||||
<h1>Login</h1>
|
||||
|
||||
<?php if (isset($error)): ?>
|
||||
<p style="color: red;"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.form-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.form-group label {
|
||||
display: inline-block;
|
||||
width: 150px;
|
||||
text-align: right;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
@media (min-width: 701px) {
|
||||
.form-actions {
|
||||
margin-left: calc(150px + 10px);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<form action="/index.php?page=login" method="post">
|
||||
<div class="form-group">
|
||||
<label for="firstname">Vorname:</label>
|
||||
<input type="text" id="firstname" name="firstname" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastname">Nachname:</label>
|
||||
<input type="text" id="lastname" name="lastname" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Passwort:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="submit">Anmelden</button>
|
||||
<?php if (App\Models\Setting::isRegistrationOpen()): ?>
|
||||
<button type="button" onclick="location.href='/index.php?page=register'">Registrieren</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php require __DIR__ . '/partials/footer.php'; ?>
|
||||
11
tippspiel/src/Views/partials/footer.php
Normal file
11
tippspiel/src/Views/partials/footer.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
</main>
|
||||
<footer class="site-footer">⚽ Tippspiel 2027</footer>
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', function () {
|
||||
navigator.serviceWorker.register('/sw.js');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
65
tippspiel/src/Views/partials/header.php
Normal file
65
tippspiel/src/Views/partials/header.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php $pageTitle = $pageTitle ?? 'Tippspiel 2027'; ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title><?php echo htmlspecialchars($pageTitle); ?></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#14632f">
|
||||
<meta name="description" content="Hoschis Tippspiel 2027 – Tippgemeinschaft unter Freunden.">
|
||||
<link rel="manifest" href="/manifest.json">
|
||||
<link rel="icon" href="/img/icon-192.png">
|
||||
<link rel="apple-touch-icon" href="/img/icon-180.png">
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
</head>
|
||||
<body>
|
||||
<nav class="site-nav">
|
||||
<a href="/" class="brand"><span class="brand-ball">⚽</span> Tippspiel <span class="brand-year">2027</span></a>
|
||||
<a href="/">Start</a>
|
||||
<?php if (App\Core\Auth::isAdmin()): $registrationOpen = App\Models\Setting::isRegistrationOpen(); ?>
|
||||
<span class="nav-dropdown">
|
||||
<a href="#" onclick="return false;">Administration</a>
|
||||
<span class="nav-dropdown-content">
|
||||
<a href="/index.php?page=admin_users">Benutzer verwalten</a>
|
||||
<a href="/index.php?page=admin_seasons">Saisons verwalten</a>
|
||||
<a href="/index.php?page=admin_rounds">Spiele & Ergebnisse eintragen</a>
|
||||
<a href="/index.php?page=admin_roundmails">Runden-E-Mails versenden</a>
|
||||
<a href="/index.php?page=admin_accounts">Kontoliste</a>
|
||||
<form method="post" action="/index.php?page=admin" class="nav-dropdown-form">
|
||||
<input type="hidden" name="action" value="set_registration">
|
||||
<input type="hidden" name="registration_open" value="<?php echo $registrationOpen ? '0' : '1'; ?>">
|
||||
<input type="hidden" name="return" value="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'] ?? '/'); ?>">
|
||||
<button type="submit" title="Registrierung ist derzeit <?php echo $registrationOpen ? 'offen' : 'geschlossen'; ?>">
|
||||
Registrierung <?php echo $registrationOpen ? 'schließen' : 'öffnen'; ?>
|
||||
<small>(derzeit <?php echo $registrationOpen ? 'offen' : 'geschlossen'; ?>)</small>
|
||||
</button>
|
||||
</form>
|
||||
</span>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<a href="/index.php?page=tipps">Tipps</a>
|
||||
<a href="/index.php?page=ranking">Rangliste</a>
|
||||
<span class="nav-dropdown">
|
||||
<a href="#" onclick="return false;">Info</a>
|
||||
<span class="nav-dropdown-content">
|
||||
<a href="/index.php?page=guide">Anleitung</a>
|
||||
<a href="/index.php?page=info_quotas">Quoten</a>
|
||||
<a href="/index.php?page=money_ranking">Geldrangliste</a>
|
||||
</span>
|
||||
</span>
|
||||
<span class="nav-user">
|
||||
<?php if (App\Core\Auth::check()): ?>
|
||||
<span class="nav-dropdown">
|
||||
<a href="#" onclick="return false;">( <?php echo htmlspecialchars(App\Core\Auth::user()['name']); ?> )</a>
|
||||
<span class="nav-dropdown-content">
|
||||
<a href="/index.php?page=settings">Einstellungen</a>
|
||||
<a href="/index.php?page=logout">Abmelden</a>
|
||||
</span>
|
||||
</span>
|
||||
<?php else: ?>
|
||||
<a href="/index.php?page=login">Login</a>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</nav>
|
||||
<main class="page">
|
||||
188
tippspiel/src/Views/ranking.php
Normal file
188
tippspiel/src/Views/ranking.php
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
<?php
|
||||
$pageTitle = 'Rangliste';
|
||||
if ($selectedRound) {
|
||||
$pageTitle .= ' - ' . htmlspecialchars($selectedRound['name']);
|
||||
}
|
||||
require __DIR__ . '/partials/header.php';
|
||||
|
||||
// Stellt sicher, dass die benötigten Variablen vorhanden sind
|
||||
if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allRounds) || !isset($selectedRound)) {
|
||||
echo "Fehler: Daten für die Rangliste nicht gefunden.";
|
||||
// exit; // Besser, eine freundliche Nachricht im Layout anzuzeigen
|
||||
}
|
||||
?>
|
||||
|
||||
<style>
|
||||
.game-header {
|
||||
width: 100px; /* Feste Breite für die Spiele-Spalten */
|
||||
}
|
||||
.tipp-points {
|
||||
width: 55px; /* Breite für den Tipp (z.B. 2:1) */
|
||||
box-sizing: border-box;
|
||||
text-align: center;
|
||||
}
|
||||
.tipp-joker {
|
||||
width: 70px; /* Breite für vergrößerten Joker */
|
||||
box-sizing: border-box;
|
||||
padding-left: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
.joker-icon {
|
||||
width: 2rem; /* Größe weiter auf 75% reduziert */
|
||||
height: 2rem; /* Größe weiter auf 75% reduziert */
|
||||
vertical-align: middle;
|
||||
}
|
||||
.daily-winner-icon {
|
||||
font-size: 2rem; /* Größe verdoppeln */
|
||||
vertical-align: middle;
|
||||
}
|
||||
#round_id {
|
||||
font-size: inherit; /* Schriftgröße an die Umgebung anpassen */
|
||||
}
|
||||
table th, table td {
|
||||
padding-top: 0.1rem;
|
||||
padding-bottom: 0.1rem;
|
||||
}
|
||||
|
||||
/* Kompakter Kopfbereich: Titel, Saison und Rundenwahl auf einer Zeile */
|
||||
.ranking-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: baseline;
|
||||
gap: 0.3em 0.9em;
|
||||
margin-bottom: 0.8em;
|
||||
}
|
||||
.ranking-toolbar h1 {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border-bottom: none;
|
||||
font-size: 1.3em;
|
||||
}
|
||||
.ranking-toolbar .season {
|
||||
font-family: var(--font-display);
|
||||
font-weight: 700;
|
||||
color: var(--pitch-dark);
|
||||
}
|
||||
.ranking-toolbar .round-filter {
|
||||
margin: 0 0 0 auto;
|
||||
}
|
||||
.ranking-toolbar .round-filter label {
|
||||
margin-right: 0.3em;
|
||||
}
|
||||
|
||||
/* Legende als kompakte Fußzeile unter der Tabelle */
|
||||
.legend.legend-footer {
|
||||
margin: 10px 0 0;
|
||||
padding: 6px 10px;
|
||||
font-size: 0.8em;
|
||||
gap: 6px 12px;
|
||||
justify-content: center;
|
||||
}
|
||||
.legend.legend-footer .legend-color { width: 12px; height: 12px; }
|
||||
.legend.legend-footer .joker-icon { width: 1.1em; height: 1.1em; }
|
||||
.legend.legend-footer .daily-winner-icon { font-size: 1em; }
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.ranking-toolbar h1 { font-size: 1.1em; }
|
||||
.ranking-toolbar .round-filter { margin-left: 0; }
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="ranking-toolbar">
|
||||
<h1>Rangliste</h1>
|
||||
<span class="season"><?php echo htmlspecialchars($currentSeason['name']); ?></span>
|
||||
<?php if ($selectedRound): ?>
|
||||
<form method="get" class="round-filter">
|
||||
<input type="hidden" name="page" value="ranking">
|
||||
<label for="round_id">Runde:</label>
|
||||
<select name="round_id" id="round_id" onchange="this.form.submit()">
|
||||
<?php foreach ($allRounds as $round): ?>
|
||||
<option value="<?php echo $round['id']; ?>" <?php echo ($round['id'] == $selectedRound['id']) ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($round['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if ($selectedRound): ?>
|
||||
<div class="table-container sticky-header">
|
||||
<?php if (!empty($ranking)): ?>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">Platz</th>
|
||||
<th>Name</th>
|
||||
<th class="text-center"><span class="daily-winner-icon">🏆</span></th>
|
||||
<th class="text-center">Punkte (Gesamt)</th>
|
||||
<th class="text-center">Punkte (Runde)</th>
|
||||
<?php foreach ($games as $game): ?>
|
||||
<th class="game-header" colspan="2">
|
||||
<?php echo htmlspecialchars($game['team1']); ?><br>
|
||||
<?php echo htmlspecialchars($game['team2']); ?><br>
|
||||
<small>(<?php echo htmlspecialchars(App\Models\Game::getResultString($game['score1'], $game['score2'], $game['kickoff'])); ?>)</small>
|
||||
</th>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($ranking as $entry):
|
||||
$rowClasses = [];
|
||||
if ($entry['rank'] <= 3) $rowClasses[] = 'rank-' . $entry['rank'];
|
||||
if ((int)$entry['user_id'] === (int)App\Core\Auth::id()) $rowClasses[] = 'me';
|
||||
?>
|
||||
<tr<?php if ($rowClasses) echo ' class="' . implode(' ', $rowClasses) . '"'; ?>
|
||||
<?php if ((int)$entry['user_id'] === (int)App\Core\Auth::id()) echo ' id="me-row"'; ?>>
|
||||
<td class="text-center"><span class="rank-badge"><?php echo $entry['rank']; ?>.</span></td>
|
||||
<td><?php echo htmlspecialchars($entry['name']); ?></td>
|
||||
<td class="text-center"><?php echo $entry['is_day_winner'] ? '<span class="daily-winner-icon">🏆</span>' : ''; ?></td>
|
||||
<td class="text-center"><strong><?php echo $entry['total']; ?></strong></td>
|
||||
<td class="text-center"><?php echo $entry['points']; ?></td>
|
||||
<?php foreach ($games as $game): ?>
|
||||
<?php
|
||||
$tipp = $entry['cells'][$game['id']];
|
||||
// Farbklasse kommt fertig aus Tipp::getCol (col_tendenz / col_exact / col_joker_exact)
|
||||
$td_class = $tipp['color'];
|
||||
$title = "Punkte: " . $tipp['points'];
|
||||
?>
|
||||
<td class="tipp-cell tipp-points <?php echo htmlspecialchars($td_class); ?>" title="<?php echo $title; ?>">
|
||||
<?php echo htmlspecialchars($tipp['text']); ?>
|
||||
</td>
|
||||
<td class="tipp-cell tipp-joker" title="<?php echo $title; ?>">
|
||||
<?php if ($tipp['joker']): ?>
|
||||
<img src="/img/joker.png" alt="Joker" class="joker-icon" title="Joker">
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php else: ?>
|
||||
<p>Für diese Saison gibt es noch keine Rangliste (möglicherweise haben noch keine Spieler bezahlt).</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="legend legend-footer">
|
||||
<div class="legend-item"><span class="daily-winner-icon">🏆</span> Tagessieger</div>
|
||||
<div class="legend-item"><img src="/img/joker.png" alt="Joker" class="joker-icon"> Joker gesetzt</div>
|
||||
<div class="legend-item"><div class="legend-color" style="background-color: var(--col-tendenz);"></div> Richtige Tendenz</div>
|
||||
<div class="legend-item"><div class="legend-color" style="background-color: var(--col-exact);"></div> Richtiges Ergebnis</div>
|
||||
<div class="legend-item"><div class="legend-color" style="background-color: var(--col-joker-exact);"></div> Richtiges Ergebnis mit Joker</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p>Keine Runde für die Anzeige ausgewählt oder gefunden.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<script>
|
||||
// Springe beim Laden zur eigenen Zeile, falls der eingeloggte Spieler in der Tabelle ist
|
||||
window.addEventListener('load', function () {
|
||||
var me = document.getElementById('me-row');
|
||||
if (me) {
|
||||
me.scrollIntoView({ block: 'center' });
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php require __DIR__ . '/partials/footer.php'; ?>
|
||||
58
tippspiel/src/Views/register.php
Normal file
58
tippspiel/src/Views/register.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
$pageTitle = 'Registrieren';
|
||||
require __DIR__ . '/partials/header.php';
|
||||
?>
|
||||
|
||||
<h1>Registrieren</h1>
|
||||
|
||||
<?php if (!empty($registrationClosed)): ?>
|
||||
<p>Die Registrierung neuer Spieler ist derzeit geschlossen. Bitte wende dich an einen Administrator.</p>
|
||||
<p><a href="/index.php?page=login">Zum Login</a></p>
|
||||
<?php require __DIR__ . '/partials/footer.php'; return; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($error)): ?>
|
||||
<p style="color: red;"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.form-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.form-group label {
|
||||
display: inline-block;
|
||||
width: 200px;
|
||||
text-align: right;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.form-group button {
|
||||
margin-left: calc(200px + 10px);
|
||||
}
|
||||
</style>
|
||||
<form action="/index.php?page=register" method="post">
|
||||
<div class="form-group">
|
||||
<label for="firstname">Vorname:</label>
|
||||
<input type="text" id="firstname" name="firstname" value="<?php echo htmlspecialchars($_POST['firstname'] ?? ''); ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastname">Nachname:</label>
|
||||
<input type="text" id="lastname" name="lastname" value="<?php echo htmlspecialchars($_POST['lastname'] ?? ''); ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">E-Mail:</label>
|
||||
<input type="email" id="email" name="email" value="<?php echo htmlspecialchars($_POST['email'] ?? ''); ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Passwort:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password_confirm">Passwort bestätigen:</label>
|
||||
<input type="password" id="password_confirm" name="password_confirm" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit">Registrieren</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php require __DIR__ . '/partials/footer.php'; ?>
|
||||
88
tippspiel/src/Views/round.php
Normal file
88
tippspiel/src/Views/round.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
use App\Models\Game;
|
||||
use App\Models\Tipp;
|
||||
|
||||
// Stellt sicher, dass die benötigten Variablen vorhanden sind
|
||||
if (!isset($selectedRound) || !isset($roundsToShow) || !isset($users) || !isset($tipps_map)) {
|
||||
echo "Fehler: Daten für die Rundenansicht nicht gefunden.";
|
||||
exit;
|
||||
}
|
||||
|
||||
$pageTitle = 'Tippübersicht - ' . htmlspecialchars($selectedRound['name']);
|
||||
require __DIR__ . '/partials/header.php';
|
||||
?>
|
||||
|
||||
<h1>Tippübersicht bis: <?php echo htmlspecialchars($selectedRound['name']); ?></h1>
|
||||
|
||||
<?php if (empty($users)): ?>
|
||||
<p>Keine teilnehmenden Spieler für diese Saison gefunden.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($roundsToShow as $round): ?>
|
||||
<h2><?php echo htmlspecialchars($round['name']); ?></h2>
|
||||
<?php if (!empty($round['games'])): ?>
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Spieler</th>
|
||||
<?php foreach ($round['games'] as $game): ?>
|
||||
<th class="game-header">
|
||||
<?php echo htmlspecialchars($game['team1']); ?><br>
|
||||
<?php echo htmlspecialchars($game['team2']); ?><br>
|
||||
<small>(<?php echo Game::getResultString($game['score1'], $game['score2'], $game['kickoff']); ?>)</small>
|
||||
</th>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($users as $user): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($user['name']); ?></td>
|
||||
<?php foreach ($round['games'] as $game): ?>
|
||||
<?php
|
||||
$tipp = $tipps_map[$user['id']][$game['id']] ?? null;
|
||||
$color = '';
|
||||
$text = '-';
|
||||
$is_joker = false;
|
||||
|
||||
if ($tipp && $game['score1'] > -1) {
|
||||
$color = Tipp::getCol($game['score1'], $game['score2'], $tipp['tipp1'], $tipp['tipp2'], $tipp['joker']);
|
||||
}
|
||||
if ($tipp) {
|
||||
// Zeige Tipps nur für gesperrte Spiele
|
||||
if (Game::isLocked($game['kickoff'])) {
|
||||
$text = $tipp['tipp1'] . ':' . $tipp['tipp2'];
|
||||
} else {
|
||||
$text = 'verdeckt';
|
||||
}
|
||||
$is_joker = (bool)$tipp['joker'];
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
$td_class = $color;
|
||||
// Spezielle Farbe für exakten Tipp mit Joker
|
||||
if ($td_class === 'col_exact' && $is_joker) {
|
||||
$td_class = 'col_joker_exact';
|
||||
}
|
||||
?>
|
||||
<td class="tipp-cell <?php echo htmlspecialchars($td_class); ?>" title="Tipp: <?php echo htmlspecialchars($text); ?>">
|
||||
<?php echo htmlspecialchars($text); ?>
|
||||
<?php if ($is_joker && Game::isLocked($game['kickoff'])): ?>
|
||||
<img src="/img/joker.png" alt="Joker" class="joker-icon" title="Joker">
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p>Für diese Runde wurden keine Spiele gefunden.</p>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<p><a href="/">Zurück zur Startseite</a></p>
|
||||
|
||||
<?php require __DIR__ . '/partials/footer.php'; ?>
|
||||
75
tippspiel/src/Views/settings.php
Normal file
75
tippspiel/src/Views/settings.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
$pageTitle = 'Einstellungen';
|
||||
require __DIR__ . '/partials/header.php';
|
||||
?>
|
||||
|
||||
<h1>Spielerdaten</h1>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<p style="color: green;"><?php echo htmlspecialchars($message); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if ($error): ?>
|
||||
<p style="color: red;"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="/index.php?page=settings" class="settings-form">
|
||||
<div class="form-group">
|
||||
<label for="name">Login:</label>
|
||||
<input type="text" id="name" value="<?php echo htmlspecialchars($user['name']); ?>" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="firstname">Vorname:</label>
|
||||
<input type="text" id="firstname" value="<?php echo htmlspecialchars($user['firstname']); ?>" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastname">Nachname:</label>
|
||||
<input type="text" id="lastname" value="<?php echo htmlspecialchars($user['lastname']); ?>" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="iban">IBAN:</label>
|
||||
<input type="text" id="iban" name="iban" maxlength="34" value="<?php echo htmlspecialchars((string)$user['iban']); ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="bankname">Bankname:</label>
|
||||
<input type="text" id="bankname" name="bankname" value="<?php echo htmlspecialchars((string)$user['bankname']); ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="blz">BLZ:</label>
|
||||
<input type="text" id="blz" name="blz" value="<?php echo htmlspecialchars((string)$user['blz']); ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="kontonr">Kontonummer:</label>
|
||||
<input type="text" id="kontonr" name="kontonr" value="<?php echo htmlspecialchars((string)$user['kontonr']); ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="mobile">Handynummer:</label>
|
||||
<input type="text" id="mobile" name="mobile" value="<?php echo htmlspecialchars((string)$user['mobile']); ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" id="email" name="email" class="wide" required value="<?php echo htmlspecialchars((string)$user['email']); ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="gets_reminders">Erinnerungen:</label>
|
||||
<input type="checkbox" id="gets_reminders" name="gets_reminders" value="1" <?php if (!empty($user['gets_reminders'])) echo 'checked'; ?>>
|
||||
<label for="gets_reminders" class="inline">Ich möchte E-Mail-Erinnerungen erhalten</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit">Ok</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.settings-form .form-group { margin-bottom: 0.8rem; }
|
||||
.settings-form .form-group > label:first-child { display: inline-block; width: 160px; }
|
||||
.settings-form label.inline { width: auto; }
|
||||
.settings-form input[readonly] { background: #f4f4f4; color: #666; border: 1px solid #ccc; }
|
||||
.settings-form input.wide { width: 25em; max-width: 100%; }
|
||||
.settings-form button { margin-left: 164px; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/partials/footer.php'; ?>
|
||||
40
tippspiel/src/Views/tipps/game.php
Normal file
40
tippspiel/src/Views/tipps/game.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
$pageTitle = 'Spieltipp';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
?>
|
||||
|
||||
<h1>Spieltipp:</h1>
|
||||
|
||||
<p><strong><?php echo htmlspecialchars($game['team1'] . ' : ' . $game['team2']); ?></strong></p>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<p style="color: red;"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($locked): ?>
|
||||
<p style="color: red;">Die Runde hat bereits begonnen, der Tipp kann nicht mehr verändert werden.</p>
|
||||
<p><a href="/index.php?page=tipps#round-<?php echo (int)$round['id']; ?>">Zu den Tipps</a></p>
|
||||
<?php else: ?>
|
||||
<form method="post" action="/index.php?page=tipp_game&id=<?php echo (int)$game['id']; ?>" class="tipp-form">
|
||||
<p class="score">
|
||||
<input type="number" min="0" max="99" name="score1" required
|
||||
value="<?php echo htmlspecialchars((string)$formTipp['score1']); ?>">
|
||||
:
|
||||
<input type="number" min="0" max="99" name="score2" required
|
||||
value="<?php echo htmlspecialchars((string)$formTipp['score2']); ?>">
|
||||
<label style="margin-left: 1.5em;">
|
||||
Joker
|
||||
<input type="checkbox" name="joker" value="yes" <?php if ($formTipp['joker']) echo 'checked'; ?>>
|
||||
</label>
|
||||
</p>
|
||||
<p class="hint">Wird der Joker hier gesetzt, wird er bei den anderen Spielen dieser Runde entfernt.</p>
|
||||
<p><button type="submit">Ok</button></p>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.tipp-form .score input[type="number"] { width: 3.5em; font-size: 1em; }
|
||||
.tipp-form .hint { color: #666; font-size: 0.8em; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
84
tippspiel/src/Views/tipps/index.php
Normal file
84
tippspiel/src/Views/tipps/index.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
use App\Models\Tipp;
|
||||
|
||||
$pageTitle = 'Tipps';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
?>
|
||||
|
||||
<p>Aktive Saison: <?php echo htmlspecialchars($activeSeason['name']); ?></p>
|
||||
<h1>Tipps</h1>
|
||||
|
||||
<?php foreach ($rounds as $round): ?>
|
||||
<section class="tipp-round" id="round-<?php echo (int)$round['id']; ?>">
|
||||
<h2><?php echo htmlspecialchars($round['name']); ?></h2>
|
||||
<?php if ($round['lock_time']): ?>
|
||||
<div>Runde sperrt sich: <?php echo $round['lock_time']->format('d.m.Y H:i'); ?></div>
|
||||
<?php endif; ?>
|
||||
<div>Bereits verwendete Joker: <?php echo htmlspecialchars($round['joker_usage']); ?></div>
|
||||
<div>Maximale Anzahl gleicher Joker: <?php echo $maxIdenticalJokertipps; ?></div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Spiel</th>
|
||||
<th>Anstoss</th>
|
||||
<th>Ergebnis</th>
|
||||
<th>Tipp</th>
|
||||
<th>Joker</th>
|
||||
<th>Punkte</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($round['games'] as $game):
|
||||
$tipp = $round['tipps'][$game['id']] ?? null;
|
||||
$tipp1 = $tipp ? (int)$tipp['score1'] : -1;
|
||||
$tipp2 = $tipp ? (int)$tipp['score2'] : -1;
|
||||
$joker = $tipp && $tipp['joker'];
|
||||
$tippText = $tipp1 > -1 ? $tipp1 . ' : ' . $tipp2 : null;
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($game['team1'] . ' : ' . $game['team2']); ?></td>
|
||||
<td><?php echo date('d.m.Y H:i', strtotime($game['kickoff'])); ?></td>
|
||||
<td><?php echo (int)$game['score1'] > -1 ? (int)$game['score1'] . ' : ' . (int)$game['score2'] : ''; ?></td>
|
||||
<td>
|
||||
<?php if ($round['locked']): ?>
|
||||
<?php echo $tippText ?? 'Ungetippt'; ?>
|
||||
<?php else: ?>
|
||||
<a href="/index.php?page=tipp_game&id=<?php echo (int)$game['id']; ?>"><?php echo $tippText ?? 'Tippen'; ?></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<?php if ($joker): ?>
|
||||
<img src="/img/joker.png" alt="Joker" class="joker-icon" title="Joker">
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?php echo Tipp::getScoreLocal((int)$game['score1'], (int)$game['score2'], $tipp1, $tipp2, $joker); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php if (!$round['locked'] && !empty($round['games'])): ?>
|
||||
<p><a href="/index.php?page=tipp_round&id=<?php echo (int)$round['id']; ?>">Runde Tippen</a></p>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($firstTippableRoundId !== null): ?>
|
||||
<script>
|
||||
// Wie im Legacy: ohne Anker zur ersten tippbaren Runde springen
|
||||
if (!location.hash) {
|
||||
document.getElementById('round-<?php echo $firstTippableRoundId; ?>').scrollIntoView();
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.tipp-round { margin-bottom: 2.5em; }
|
||||
.tipp-round h2 { margin-bottom: 0.3em; scroll-margin-top: 1em; }
|
||||
.tipp-round .joker-icon { width: 1.5em; height: 1.5em; }
|
||||
.tipp-round td:not(:first-child) { white-space: nowrap; }
|
||||
.tipp-round table { max-width: 1050px; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
9
tippspiel/src/Views/tipps/no_payment.php
Normal file
9
tippspiel/src/Views/tipps/no_payment.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
$pageTitle = 'Tipps';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
?>
|
||||
|
||||
<p style="color: red;">Dein Zahlungseingang für die Saison wurde noch nicht registriert.</p>
|
||||
<p><a href="/">Ok</a></p>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
75
tippspiel/src/Views/tipps/round.php
Normal file
75
tippspiel/src/Views/tipps/round.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
$pageTitle = 'Runde tippen';
|
||||
require __DIR__ . '/../partials/header.php';
|
||||
?>
|
||||
|
||||
<h2><?php echo htmlspecialchars($round['name']); ?></h2>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<p style="color: red;"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($locked): ?>
|
||||
<p style="color: red;">Die Runde ist bereits gesperrt, Tipps können nicht mehr geändert werden.</p>
|
||||
<p><a href="/index.php?page=tipps#round-<?php echo (int)$round['id']; ?>">Zu den Tipps</a></p>
|
||||
<?php else: ?>
|
||||
<form method="post" action="/index.php?page=tipp_round&id=<?php echo (int)$round['id']; ?>" class="tipp-form">
|
||||
<table>
|
||||
<?php foreach ($games as $game):
|
||||
$gameId = (int)$game['id'];
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($game['team1']); ?></td>
|
||||
<td>:</td>
|
||||
<td><?php echo htmlspecialchars($game['team2']); ?></td>
|
||||
<td class="score">
|
||||
<input type="number" min="0" max="99" name="scores[<?php echo $gameId; ?>][score1]" required
|
||||
value="<?php echo htmlspecialchars((string)($formScores[$gameId]['score1'] ?? '')); ?>">
|
||||
:
|
||||
<input type="number" min="0" max="99" name="scores[<?php echo $gameId; ?>][score2]" required
|
||||
value="<?php echo htmlspecialchars((string)($formScores[$gameId]['score2'] ?? '')); ?>">
|
||||
</td>
|
||||
<td>
|
||||
<label>
|
||||
Joker
|
||||
<input type="checkbox" class="joker-checkbox" name="joker" value="<?php echo $gameId; ?>"
|
||||
<?php if ($formJoker === $gameId) echo 'checked'; ?>>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<p><button type="submit" id="btn_submit">Ok</button></p>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
// Wie im Legacy: genau ein Joker pro Runde. Ein gesetzter Joker kann nur durch
|
||||
// einen anderen ersetzt werden; ohne Joker bleibt "Ok" deaktiviert.
|
||||
(function () {
|
||||
const boxes = document.querySelectorAll('.joker-checkbox');
|
||||
const submit = document.getElementById('btn_submit');
|
||||
const update = () => { submit.disabled = !Array.from(boxes).some(b => b.checked); };
|
||||
boxes.forEach(function (box) {
|
||||
box.addEventListener('change', function () {
|
||||
if (box.checked) {
|
||||
boxes.forEach(other => { if (other !== box) other.checked = false; });
|
||||
} else {
|
||||
box.checked = true;
|
||||
}
|
||||
update();
|
||||
});
|
||||
});
|
||||
update();
|
||||
})();
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
.tipp-form table { width: auto; }
|
||||
.tipp-form td { border: none; padding: 6px 8px; }
|
||||
.tipp-form td.score { white-space: nowrap; }
|
||||
.tipp-form td.score input { width: 3.5em; font-size: 1em; }
|
||||
</style>
|
||||
|
||||
<?php require __DIR__ . '/../partials/footer.php'; ?>
|
||||
26
tippspiel/src/autoload.php
Normal file
26
tippspiel/src/autoload.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
spl_autoload_register(function ($class) {
|
||||
// Projekt-Namespace Prefix
|
||||
$prefix = 'App\\';
|
||||
|
||||
// Basisverzeichnis für den Namespace Prefix
|
||||
$base_dir = __DIR__ . '/';
|
||||
|
||||
// Prüfen ob die Klasse das Prefix verwendet
|
||||
$len = strlen($prefix);
|
||||
if (strncmp($prefix, $class, $len) !== 0) {
|
||||
return; // Gehört nicht zu diesem Autoloader
|
||||
}
|
||||
|
||||
// Den relativen Klassennamen extrahieren
|
||||
$relative_class = substr($class, $len);
|
||||
|
||||
// Namespace-Trenner (\) durch Verzeichnis-Trenner (/) ersetzen und .php anhängen
|
||||
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
||||
|
||||
// Wenn die Datei existiert, einbinden
|
||||
if (file_exists($file)) {
|
||||
require $file;
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue