<?php ob_start();
include("security.php"); ?>
<?php require_once('../setup.php'); ?>
<!DOCTYPE html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title><?= $main_capital_name; ?></title>
  <!-- plugins:css -->
  <link rel="stylesheet" href="vendors/feather/feather.css">
  <link rel="stylesheet" href="vendors/ti-icons/css/themify-icons.css">
  <link rel="stylesheet" href="vendors/css/vendor.bundle.base.css">
  <!-- endinject -->
  <!-- Plugin css for this page -->
  <link rel="stylesheet" href="vendors/datatables.net-bs4/dataTables.bootstrap4.css">
  <link rel="stylesheet" href="vendors/ti-icons/css/themify-icons.css">
  <link rel="stylesheet" type="text/css" href="js/select.dataTables.min.css">
  <link rel="stylesheet" href="vendors/mdi/css/materialdesignicons.min.css">
  <!-- End plugin css for this page -->
  <!-- inject:css -->
  <link rel="stylesheet" href="css/vertical-layout-light/style.css">
  <!-- endinject -->
  <link rel="shortcut icon" href="../assets/images/logo.png" />
</head>

<body>
  <div class="container-scroller">
    <!-- partial:partials/_navbar.html -->
    <?php include('topbar.php'); ?>
    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
      <!-- partial:partials/_sidebar.html -->
      <?php include('nav.php'); ?>
      <!-- partial -->
      <div class="main-panel">
        <div class="content-wrapper">
          <div class="row">
            <div class="col-md-6 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h4 class="card-title">Quick Loan Application Form</h4>
                  <p class="card-description">
                    Please, carefully fill required details below to apply for a loan.
                  </p>
                  <?php

                    use PHPMailer\PHPMailer\PHPMailer;

                    if (isset($_POST['apply'])) {
                      require_once("conn.php");
                      //Send Debit Alert
                      require 'PHPMailer/src/Exception.php';

                      /* The main PHPMailer class. */
                      require 'PHPMailer/src/PHPMailer.php';

                      /* SMTP class, needed if you want to use SMTP. */
                      require 'PHPMailer/src/SMTP.php';

                      $date = date('Y');

                      /* Create a new PHPMailer object. */
                      $mail = new PHPMailer();

                      /* Set the mail sender. */
                      $mail->setFrom($dbemail);

                      /* Add a recipient. */
                      $mail->addAddress($main_email_support, $main_name);

                      /* Set the subject. */
                      $mail->Subject = 'Loan Application';

                      /* Set the mail message body. */
                      $mail->isHTML(TRUE);
                      $mail->Body = '<html>
                        <head>
                          <meta http-equiv="Content-Type" content="text/html;charset=charset=utf-8" />
                          <title>' . $main_name . '</title>
                          </head>
                          <body>
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tbody>
                                <tr>
                                  <td valign="middle" align="center" style="background-color:#333; border-bottom:3px solid #7b59d0;"><h1 style="color:#fff;"><span style="color:#7b59d0; font-weight:bolder;">' . $main_name . '</span></h1></td>
                                </tr>
                                <tr>
                                  <td style="background-color:#fff; padding:10px;" align="justify" width="100">
                                    <p><u><b>Loan Application Form</b></u></p>
                                    <table border="0">
                                      <tr>
                                        <td>Borrower Name</td>
                                        <td>'.$_POST['borrower_name'].'</td>
                                      </tr>
                                      <tr>
                                        <td>Borrower Address</td>
                                        <td>'.$_POST['borrower_address'].'</td>
                                      </tr>
                                      <tr>
                                        <td>Property Address</td>
                                        <td>'.$_POST['property_address'].'</td>
                                      </tr>
                                      <tr>
                                        <td>Property Value</td>
                                        <td>'.$_POST['property_value'].'</td>
                                      </tr>
                                      <tr>
                                        <td>Loan Amount</td>
                                        <td>'.$_POST['loan_amount'].'</td>
                                      </tr>
                                      <tr>
                                        <td>Purpose of Loan</td>
                                        <td>'.$_POST['loan_purpose'].'</td>
                                      </tr>
                                      <tr>
                                        <td>Telephone Number</td>
                                        <td>'.$_POST['phone'].'</td>
                                      </tr>
                                      <tr>
                                        <td>Email Address</td>
                                        <td>'.$_POST['email'].'</td>
                                      </tr>
                                  </td>
                                </tr>
                                <tr>
                                  <td valign="middle" align="center" style="background-color:#333; border-top:3px solid #7b59d0; padding:10px; color:#fff;">© <span style="color: #7b59d0;">' . $main_name . '</span> ' . $date . '.  All Rights Reserved</td>
                                </tr>
                              </tbody>
                            </table>
                          </body>
                        </html>';
                      /* Finally send the mail. */
                      if ($mail->send()) {
                        header("Refresh: 5; url=dashboard");
                        echo '<div align="center" class=" alert alert-success">You have successfully submitted your application form<br><b>We would get back to you shortly!</b></div>';
                      }
                    }
                  ?>
                  <form class="forms-sample" action="" method="POST">
                    <div class="form-group">
                      <label for="exampleInputUsername1">Borrower Name<sup style="color: red;">*</sup></label>
                      <input style="text-transform: capitalize;" type="text" class="form-control" id="exampleInputUsername1" value="<?= $dbfirst_name . ' ' . $dbmiddle_initial . ' ' . $dblast_name; ?>" name="borrower_name" readonly required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputUsername1">Borrower Address<sup style="color: red;">*</sup></label>
                      <input style="text-transform: capitalize;" type="text" class="form-control" id="exampleInputUsername1" value="<?= $dbaddress; ?>" name="borrower_address" readonly required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputUsername1">Property Address<sup style="color: red;">*</sup></label>
                      <input type="text" class="form-control" id="exampleInputUsername1" placeholder="eg. Bronx, NY 10465" value="<?php if (isset($_POST['property_address'])) {
                                                                                                                                    echo $_POST['property_address'];
                                                                                                                                  } ?>" name="property_address" required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputUsername1">Property Value<sup style="color: red;">*</sup></label>
                      <input type="number" class="form-control" id="exampleInputUsername1" placeholder="eg. 37,000.00" value="<?php if (isset($_POST['property_value'])) {
                                                                                                                                echo $_POST['property_value'];
                                                                                                                              } ?>" name="property_value" required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputUsername1">Loan Amount Requested<sup style="color: red;">*</sup></label>
                      <input type="number" class="form-control" id="exampleInputUsername1" placeholder="eg. 105,000.00" value="<?php if (isset($_POST['loan_amount'])) {
                                                                                                                                  echo $_POST['loan_amount'];
                                                                                                                                } ?>" name="loan_amount" required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputUsername1">Purpose of Loan<sup style="color: red;">*</sup></label>
                      <input type="text" class="form-control" id="exampleInputUsername1" placeholder="eg. New Car" value="<?php if (isset($_POST['loan_purpose'])) {
                                                                                                                                    echo $_POST['loan_purpose'];
                                                                                                                                  } ?>" name="loan_purpose" required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputUsername1">Telephone Number<sup style="color: red;">*</sup></label>
                      <input style="text-transform: capitalize;" type="text" class="form-control" id="exampleInputUsername1" value="<?= $dbphone; ?>" name="phone" readonly required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputUsername1">Email Address<sup style="color: red;">*</sup></label>
                      <input style="text-transform: capitalize;" type="text" class="form-control" id="exampleInputUsername1" value="<?= $dbemail; ?>" name="email" readonly required>
                    </div>
                    <button type="submit" class="btn btn-primary mr-2" name="apply">Apply For Loan</button>
                    <a href="dashboard" class="btn btn-light">Cancel</a>
                  </form>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- content-wrapper ends -->
        <!-- partial:partials/_footer.html -->
        <footer class="footer">
          <?php
          include('footer.php');
          ?>
        </footer>
        <!-- partial -->
      </div>
      <!-- main-panel ends -->
    </div>
    <!-- page-body-wrapper ends -->
  </div>
  <!-- container-scroller -->

  <!-- plugins:js -->
  <script src="vendors/js/vendor.bundle.base.js"></script>
  <!-- endinject -->
  <!-- Plugin js for this page -->
  <script src="vendors/chart.js/Chart.min.js"></script>
  <script src="vendors/datatables.net/jquery.dataTables.js"></script>
  <script src="vendors/datatables.net-bs4/dataTables.bootstrap4.js"></script>
  <script src="js/dataTables.select.min.js"></script>

  <!-- End plugin js for this page -->
  <!-- inject:js -->
  <script src="js/off-canvas.js"></script>
  <script src="js/hoverable-collapse.js"></script>
  <script src="js/template.js"></script>
  <script src="js/settings.js"></script>
  <script src="js/todolist.js"></script>
  <!-- endinject -->
  <!-- Custom js for this page-->
  <script src="js/dashboard.js"></script>
  <script src="js/Chart.roundedBarCharts.js"></script>
  <!-- End custom js for this page-->
  <?php include('../chat.php'); ?>
</body>

</html>
