34915-vm/my_certificates.php
2025-10-14 07:40:18 +00:00

46 lines
1.3 KiB
PHP

<?php
session_start();
require_once 'includes/header.php';
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$user_id = $_SESSION['user_id'];
$pdo = db();
$stmt = $pdo->prepare("
SELECT
c.certificate_code,
comp.title as competition_title
FROM certificates c
JOIN submissions s ON c.submission_id = s.id
JOIN competitions comp ON s.competition_id = comp.id
WHERE s.user_id = ?
");
$stmt->execute([$user_id]);
$certificates = $stmt->fetchAll();
?>
<div class="container mt-5">
<h1 class="mb-4">My Certificates</h1>
<?php if (empty($certificates)): ?>
<div class="alert alert-info">You have not earned any certificates yet.</div>
<?php else: ?>
<ul class="list-group">
<?php foreach ($certificates as $certificate): ?>
<li class="list-group-item d-flex justify-content-between align-items-center">
<?php echo htmlspecialchars($certificate['competition_title']); ?>
<a href="generate_certificate.php?code=<?php echo htmlspecialchars($certificate['certificate_code']); ?>" class="btn btn-primary" target="_blank">View Certificate</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php require_once 'includes/footer.php'; ?>