34921-vm/certificate.php
Flatlogic Bot fd7bfb0869 2.2
2025-10-14 15:07:23 +00:00

125 lines
4.1 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'db/config.php';
$db = db();
$skill_id = $_GET['skill_id'] ?? 0;
$user_id = $_SESSION['user_id'];
// Fetch user name
$user_stmt = $db->prepare("SELECT name FROM users WHERE id = ?");
$user_stmt->execute([$user_id]);
$user_name = $user_stmt->fetchColumn();
// Fetch skill title
$skill_stmt = $db->prepare("SELECT title FROM skills WHERE id = ?");
$skill_stmt->execute([$skill_id]);
$skill_title = $skill_stmt->fetchColumn();
// Fetch latest quiz attempt with a score of 70% or higher
$attempt_stmt = $db->prepare("SELECT score, completed_at FROM quiz_attempts WHERE user_id = ? AND skill_id = ? AND score >= 70 ORDER BY completed_at DESC LIMIT 1");
$attempt_stmt->execute([$user_id, $skill_id]);
$attempt = $attempt_stmt->fetch(PDO::FETCH_ASSOC);
if (!$user_name || !$skill_title || !$attempt) {
// Redirect or show an error if the user is not eligible for a certificate
header('Location: dashboard.php?error=not_eligible');
exit;
}
$completion_date = date("F j, Y", strtotime($attempt['completed_at']));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Certificate of Completion</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<style>
body {
background-color: #f0f2f5;
}
.certificate-container {
max-width: 800px;
margin: 50px auto;
padding: 40px;
background: white;
border: 10px solid #0d6efd;
border-radius: 15px;
box-shadow: 0 0 20px rgba(0,0,0,0.1);
text-align: center;
font-family: serif;
position: relative;
}
.certificate-container::before, .certificate-container::after {
content: '';
position: absolute;
left: -15px;
top: -15px;
right: -15px;
bottom: -15px;
border: 2px solid #0d6efd;
border-radius: 15px;
}
.certificate-title {
font-size: 48px;
font-weight: bold;
color: #0d6efd;
margin-bottom: 20px;
}
.certificate-subtitle {
font-size: 24px;
color: #6c757d;
margin-bottom: 30px;
}
.user-name {
font-size: 40px;
font-weight: bold;
color: #343a40;
margin-bottom: 20px;
border-bottom: 2px solid #dee2e6;
display: inline-block;
padding-bottom: 10px;
}
.completion-text {
font-size: 20px;
margin-bottom: 30px;
}
.skill-title {
font-size: 28px;
font-style: italic;
color: #495057;
}
.completion-date {
font-size: 18px;
color: #6c757d;
margin-top: 40px;
}
.actions {
margin-top: 30px;
}
</style>
</head>
<body>
<div class="certificate-container">
<div class="certificate-title">Certificate of Completion</div>
<div class="certificate-subtitle">This is to certify that</div>
<div class="user-name"><?php echo htmlspecialchars($user_name); ?></div>
<div class="completion-text">has successfully completed the skill</div>
<div class="skill-title">"<?php echo htmlspecialchars($skill_title); ?>"</div>
<div class="completion-date">on <?php echo $completion_date; ?></div>
<div class="actions">
<a href="dashboard.php" class="btn btn-secondary"><i class="bi bi-arrow-left"></i> Back to Dashboard</a>
<button onclick="window.print()" class="btn btn-primary"><i class="bi bi-printer"></i> Print Certificate</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>