34918-vm/user_dashboard.php
2025-10-13 09:42:24 +00:00

83 lines
3.1 KiB
PHP

<?php
session_start();
require_once 'db/config.php'; // Ensure DB config is loaded
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'user') {
if(isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin'){
header("location: admin_dashboard.php");
exit;
}
header("location: login.php");
exit;
}
// Fetch competitions from the database
try {
$pdo = db();
$stmt = $pdo->query('SELECT title, description, start_date FROM competitions ORDER BY start_date ASC');
$competitions = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// Handle DB error
$competitions = [];
$db_error = "Failed to load competitions.";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Dashboard - READY BUDDY</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/style.css?v=<?php echo time(); ?>">
</head>
<body>
<header class="navbar">
<div class="container">
<a class="navbar-brand" href="index.php">READY BUDDY</a>
<nav>
<a href="logout.php">Logout</a>
</nav>
</div>
</header>
<main class="container" style="margin-top: 2rem; margin-bottom: 2rem;">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>User Dashboard</h1>
<h2>Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!</h2>
</div>
<p>This is your user dashboard. You can view available competitions below.</p>
<section id="competitions" class="mt-5">
<h3>Available Competitions</h3>
<div class="row">
<?php if (isset($db_error)): ?>
<p class="text-danger"><?php echo $db_error; ?></p>
<?php elseif (empty($competitions)): ?>
<p>No competitions available at the moment.</p>
<?php else: ?>
<?php foreach ($competitions as $competition): ?>
<div class="col-md-4 mb-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($competition['title']); ?></h5>
<p class="card-text"><?php echo htmlspecialchars($competition['description']); ?></p>
<p class="card-text"><small class="text-muted">Starts on: <?php echo date("F j, Y", strtotime($competition['start_date'])); ?></small></p>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</section>
</main>
<footer class="footer">
<div class="container">
<p>&copy; <?php echo date("Y"); ?> READY BUDDY. All rights reserved.</p>
</div>
</footer>
</body>
</html>