<?php
session_start();

require('../includes/database.php');

if (isset($_SESSION['username']) && $_SESSION['password'] != "") {
} else {
    header("Location:index.php");
}
$username = $_SESSION['username'];


$username = $_SESSION['username'];
$password = $_SESSION['password'];

$query = "SELECT *
			FROM admin	
			WHERE username = '$username'
			&&   password = '$password'";

$result = mysqli_query($con, $query) or die(mysqli_connect_error());
$rows = mysqli_num_rows($result);
if ($rows == 1) {
    while ($data = mysqli_fetch_assoc($result)) {

        extract($data);
        include('head.php');

?>

        <body class="theme-blush">

            <!-- Page Loader -->
            <?php
            include('loader.php');
            ?>

            <!-- Overlay For Sidebars -->
            <div class="overlay"></div>

            <!-- Main Search -->
            <div id="search">
                <button id="close" type="button" class="close btn btn-primary btn-icon btn-icon-mini btn-round">x</button>
                <form>
                    <input type="search" value="" placeholder="Search..." />
                    <button type="submit" class="btn btn-primary">Search</button>
                </form>
            </div>

            <?php
            include('right-sidebar.php');
            include('left-side.php');
            ?>


            <!-- Right Sidebar -->
            <?php
            include('settings&pops.php');
            ?>

            <!-- Main Content -->

            <section class="content">
                <div class="">
                    <div class="block-header">
                        <div class="row">
                            <div class="col-lg-7 col-md-6 col-sm-12">
                                <h2>Loan Application</h2>
                                <ul class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="dashboard.php"><i class="zmdi zmdi-home"></i> Online Bank </a></li>
                                    <li class="breadcrumb-item active">loan</li>
                                </ul>
                                <button style="background:red;" class="btn btn-icon mobile_menu" type="button"><i class="zmdi zmdi-sort-amount-desc"></i></button>
                            </div>
                            <div class="col-lg-5 col-md-6 col-sm-12">
                                <button style="background:red;" class="btn btn-icon float-right right_icon_toggle_btn" type="button"><i class="zmdi zmdi-arrow-right"></i></button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <div class="row clearfix">
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <div style="margin-top: -20px;" class="card project_list">
                                    <div class="header">
                                        <h2>All Recent Loan Application</h2>
                                    </div>
                                    <div class="table-responsive">
                                        <table class="table table-hover c_table text-center">
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>Acc Number</th>
                                                    <th>Username</th>
                                                    <th>Type</th>
                                                    <th>Amount</th>
                                                    <th>Duration</th>
                                                    <th>Delete</th>
                                                    <th>Action</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                require('../includes/database.php');
                                                $query = "SELECT * FROM loan ORDER BY id DESC";
                                                $result = mysqli_query($con, $query) or die(mysqli_connect_error());
                                                $i = 0;
                                                while ($row = mysqli_fetch_assoc($result)) {
                                                    $i = $i + 1;
                                                ?>
                                                    <tr>
                                                        <td><strong><?php echo $i ?></strong></td>
                                                        <td><?php echo $row['account_number']; ?></td>
                                                        <td><?php echo $row['username']; ?></td>
                                                        <td><?php echo $row['type']; ?></td>
                                                        <td><?php echo number_format($row['amount'], 2); ?></td>
                                                        <td><?php echo $row['duration']; ?></td>
                                                        <?php $id = ($row['id']); ?>
                                                        <td>
                                                            <form action="../bank-manager.php?action=delete-loan-app" method="post">
                                                                <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                                                                <input style="background:red;" type="submit" value="Delete" class="btn-xs btn-danger form-control">
                                                            </form>
                                                        </td>
                                                        <td>
                                                            <?php $status = ($row['status']);
                                                            if ($status == 'Unapproved' || ($status == 'Processing')) {
                                                            ?>
                                                                <form action="../bank-manager.php?action=loan-approve" method="post">
                                                                    <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                                                                    <input style="background:blue;" type="submit" value="Approve" class="btn-xs btn-danger form-control">
                                                                </form>
                                                            <?php } else { ?>
                                                                <form action="../bank-manager.php?action=loan-decline" method="post">
                                                                    <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
                                                                    <input style="background:red;" type="submit" value="Decline" class="btn-xs btn-danger form-control">
                                                                </form>
                                                            <?php } ?>
                                                        </td>
                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <ul class="pagination pagination-primary mt-4">
                                        <li class="page-item active"><a class="page-link" href="javascript:void(0);">1</a></li>
                                        <li class="page-item"><a class="page-link" href="javascript:void(0);">2</a></li>
                                        <li class="page-item"><a class="page-link" href="javascript:void(0);">3</a></li>
                                        <li class="page-item"><a class="page-link" href="javascript:void(0);">4</a></li>
                                        <li class="page-item"><a class="page-link" href="javascript:void(0);">5</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
                </div>
            </section>

    <?php include('footer.php');
    }
} ?>