<?php

    session_start();

    include "../db.php";

    date_default_timezone_set('Asia/Kolkata');

    $currentTime = date('M j, Y g:i a');



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

        header("Location: logout.php");

?>

<!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">

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

                        <div cla ss="card-body">



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

                            <hr>

                                <div class="row filter">

                                        

                                        <div class="filter-input-3" style=" margin-left:18px">

                                               <div class="form-group">

                                                Name

                                                <input type="text" list="First" class="fo rm-control" id="FirstFilterValue">

                                                <datalist id="First">

                                                  <?php 

                                                  $sql = "SELECT DISTINCT uname, uid FROM users WHERE     utype='Student' ORDER BY uname ASC";

                                                  $res = mysqli_query($con,$sql);

                                                  while ($row = mysqli_fetch_assoc($res)) {

                                                  ?>

                                                     <option value="<?php echo $row['uname']; ?>"><?php echo $row['uname']; ?></option>

                                                    <?php } ?>

                                                </select>

                                              </div>

                                        </div>

                                         <div class="filter-input-3">

                                            <div class="form-group">

                                               Admin

                                                <input type="text" list="Second" class="for m-control" id="SecondFilterValue">

                                                <datalist id="Second">

                                                  <?php 

                                                  $sql = "SELECT DISTINCT uname, uref FROM users WHERE     utype='Admin'";

                                                  $res = mysqli_query($con,$sql);

                                                  while ($row = mysqli_fetch_assoc($res)) {

                                                  ?>

                                                     <option value="<?php echo $row['uname']; ?>"><?php echo $row['uname']; ?></option>

                                                    <?php } ?>

                                                </select>

                                              </div>

                                        </div>

                                        <div  class="filter-input-3">

                                            <div class="form-group">

                                                Ph No.

                                                <input type="text" list="Third" class="form-c ontrol" id="ThirdFilterValue">

                                                <datalist id="Third">

                                                  <?php 

                                                  $sql = "SELECT DISTINCT uphone FROM users  WHERE utype = 'Student' ORDER BY uphone ASC";

                                                  $res = mysqli_query($con,$sql);

                                                  while ($row = mysqli_fetch_assoc($res)) {

                                                  ?>

                                                     <option value="<?php echo $row['uphone']; ?>"><?php echo $row['uphone']; ?></option>

                                                    <?php } ?>

                                                </datalist>

                                              </div>

                                        </div>

                                        <div class="filter-btn">

                                              <button type="button" style="" id="filter">Search</button>

                                        </div>

                                        <div class="col-sm-1"></div>

                                </div>

                            <hr>

                            <div class="row">

                              <!--loader -->

                              <div class="col-12" id='loader'>

                                    <ul style="list-style: none; padding-left: 0;">

                                      <?php 

                                        for ($count = 0; $count < 4; $count++) {

                                  

                                            echo '<li>

                                            <div class="ph-item">

                                            <div cl ass="ph-test">

                                            <div class="ph-row">

                                            <div class="ph-col-12 big"></div>

                                            <div class="ph-col-12"></div>

                                            <div class="ph-col-12"></div>

                                            <div class="ph-col-12"></div>

                                            <div class="ph-col-12"></div>

                                            <div class="ph-col-12"></div>

                                            </div></div>

                                            </div>

                                            </li>';

                                        }

                                      ?>

                                    </ul>

                                </div>

                                <!-- loader -->

                                <div class="col-12" id="full-table">

                                        <ul class="timeline" id="full-table-data"></></ul>

                                </div>

                                <div class="col-12" id="filter-table" style="display: none;">

                                        <ul class="timeline" id="filter-table-data"></></ul>

                                </div>

                            </div>



                        </div>

                    </div>

                </div>

            </div>



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

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



    <div class="modal fade" id="studentDetailsModal" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">

        <div class="modal-dialog" role="document">

            <div class="modal-content">

                <div class="modal-header">

                    <h5 class="modal-name badge badge-success text-light" id="modalName" style="font-size: 20px;"></h5>

                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">

                        <span aria-hidden="true">&times;</span>

                    </button>

                </div>

                <div class="modal-body">

                    <div class="row">

                        <div class="col-xs-6 text-right">

                            <h5 class="modal-css">User ID</h5>

                            <h5 class="modal-css">Password</h5>

                            <h5 class="modal-css">Class</h5>

                            <h5 class="modal-css">Address</h5>

                            <h5 class="modal-css">Dist</h5>

                            <h5 class="modal-css">Pin</h5>

                            <h5 class="modal-css">Date</h5>

                        </div>

                        <div class="col-xs-6">

                            <h5 class="modal-id" id="modalId"></h5>

                            <h5 class="modal-id" id="modalPass"></h5>

                            <h5 class="modal-css" id="modalClass"></h5>

                            <h5 class="modal-css" id="modalAddress"></h5>

                            <h5 class="modal-css" id="modalDist"></h5>

                            <h5 class="modal-css" id="modalPin"></h5>

                            <h5 class="modal-css" id="modalDate"></h5>

                        </div>

                    </div>

                </div>

                <div class="modal-footer">

                    <button type="button" class="btn btn-warning text-dark" data-dismiss="modal">Close</button>

                </div>

            </div>

        </div>

    </div>





    <div class="modal fade" id="studentPayment" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">

        <div class="modal-dialog" role="document">

            <div class="modal-content">

                <div class="modal-header">

                    <div class="text-center">

                        <h5 class="badge badge-warning text-dark" style="font-size: 20px"> Fee Structure </h5>

                    </div>

                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">

                        <span aria-hidden="true">&times;</span>

                    </button>

                </div>

                <div class="modal-body">

                    <div class="row mx-0">

                        <div class="col-12">

                            <h5 id="modalUname"></h5>

                        </div>



                        <div class="col-12" id="feedetails"></div>

                    </div>

                </div>

                <div class="modal-footer">

                    <button type="button" class="btn btn-warning text-dark" data-dismiss="modal">Close</button>

                </div>

            </div>

        </div>

    </div>

      

    

<script>

    //dropdown TWO filter Start//

  $(document).ready(function(){

                                                                 

        var load_filter_flag = '';

        var FirstFilterValue = '';

        var SecondFilterValue = '';

        var ThirdFilterValue = '';

        $("#filter").click(function(){

            FirstFilterValue = $('#FirstFilterValue').val();

            SecondFilterValue = $('#SecondFilterValue').val();

            ThirdFilterValue = $('#ThirdFilterValue').val();

            load_filter_flag = 0;

            if (FirstFilterValue != '' || SecondFilterValue != '' || ThirdFilterValue != '') {

                //alert(name);

                $.ajax({

                    url:'view-student-Ajax.php',

                    type:'post',

                    data:{

                      FirstFilterValue:FirstFilterValue,

                      SecondFilterValue:SecondFilterValue,

                      ThirdFilterValue:ThirdFilterValue,

                      start:load_filter_flag

                    },

                    success:function(result){

                      $('#full-table').hide();

                      $('#filter-table').show();

                      $('#filter-table-data').html(result);

                      load_filter_flag += 10;

                    },

                    complete:function(data){

                        /* Hide loader container */

                        $("#loader").hide();

                    }

                });

            }else{

                alert('Plz Select an Option');

                $('#full-table').show();

                $('#filter-table').hide();

            }

        });





        function loadMoreFilter(start){

            console.log('Filter'+start);

            if (load_filter_flag > 0) {

              //alert(name);

                  $.ajax({

                    url:'view-student-Ajax.php',

                    type:'post',

                    data:{

                      FirstFilterValue:FirstFilterValue,

                      SecondFilterValue:SecondFilterValue,

                      ThirdFilterValue:ThirdFilterValue,

                      start:start

                    },

                    success:function(result){

                      $('#filter-table-data').append(result);

                      load_filter_flag += 10;

                    }

                  });

             

            }

        }

// Scroll Loading of Full Data //

        var load_flag = 0;

        loadMore(load_flag);

        function loadMore(start){

            //console.log('total'+start);

            $.ajax({

                url: 'view-student-Ajax.php',

                type: 'post',

                data: 'start='+start,

                success:function(result){

                    $('#full-table-data').append(result);

                    load_flag += 10;

                },

                complete:function(data){

                    /* Hide loader container */

                    $("#loader").hide();

                }

            });

        }



        $(window).scroll(function(){

        

            if ($(window).scrollTop() >= $(document).height()-$(window).height()) {

                //console.log('call');

                if (load_filter_flag>0) {

                    loadMoreFilter(load_filter_flag); 

                }else{

                    loadMore(load_flag);

                }

                

                

            }

            

        });



  });

</script>



</body>

</html>

<?php

if ( isset($_GET["del_id"]) ) {



$del_sql = "DELETE FROM users WHERE uid = '$_GET[del_id]'";



if ( mysqli_query($con, $del_sql) ) {

    ?>

    <script>window.location = "view-student.php";</script>

    <?php

} else {

    ?>

    <script>

        alert('OOPS !!!!');

        setTimeout(() => {

            window.location = 'view-student.php';

        }, 1200);

    </script>

    <?php

}



}

?>



