<?php
session_start();
// session_destroy();

if(isset($_SESSION['log_session']) && !empty($_SESSION['log_session'] && $_SESSION['log_session']['user_role_id'] == '1')) { // Student

    $user_id = $_SESSION['log_session']['user_id'];
    $user_role_name = $_SESSION['log_session']['user_role_name'];
    $user_role_id = $_SESSION['log_session']['user_role_id'];
    $user_first_name =  $_SESSION['log_session']['user_first_name'];

}else {
    header('Location: ../login.php');
    exit();
}

// Include the database connection file
include('../includes/DB/Connection.php');


// Create a new connection instance
$connection = new Connection();
$db = $connection->connect();


// Fetch student data
// $query = "SELECT student_id, student_first_name, student_last_name, student_email, student_updated_date FROM student ";
$query = "SELECT 
           DISTINCT s.student_id, s.student_first_name,s.student_last_name,s.student_email,s.student_phone_1
          FROM 
            student s
          JOIN 
            education e ON s.student_id = e.student_id
          WHERE
           e.education_doc_status = 1;";

$statement = $db->prepare($query);
$statement->execute();
$result = $statement->get_result();
// $statement = $db->prepare($query);
//         $statement->bind_param("i", $education_doc_verify);
//         $statement->execute();
//         $result = $statement->get_result();

?>

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

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description"
        content="Multikart admin is super flexible, powerful, clean &amp; modern responsive bootstrap 4 admin template with unlimited possibilities.">
    <meta name="keywords"
        content="admin template, Multikart admin template, dashboard template, flat admin template, responsive admin template, web app">
    <meta name="author" content="pixelstrap">
    <link rel="icon" href="../assets/images/dashboard/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="../assets/images/dashboard/favicon.png" type="image/x-icon">
    <title>Multikart - Premium Admin Template</title>

    <!-- Google font-->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css2?family=Work+Sans:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,500;1,600;1,700;1,800;1,900&display=swap">

    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap">


    <!-- Font Awesome-->
    <link rel="stylesheet" type="text/css" href="../assets/css/vendors/font-awesome.css">

    <!-- Flag icon-->
    <link rel="stylesheet" type="text/css" href="../assets/css/vendors/flag-icon.css">

    <!-- Bootstrap css-->
    <link rel="stylesheet" type="text/css" href="../assets/css/vendors/bootstrap.css">

    <!-- App css-->
    <link rel="stylesheet" type="text/css" href="../assets/css/style.css">
</head>

<body>
    <!-- page-wrapper Start-->
    <div class="page-wrapper">

        <!-- page-header Start-->
        <?php include('../includes/headers/header.php'); ?>
        <!-- page-header end-->

        <!-- Page Body Start-->
        <div class="page-body-wrapper">

            <!-- Page Sidebar Start-->
            <?php include('../includes/Sidebar/sidebar.php'); ?>
            <!-- Page Sidebar Ends-->

            <!-- Right sidebar Start-->
            <?php include('../includes/rightsidebar/rightsiderbar.php'); ?>
            <!-- Right sidebar Ends-->

            <div class="page-body">
                <!-- Container-fluid starts-->
                <div class="container-fluid">
                    <div class="page-header">
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="page-header-left">
                                    <h3>Academic Admin
                                        <small>AIC/IMC</small>
                                    </h3>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <ol class="breadcrumb pull-right">
                                    <li class="breadcrumb-item">
                                        <a href="./dashboard.php">
                                            <i data-feather="home"></i>
                                        </a>
                                    </li>
                                    <li class="breadcrumb-item">Settings</li>
                                    <li class="breadcrumb-item active">Academic admin</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Container-fluid Ends-->

                <!-- Container-fluid starts-->
                <div class="container-fluid">
                    <div class="card">
                        <div class="card-header">
                            <form class="form-inline search-form search-box">
                                <div class="form-group">
                                    <!-- <input class="form-control-plaintext" type="text" placeholder="Search.."><span
                                        class="d-sm-none mobile-search" id="searchInput" oninput="searchTable()"><i
                                            data-feather="
                                        search"></i></span> -->
                                    <input class="form-control-plaintext" type="text" placeholder="Search by Student ID"
                                        id="searchInput" oninput="searchTable()">

                                    <!-- <input type="text" class="form-control " id="searchInput"
                                        placeholder="Search by Client" oninput="searchTable()"> -->
                                </div>
                            </form>


                        </div>

                        <div class="card-body">
                            <div class="table-responsive table-desi">
                                <table class="all-package coupon-table table table-striped">
                                    <thead>
                                        <tr>
                                            <!-- <th>
                                                <button type="button"
                                                    class="btn btn-primary add-row delete_all">Delete</button>
                                            </th> -->

                                            <th>Student Id</th>
                                            <th>First Name</th>
                                            <th>Last Name</th>
                                            <th>Email</th>
                                            <th></th>
                                        </tr>
                                    </thead>

                                    <tbody>

                                        <!-- <td>
                                                <input class="checkbox_animated check-it" type="checkbox" value=""
                                                    id="flexCheckDefault" data-id="1">
                                            </td> -->

                                        <!-- <td>
                                                <img src="assets/images/dashboard/user.jpg" alt="">
                                            </td> -->



                                        <?php
                                        if ($result->num_rows > 0) {
                                            while ($row = $result->fetch_assoc()) {

                                                echo "<td>{$row['student_id']}</td>";
                                                echo "<td>{$row['student_first_name']}</td>";
                                                echo "<td>{$row['student_last_name']}</td>";
                                                echo "<td>{$row['student_email']}</td>";                                               
                                                echo "<td>
                <form action='view-details.php' method='GET'>
                    <input type='hidden' name='student_id' value='{$row['student_id']}'>
                    <button type='submit' class='btn btn-primary'>View</button>
                </form>
              </td>";

                                                echo "</tr>";
                                            }
                                        } else {
                                            echo "<tr><td colspan='6'>No students found</td></tr>";
                                        }
                                        $statement->close();
                                        $db->close();
                                        ?>

                                        </tr>


                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Container-fluid Ends-->
            </div>

            <!-- footer start-->
            <footer class="footer">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-6 footer-copyright text-start">
                            <p class="mb-0">Copyright </p>
                        </div>
                        <div class="col-md-6 pull-right text-end">
                            <p class=" mb-0">Hand crafted & made with<i class="fa fa-heart"></i></p>
                        </div>
                    </div>
                </div>
            </footer>
            <!-- footer end-->
        </div>
    </div>
    <script>
    function searchTable() {
        // Get the input field and its value
        var input = document.getElementById("searchInput");
        var filter = input.value.trim(); // Remove any extra spaces

        // Convert the input value to a number for numeric comparison
        var filterNumber = parseInt(filter, 10);

        // Get the table and its rows
        var table = document.querySelector('.table');
        var tr = table.getElementsByTagName("tr");

        // Loop through all table rows, except the header row
        for (var i = 1; i < tr.length; i++) {
            var td = tr[i].getElementsByTagName("td")[0]; // Assuming student_id is in the first column
            if (td) {
                var txtValue = td.textContent || td.innerText;
                // Convert the text value of td to a number
                var studentId = parseInt(txtValue, 10);
                // Check if the filterNumber matches the studentId
                if (isNaN(filterNumber) || studentId === filterNumber) {
                    tr[i].style.display = ""; // Show the row if match is found or if input is not a valid number
                } else {
                    tr[i].style.display = "none"; // Hide the row if no match
                }
            }
        }
    }
    </script>



    <!-- latest jquery-->
    <script src="assets/js/jquery-3.3.1.min.js"></script>

    <!-- Bootstrap js-->
    <script src="assets/js/bootstrap.bundle.min.js"></script>

    <!-- feather icon js-->
    <script src="assets/js/icons/feather-icon/feather.min.js"></script>
    <script src="assets/js/icons/feather-icon/feather-icon.js"></script>

    <!-- Sidebar jquery-->
    <script src="assets/js/sidebar-menu.js"></script>

    <!-- Table Row Delete js -->
    <script src="assets/js/table-row-delete.js"></script>

    <!--Customizer admin-->
    <script src="assets/js/admin-customizer.js"></script>

    <!-- lazyload js-->
    <script src="assets/js/lazysizes.min.js"></script>

    <!--right sidebar js-->
    <script src="assets/js/chat-menu.js"></script>

    <!--script admin-->
    <script src="assets/js/admin-script.js"></script>

</body>

</html>