<?php session_start(); include"../connect/db.php" ?>    
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Admin| Users</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Font Awesome -->
 <!-- Font Awesome -->
 <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- DataTables -->
  <link rel="stylesheet" href="../plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">
  <!-- Google Font: Source Sans Pro -->
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Navbar -->
  <nav class="main-header navbar navbar-expand navbar-white navbar-light">
    <!-- Left navbar links -->
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
      </li>
      <li class="nav-item d-none d-sm-inline-block">
       
      </li>
      <li class="nav-item d-none d-sm-inline-block">
   
      </li>
    </ul>

    <!-- SEARCH FORM -->
    
    <!-- Right navbar links -->
    <ul class="navbar-nav ml-auto">
      <!-- Messages Dropdown Menu -->
      
      <!-- Notifications Dropdown Menu -->
      
      <li class="nav-item">
        <a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#" role="button">
          <i class="fas fa-th-large"></i>
        </a>
      </li>
    </ul>
  </nav>
  <!-- /.navbar -->

  <!-- Main Sidebar Container -->


  <?php           


?> 
  <aside class="main-sidebar sidebar-dark-primary elevation-4">
    <!-- Brand Logo -->
    <a href="index3.html" class="brand-link">
      <img src="../dist/img/AdminLTELogo.png"
           alt="AdminLTE Logo"
           class="brand-image img-circle elevation-3"
           style="opacity: .8">
      <span class="brand-text font-weight-light">Admin</span>
    </a>

    <!-- Sidebar -->

    <?php include"includes/sidebar.php" ?>        
 
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Loans</h1>
            
          <div class="col-sm-6">
        
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
   
      <div class="container-fluid">
        
     
        <div class="row">
        
       
          
          <div class="col-12">
        
         
         
            <!-- /.card -->
            <!-- /.card -->

            <div class="card">
              <div class="card-header">
                <h3 class="card-title"><?php $maga = mysqli_real_escape_string($con, $_GET['user'] ?? ''); echo htmlspecialchars($maga ?: 'All') ?> Loans</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <table id="example1" class="table table-bordered table-striped ">
                  <thead>
                  <tr>
                                                        <th scope="col">#</th>
                                                        <th scope="col">User</th>
                                                        <th scope="col">Amount</th>
                                                        <th scope="col">Date</th>
                                                        <th scope="col">Credit Facility</th>
                                                        <th scope="col">Tenure</th>
                                                        <th scope="col">Edit Loan</th>                    
                                                        <th scope="col">Delete</th>
                                                       
                                                    </tr>     

   <!-- Button trigger modal -->
   <span id="scamBtn" style="display: none" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
    </span>

    <!-- Modal -->
    <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Edit User</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="card">
                <div class="card-body card-profile">
                    
                </div>
            </div> 
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
                                                    
                  </thead>
                  <tbody> 
                  <?php
                                                        $tosin = mysqli_query($con,"SELECT * FROM loan WHERE user = '$maga'");
                                                        $transactions = mysqli_num_rows($tosin);
                                                        if( $transactions == 0 ){
                                                            echo'
                                                                <tr>
                                                                    <td colspan="8">Oops! No Beneficiary have been made</td>
                                                                </tr>
                                                            '
                                                            ;
                                                        }
                                                        else{
                                                            $i = 1;
                                                            while( $tosin_req = mysqli_fetch_assoc($tosin) ){
                                                                echo'
                                                                <tr>
                                                                <td>'.$i.'</td>
                                                                <td>'.$tosin_req['user'].'</td>
                                                                <td>'.$tosin_req['amt'].'</td>
                                                                <td>'.$tosin_req['date'].'</td>
                                                                <td>'.$tosin_req['credit_facility'].'</td>
                                                                <td>'.$tosin_req['tenure'].'</td>

                                                                <td><a href= "editloan.php?user='.$tosin_req['id'].'" ><span class="btn btn-sm btn-success"><i class="fa fa-edit"></i></span><a/></td>
                                                                <td><span onclick={deleteBen("'.$tosin_req['user'].'")} class="btn btn-sm btn-danger"><i class="fa fa-trash"></i></span></td>
                                                              
                                                            </tr>
                                                                '
                                                                ;
                                                                $i++ ;
                                                            }                                                    
                                                        }
                                                    ?>                   
                                                </tbody>
                  <tfoot>
                  <tr>
                  <th scope="col">#</th>
                                                        <th scope="col">User</th>
                                                        <th scope="col">Amount</th>
                                                        <th scope="col">Date</th>
                                                        <th scope="col">Credit Facility</th>
                                                        <th scope="col">Tenure</th>

                                                        <th scope="col">Edit Loan</th>
                                                                              
                                                        <th scope="col">Delete</th>
                                                    </tr>     
                  </tfoot>
                </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
      <!-- MODAL CREATE TRANSACTION -->
      <span id="scamBtn" style="display: none" class="btn btn-primary" data-toggle="modal" data-target="#profileModal">
    </span>

    <!-- Modal -->
    <div class="modal fade" id="profileModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="card">
                <div class="card-body card-profile">
                           
                </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
    

    <!-- Button trigger modal -->
    <span id="scamBtn2" style="display: none" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenterPic">
    </span>

    <!-- Modal -->
    <div class="modal fade" id="exampleModalCenterPic" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Edit Profile</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="card">
                <div class="card-body card-profile-pic">
                    
                </div>
            </div> 
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>    

    <!-- Modal -->
   
    </div>
    <div class="modal fade" id="depositModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
          <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <?php

              $maga = mysqli_real_escape_string($con, $_GET['user'] ?? '');
          $vanila = mysqli_query($con,"SELECT * FROM transactions  WHERE user = '$maga' ");
          $crow = mysqli_fetch_assoc($vanila);
          ?>
              <div class="modal-body">
              <div class="card">
                                    <div class="card-body">
                                        <div class="login-form">
                                    <form class="regForm form">
                                        <div class="form-group" style="text-align: center;">
                                        <p style="font-size: 2.1rem;
    font-weight: 300;
    margin-bottom: .9rem;
    text-align: center;"> Midlight Credit Union </p>
                                            <img id="blah" src="../dist/img/avatar.png" style="margin: 20px;    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);" class="img-thumbnail" alt="your image">
                                            <input style="margin:0 auto;" type="file" class="form-control-file" id="profile-pic" name="profile-pic" >                                   
                                        </div>
                                        <div class="form-group">
                                            <label for="acc_num">Account Number</label>
                                            <input class="form-control"  type="text" name="acc_num" value="<?=$maga?>" placeholder="Account Number" readonly>
                                        </div>                                        
                                        <div class="form-group">
                                            <label for="f_name">Title</label>
                                            <input class="form-control" type="text" name="title" placeholder="Title">
                                        </div>
                                        <div class="form-group">
                                            <label for="f_name">Full Name</label>
                                            <input class="form-control" type="text" name="f_name" placeholder="First Name">
                                        </div>
                                        <div class="form-group">
                                            <label for="m_name">Middle Name</label>
                                            <input class="form-control" type="text" name="m_name" placeholder="Middle Name">
                                        </div>                                        
                                        <div class="form-group">
                                            <label for="l_name">Last Name</label>
                                            <input class="form-control" type="text" name="l_name" placeholder="Last Name">
                                        </div>
                                        <div class="form-group">
                                            <label for="phone">Mobile Number</label>
                                            <input class="form-control" type="text" name="phone" placeholder="Mobile Number">
                                        </div>                                                      
                                        <div class="form-group">
                                            <label for="email">Email</label>
                                            <input class="form-control" type="email" name="email" placeholder="Email">
                                        </div>
                                        <div class="form-group">
                                            <label for="relationship">Relationship</label>
                                            <input class="form-control" type="email" name="relationship" placeholder="Relationship">
                                        </div>                                        
                                        <div class="form-group">
                                            <label for="d_o_b">Date Of Birth</label>
                                            <input class="form-control" type="date" name="d_o_b" placeholder="Date Of Birth" style="border:1px soild #E5E5E5; height:45px">
                                        </div>   
                                        <div class="form-group">
                                            <label for="gender">Gender</label>
                                            <select id="gender" name="gender" class="form-control">
                                                <option value="">--Select Gender--</option>
                                                <option value="Male">Male</option>
                                                <option value="Female">Female</option>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="address">Home Address</label>
                                            <textarea rows="4" class="form-control" name="address" id="address" placeholder="Address"></textarea>
                                        </div>
                                        <div class="form-group">
                                            <label for="city">City</label>
                                            <input class="form-control" type="text" name="city" placeholder="City">
                                        </div>
                                        <div class="form-group">
                                            <label for="state">State</label>
                                            <input class="form-control" type="text" name="state" placeholder="State">
                                        </div>
                                        <div class="form-group">
                                            <label for="zip_code">Zip Code</label>
                                            <input class="form-control" type="text" name="zip_code" placeholder="Zip Code">
                                        </div>
                                        <span onclick="sbtBen()" style="text-align:center; background-color:#03d0ea;" class="btn btn-success">register</span>
                                    </form>    
                                </div>
                                    </div>
                                </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
              </div>
            </div>
          </div>
        </div> 
  <!-- /.content-wrapper -->




  <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
          <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <?php

              $maga = mysqli_real_escape_string($con, $_GET['user'] ?? '');
          $vanila = mysqli_query($con,"SELECT * FROM beneficiary  WHERE user = '$maga' ");
          $crow = mysqli_fetch_assoc($vanila);
          ?>


                        
                             <div class="modal-body">
                            <div class="card">
                                    <div class="card-body">
                                        <div class="login-form">
                                    <form class="regForm form">
                                        <div class="form-group" style="text-align: center;">
                                        <p style="font-size: 2.1rem;
                                               font-weight: 300;
                                                      margin-bottom: .9rem;
                                                                  text-align: center;"> Midlight Credit Union </p>
                                            <img id="blah" src="../dist/img/avatar.png" style="margin: 20px;    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);" class="img-thumbnail" alt="your image">
                                            <input style="margin:0 auto;" type="file" class="form-control-file" id="profile-pic" name="profile-pic" >                                   
                                        </div>
                                        <div class="form-group">
                                            <label for="acc_num">Account Number</label>
                                            <input class="form-control"  type="text" name="acc_num" value="<?=$maga?>" placeholder="Account Number" readonly>
                                        </div>                                        
                                        <div class="form-group">
                                            <label for="f_name">Title</label>
                                            <input class="form-control" type="text" name="title" placeholder="Title">
                                        </div>
                                        <div class="form-group">
                                            <label for="f_name">Full Name</label>
                                            <input class="form-control" type="text" name="f_name" placeholder="First Name">
                                        </div>
                                        <div class="form-group">
                                            <label for="m_name">Middle Name</label>
                                            <input class="form-control" type="text" name="m_name" placeholder="Middle Name">
                                        </div>                                        
                                        <div class="form-group">
                                            <label for="l_name">Last Name</label>
                                            <input class="form-control" type="text" name="l_name" placeholder="Last Name">
                                        </div>
                                        <div class="form-group">
                                            <label for="phone">Mobile Number</label>
                                            <input class="form-control" type="text" name="phone" placeholder="Mobile Number">
                                        </div>                                                      
                                        <div class="form-group">
                                            <label for="email">Email</label>
                                            <input class="form-control" type="email" name="email" placeholder="Email">
                                        </div>
                                        <div class="form-group">
                                            <label for="relationship">Relationship</label>
                                            <input class="form-control" type="email" name="relationship" placeholder="Relationship">
                                        </div>                                        
                                        <div class="form-group">
                                            <label for="d_o_b">Date Of Birth</label>
                                            <input class="form-control" type="date" name="d_o_b" placeholder="Date Of Birth" style="border:1px soild #E5E5E5; height:45px">
                                        </div>   
                                        <div class="form-group">
                                            <label for="gender">Gender</label>
                                            <select id="gender" name="gender" class="form-control">
                                                <option value="">--Select Gender--</option>
                                                <option value="Male">Male</option>
                                                <option value="Female">Female</option>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="address">Home Address</label>
                                            <textarea rows="4" class="form-control" name="address" id="address" placeholder="Address"></textarea>
                                        </div>
                                        <div class="form-group">
                                            <label for="city">City</label>
                                            <input class="form-control" type="text" name="city" placeholder="City">
                                        </div>
                                        <div class="form-group">
                                            <label for="state">State</label>
                                            <input class="form-control" type="text" name="state" placeholder="State">
                                        </div>
                                        <div class="form-group">
                                            <label for="zip_code">Zip Code</label>
                                            <input class="form-control" type="text" name="zip_code" placeholder="Zip Code">
                                        </div>
                                        <span onclick="sbtBen()" style="text-align:center; background-color:#03d0ea;" class="btn btn-success">register</span>
                                    </form>    
                                </div>
                                    </div>
                                </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
              </div>
            </div>
          </div>
        </div> 









  <footer class="main-footer">
    <div class="float-right d-none d-sm-block">
      <b>Version</b> 1.0.0
    </div>
    <strong>Copyright &copy; 2021 <a href="#">Swagalomo's Admin</a>.</strong> All rights
    reserved.
  </footer>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables -->
<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script>
<!-- page script -->

<script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true,
      "autoWidth": false,
    });
    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script>

<script src="js/sweetalert2.all.min.js" ></script>

<!-- Main JS-->
<script src="js/main.js"></script>
<script src="js/custom.js"></script>
<script>

        function readURL(input) {
          if (input.files && input.files[0]) {
            var reader = new FileReader();
            
            reader.onload = function(e) {
              $('#blah').attr('src', e.target.result);
            }
            
            reader.readAsDataURL(input.files[0]);
          }
        }

        $("#profile-pic").change(function() {
          readURL(this);
        });

        function readURL1(input) {
          if (input.files && input.files[0]) {
            var reader = new FileReader();
            
            reader.onload = function(e) {
              $('#blah1').attr('src', e.target.result);
            }
            
            reader.readAsDataURL(input.files[0]);
          }
        }

        $("#profile-pic-update").change(function() {
          readURL(this);
        });
    function sly(x){
        x.type='date';
    }
</script>    
</body>
</html>
