119 lines
5.3 KiB
PHP
119 lines
5.3 KiB
PHP
<?php
|
|
require_once 'auth_check.php'; // Protect this page
|
|
require_once 'db/config.php'; // Database connection
|
|
|
|
// Fetch all tournaments from the database
|
|
$tournaments = [];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query('SELECT id, name, description, created_at FROM tournaments ORDER BY created_at DESC');
|
|
$tournaments = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$error_message = "Database error: " . $e->getMessage();
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="pt-BR">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Gerenciar Torneios - PicklePRO</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Header -->
|
|
<header class="navbar navbar-expand-lg navbar-light bg-white">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">
|
|
<img src="https://www.svgrepo.com/show/494426/pickleball-paddle.svg" alt="PicklePRO Logo" width="30" height="30" class="d-inline-block align-text-top me-2">
|
|
Pickle<span class="text-primary">PRO</span>
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav mx-auto">
|
|
<li class="nav-item"><a class="nav-link" href="index.php">Home</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="#">Torneios</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="#">Reservas</a></li>
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="admin.php">Administrativo</a>
|
|
</li>
|
|
<?php endif; ?>
|
|
</ul>
|
|
<div class="d-flex align-items-center">
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<span class="navbar-text me-3">
|
|
Olá, <?php echo htmlspecialchars($_SESSION['username']); ?>
|
|
</span>
|
|
<a href="logout.php" class="btn btn-outline-primary">Sair</a>
|
|
<?php else: ?>
|
|
<a href="/login.php" class="btn btn-link text-decoration-none me-2">Entrar</a>
|
|
<a href="#" class="btn btn-primary">Cadastrar</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- Main Content -->
|
|
<main class="container my-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="display-6 fw-bold">Gerenciar Torneios</h1>
|
|
<a href="add_tournament.php" class="btn btn-primary"><i class="bi bi-plus-circle me-2"></i>Cadastrar Novo Torneio</a>
|
|
</div>
|
|
|
|
<?php if (isset($error_message)): ?>
|
|
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<?php if (empty($tournaments) && !isset($error_message)): ?>
|
|
<div class="text-center p-4">
|
|
<p>Nenhum torneio cadastrado ainda.</p>
|
|
</div>
|
|
<?php else:
|
|
if (!empty($tournaments)) : ?>
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Nome</th>
|
|
<th>Descrição</th>
|
|
<th>Data de Criação</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($tournaments as $tournament): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($tournament['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($tournament['description']); ?></td>
|
|
<td><?php echo date("d/m/Y H:i", strtotime($tournament['created_at'])); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="mt-4">
|
|
<a href="admin.php" class="btn btn-secondary">Voltar ao Painel</a>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Footer -->
|
|
<footer class="footer mt-auto py-4 bg-light">
|
|
<div class="container text-center">
|
|
<p class="mb-1 text-muted small">© <?php echo date("Y"); ?> PicklePRO. Todos os direitos reservados.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<!-- Scripts -->
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|