128 lines
5.2 KiB
PHP
128 lines
5.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Handle form submission
|
|
$message = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$title = $_POST['title'] ?? '';
|
|
$description = $_POST['description'] ?? '';
|
|
$start_date = $_POST['start_date'] ?? '';
|
|
$end_date = $_POST['end_date'] ?? '';
|
|
|
|
if (!empty($title) && !empty($start_date) && !empty($end_date)) {
|
|
try {
|
|
$pdo = db();
|
|
$sql = "INSERT INTO competitions (title, description, start_date, end_date) VALUES (?, ?, ?, ?)";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$title, $description, $start_date, $end_date]);
|
|
$message = '<div class="alert alert-success">Competition created successfully!</div>';
|
|
} catch (PDOException $e) {
|
|
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
|
}
|
|
} else {
|
|
$message = '<div class="alert alert-danger">Please fill in all required fields.</div>';
|
|
}
|
|
}
|
|
|
|
// Fetch all competitions
|
|
$competitions = [];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT id, title, description, start_date, end_date FROM competitions ORDER BY created_at DESC");
|
|
$competitions = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
// Handle error if needed
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Admin: Manage Competitions</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<?php include 'includes/header.php'; ?>
|
|
|
|
<main class="container mt-5">
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<h2>Manage Competitions</h2>
|
|
<hr>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<!-- Create Competition Form -->
|
|
<div class="col-md-4">
|
|
<h3>Create New Competition</h3>
|
|
<?php echo $message; ?>
|
|
<form action="admin_competitions.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="title" class="form-label">Title</label>
|
|
<input type="text" class="form-control" id="title" name="title" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="description" class="form-label">Description</label>
|
|
<textarea class="form-control" id="description" name="description" rows="3"></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="start_date" class="form-label">Start Date</label>
|
|
<input type="datetime-local" class="form-control" id="start_date" name="start_date" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="end_date" class="form-label">End Date</label>
|
|
<input type="datetime-local" class="form-control" id="end_date" name="end_date" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Create Competition</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Competitions List -->
|
|
<div class="col-md-8">
|
|
<h3>Existing Competitions</h3>
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Title</th>
|
|
<th>Start Date</th>
|
|
<th>End Date</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($competitions)): ?>
|
|
<tr>
|
|
<td colspan="5" class="text-center">No competitions found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($competitions as $comp): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($comp['id']); ?></td>
|
|
<td><?php echo htmlspecialchars($comp['title']); ?></td>
|
|
<td><?php echo htmlspecialchars($comp['start_date']); ?></td>
|
|
<td><?php echo htmlspecialchars($comp['end_date']); ?></td>
|
|
<td>
|
|
<a href="#" class="btn btn-sm btn-warning">Edit</a>
|
|
<a href="#" class="btn btn-sm btn-danger">Delete</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|