<?php
include('session_validator.php');
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Assign Subjects</title>
    <!-- Include your CSS and other necessary files here -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- DataTables CSS -->
    <link rel="stylesheet" href="css/jquery.dataTables.min.css">
    <!-- DataTables JavaScript -->
    <script src="js/jquery.dataTables.min.js"></script>
    <style>
        /* Example DataTable styling */
#studentTable {
    width: 100%;
}

        /* Add your CSS styles here */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            padding: 15px;
        }

        .container {
            max-width: 900px;
            margin: 0 auto;
            background-color: white;
            padding: 10px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

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

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

        th {
            background-color: #4caf50;
            color: white;
        }

        tr:nth-child(even) {
            background-color: #f2f2f2;
        }

        .action-buttons a {
            text-decoration: none;
            margin-right: 10px;
            color: #4caf50;
        }
    </style>
</head>
<?php
// get_assigned_subjects.php

// Include your database connection file
include("includes/db.php");

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["class_id"])) {
    $classId = $conn->real_escape_string($_POST["class_id"]);

    // Fetch assigned subjects for the selected class
    $query = "SELECT * FROM class_subject_mapping
              INNER JOIN subjects ON class_subject_mapping.subject_id = subjects.id

              WHERE class_id = '$classId' ORDER BY subject_id ";
    $result = $conn->query($query);

    if ($result->num_rows > 0) {


        echo '<h2>Assigned Subjects</h2>';
        echo '<table class="studentTable">';
        echo '<thead>';
        echo '<tr>';
        echo '<th>Subject ID</th>';
        echo '<th>Subject Name</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';

        while ($row = $result->fetch_assoc()) {


            echo '<tr>';
            echo '<td>' . $row['subject_id'] . '</td>';
            echo '<td>' . $row['subject_name'] . '</td>';
            echo '</tr>';
        }

        echo '</tbody>';
        echo '</table>';
    } else {
        echo '<p>No subjects assigned for this class.</p>';
    }

    // Close the database connection
    $conn->close();
}
?>
</html>