35861-vm/dashboard.php
Flatlogic Bot f05220da7c tre
2025-11-19 23:45:40 +00:00

107 lines
4.6 KiB
PHP

<?php
require_once 'includes/session.php';
require_login();
// Redirect admin users to the admin dashboard
if (is_admin()) {
header('Location: admin/index.php');
exit();
}
require_once 'includes/header.php';
?>
<div class="main-content">
<main class="container my-5">
<h1 class="mb-4">User Dashboard</h1>
<p>Welcome back, <?php echo htmlspecialchars($_SESSION['user']['email']); ?>. Here you can view your applications and manage your profile.</p>
<hr class="my-5">
<h2 class="mb-4">My Applications</h2>
<?php
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->prepare(
'SELECT a.id, a.status, a.created_at, e.title AS event_name, e.event_date
FROM applications a
JOIN events e ON a.event_id = e.id
WHERE a.user_id = ?
ORDER BY a.created_at DESC'
);
$stmt->execute([$_SESSION['user']['id']]);
$applications = $stmt->fetchAll();
if (count($applications) > 0):
?>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-dark">
<tr>
<th>Event</th>
<th>Applied On</th>
<th>Status</th>
<th>Action / Proof</th>
</tr>
</thead>
<tbody>
<?php foreach ($applications as $app): ?>
<tr>
<td><?php echo htmlspecialchars($app['event_name']); ?></td>
<td><?php echo date('M j, Y, g:i a', strtotime($app['created_at'])); ?></td>
<td>
<span class="badge bg-<?php
switch ($app['status']) {
case 'approved': echo 'success'; break;
case 'rejected': echo 'danger'; break;
case 'pending_approval': echo 'warning'; break;
default: echo 'secondary';
}
?>">
<?php echo htmlspecialchars(str_replace('_', ' ', ucfirst($app['status']))); ?>
</span>
</td>
<td>
<?php
// Fetch proofs for the application
$proofs_stmt = $pdo->prepare('SELECT file_path FROM application_proofs WHERE application_id = ? ORDER BY uploaded_at DESC');
$proofs_stmt->execute([$app['id']]);
$proofs = $proofs_stmt->fetchAll();
if (count($proofs) > 0) {
echo '<ul class="list-unstyled mb-0">';
foreach ($proofs as $proof) {
echo '<li><a href="' . htmlspecialchars($proof['file_path']) . '" target="_blank">View Proof</a></li>';
}
echo '</ul>';
}
if ($app['status'] == 'awaiting_proof' || $app['status'] == 'pending_approval') { ?>
<form action="upload_proof.php" method="post" enctype="multipart/form-data" class="mt-2">
<input type="hidden" name="application_id" value="<?php echo $app['id']; ?>">
<div class="input-group">
<input type="file" name="proof_screenshot" class="form-control form-control-sm" required>
<button type="submit" class="btn btn-primary btn-sm">Upload</button>
</div>
</form>
<?php } elseif (count($proofs) == 0) {
echo '-';
}
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="alert alert-info">
You have not applied to any events yet. <a href="/index.php#events">Find events to apply for.</a>
</div>
<?php endif; ?>
</main>
</div>
<?php require_once 'includes/footer.php'; ?>