<?php 
session_start();
require('../db.php');
include('inc/access.php');
							

								
if(isset($_GET['email'])){
					
$res_user = $_GET['email'];	
					
							
$mems = "SELECT * FROM users WHERE email='$res_user'  ";
$details = $conn->query($mems);
}							
							
include('../inc/logo.php');								
?> 
<?php include('inc/header.php');?>

<body class="fixed-nav sticky-footer bg-dark" id="page-top">
  <!-- Navigation-->
         
 <?php include('inc/nav.php');?>       
  <!-- Navigation Ends--> 
      </ul>
    </div>
  </nav>
  <div class="content-wrapper">
    <div class="container-fluid">
      <!-- Breadcrumbs-->
      <ol class="breadcrumb">
        <li class="breadcrumb-item">
          <a href="dashboard.php">Dashboard</a>
        </li>
        <li class="breadcrumb-item active">Activation / </li>
      </ol>
      <div class="row">
        <div class="col-12">
          
          <div class="card mb-3">
        <div class="card-header">
          <i class="fa fa-table"></i> <?php echo $data['firstname']; ?> <?php echo $data['lastname']; ?> </div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
            <thead>
              <tr>
                <th>Name</td>
                <th>Email Address</td>
                <th>Phone</td>
                <th>Status</td>
                <th>Email</td>
              
              </tr>
              </thead>
             
              <tbody>      
                <tr>
                <?php 
				
				while( $row_details = $details->fetch_assoc())
				
				{
				
				?>
                  <td><?php echo $row_details['firstname']; ?> <?php echo $row_details['lastname']; ?></td>
                  <td><?php echo $row_details['email']; ?></td>
                  <td><?php echo $row_details['phone']; ?></td>
                  <td><?php echo $row_details['blockstat']; ?></td>
                  <td><?php echo $row_details['emailverify']; ?></td>
                  
                  <?php } ?>
                </tr>
                </tbody>
            </table>
             <?php
			 $mem = "SELECT * FROM users WHERE email='$res_user'  ";
			$rek_user = $conn->query($mem);
			
			 $user_data = mysqli_fetch_array($rek_user);
		  
		  if(isset($_POST['subt'])){
			  

		  $email = $_POST['email'];
		  $status = $_POST['status'];

		  if($status === "Email"){
		  $say = "Email Verified Successfully";    
		   $update = "UPDATE users set emailverify='Completed' WHERE email='$email'";
		  mysqli_query($conn,$update);
		  
		  }elseif($status === "Blocked"){
		      
		   $say = "Account Blocked Successfully";    
		   $update = "UPDATE users set blockstat='Blocked' WHERE email='$email'";
		  mysqli_query($conn,$update);
		  
		  }elseif($status === "Unblock"){
		      
		   $say = "Account Unblocked Successfully";    
		   $update = "UPDATE users set blockstat='Active' WHERE email='$email'";
		  mysqli_query($conn,$update);
		  
		  }else{
		  $say = "Account SET as $status Successfully";    
		   $update = "UPDATE users set status='$status' WHERE email='$email'";
		  mysqli_query($conn,$update);
		  }
		  
		 
		 
	
	// referral end
             if($update){
				 
				echo "$say<br>
				 <div class='btn btn-primary btn-block'>Redirecting....Please wait.</div>      
			<script> setTimeout(function(){window.location.href='dashboard.php';},5000);</script>";
			 }else{
			 echo "Account Action Failed";
			 }
		      
		  }
			 

		  
		   ?>
		   
          <form action="" method="post">
        <div class="form-group">
        <label><strong>Account Action:</strong></label>
		
 <select class="form-control" placeholder="Please Select Level" id="level" name="status" required="required" >
     <option value = "" selected="selected" required="required">Please Select Action</option>
                                       
<!--<option value="Active">Activate Account</option>
<option value="Pending">Deactivate Account</option>-->
<option value="Blocked">Block Account</option>
<option value="Unblock">Unblock Account</option>
<option value="Email">Verify Email</option>
</select>      
         
 <input name="email" type="hidden" value="<?php echo $user_data['email']; ?>">
          
<br>

         <input type="submit" value="Activate Account." name="subt" class="btn btn-primary">
          
          </form>
          </div>
        </div>
        <div class="card-footer small text-muted"></div>
      </div>
    </div>
    <!-- /.container-fluid-->
        </div>
      </div>
    </div>
    <!-- /.container-fluid-->
    <!-- /.content-wrapper-->
    <?php include('inc/footer.php');?>

