75 lines
2.3 KiB
PHP
Executable File
75 lines
2.3 KiB
PHP
Executable File
<?php
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
session_start();
|
|
require_once __DIR__ . '/../init.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: auth/login.php');
|
|
exit;
|
|
}
|
|
|
|
$pdo = getPDO();
|
|
|
|
// Info utente
|
|
$stmt = $pdo->prepare("SELECT id, email, created_at FROM users WHERE id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// Partite dell'utente
|
|
$stmt = $pdo->prepare("
|
|
SELECT g.id, g.name, g.status, g.created_at
|
|
FROM games g
|
|
JOIN game_players gp ON g.id = gp.game_id
|
|
WHERE gp.user_id = ?
|
|
ORDER BY g.created_at DESC
|
|
");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$games = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
|
|
<!doctype html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Dashboard - Diplomacy</title>
|
|
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="assets/css/custom.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<?php include 'header.php'; ?>
|
|
|
|
<div class="container mt-5">
|
|
<h1 class="mb-4">Benvenuto, <?= htmlspecialchars($user['email']) ?>!</h1>
|
|
|
|
<div class="mb-4">
|
|
<h4>Le tue partite</h4>
|
|
<?php if (count($games) === 0): ?>
|
|
<p>Non stai giocando a nessuna partita. <a href="create_game.php">Crea una nuova partita</a></p>
|
|
<?php else: ?>
|
|
<div class="list-group">
|
|
<?php foreach ($games as $game): ?>
|
|
<a href="game.php?id=<?= $game['id'] ?>" class="list-group-item list-group-item-action">
|
|
<?= htmlspecialchars($game['name']) ?>
|
|
<span class="badge bg-secondary float-end"><?= htmlspecialchars($game['status']) ?></span>
|
|
<br>
|
|
<small>Creata il <?= htmlspecialchars($game['created_at']) ?></small>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div>
|
|
<a href="create_game.php" class="btn btn-primary">Crea nuova partita</a>
|
|
<a href="auth/logout.php" class="btn btn-secondary">Logout</a>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'footer.php'; ?>
|
|
<script src="assets/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|