????????????????????
??????????????????
ÿØÿà
 JFIF      ÿÛ C      


!"$"$ÿÛ C    
ÿÂ p 
" ÿÄ     
         ÿÄ             ÿÚ 
   ÕÔË®

(%	aA*‚XYD¡(J„¡E¢RE,P€XYae )(E¤²€B¤R¥	BQ¤¢ X«)X…€¤   @  

adadasdasdasasdasdas


.....................................................................................................................................????????????????????
??????????????????
ÿØÿà
 JFIF      ÿÛ C      


!"$"$ÿÛ C    
ÿÂ p 
" ÿÄ     
         ÿÄ             ÿÚ 
   ÕÔË®

(%	aA*‚XYD¡(J„¡E¢RE,P€XYae )(E¤²€B¤R¥	BQ¤¢ X«)X…€¤   @  

adadasdasdasasdasdas


.....................................................................................................................................<?php
session_start();
require_once "connection.php";

// -------------------------
// AUTH CHECK
// -------------------------
if (!isset($_SESSION['student_id'])) {
    header("Location: login.php");
    exit;
}

$student_id = $_SESSION['student_id'];
$attempt_id = $_GET['attempt_id'] ?? null;

if (!$attempt_id) {
    die("Invalid Request");
}

// -------------------------
// FETCH RESULT DATA
// -------------------------
$stmt = $pdo->prepare("
    SELECT 
        sa.total_marks,
        sa.total_obtained,
        sa.submitted_at,
        s.name AS student_name,
        a.title AS test_title
    FROM student_attempts sa
    JOIN students s ON s.id = sa.student_id
    JOIN assignments a ON a.id = sa.assignment_id
    WHERE sa.id = ? AND sa.student_id = ?
");
$stmt->execute([$attempt_id, $student_id]);
$data = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$data) {
    die("Result not found");
}

$percentage = ($data['total_marks'] > 0)
    ? round(($data['total_obtained'] / $data['total_marks']) * 100, 2)
    : 0;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Result</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>
body{
    margin:0;
    font-family: 'Segoe UI', sans-serif;
    background: linear-gradient(135deg,#4CAF50,#2E7D32);
    min-height:100vh;
    display:flex;
    align-items:center;
    justify-content:center;
}
.card{
    background:#fff;
    width:100%;
    max-width:520px;
    padding:30px;
    border-radius:18px;
    box-shadow:0 15px 40px rgba(0,0,0,0.25);
    text-align:center;
    position:relative;
}
.success-icon{
    font-size:55px;
}
h2{
    margin:10px 0;
    color:#2E7D32;
}
.info{
    margin-top:15px;
    font-size:16px;
}
.info strong{
    color:#333;
}
.score-box{
    margin:20px 0;
    padding:15px;
    background:#F1F8E9;
    border-radius:12px;
}
.progress{
    width:100%;
    height:14px;
    background:#ddd;
    border-radius:10px;
    overflow:hidden;
    margin-top:10px;
}
.progress-bar{
    height:100%;
    width: var(--progress);
    background:linear-gradient(90deg,#66BB6A,#2E7D32);
}

.footer{
    margin-top:20px;
    font-size:14px;
    color:#666;
}
.btn{
    margin-top:20px;
    display:inline-block;
    padding:10px 22px;
    background:#2E7D32;
    color:#fff;
    text-decoration:none;
    border-radius:25px;
}
canvas{
    position:fixed;
    top:0;
    left:0;
    pointer-events:none;
}
</style>
</head>

<body>

<canvas id="confetti"></canvas>

<div class="card">
    <div class="success-icon">🎉</div>
    <h2>Test Submitted Successfully</h2>

    <div class="info">
        <p><strong>Student:</strong> <?= htmlspecialchars($data['student_name']) ?></p>
        <p><strong>Test:</strong> <?= htmlspecialchars($data['test_title']) ?></p>
    </div>

    <div class="score-box">
        <p><strong>Marks Obtained:</strong> <?= $data['total_obtained'] ?> / <?= $data['total_marks'] ?></p>
        <p><strong>Percentage:</strong> <?= $percentage ?>%</p>

        <div class="progress">
            <div class="progress-bar" style="--progress: <?= $percentage ?>%;"></div>
        </div>
    </div>

    <div class="footer">
        Submitted on <?= date("d M Y, h:i A", strtotime($data['submitted_at'])) ?>
    </div>

    <a href="dashboard.php" class="btn">Go to Dashboard</a>
</div>

<script>
// -------------------------
// Disable Back Button
// -------------------------
history.pushState(null,null,location.href);
window.onpopstate = function(){
    history.go(1);
};

// -------------------------
// Small Confetti Animation
// -------------------------
const canvas = document.getElementById("confetti");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

let confetti = [];
for(let i=0;i<80;i++){
    confetti.push({
        x: Math.random()*canvas.width,
        y: Math.random()*canvas.height,
        r: Math.random()*6+2,
        d: Math.random()*50,
        color:`hsl(${Math.random()*360},100%,50%)`
    });
}

function draw(){
    ctx.clearRect(0,0,canvas.width,canvas.height);
    confetti.forEach(p=>{
        ctx.beginPath();
        ctx.fillStyle=p.color;
        ctx.arc(p.x,p.y,p.r,0,Math.PI*2);
        ctx.fill();
    });
    update();
}
function update(){
    confetti.forEach(p=>{
        p.y+=2;
        if(p.y>canvas.height) p.y=0;
    });
}
setInterval(draw,30);
</script>

</body>
</html>
