70 lines
2.3 KiB
PHP
70 lines
2.3 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Gatekeeper: redirect if not logged in
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
$stmt = $pdo->query("
|
|
SELECT
|
|
s.score,
|
|
s.time_taken,
|
|
s.moves,
|
|
s.completed_at,
|
|
u.username,
|
|
p.name as puzzle_name
|
|
FROM scores s
|
|
JOIN users u ON s.user_id = u.id
|
|
JOIN puzzles p ON s.puzzle_id = p.id
|
|
ORDER BY s.score DESC
|
|
LIMIT 100
|
|
");
|
|
$scores = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$page_title = 'Classifica';
|
|
require_once 'includes/header.php';
|
|
?>
|
|
|
|
<main class="container mt-5">
|
|
<h1 class="mb-4 text-center">Classifica Generale</h1>
|
|
<div class="table-responsive card p-3">
|
|
<table class="table table-striped table-hover table-dark">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Utente</th>
|
|
<th>Puzzle</th>
|
|
<th>Punteggio</th>
|
|
<th>Tempo</th>
|
|
<th>Mosse</th>
|
|
<th>Data</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($scores)): ?>
|
|
<tr>
|
|
<td colspan="7" class="text-center">Nessun punteggio registrato.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($scores as $index => $score): ?>
|
|
<tr>
|
|
<td><?php echo $index + 1; ?></td>
|
|
<td><?php echo htmlspecialchars($score['username']); ?></td>
|
|
<td><?php echo htmlspecialchars($score['puzzle_name']); ?></td>
|
|
<td><?php echo htmlspecialchars($score['score']); ?></td>
|
|
<td><?php echo htmlspecialchars($score['time_taken']); ?>s</td>
|
|
<td><?php echo htmlspecialchars($score['moves']); ?></td>
|
|
<td><?php echo htmlspecialchars(date("d/m/Y H:i", strtotime($score['completed_at']))); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</main>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|