36459-vm/admin/competitions.php
2025-11-29 17:28:26 +00:00

90 lines
3.4 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: login.php');
exit;
}
require_once '../db/config.php';
$pdo = db();
$stmt = $pdo->query('SELECT * FROM competitions ORDER BY created_at DESC');
$competitions = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Competitions</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="index.php">Admin Panel</a>
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="challenges.php">Challenges</a>
</li>
<li class="nav-item">
<a class="nav-link" href="competitions.php">Competitions</a>
</li>
<li class="nav-item">
<a class="nav-link" href="users.php">Users</a>
</li>
</ul>
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</nav>
<div class="container py-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="display-4 fw-bold">Manage Competitions</h1>
<a href="add_competition.php" class="btn btn-primary">Add Competition</a>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Start Date</th>
<th>End Date</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (count($competitions) > 0) : ?>
<?php foreach ($competitions as $competition) : ?>
<tr>
<td><?php echo $competition['id']; ?></td>
<td><?php echo htmlspecialchars($competition['title']); ?></td>
<td><?php echo $competition['start_date']; ?></td>
<td><?php echo $competition['end_date']; ?></td>
<td><?php echo $competition['created_at']; ?></td>
<td>
<a href="edit_competition.php?id=<?php echo $competition['id']; ?>" class="btn btn-sm btn-primary">Edit</a>
<a href="delete_competition.php?id=<?php echo $competition['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this competition?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="6" class="text-center">No competitions found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</body>
</html>