<?php  session_start(); error_reporting(0); 
//if session
if(isset($_SESSION['j_admin'])){ }else{ 
    die(
    "
    <div class='alert alert-danger'> Error 100. Try again.</div>
    "
    );
}
require_once("../j_conn/url.php");
require_once("../j_conn/dbc.php");
require_once("../j_incs/functions.php");
if(isset($_POST['search'])){ }else{ 
die(
"
<div class='alert alert-danger'> Error 101. Try again.</div>
"
);
}

$name_old = $name;
$phone_old = $phone;
$email_old = $email;
$username_old = $username;
//
$search = RMC($_POST["search"]);  
$i_url = RMC($_POST["url"]);  
if(!empty($search) 
 ){ //check if required field is not empty
}else{ die("<div class='alert alert-danger'> Enter Search.</div>");}  
//search now

if(strpos($i_url, 'users') !== false){
	$url = urlencode("".$dir."users/");
	if(isset($_SESSION['j_admin'])){
    $sql4="SELECT * from j_users WHERE 
    j_deleted < 1 AND j_gender LIKE '%".$search."%'
    || j_deleted < 1 AND j_username LIKE '%".$search."%'
    || j_deleted < 1 AND j_firstname LIKE '%".$search."%'
    || j_deleted < 1 AND j_lastname LIKE '%".$search."%'
    || j_deleted < 1 AND j_email LIKE '%".$search."%'
    || j_deleted < 1 AND j_phone LIKE '%".$search."%'
    || j_deleted < 1 AND j_country LIKE '%".$search."%'
    || j_deleted < 1 AND j_address LIKE '%".$search."%'
    || j_deleted < 1 AND j_date LIKE '%".$search."%'
    order by j_id desc limit 50"; //check  
    $result4 = runSQL($sql4);
	$count = mysqli_num_rows($result4);
}
}


if($count<1){
    die("<div class='alert alert-danger'> No record found. Try another search.</div>
    <script> $('[name=search]').css({'border-color': 'brown', 'border-width':'1px', 'border-style':'solid'});</script>
    ");
}
echo ("<script> $('[name=search]').css({'border-color': '#efefef', 'border-width':'1px', 'border-style':'solid'});</script>");
?>

<?php 
$num = 1;
?>
<div class="table-responsive m-t-10 my-content">
     <br/> <br/> <br/>
    <table style="font-size:11px;" class="table table-hover table-bordered">
        <thead>
				<tr>
					<th>S/N</th>
					  <th>Name</th>
					 <th>BTC Wallet</th>
					 <th>ETH Wallet</th>
					 <th>Gender</th>
						<th>Email</th>
					   <th>Password</th>
					   <th>Referrer</th>
					   <th>Referrals</th>
					   
					 <th>Date</th>
					  <th>Menu </th>
				  </tr>
			</thead>
		<tbody>
			<?php
			while ($row = mysqli_fetch_array($result4)){
			$cd = get_cd($row['j_currency']);
			$currency_in_use = $cd[0];
			$currency_code_in_use = $cd[1];
			$currency_sort_in_use = $cd[2];
				
			//get referrer name and username
			$sql2 = "SELECT * FROM j_users where j_id='".$row['j_referrer_id']."'";
			$result2 = runSQL($sql2);
			$data2 = mysqli_fetch_array($result2);
			$r_firstname = $data2['j_firstname'];
			$r_lastname = $data2['j_lastname'];
			$r_username = $data2['j_username'];
			$r_name = trim("$r_firstname $r_lastname");
			//count number of users referred
			 $sql44="SELECT j_referrer_id from j_users WHERE 
			 j_referrer_id='".$row['j_id']."' AND j_deleted < 1 
			 order by j_id desc"; //check 
			$result44 = runSQL($sql44);
			$total_ref = mysqli_num_rows($result44);
			//check if user has activated basic
			$sql41="SELECT * from j_pays WHERE j_user_id='".$row['j_id']."' AND j_paid > 0 AND j_deleted < 1 order by j_id desc";  
			$result41 = runSQL($sql41);
			$check = mysqli_num_rows($result41);
			$check_activate = $check; 
			//
			
			if($check_activate > 0){
				$pay_status = "<b style='color:green;'>Paid</b>";
			}else{
				$pay_status = "<b style='color:red;'>Unpaid</b>";
			}
			//
			$user_pass = base64_decode($row['j_password']);
			$user_pass = str_replace($hash,'',$user_pass);
			?>
			 
			<tr id="i<?php echo $row['j_id']; ?>">
				
				
				<td> <?php echo $num++; ?></td>
				 
				<td> <?php echo $row['j_firstname']; echo ' '; echo $row['j_lastname'] ?>
				<?php 
					if($row['j_blocked']<1){ ?>
					<i class="anticon anticon-check-o text-success"></i>
					<?php }else{ ?>
					<i class="anticon anticon-close-circle text-danger"></i>
					<?php } ?>
				</td>
				<td> <?php echo amount_w_c($row['j_wallet_btc'],'USD'); ?></td>
				<td> <?php echo amount_w_c($row['j_wallet_eth'],'USD'); ?></td>
				<td> <?php echo $row['j_gender']; ?></td>
				 <td> <?php echo $row['j_email']; ?></td>
				<td> <?php if($row['j_status'] < 1){ echo $user_pass; }else{ echo "***"; } ?></td>
				<td> 
					<?php 
						if(!empty($r_username)){
							echo "$r_username <em>$r_name</em>";
						}
					?>
				</td>
				
				<td> <?php  echo number_format($total_ref); ?></td>
				<?php /*<td> <?php  echo $pay_status; ?></td>*/ ?>
				
				
				<td> <?php echo FULL_DATE($row['j_date']); ?></td>
				
				
				<td>
					
					<div class="btn-group dropup">
					<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
						Options
					</button>
					<div class="dropdown-menu">
					 
					<a class="dropdown-item" href="<?php echo $dir; ?>profile?u=<?php echo ($row['j_id']); ?>">
						<i class="anticon anticon-eye"></i>
						<span class="m-l-10">View</span>
					</a>
					<div class="dropdown-divider"></div> 
					<a class="dropdown-item" href="<?php echo $dir; ?>users/login.php?t_id=<?php echo $row['j_id'];?>&b_url=<?php echo $url;?>">
						<i class="anticon anticon-login"></i>
						<span class="m-l-10">Log In</span>
					</a>
						
					<?php 
					if($row['j_status'] < 1){ ?>
					<div class="dropdown-divider"></div>
					<a class="dropdown-item" href="<?php echo $dir; ?>users/block-unblock.php?t_id=<?php echo $row['j_id'];?>&b_url=<?php echo $url;?>">
						<?php if($row['j_blocked']<1){ ?>
						<i class="anticon anticon-close-circle"></i>
						<span class="m-l-10">Block</span>
						<?php }else{ ?>
						<i class="anticon anticon-check"></i>
						<span class="m-l-10">UnBlock</span>
						<?php } ?>
					</a>
					<?php } ?>
					<?php 
					if($row['j_status'] < 1){ ?>
					<div class="dropdown-divider"></div>
					  <a class="dropdown-item" href="<?php echo $dir; ?>users/del.php?t_id=<?php echo $row['j_id'];?>&b_url=<?php echo $url;?>">
						<i class="fa fa-trash"></i>
						<span class="m-l-10">Delete</span>
					</a>
					<?php } ?>
		
					</div>
				</div>

					
				</td>
	
				
			
				
			</tr>
			<?php } ?>

		</tbody>
    </table>
    <br/> <br/>

</div>