<?php 

  include "../../db.php";



if (isset($_POST['start'])) {

    

    $start= mysqli_real_escape_string($con,$_POST['start']);

    $AndWhere ='';



    if ( !empty($_POST['FirstFilterValue']) ) {



        $AndWhere .= "AND u.uname='$_POST[FirstFilterValue]' ";



    }



    if ( !empty($_POST['SecondFilterValue']) ) {



        $sf_sql = "SELECT uref FROM users WHERE utype='Admin' AND uname='$_POST[SecondFilterValue]'";

        $sf_run = mysqli_query($con, $sf_sql);

        $sf_rows = mysqli_fetch_assoc($sf_run);



        $AndWhere .= "AND u.admin_ref='$sf_rows[uref]' ";



    }



    if (!empty($_POST['ThirdFilterValue'])) {



            $AndWhere .="AND u.uphone='$_POST[ThirdFilterValue]' ";

    }





    $sql = "SELECT  u.*, f.sid, f.fmonth, f.amount, f.fdate FROM users AS u LEFT JOIN fees AS f ON u.uid = f.sid WHERE u.utype = 'student' AND u.udisplay ='disable' $AndWhere GROUP BY u.uname LIMIT $start,10";



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

    if ($total_rows=mysqli_num_rows($res)>0) {

        $s_output='';

          $c = $start+1;

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

            $m_sql = "SELECT uname, uref FROM users WHERE uref = '$rows[admin_ref]' ";

            $m_run = mysqli_query($con, $m_sql);

            $m_rows = mysqli_fetch_assoc($m_run);

            $s_output .= 

                "

                <li class='clearfix' style='float: none;'>

                <div class='row'>

                    



                    <div class='col-md-10 col-xs-9 second-item'>

                    <a class='viewDetails' data-toggle='modal' data-target='#studentDetailsModal' data-name='$rows[uname]'  data-dist='$rows[dist]' data-pin='$rows[pin]' data-userid='$rows[uphone]' data-pass='$rows[upass]' data-address='$rows[saddress]' data-classs='$rows[sclass]' data-date='$rows[ucreated]'>



                        <i class='fa fa-user-circle' aria-hidden='true' style='color:orange;font-size:17px;'></i> <b style='color:black;font-size:17px;'>$rows[uname]</b>  

                        </a>

                        <br>    

                        <a href='tel:$rows[uphone]' class='small text-dark text-decoration-none' title='Click here to Call'> <i class='fa fa-phone fa-rotate-90'></i> $rows[uphone] </a> 

                       &nbsp;

                        <b><i class='fa fa-user'></i> </b>$m_rows[uname]

                           

                    </div>



                    <div class='col-md-2 col-xs-3 third-item'>

                                                

                        <a href='view-student.php?restore_id=$rows[uid]' class='m-2 btn btn-success btn-sm' sty le='width:35px;'> Restore </a>



                    </div>

                </div>

                </li>

                ";

          $c++;

        }



        mysqli_close($con);



        echo $s_output;

    }



}

?>



    <script>

        $(document).ready(function(){



            $('.viewDetails').on('click', function () {

                var name = $(this).data('name');

                $('#modalName').text(name);

                $('.modal-css').css({

                    'color' : 'black'

                    

                });

                $('.modal-name').css({

                    'text-align' : 'center',

                    'color' : 'black'

                });

                $('.modal-id').css({

                    'color' : 'red',

                    'font-weight' : 'bold'

                });

                var dist = $(this).data('dist');

                $('#modalDist').text(dist);

                var pin = $(this).data('pin');

                $('#modalPin').text(pin);

                var userid = $(this).data('userid');

                $('#modalId').text(userid);

                var pass = $(this).data('pass');

                $('#modalPass').text(pass);

                var classs = $(this).data('classs');

                $('#modalClass').text(classs);

                var address = $(this).data('address');

                $('#modalAddress').text(address);

                var date = $(this).data('date');

                $('#modalDate').text(date);

                

            });

            $('.viewPayment').on('click', function(){

                // var uname = $(this).data('uname');

                var stuid = $(this).data('stuid');

                // $('#modalUname').text(uname);



                $.ajax({

                    url: 'view-student-fees_ajax.php?stuid='+stuid,

                    data: stuid,

                    method: 'GET',

                    success: function (data) {

                        $('#feedetails').html(data);

                    }

                });

            });

        });

    </script>