<?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">Change Account Password</h4>
                  <p class="card-description">
                    Note: By changing filling the form below you would be changing your account password. The username remains the same.
                  </p>
                  <?php
                  if(isset($_POST['change'])){
                    require_once("conn.php");

                    $old_password = mysqli_real_escape_string($dbconfig, $_POST['old_password']);
                    $new_password = mysqli_real_escape_string($dbconfig, $_POST['new_password']);
                    $retype_new_password = mysqli_real_escape_string($dbconfig, $_POST['retype_new_password']);

                    if($old_password != $dbpassword){
                      echo '<div align="center" class=" alert alert-danger">
                              <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                              <strong>Warning!</strong> Incorrect Old Password
                            </div>';
                    } elseif($new_password != $retype_new_password){
                      echo '<div align="center" class=" alert alert-danger">
                              <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                              <strong>Warning!</strong> New Passwords Don\'t Match
                            </div>';
                    } else {
                      $sql = "UPDATE accounts SET password='$new_password' WHERE id='$dbid'";

                      if ($dbconfig->query($sql) === TRUE) {
                        header("Refresh: 2; url=dashboard");
                        echo '<div align="center" class="alert alert-success">Your <b>Account Password</b> was changed successfully...</div>';
                      }
                    }
                  }
                  ?>
                  <form class="forms-sample" action="" method="POST">
                    <div class="form-group">
                      <label for="exampleInputUsername1">Old Password<sup style="color: red;">*</sup></label>
                      <input type="password" class="form-control" id="exampleInputUsername1" name="old_password" minlength="6" required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputUsername1">New Password<sup style="color: red;">*</sup></label>
                      <input type="password" class="form-control" id="exampleInputUsername1" name="new_password" minlength="6" required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputUsername1">Retype New Password<sup style="color: red;">*</sup></label>
                      <input type="password" class="form-control" id="exampleInputUsername1" name="retype_new_password" minlength="6" required>
                    </div>
                    <button type="submit" class="btn btn-primary mr-2" name="change">Change Password</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>
