<?php  session_start(); error_reporting(0); 
//if session
if(isset($_SESSION['j_admin']) || 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>
"
);
}
//exec('sox /mypath/my_audio.amr /mypath/my_audio.mp3');
$name_old = $name;
$phone_old = $phone;
$email_old = $email;
$username_old = $username;
//
$search = RMC($_POST["search"]);  
if(!empty($search) 
 ){ //check if required field is not empty
}else{ die("<div class='alert alert-danger'> Enter Search.</div>");}  
//search now

$sql4="SELECT * from j_pays WHERE 
j_deleted < 1 AND j_paid > 0 AND j_disburse < 1 AND j_kind='WITHDRAW' AND j_package LIKE '%".$search."%'
|| j_deleted < 1 AND j_paid > 0 AND j_disburse < 1 AND j_kind='WITHDRAW' AND j_amount LIKE '%".$search."%'
|| j_deleted < 1 AND j_paid > 0 AND j_disburse < 1 AND j_kind='WITHDRAW' AND j_kind LIKE '%".$search."%'
|| j_deleted < 1 AND j_paid > 0 AND j_disburse < 1 AND j_kind='WITHDRAW' AND j_transact_id LIKE '%".$search."%'
|| j_deleted < 1 AND j_paid > 0 AND j_disburse < 1 AND j_kind='WITHDRAW' AND j_date LIKE '%".$search."%'
|| j_deleted < 1 AND j_paid > 0 AND j_disburse < 1 AND j_kind='WITHDRAW' AND j_account_no LIKE '%".$search."%'
|| j_deleted < 1 AND j_paid > 0 AND j_disburse < 1 AND j_kind='WITHDRAW' AND j_account_name LIKE '%".$search."%'
|| j_deleted < 1 AND j_paid > 0 AND j_disburse < 1 AND j_kind='WITHDRAW' AND j_bank 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>");
?>
<div class="table-responsive m-t-10">
    <table class="table table-hover" style="font-size:11px;">
        <thead>
            <tr>
				<th>S/N</th>
				<?php if(isset($_SESSION['j_admin'])){  ?>
				  <th>User</th>
				<?php } ?>
				  <th>Reference ID</th>
				<th>Amount</th>
				  <th>Balance</th>
				<th>Recipient</th>
				<th>Date</th>
				<th>Status</th>
				
			 </tr>
        </thead>
        <tbody>
            <?php 
            $num = 1;
            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];
                
                //user profile
                $sql25="SELECT * from j_users WHERE 
                j_id='".$row['j_user_id']."'"; //  
                $result25 = runSQL($sql25);
                $data25 = mysqli_fetch_array($result25);
                $a_username = $data25['j_username'];
                $a_passport = $data25['j_passport'];
                $a_email = $data25['j_email'];
                $a_phone = $data25['j_phone'];
                $a_firstname = $data25['j_firstname'];
                $a_lastname = $data25['j_lastname'];
                $a_name = "$a_firstname $a_lastname"; $a_name = trim($a_name);

                ?>
                <tr>
					<td> <?php echo $num++; ?>. </td>
					<?php if(isset($_SESSION['j_admin'])){  ?>
					<td> <?php echo $a_name; ?> </td>
					<?php } ?>
					<td> <?php echo $row['j_transact_id']; ?> </td>
					  <td> <?php echo amount_w_c($row['j_amount'],$row['j_currency']); ?> </td>
					  <td> <?php echo amount_w_c($row['j_bal'],$row['j_currency']); ?> </td>
					<td> [<?php echo $row['j_bank']; ?> - <?php echo $row['j_account_no']; ?>] </td>
					 <td> <?php echo time_ago($row['j_date']); ?> </td>
					 <td> <?php 
						if($row['j_disburse'] > 0){
						 echo "<span class='text-success'>Paid</span>";
						}else{
							 if(isset($_SESSION['j_admin'])){
								echo "<span class='text-warning'><a href='".$dir."confirm-transfer/?r=".$row['j_transact_id']."'>Confirm</a></span>";
							 }else{
								echo "<span class='text-warning'>Pending</span>";
							 }
						}
						 ?> 
					</td>
				</tr>
				
             <?php } ?>
        </tbody>
    </table>

</div>