<?php 

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



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

    

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

    $AndWhere ='';



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



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



    }elseif (empty($_POST['FirstFilterValue']) && !empty($_POST['SecondFilterValue'])) {



        $AndWhere = "";



    }elseif (!empty($_POST['FirstFilterValue']) && !empty($_POST['SecondFilterValue'])) {

        

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

    }



    $sql = "SELECT * FROM users  WHERE utype = 'Admin' AND udisplay ='disable' $AndWhere ORDER BY uid DESC 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)) {



            $c_sql = mysqli_query($con, "SELECT sid FROM class WHERE uploadedby = '$rows[uref]'");

            $class_count = mysqli_num_rows($c_sql);



            $s_sql = mysqli_query($con, "SELECT sc_id FROM subject WHERE uploadedby = '$rows[uref]'");

            $subject_count = mysqli_num_rows($s_sql);



            $t_sql = mysqli_query($con, "SELECT uid FROM users WHERE utype = 'Teacher' AND admin_ref = '$rows[uref]'");

            $teacher_count = mysqli_num_rows($t_sql);



            $st_sql = mysqli_query($con, "SELECT uid FROM users WHERE utype = 'Student' AND admin_ref = '$rows[uref]'");

            $student_count = mysqli_num_rows($st_sql);



            //referance count start//

            $ap_total_rows= 0;

            $ap_sql = "SELECT * FROM users WHERE upload_ref_code = '$rows[uref_code]' AND reg_approved= '1'";

            $ap_res = mysqli_query($con,$ap_sql);

            $ap_total_rows=mysqli_num_rows($ap_res);



            $not_ap_total_rows= 0;

            $not_ap_sql = "SELECT * FROM users WHERE upload_ref_code = '$rows[uref_code]' AND reg_approved= '0'";

            $not_ap_res = mysqli_query($con,$not_ap_sql);

            $not_ap_total_rows=mysqli_num_rows($not_ap_res);

            //referance count end//



            $s_output .= 

                "

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

                <div class='row'>

                    

                    

                    <div class='col-md-5 col-xs-4 second-item'>

                        <a class='viewDetails' data-toggle='modal' data-target='#adminDetailsModal' 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-qualification='$rows[uqualification]' 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[ucontact]' class='small text-dark text-decoration-none' title='Click here to Call'> <i class='fa fa-phone fa-rotate-90'></i> $rows[ucontact] </a>  



                       

                    

                    </div>

                    <div class='col-md-5 col-xs-4 first-item'>

                            <font class='small mb-0'>

                                <span class='font-weight-bold text-dark'>Class :</span>

                                <span class='text-muted'>$class_count</span>

                            </font>

                            <font class='small mb-0'>

                                <span class='font-weight-bold text-dark'>Subject :</span>

                                <span class='text-muted'>$subject_count</span>

                            </font>

                            <br>

                            <font class='small mb-0'>

                                <span class='font-weight-bold text-dark'>Teacher :</span>

                                <span class='text-muted'>$teacher_count</span>

                            </font>

                            <font class='small mb-0'>

                                <span class='font-weight-bold text-dark'>Student :</span>

                                <span class='text-muted'>$student_count</span>

                            </font>

                            <br>

                            <i class='fa fa-line-chart'></i> $ap_total_rows

                            &nbsp;

                            <i class='fa fa-ban'></i> $not_ap_total_rows

                        

                    </div>



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

                        <a href='view-admin.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 qualification = $(this).data('qualification');

                $('#modalqualification').text(qualification);

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

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

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

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

                

            });

        });

    </script>