<?php
require_once("../../app/config.php");
$id=$_GET['id'];
$row=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM users where id='$id'")); 
$title=$row['name'];
require_once('../include/user_header.php');
require_once('../include/user_navbar.php');
require_once('../include/user_sidebar.php');
if(empty($row['image_link'])){
  $cast="../asset/global_assets/images/placeholders/placeholder.jpg";
}else{
  $cast="../asset/profile/".$row['image_link'];
}?>
<div class="content-wrapper">

      <!-- Page header -->
      <div class="page-header page-header-light">
        <div class="page-header-content header-elements-md-inline">
          <div class="page-title d-flex">
            <h4><i class="icon-user-plus mr-2"></i> <span class="font-weight-semibold"><?php echo $row['name'];?> Profile</span></h4>
          </div>
        </div>

        <div class="breadcrumb-line breadcrumb-line-light header-elements-md-inline">
          <div class="d-flex">
            <div class="breadcrumb">
              <a href="./" class="breadcrumb-item"><i class="icon-home2 mr-2"></i> Home</a>
              <a href="./users" class="breadcrumb-item">Users</a>
              <a href="./manage_users/<?php echo $id;?>" class="breadcrumb-item">Profile</a>
            </div>
          </div>

          <div class="header-elements d-none">
            <div class="breadcrumb justify-content-center">
            </div>
          </div>
        </div>
      </div>
      <div class="content">
<?php
if($row['active']==0){
  if($set['email_activation']==1){
    if($eset['status']==1){?>
        <div class="alert bg-info alert-styled-left alert-arrow-left alert-dismissible">
          <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
          <h6 class="alert-heading font-weight-semibold mb-1">Email verification</h6>
          User account has not yet been verified, account funding is currently disabled until this account is verified.
          </div>
<?php
    }
  }
}?>
<div class="row">
  <div class="col-md-8">
     <?php if($set['kyc']==1){?>
        <div class="card">
          <div class="card-header header-elements-inline">
            <h6 class="card-title font-weight-semibold">Kyc verification</h6>
            <div class="header-elements">
              <div class="list-icons text-orange-600">
                  <a class="list-icons-item" data-action="collapse"></a>
              </div>
            </div>
          </div>
          <div class="table-responsive">
            <table class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>#</th>
                  <th class="text-center">Verification</th>
                  <th class="text-center">Status</th>
                  <th class="text-center">Action</th>
                </tr>
              </thead>
              <tbody>
              <tr>
                <td>Identification verification</td>
                <td class="text-center"><?php if($row['kyc_status']==0){echo'unverified';}else{echo'verified';}?></td>
                <td class="text-center"><?php if(!empty($row['kyc_link'])){?><a href="../asset/profile/<?php echo $row['kyc_link'];?>">view</a><?php }else{echo'No file';}?></td>
                <td class="text-center">
                  <div class="list-icons">
                    <div class="dropdown">
                        <a href="#" class="list-icons-item" data-toggle="dropdown">
                          <i class="icon-menu9"></i>
                        </a>
                      <div class="dropdown-menu dropdown-menu-right">
                        <?php 
                        if($row['kyc_status']!=1) {
                        if(!empty($row['kyc_link'])){?> 
                        <a class='dropdown-item' href ='../app/admin?id=akyc&stat=<?php echo $row['id'];?>'><i class="icon-eye mr-2"></i>Approve</a>
                        <?php }}if(!empty($row['kyc_link'])){?>
                        <a class='dropdown-item' href ='../app/admin?id=rkyc&stat=<?php echo $row['id']; ?>'><i class="icon-eye-blocked2 mr-2"></i>Reject</a>
                        <?php }?> 
                      </div>
                    </div>
                  </div>
                </td>             
                  </tr> 
                  <tr>
                    <td>Address verification</td>
                <td class="text-center"><?php if($row['add_status']==0){echo'unverified';}else{echo'verified';}?></td>
                <td class="text-center"><?php if(!empty($row['add_link'])){?><a href="../asset/profile/<?php echo $row['add_link'];?>">view</a><?php }else{echo'No file';}?></td>
                <td class="text-center">
                  <div class="list-icons">
                    <div class="dropdown">
                        <a href="#" class="list-icons-item" data-toggle="dropdown">
                          <i class="icon-menu9"></i>
                        </a>
                      <div class="dropdown-menu dropdown-menu-right">
                        <?php
                        if($row['add_status']!=1) {
                        if(!empty($row['add_link'])){?> 
                        <a class='dropdown-item' href ='../app/admin?id=aadd&stat=<?php echo $row['id'];?>'><i class="icon-eye mr-2"></i>Approve</a>
                        <?php } }if(!empty($row['add_link'])){?>
                        <a class='dropdown-item' href ='../app/admin?id=radd&stat=<?php echo $row['id']; ?>'><i class="icon-eye-blocked2 mr-2"></i>Reject</a>
                        <?php }?> 
                      </div>
                    </div>
                  </div>
                </td>
                  </tr>
              </tbody>
            </table>
          </div>
        </div>
        <?php }?>
        <div class="card">
          <div class="card-header header-elements-inline">
            <h6 class="card-title font-weight-semibold">Update account information</h6>
                <div class="header-elements">
                  <div class="list-icons text-orange-600">
                  <a class="list-icons-item" data-action="collapse"></a>
                </div>
              </div>
          </div>

          <div class="card-body">
            <form action="../app/admin/profile" method="post">
                <div class="form-group row">
                  <label class="col-form-label col-lg-2">Username:</label>
                  <div class="col-lg-10">
                    <input type=""hidden value="<?php echo $row['id']; ?>"name="user_id">
                    <input type="text" name="username" class="form-control" value="<?php echo $row['username'];?>">
                  </div>
                </div>
               <div class="form-group row">
                  <label class="col-form-label col-lg-2">Name:</label>
                  <div class="col-lg-10">
                    <input type="text" name="name" class="form-control" value="<?php echo $row['name'];?>">
                  </div>
                </div>  
               <div class="form-group row">
                  <label class="col-form-label col-lg-2">Email:</label>
                  <div class="col-lg-10">
                    <input type="email" name="email" class="form-control" readonly value="<?php echo $row['email'];?>">
                  </div>
                </div>
               <div class="form-group row">
                  <label class="col-form-label col-lg-2">Mobile:</label>
                  <div class="col-lg-10">
                    <input type="text" name="mobile" class="form-control" value="<?php echo $row['phonenumber'];?>">
                  </div>
                </div>
                <div class="form-group row">
                    <label class="col-form-label col-lg-2">Balance:</label>
                    <div class="col-lg-10">
                      <div class="input-group">
                        <span class="input-group-prepend">
                          <span class="input-group-text"><?php echo $scan2['currency'];?></span>
                        </span>
                      <input type="number" name="dep_bal" max-length="10" value="<?php echo $row['dep_balance'];?>" class="form-control">
                        </div>
                      </div>
                  </div> 
              <div class="form-group row">
                <label class="col-form-label col-lg-2">2fa Status <span class="text-danger">*</span></label>
                <div class="col-lg-10">
                  <div class="form-check form-check-inline form-check-switchery">
                    <label class="form-check-label">
              <?php if($row['2fa_status']=='1'){
                  echo'<input type="checkbox" name="2fa_status" class="form-check-input-switchery" value="1" checked>';
              }else{
                  echo'<input type="checkbox" name="2fa_status" class="form-check-input-switchery" value="1">';
              }?>     
                      </label>
                  </div>
                </div>
              </div>                
              <div class="text-right">
                <button type="submit" class="btn bg-<?php echo $set['dashboard_color'];?>">Update<i class="icon-paperplane ml-2"></i></button>
              </div>
            </form>
          </div>
        </div>
  </div>
  <div class="col-md-4">
    <div class="card">
      <div class="card-body text-center">
        <div class="card-img-actions d-inline-block mb-3">
          <img class="img-fluid rounded-circle" src="<?php echo $cast;?>" width="120" height="120" alt="">
        </div>
          <h6 class="font-weight-semibold mb-0"><?php echo $row['name'];?></h6>
        </div>
      </div>
      <div class="card">
        <div class="card-body">
          <div class="d-sm-flex align-item-sm-center flex-sm-nowrap">
            <div>
              <ul class="list list-unstyled mb-0">
                <li>Merchant ID: <span class="font-weight-semibold">[#<?php echo $row['token'];?>]</span></li>
                <li>Country: <span class="font-weight-semibold"><?php echo $row['country'];?></span></li>
                <li>Joined: <span class="font-weight-semibold"><?php echo date("Y/m/d h:i:A", strtotime($row['date']));?></span></li>
                <li>Last Login: <span class="font-weight-semibold"><?php echo date("Y/m/d h:i:A", strtotime($row['last_login']));?></span></li>
              </ul>
            </div>
            <div class="text-sm-right mb-0 mt-3 mt-sm-0 ml-auto">
              <ul class="list list-unstyled mb-0">
                <?php if($row['active']==0){echo'<li>Account Status: <span class="badge bg-danger-800 font-weight-semibold">Not verified</span></li>';}else{echo'<li>Account Status: <span class="badge bg-success-800 font-weight-semibold">Verified</span></li>';}?>
                
              </ul>
            </div>
          </div>
        </div>
        <div class="card-footer d-sm-flex justify-content-sm-between align-items-sm-center">
          <span>
            <span class="badge badge-mark border-success mr-2"></span>
            IP Address:
            <span class="font-weight-semibold"><?php echo $row['ip_address'];?></span>
          </span>
        </div>
      </div>
  </div> 
</div> 
  <div class="row">
    <div class="col-md-12">
      <div class="card">
        <div class="card-body">
          <ul class="nav nav-tabs justify-content-center nav-tabs-highlight nav-justified">
            <li class="nav-item"><a href="#basic-tab3" class="nav-link active" data-toggle="tab">Credit account</a></li>
            <li class="nav-item"><a href="#basic-tab4" class="nav-link" data-toggle="tab">Debit account</a></li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane fade show active" id="basic-tab3">
          <div class="card-body">
            <form action="../app/admin/credit" method="post">
                <div class="form-group row">
                  <label class="col-form-label col-lg-2">Amount:</label>
                  <div class="col-lg-10">
                    <div class="input-group">
                      <span class="input-group-prepend">
                        <span class="input-group-text"><?php echo $scan2['currency'];?></span>
                      </span>
                    <input type="number" name="amount" step="any" max-length="10" class="form-control">
                    <input type="hidden" value="<?php echo $row['id']; ?>"name="user_id">
                      </div>
                    </div>
                </div> 
               <div class="form-group row">
                  <label class="col-form-label col-lg-2">Description:</label>
                  <div class="col-lg-10">
                    <textarea type="text" name="content" class="form-control"></textarea>
                  </div>
                </div>                
              <div class="text-right">
                <button type="submit" class="btn bg-<?php echo $set['dashboard_color'];?>">Update<i class="icon-paperplane ml-2"></i></button>
              </div>
            </form>
          </div>
              </div>
            <div class="tab-pane fade" id="basic-tab4">
              <div class="card-body">
                <form action="../app/admin/debit" method="post">
                    <div class="form-group row">
                      <label class="col-form-label col-lg-2">Amount:</label>
                      <div class="col-lg-10">
                        <div class="input-group">
                          <span class="input-group-prepend">
                            <span class="input-group-text"><?php echo $scan2['currency'];?></span>
                          </span>
                        <input type="number" name="amount" step="any" max-length="10" class="form-control">
                        <input type="hidden" value="<?php echo $row['id']; ?>"name="user_id">
                          </div>
                        </div>
                    </div> 
                   <div class="form-group row">
                      <label class="col-form-label col-lg-2">Description:</label>
                      <div class="col-lg-10">
                        <textarea type="text" name="content" class="form-control"></textarea>
                      </div>
                    </div>                
                  <div class="text-right">
                    <button type="submit" class="btn bg-<?php echo $set['dashboard_color'];?>">Update<i class="icon-paperplane ml-2"></i></button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12">
      <div class="card">
        <div class="card-body">
          <ul class="nav nav-tabs justify-content-center nav-tabs-highlight nav-justified">
            <li class="nav-item"><a href="#basic-tab1" class="nav-link active" data-toggle="tab">Credit</a></li>
            <li class="nav-item"><a href="#basic-tab2" class="nav-link" data-toggle="tab">Debit</a></li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane fade show active" id="basic-tab1">
              <table class="table datatable-show-all">
                  <a href="javascript:void;" onclick="window.print();" class="pull-right text-default"><i class="icon-printer2 mr-2"></i>PRINT</a>
                <thead>
                  <tr>
                    <th>#</th>                                                                       
                    <th>Reference</th>                                                                       
                    <th>Amount</th>                                                                       
                    <th>Details</th>                                                                       
                    <th>Date</th>      
                    <th>Seen</th>      
                  </tr>
                </thead>
                <tbody>  
                  <?php
                  $trans = mysqli_query($dbc, "SELECT * FROM tran_acct WHERE user_id = '".$row['id']."' AND type=1  ORDER BY tran_acct.date DESC");
                  while($row1 = mysqli_fetch_array($trans)){?>
                  <tr>
                    <td><?php echo $index++;?>.</td>
                    <td>#<?php echo $row1['ref'];?></td>
                    <td><?php echo number_format($row1['amount']).$scan2['currency'];?></td>
                    <td><?php echo $row1['content'];?></td>
                    <td><?php echo date("Y/m/d h:i:A", strtotime($row1['date'])); ?></td>
                    <td><?php if($row1['seen']==0){echo '<span class="badge badge-danger">No</span>';}else if($row1['seen']==1){echo '<span class="badge badge-success">Yes</span>';}?></td>
                  </tr>
                  <?php }?> 
                </tbody>
              </table>
              </div>
            <div class="tab-pane fade" id="basic-tab2">
              <table class="table datatable-show-all">
                <a href="javascript:void;" onclick="window.print();" class="pull-right text-default"><i class="icon-printer2 mr-2"></i>PRINT</a>
                <thead>
                  <tr>
                    <th>#</th>                                                                       
                    <th>Reference</th>                                                                       
                    <th>Amount</th>                                                                       
                    <th>Details</th>                                                                       
                    <th>Date</th>   
                    <th>Seen</th>   
                  </tr>
                </thead>
                <tbody>  
                 <?php
                  $trans = mysqli_query($dbc, "SELECT * FROM tran_acct WHERE user_id = '".$row['id']."' AND type=2  ORDER BY tran_acct.date DESC");
                  while($row1 = mysqli_fetch_array($trans)){?>
                  <tr>
                    <td><?php echo $index++;?>.</td>
                    <td>#<?php echo $row1['ref'];?></td>
                    <td><?php echo number_format($row1['amount']).$scan2['currency'];?></td>
                    <td><?php echo $row1['content'];?></td>
                    <td><?php echo date("Y/m/d h:i:A", strtotime($row1['date'])); ?></td>
                    <td><?php if($row1['seen']==0){echo '<span class="badge badge-danger">No</span>';}else if($row1['seen']==1){echo '<span class="badge badge-success">Yes</span>';}?></td>
                  </tr>
                  <?php }?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12">
      <div class="card">
        <div class="card-body">
          <ul class="nav nav-tabs justify-content-center nav-tabs-highlight nav-justified">
            <li class="nav-item"><a href="#basic-tab1" class="nav-link active" data-toggle="tab">Own bank</a></li>
            <li class="nav-item"><a href="#basic-tab2" class="nav-link" data-toggle="tab">Other bank</a></li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane fade show active" id="basic-tab1">
              <table class="table datatable-show-all">
                  <a href="javascript:void;" onclick="window.print();" class="pull-right text-default"><i class="icon-printer2 mr-2"></i>PRINT</a>
                <thead>
                  <tr>
                      <th>#</th>                                                                       
                      <th>Reference</th>                                                                       
                      <th>Amount</th>                                                                       
                      <th>Sender</th>                                                                       
                      <th>Receiver</th>                                                                       
                      <th>Acct no</th>                                                                       
                      <th>Type</th>                                                                       
                      <th>Date</th>   
                      <th>Status</th>   
                  </tr>
                </thead>
                <tbody>  
                  <?php
                  $trans = mysqli_query($dbc, "SELECT * FROM transfers WHERE (status=1 AND sender_id = '".$row['id']."') OR (status=1 AND receiver_id = '".$row['id']."')");
                  while($row1 = mysqli_fetch_array($trans)){
                  $sender=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM users WHERE id='".$row1['sender_id']."'"));
                  $receiver=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM users WHERE id='".$row1['receiver_id']."'"));?>
                  <tr>
                  <td><?php echo $index++;?>.</td>
                  <td>#<?php echo $row1['ref_id'];?></td>
                  <td><?php echo number_format($row1['amount']).$scan2['currency'];?></td>
                  <td><?php echo $sender['name'];?></td>
                  <td><?php echo $receiver['name'];?></td>
                  <td>#<?php echo $receiver['acct_no'];?></td>
                  <td><?php if($row1['type']==1){echo'Bank Transfer';}else if($row1['type']==2){echo'Bank charges';}?></td>
                  <td><?php echo date("Y/m/d h:i:A", strtotime($row1['date'])); ?></td>
                  <td><span class="badge badge-success">Successful</span></td>
                  </tr>
                  <?php }?> 
                </tbody>
              </table>
              </div>
            <div class="tab-pane fade" id="basic-tab2">
              <table class="table datatable-show-all">
                <a href="javascript:void;" onclick="window.print();" class="pull-right text-default"><i class="icon-printer2 mr-2"></i>PRINT</a>
                <thead>
                  <tr>
                      <th>#</th>                                                                       
                      <th>Reference</th>                                                                       
                      <th>Amount</th>                                                                       
                      <th>Sender</th>                                                                     
                      <th>Details</th>                                                                       
                      <th>Type</th>                                                                       
                      <th>Date</th>   
                      <th>Status</th>   
                  </tr>
                </thead>
                <tbody>  
                  <?php
                  $trans = mysqli_query($dbc, "SELECT * FROM int_transfer WHERE  user_id = '".$row['id']."'");
                  $index=1;
                  while($row1 = mysqli_fetch_array($trans)){
                  $sender=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM users WHERE id='".$row1['user_id']."'"));
                  ?>
                  <tr>
                  <td><?php echo $index++;?>.</td>
                  <td>#<?php echo $row1['ref_id'];?></td>
                  <td><?php echo number_format($row1['amount']).$scan2['currency'];?></td>
                  <td><?php echo $sender['name'];?></td>
                  <td><?php echo $row1['details'];?></td>
                  <td><?php if($row1['type']==1){echo'Bank Transfer';}else if($row1['type']==2){echo'Bank charges';}?></td>
                  <td><?php echo date("Y/m/d h:i:A", strtotime($row1['date'])); ?></td>
                  <td><?php if($row1['status']==1){echo'<span class="badge badge-success">Successful</span>';}
                  else{echo'<span class="badge badge-danger">Pending</span>';}?></td> 
                  </tr>
                  <?php }?> 
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>     