<?php
session_start();

if ($_SERVER["REQUEST_METHOD"] === "POST") {

    // 1️⃣ Save teacher inputs
    $_SESSION["teacher_name"] = $_POST["teacher_name"];
    $_SESSION["class"]        = $_POST["class"];
    $_SESSION["section"]      = $_POST["section"];

    // 2️⃣ Handle CSV upload
    if (isset($_FILES["student_csv"]) && $_FILES["student_csv"]["error"] === 0) {

        $uploadDir = __DIR__ . "/uploads/";
        if (!is_dir($uploadDir)) {
            mkdir($uploadDir, 0777, true);
        }

        $filePath = $uploadDir . "student_list.csv";
        move_uploaded_file($_FILES["student_csv"]["tmp_name"], $filePath);

        $_SESSION["student_csv"] = $filePath;

        // 3️⃣ Go to assessment session
        header("Location: facilitated_assessment.php");
        exit;
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Facilitated Mode – Teacher Setup</title>

    <style>
        body{
            margin:0;
            background:radial-gradient(circle at top,#0f172a,#020617);
            font-family:Segoe UI,sans-serif;
            color:#e5e7eb;
        }
        .wrap{
            max-width:900px;
            margin:60px auto;
            padding:20px;
        }
        h1{
            margin-bottom:10px;
        }
        .card{
            background:#020617;
            border:1px solid #1f2937;
            border-radius:18px;
            padding:30px;
            margin-bottom:30px;
        }
        label{
            display:block;
            margin-bottom:6px;
            font-size:14px;
            opacity:.8;
        }
        input{
            width:100%;
            padding:12px;
            margin-bottom:18px;
            border-radius:10px;
            border:1px solid #1f2937;
            background:#020617;
            color:white;
        }
        input[type=file]{
            padding:8px;
        }
        button{
            background:#0ea5e9;
            border:none;
            padding:12px 22px;
            border-radius:10px;
            font-weight:600;
            cursor:pointer;
        }
        button:hover{
            background:#38bdf8;
        }
    </style>
</head>
<body>

<div class="wrap">
    <h1>👨‍🏫 Facilitated Mode – Setup</h1>
    <p style="opacity:.7">
        Enter teacher details and upload the student list to begin the assessment session.
    </p>

    <form method="POST" enctype="multipart/form-data">

        <div class="card">
            <h3>Teacher & Class Details</h3>

            <label>Teacher Name</label>
            <input type="text" name="teacher_name" required placeholder="Eg: Mrs. Lakshmi">

            <label>Class</label>
            <input type="text" name="class" required placeholder="Eg: 8">

            <label>Section</label>
            <input type="text" name="section" required placeholder="Eg: A">
        </div>

        <div class="card">
            <h3>Upload Student List (CSV)</h3>

            <label>CSV / Excel File</label>
            <input type="file" name="student_csv" required>

            <p style="font-size:13px;opacity:.6">
                Expected columns: Roll No, Student Name
            </p>
        </div>

        <button type="submit">Start Assessment Session</button>
    </form>
</div>

</body>
</html>
