<?php
include('db_connection.php');
include 'header.php'; 
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $term_id = $_POST['term_id'];
    $session_id = $_POST['session_id'];
    $topic = $_POST['topic'];
    $details = $_POST['details'];

    $stmt = $conn->prepare("INSERT INTO scheme_of_work (term_id, session_id, topic, details) VALUES (?, ?, ?, ?)");
    $stmt->bind_param("iiss", $term_id, $session_id, $topic, $details);

    if ($stmt->execute()) {
        echo "New scheme of work added successfully!";
    } else {
        echo "Error: " . $stmt->error;
    }

    $stmt->close();
    $conn->close();
}

// Fetch terms and sessions for dropdowns
$terms = $conn->query("SELECT * FROM terms");
$sessions = $conn->query("SELECT * FROM sessions");
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Add Scheme of Work</title>
    <link rel="stylesheet" href="#"> <!-- Add your CSS file -->
    <style type="text/css">
        body {
    font-family: Arial, sans-serif;
}

h2 {
    color: #333;
}

form {
    margin: 20px;
}

label {
    display: block;
    margin-top: 10px;
}

input, select, textarea {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    box-sizing: border-box;
}

input[type="submit"] {
    background-color: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
    margin-top: 20px;
}

input[type="submit"]:hover {
    background-color: #45a049;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

table, th, td {
    border: 1px solid #ddd;
}

th, td {
    padding: 10px;
    text-align: left;
}

th {
    background-color: #f2f2f2;
}

    </style>
</head>
<body>
    <h2>Add Scheme of Work</h2>
    <form method="post" action="">
        <label for="term_id">Term:</label>
        <select id="term_id" name="term_id" required>
            <?php while ($row = $terms->fetch_assoc()): ?>
                <option value="<?php echo $row['term_id']; ?>"><?php echo $row['term_name']; ?></option>
            <?php endwhile; ?>
        </select>

        <label for="session_id">Session:</label>
        <select id="session_id" name="session_id" required>
            <?php while ($row = $sessions->fetch_assoc()): ?>
                <option value="<?php echo $row['session_id']; ?>"><?php echo $row['session_name']; ?></option>
            <?php endwhile; ?>
        </select>

        <label for="topic">Topic:</label>
        <input type="text" id="topic" name="topic" required>

        <label for="details">Details:</label>
        <textarea id="details" name="details" required></textarea>

        <input type="submit" value="Add Scheme of Work">
    </form>
</body>
</html>
