diff --git a/certificate.php b/certificate.php new file mode 100644 index 0000000..904e07e --- /dev/null +++ b/certificate.php @@ -0,0 +1,125 @@ +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'])); + +?> + + +
+ + +No lessons in this module yet.
You scored % on your last attempt.
+ = 70): ?> + + View Certificate + + +You need a score of 70% or higher to get a certificate.
+ + Retake Quiz + + + +You have completed all the lessons. It's time to take the quiz!
+ Take Quiz + +