<?php

include("../config.php");
session_start();

if(isset($_SESSION["user_login"])){
	$userid = $_SESSION["user_login"];
}






	//SEARCH USERS LISTS
	
	if(isset($_POST["query"])){
	
	$key = htmlspecialchars($_POST["query"]);
	
    $stmt=$pdo->prepare("SELECT * FROM users WHERE fullName LIKE '%{$key}%' OR email LIKE '%{$key}%'");
    $stmt->execute();
    
	if($stmt->rowCount()<1){
		echo "<br><br><h2 style='color:#8d8d8d'>User not found</h2>";
	}else{
	
	echo '<div class="row" style="justify-content: space-evenly;">';
		
    $rows = $stmt->fetchAll();
    foreach($rows as $row){
    
	$userimage = (!empty($row["profilepix"]) ? "../img/users/".$row["profilepix"]: "../img/avatar.png");
		
	
	
?>


				
				
				<div class="col-md-4">
				<div class="card-box" style="background-image: radial-gradient(ellipse closest-side, rgba(255, 255, 255, 0),#f1f6fb); background-repeat:no-repeat; background-position:center; padding:12px;">
				
				<section style="display:flex">
				<div><img src="<?php echo $userimage;?>" class="avatars"></div>
				<div style="margin:18px 6px; font-size:18px; color:#405972; font-weight:500;">
				<?php echo htmlspecialchars($row["fullName"]);?><br>
				<div style="color:#405972; font-size:14px; margin-top:4px;">
				<?php if($row["userid"]==5){echo $row["email"];}else{echo 'Approved User';}?>
				</div>
			
				</section>
				
				<!--if its admin, then show profile button-->
				<?php if($row["userid"]==5){?>
				<a href="profile.php" style="color:#fff;">
				<div style="font-size:16px;margin:5px auto;padding:5px;" class="btn btn-primary btnss btn-block">
				Admin Profile &nbsp; <i class="fa fa-caret-right"></i>
				</div></a>
				<?php }else{?>
				
				<a href="userStats.php?getUser=<?php echo intval($row["userid"]);?>" style="color:#fff;">
				<div style="font-size:16px;margin:5px auto;padding:5px;" class="btn btn-primary btnss btn-block">
				User info &nbsp; <i class="fa fa-caret-right"></i>
				</div></a>
				
				<?php }?>
				
				</div>
				</div>
				
				
				
		<?php

   }
   
   echo '</div>';
	}
	
	}
	













	//SEARCH pending investments
	
	if(isset($_POST["pendingInv"])){
	
	$key = htmlspecialchars($_POST["pendingInv"]);
	
    $stmt=$pdo->prepare("SELECT * FROM users WHERE fullName LIKE '%{$key}%' OR email LIKE '%{$key}%'");
    $stmt->execute();
    
	if($stmt->rowCount()<1){
		echo "<br><br><h2 style='color:#8d8d8d'>User not found</h2>";
	}else{
	
	echo '<div class="row" style="justify-content: space-evenly;">';
		
    $rows = $stmt->fetchAll();
    foreach($rows as $row){
    
	$userimage = (!empty($row["profilepix"]) ? "../img/users/".$row["profilepix"]: "../img/avatar.png");
		
	
	
?>


				
				
				<div class="col-md-4">
				<div class="card-box" style="background-image: radial-gradient(ellipse closest-side, rgba(255, 255, 255, 0),#f1f6fb); background-repeat:no-repeat; background-position:center; padding:12px;">
				
				<section style="display:flex">
				<div><img src="<?php echo $userimage;?>" class="avatars"></div>
				<div style="margin:18px 6px; font-size:18px; color:#405972; text-align:left;font-weight:500;">
				<?php echo htmlspecialchars($row["fullName"]);?><br>
				<div style="color:#405972; font-size:14px; margin-top:4px;">
				<?php if($row["userid"]==5){echo $row["email"];}else{echo 'Approved User';}?>
				</div>
			
				</section>
				
				
				
				
				<?php 
				
				//Check if users have pending investment
				$sql=$pdo->prepare("SELECT * FROM transactions WHERE userid=:userid AND status='pending' AND type='investment'");
				$sql->bindParam(":userid", $row["userid"], PDO::PARAM_STR);
				$sql->execute();
				$trans = $sql->fetch();
				if($sql->rowCount()<1){
			
				echo "<br><br><h4 style='color:#8d8d8d; margin-top:-25px;font-size:16px;'>No Pending Investments</h4>";
				
				?>
				
				<!--if its admin, then show profile button-->
				<?php if($row["userid"]==5){?>
				<a href="profile.php" style="color:#fff;">
				<div style="font-size:16px;margin:5px auto;padding:5px;" class="btn btn-primary btnss btn-block">
				Admin Profile &nbsp; <i class="fa fa-caret-right"></i>
				</div></a>
				<?php }else{?>
				
				<a href="userStats.php?getUser=<?php echo intval($row["userid"]);?>" style="color:#fff;">
				<div style="font-size:16px;margin:5px auto;padding:5px;" class="btn btn-primary btnss btn-block">
				User info &nbsp; <i class="fa fa-caret-right"></i>
				</div></a>
				
				<?php } }else{?>
				
				
				<div style="color:#405972; font-size:15px; margin:10px auto;text-align:center">
				<b>Investment amount</b>&nbsp; $<?php echo number_format(intval($trans["amount"]));?>
				</div>
				
				<div class="dropdown-divider" style="border-color:#d4dee7;"></div>
				
				<div style="color:#405972; font-size:15px; margin:10px auto;text-align:center">
				<b>Investment Date</b>&nbsp; <?php echo date("jS F, Y", strtotime($trans["dateTime"]));?>
				</div>
				
				<a href="userStats.php?getUser=<?php echo intval($row["userid"]);?>" style="color:#fff;">
				<div style="font-size:16px;margin:5px auto;padding:5px;" class="btn btn-primary btnss btn-block">
				Preview Investment &nbsp; <i class="fa fa-caret-right"></i>
				</div></a>
				
				
					
				
				<?php }?>
				
				
				
				
				</div>
				</div>
				
				
				
		<?php

   }
   
   echo '</div>';
	}
	
	}
	
?>

