<?php

    session_start();

    include "../db.php";

    date_default_timezone_set('Asia/Kolkata');

    $currentTime = date('M j, Y');



    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) && !isset($_SESSION['uname']) ){

        header("Location: logout.php");

    }



    $admin_2_run = "SELECT uname FROM users WHERE uid = '$_GET[id]'";

    $admin_2_row2 = mysqli_query($con, $admin_2_run);

    $admin_2_row = mysqli_fetch_assoc($admin_2_row2);

    $admin_2 = $admin_2_row["uname"];

    // echo $admin_2;

    // echo '<pre>';print_r($admin_2_run);exit();

?>

<!DOCTYPE html>

<html lang="en">

<head>

 <?php include "includes/meta.php"; ?>        

    <?php include "includes/css.php"; ?>  

        <link href="css/all.min.css" rel="stylesheet" type="text/css">

            <link href="css/alltable.css" rel="stylesheet">    

  



</head>

<body id="page-top" class="mt-55">



    <div style="margin-top: 70px;"></div>



      <?php include "includes/header2.php"; ?>

<div class="container">

            <div class="row mx-0 just ify-content-center">

                <div class="col-12 col-sm-12 col-md-12">

                        <div class="card-body">

                <h1 class="h3 mb-2 text-gray-800 text-center">Attendance</h1>

                <div class="w-100 text-center">

                <h4 class="mb-2 badge badge-success rounded-0" style="font-size: 17px"><?php echo $admin_2; ?></h4>

                

                </div>

                

                <div class="row mx-0">

                    <!-- <div class="col-12"> -->

                        <?php

                            $run= mysqli_query($con, "SELECT * FROM attendance_2 AS a2 JOIN attendance AS a ON a2.attendance_ref = a.ref WHERE a2.stu_id = '$_GET[id]' ORDER BY a2.a_id DESC");

                            

                            if ( mysqli_num_rows($run) > 0 ) {

                                ?>

                                <div class="col-12">

                                    <input type="text" id="myInput" placeholder="Search for field" class="form-control">

                                    <p class="my-2">

                                        <span id="filterCount"></span>

                                        <span id="no-count"></span>

                                    </p>

                                    <hr>

                                </div>

                                <?php

                                while ($rows = mysqli_fetch_assoc($run)) {

                                    ?>

                                    <div class="col-md-3 ggtt">

                                        <div class="card mb-3">

                                            <div class="card-header">

                                                <?php echo $rows["class_date"]; ?>

                                            </div>

                                            <div class="card-body text-center">

                                                <?php echo $rows["class_period"]; ?>

                                                <br>

                                                <?php

                                                    if ($rows["stu_attendance"] == "A") {

                                                        $attn = "<span class='badge badge-danger rounded-0' style='font-size:15px'><i class='fas fa-times-circle'></i></span>";

                                                    } else {

                                                        $attn = "<span class='badge badge-success rounded-0' style='font-size:15px'><i class='fas fa-check-circle'></i></span>";

                                                    }

                                                    

                                                    echo $attn; 

                                                ?>

                                                

                                            </div>

                                        </div>

                                    </div>

                                    <?php

                                }

                            } else {

                                ?>

                                <div class="w-100 text-center">

                                    <hr>

                                    <h3 class="text-center">No attendance yet</h3>

                                </div>

                                <?php

                            }

                            

                        ?>

                    <!-- </div> -->

                </div>

            </div>



            <div class="card-footer text-center">

                <a href="view-student.php" class="btn btn-sm btn-primary">Go back</a>

            </div>

        </div>

    </div>

</div>

    <?php include "includes/ft.php"; ?>



    <script src="js/jquery.min.js"></script>

    <script src="js/bootstrap.min.js"></script>

    <script src="js/jquery.easing.min.js"></script>

    <script src="js/sb-admin-2.min.js"></script>

    <!-- <script src="js/sweetalert2.min.js"></script> -->

    <!-- <script src="js/jquery.dataTables.min.js"></script> -->

    <!-- <script src="js/dataTables.bootstrap4.min.js"></script> -->

    <!-- <script src="js/datatables.mark.min.js"></script> -->

    <!-- <script src="js/jquery-ui-custom.min.js"></script> -->

    <script src="js/custom.js"></script>



    <script>

        $(document).ready(function () {

            $('#myInput').keyup(function(){

                var filter = $(this).val(), count = 0;

                // console.log(search);

                

                $(".ggtt").each(function () {

                    // If the list item does not contain the text phrase fade it out

                    if ($(this).text().search(new RegExp(filter, "i")) < 0) {

                        $(this).fadeOut();

                        // Show the list item if the phrase matches and increase the count by 1

                    } else {

                        $(this).show();

                        count++;

                    }

                });



                // Update the count

                var numberItems = count;

                $("#filterCount").text("Match Found = " + count);

                if (count < 1) {

                    $("#no-count").text('result');

                } else {

                    $("#no-count").text('');

                }

            });

        });

    </script>



</body>

</html>