<!-- Student Detail.php -->
<?php
include('session_validator.php');
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
       <link rel="stylesheet" href="css/bootstrap.min.css" media="screen">
    <link rel="stylesheet" href="css/font-awesome.min.css" media="screen">
    <link rel="stylesheet" href="css/animate-css/animate.min.css" media="screen">
    <link rel="stylesheet" href="css/lobipanel/lobipanel.min.css" media="screen">
    <link rel="stylesheet" href="css/toastr/toastr.min.css" media="screen">
    <link rel="stylesheet" href="css/icheck/skins/line/blue.css">
    <link rel="stylesheet" href="css/icheck/skins/line/red.css">
    <link rel="stylesheet" href="css/icheck/skins/line/green.css">
    <link rel="stylesheet" href="css/main.css" media="screen">
    <script src="js/modernizr/modernizr.min.js"></script>
  


  
   <link rel="stylesheet" href="styles.css">
    <!-- DataTables CSS -->
    <link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css">
  <!-- jQuery -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- DataTables JavaScript -->
    <script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>

    <style>
        .errorWrap {
            padding: 10px;
            margin: 0 0 20px 0;
            background: #fff;
            border-left: 4px solid #dd3d36;
            -webkit-box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .1);
            box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .1);
        }

        .succWrap {
            padding: 10px;
            margin: 0 0 20px 0;
            background: #fff;
            border-left: 4px solid #5cb85c;
            -webkit-box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .1);
            box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .1);
        }
        </style>

        <style>
    .table-container {
    max-height: 500px; /* Set the maximum height as needed */
    overflow-y: auto;
}

#customers {
    font-family: Arial, Helvetica, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

#customers td, #customers th {
    border: 1px solid #ddd;
    padding: 8px;
}

.lower-margin {
    margin-bottom: 2px; /* Adjust the value as needed */
}

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

#customers tr:hover {
    background-color: #ddd;
}

#customers th {
    padding-top: 12px;
    padding-bottom: 12px;
    text-align: left;
    background-color: #d6f5ab;
    position: sticky;
    top: 0;
}

</style>


<script>
function printTable() {
    var printWindow = window.open('', '_blank');
    printWindow.document.write('<html><head><title>Mohanmaya Sec. School, Student Enthic Report </title>');
    printWindow.document.write('<link rel="stylesheet" href="css/tablestyle.css" type="text/css">');
    printWindow.document.write('</head><body>');
    printWindow.document.write(document.getElementById('customers').outerHTML);
    printWindow.document.write('</body></html>');
    printWindow.document.close();

    printWindow.document.documentElement.style.zoom = '75%';

    // Use setTimeout to ensure styles are applied before printing
    setTimeout(function () {
        printWindow.print();
        printWindow.onafterprint = function () {
            printWindow.close();
        };
    }, 500);
}

    
    </script>
    </head>

<body class="top-navbar-fixed">
    <div class="main-wrapper">
        <!-- ========== TOP NAVBAR ========== -->
        <?php include('includes/topbar.php');?>
        <!-- ========== WRAPPER FOR BOTH SIDEBARS & MAIN CONTENT ========== -->
        <div class="content-wrapper">
            <div class="content-container">
                <?php include('includes/leftbar.php');?>
                <div class="main-page">
                    <div class="container-fluid">
                        <div class="row page-title-div">
                            <div class="col-md-6">
                                <h2 class="title">Manage Students</h2>
                            </div>
                        </div>
                        <div class="row breadcrumb-div">
                            <div class="col-md-6">
                                <ul class="breadcrumb">
                                    <li><a href="dashboard.php"><i class="fa fa-home"></i> Home</a></li>
                                    <li> Students</li>
                                    <li class="active">Manage Students</li>
                                </ul>
                            </div>
                        </div>
                    </div>

                    <section class="section">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="panel">
                                        <div class="panel-heading">
                                            <div class="panel-title">
                                                <h5>View Students Info with Ethnic Groups</h5>
                                                <!-- Fetch school details -->
                                                <?php
                                                // Include the database configuration file
                                                include("includes/db.php");

                                                // Fetch school details from the 'schools' table
                                                $schoolQuery = "SELECT * FROM schools LIMIT 1"; // Assuming only one school
                                                $schoolResult = $conn->query($schoolQuery);

                                                if ($schoolResult->num_rows > 0) {
                                                    $schoolDetails = $schoolResult->fetch_assoc();
                                                    $schoolname = $schoolDetails['school_name'] ;
                                                    $SchoolAddress = $schoolDetails['address'];
                                                    // Add other school details as needed
                                                }
                                                ?>
                                            </div>
                                        </div>

                                        <div class="panel-body p-20">
                                            <!-- Form to select class-section -->
                                            <form method="post" action="">
                                                <div class="form-group">
                                                    <label for="classSection">Select Class-Section:</label>
                                                    <select class="form-control" id="classSection" name="classSection">
                                                        <option value="">Select Class</option>
                                                        <?php
                                                        // Include the database configuration file
                                                        include("includes/db.php");

                                                        // Fetch class names from the 'classes' table
                                                        $query = "SELECT class_id, class_name, section FROM classes";
                                                        $result = $conn->query($query);

                                                        // Populate the dropdown with class names and sections
                                                        while ($row = $result->fetch_assoc()) {
                                                            echo "<option value='" . $row['class_id'] . "'>" . $row['class_name'] . " - " . $row['section'] . "</option>";
                                                        }
                                                        ?>
                                                    </select>
                                                </div>
                                                <button type="submit" class="btn btn-primary">Show Students</button>
                                            </form>

                                            <!-- Display students table -->
                     <button onclick="printTable()">Print Table</button>
            
                    <table id="customers" style="border-collapse: collapse; border: 1px solid #000000;">
                                                <thead>
                                                    <tr> <td colspan="8">  <center><span style="font-size:28px; font-weight: bold;"><?= $schoolname ?></span> <br><span style="font-size:18px; font-weight: bold;"> <?= $SchoolAddress ?></span> <br><span style="font-size:18px; font-weight: bold;"> Student Detail for class..........</span></center></td></tr>


                                                    <tr>
                                                        <th>S.N.</th>
                                                        <th>Iemis</th>
                                                        <th>Name</th>
                                                        <th>Gender</th>
                                                        <th>Date of Birth</th>
                                                        <th>Parent Name</th>
                                                        <th>Parent Phone</th>
                                                        <!-- Remove the Class column -->
                                                        <th>Ethnic Group</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                    // Include database connection code
                                                    include("includes/db.php");

                                                    // Check if form is submitted and the selected class ID is not empty
                                                    if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST["classSection"])) {
                                                        // Get selected class ID from the form
                                                        $selectedClassID = $_POST["classSection"];

                                                        // Fetch students with ethnic group information for the selected class
                                                        $query = "
                                                            SELECT 
                                                                s.student_id,
                                                                s.regd_id,
                                                                s.name,
                                                                s.dob,
                                                                s.gender,
                                                                s.phone,
                                                                s.parent_name,
                                                                s.parent_phone,
                                                                e.group_name
                                                            FROM 
                                                                students s
                                                                INNER JOIN std_ent_group se ON s.student_id = se.std_id
                                                                INNER JOIN ent_group e ON se.ethnic_group = e.id
                                                            WHERE
                                                                s.class = '$selectedClassID'
                                                                order by name
                                                        ";

                                                        $result = $conn->query($query);

                                                        if ($result->num_rows > 0) {
                                                            // Output data of each row
                                                            $sn = 0;
                                                            while ($row = $result->fetch_assoc()) {
                                                                $sn++;
                                                                echo "<tr>";
                                                                echo "<td>" . $sn . "</td>";
                                                                echo "<td>" . $row["regd_id"] . "</td>";
                                                                echo "<td>" . $row["name"] . "</td>";
                                                                echo "<td>" . $row["gender"] . "</td>";
                                                                echo "<td>" . $row["dob"] . "</td>";
                                                                echo "<td>" . $row["parent_name"] . "</td>";
                                                                echo "<td>" . $row["parent_phone"] . "</td>";
                                                                echo "<td>" . $row["group_name"] . "</td>";
                                                                echo "</tr>";
                                                            }
                                                        } else {
                                                            echo "<tr><td colspan='8'>No students found</td></tr>";
                                                        }

                                                        // Close the database connection
                                                        $conn->close();
                                                    }
                                                    ?>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </div>
    </div>


        <!-- ========== COMMON JS FILES ========== -->
        <script src="js/jquery/jquery-2.2.4.min.js"></script>
        <script src="js/bootstrap/bootstrap.min.js"></script>
        <script src="js/pace/pace.min.js"></script>
        <script src="js/lobipanel/lobipanel.min.js"></script>
        <script src="js/iscroll/iscroll.js"></script>

        <!-- ========== PAGE JS FILES ========== -->
        <script src="js/prism/prism.js"></script>
        <script src="js/DataTables/datatables.min.js"></script>

        <!-- ========== THEME JS ========== -->
        <script src="js/main.js"></script>

    <!-- DataTables JavaScript -->
    <script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>

    <script>
        $(function ($) {
            $('#example').DataTable();

            $('#example2').DataTable({
                "scrollY": "300px",
                "scrollCollapse": true,
                "paging": false
            });

            $('#example3').DataTable();
        });
    </script>
</body>

</html>
