<?php include('header.php');

if(isset($_GET['delete']))
{
$delete_id=$_GET['id'];

$deletepost="delete from admin where id='$delete_id'";
$run = $conn->query($deletepost);
echo "<script>alert('Admin Deleted Successfully')</script>";

echo '<script>window.location.href = "admins.php";</script>';
}
?>

    <!-- MENU SECTION END-->
    <div class="content-wrapper">
        <div class="container" >

          
            <div class="row" style="margin-top:30px">
                 
				
				
				                   <div class="col-md-12">
 <div class="panel panel-default">
                        <div class="panel-heading" style="color:White;background-color:#1D2D40;font-size:20px">
                            <i class="fa fa-cogs" style="font-size:30px;color:white"></i> Manage Admins
							<a href="addAdmin.php" class="btn btn-success" style="float: right;">Add Admin</a>
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <th style="">Admin ID</th>
                                            <th style="">Full Name</th>
                                            <th style="">Username</th>
                                            <th style="">Password</th>
                                            <th style="">Email</th>
                                            <th style="">Contact No.</th>
                                            <th style="">Create Date</th>
                                            <th style="">Last Login</th>
                                        </tr>
                                    </thead>
                                    <tbody>
										<?php 
					$num_rec_per_page=10;
					if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
					$start_from = ($page-1) * $num_rec_per_page; 
					$sql = "select * from admin order by 1 desc LIMIT $start_from, $num_rec_per_page"; 
					$rs_result =  $conn->query($sql); //run the query
					$no = 0;
					while($row = $rs_result->fetch_assoc()) { 
										$adminid=$row['id'];
										$fname=$row['fullname'];
										$uname=$row['username'];
										$pw=$row['password'];
										$email=$row['email'];
										$ph=$row['contact'];
										$cDate=$row['cDate'];
										$ll=$row['LLogin'];
										$no++;
										
										echo "
											<tr>
                                            <td style=''>$no</td>
                                            <td style=''>$fname</td>
                                            <td style=''>$uname</td>
                                            <td style=''>$pw</td>
                                            <td style=''>$email</td>
                                            <td style=''>$ph</td>
                                            <td style=''>$cDate</td>
                                            <td style=''>$ll</td>
											<td style=''><a href='addAdmin.php?id=$adminid' class='btn btn-primary' title='EDIT'><i class='fa fa-edit'></i> EDIT</a></td>
											<td style=''><a href='admins.php?id=$adminid&delete=true' class='btn btn-danger' title='DELETE'><i class='fa fa-trash'></i> DELETE</a></td>	
                                        </tr>
												
										  ";
}


?>
								</tbody>	
                                </table>
                            </div>
							<?php



$get_items="select * from admin";
$run_items=mysqli_query($conn,$get_items);
$count_items=mysqli_num_rows($run_items);
$total_pages = ceil($count_items / $num_rec_per_page); 

echo "		
						<div style='text-align: center;'>
								<ul class='pagination pagination-sm pull-center'>
                                      <li><a href='admins.php?page=1'>«</a></li>
							"; // Goto 1st page  

for ($i=1; $i<=$total_pages; $i++) { 
            echo "
						<li><a href='admins.php?page=".$i."'>".$i."</a></li>
							"; 
}; 
echo "
						
                                      <li><a href='admins.php?page=$total_pages''>»</a></li>
                                  </ul>
						</div>
							  "; // Goto last page
?>
                        </div>
                    </div>

                    </div>
             

            </div>
           
          
        </div>
    </div>
    <!-- CONTENT-WRAPPER SECTION END-->
    <footer style="background-color:#071A30">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    Copyright &copy; <?php echo date("Y"); ?> | ALL RIGHTS RESERVED. 
                </div>

            </div>
        </div>
    </footer>
    <!-- FOOTER SECTION END-->
    <!-- JAVASCRIPT AT THE BOTTOM TO REDUCE THE LOADING TIME  -->
    <!-- CORE JQUERY SCRIPTS -->
    <script src="assets/js/jquery-1.11.1.js"></script>
    <!-- BOOTSTRAP SCRIPTS  -->
    <script src="assets/js/bootstrap.js"></script>
</body>
</html>
