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

if(isset($_GET['del']))
{
	$delete_id=$_GET['del'];
	$acc_id=$_GET['login_id'];

	$deletep1="delete from users where uID='$delete_id'";
	$run1 = $conn->query($deletep1);

	$deletep2="delete from account where memID='$acc_id'";
	$run2 = $conn->query($deletep2);

	$deletep4="delete from settings where memID='$acc_id'";
	$run4 = $conn->query($deletep4);

	if($run1 && $run2 && $run4){
		echo '<script>alert("Record Deleted Successfully!")</script>';
		echo '<script>window.location.href = "client_records.php";</script>';
	}
}

if(isset($_GET['activate']))
{
	$act=$_GET['uid'];

	$deletep1="update users set status=1 where uID='$act'";
	$run1 = $conn->query($deletep1);

	if($run1){
		echo '<script>alert("User Account Activated Successfully!")</script>';
		echo '<script>window.location.href = "client_records.php";</script>';
	}	
}

if(isset($_GET['disable']))
{
	$act=$_GET['uid'];

	$deletep1="update users set status=2 where uID='$act'";
	$run1 = $conn->query($deletep1);

	if($run1){
		echo '<script>alert("User Account Disabled Successfully!")</script>';
		echo '<script>window.location.href = "client_records.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-user" style="font-size:30px;color:white"></i> CLIENT RECORDS
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Full Name</th>
                                            <th>Email</th>
                                            <th>Login ID</th>
                                            <th>Password</th>
                                            <th>Last Logged On</th>
                                            <th>Account Status</th>
                                            <th></th>
                                            <th></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 users order by uID asc LIMIT $start_from, $num_rec_per_page"; 
					$rs_result =  $conn->query($sql); //run the query
					$no = 0;
					while($row = $rs_result->fetch_assoc()) { 
										$uid=$row['uID'];
										$fname=$row['fn'];
										$lname=$row['ln'];
										$add=$row['address'];
										$ct=$row['townCity'];
										$st=$row['state'];
										$count=$row['country'];
										$pz=$row['zip'];
										$ph=$row['pNumber'];
										$em=$row['email'];
										$dob=$row['dob'];
										$gen=$row['gender'];
										$nat=$row['nation'];
										$occ=$row['occu'];
										$acc=$row['memID'];
										$pw=$row['pass'];
										$cd=$row['cDate'];
										$ll=$row['LLogin'];
										$pic=$row['picture'];
										$st=$row['status'];
										$no++;
										
										if(empty($ll)){
										   $ll_ = "";
										}else{
										   $ll_ = date("jS M, Y h:ia",strtotime("".$ll.""));
										}
										
										if($st=="1"){
											$stat = "<td style='text-align: center;'><span style='color: blue; font-weight: bold;'>Active</span><br> <a href='client_records.php?uid=$uid&disable=true' class='btn btn-warning'>Disable Account</a></td>";
										}else{
											$stat = "<td style='text-align: center;'><span style='color: darkred; font-weight: bold;'>Disabled</span><br> <a href='client_records.php?uid=$uid&activate=true' class='btn btn-primary'>Activate Account</a></td>";
										}
										
										echo "
												<tr>
													<td>$no</td>
													<td>$fname $lname</td>
													<td>$em</td>
													<td>$acc</td>
													<td>$pw</td>
													<td>".$ll_."</td>
													$stat
													<td><a href='client_info.php?id=$uid' title='VIEW DETAILS' class='btn btn-primary'>MANAGE CLIENT</a></td>
													<td><a href='client_records.php?del=$uid&login_id=$acc' title='DELETE' class='btn btn-danger'><i class='fa fa-trash'></i> DELETE</a></td>
												</tr>											
										  ";
}


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



$get_items="select * from users";
$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='client_records.php?page=1'>«</a></li>
							"; // Goto 1st page  

for ($i=1; $i<=$total_pages; $i++) { 
            echo "
						<li><a href='client_records.php?page=".$i."'>".$i."</a></li>
							"; 
}; 
echo "
						
                                      <li><a href='client_records.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>
