<?php
require("header.php")
?>


<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>Payment Setting</h1> -->
        </div>
        <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-md-12">

          <!-- general form elements -->

          <div class="card card-secondary">
            <div class="card-header">
              <h3 class="card-title">Add Bank Details</h3>
              <ol class="breadcrumb float-sm-right">
                <li class="breadcrumb-item">Setting</li>
                <li class="breadcrumb-item active">Payment Setting</li>
              </ol>
            </div>
            <!-- /.card-header -->
            <div class="card-body">


              <form class="form-horizontal" action="bank_details_code.php" method="post">

                <div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">Account Holder Name <span style="color:red; font-size:18px;">*</span> :</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" maxlength="20" name="holder_name" placeholder="Enter account holder name!">

                  </div>
                </div>
                <div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">Bank Name <span style="color:red; font-size:18px;">*</span>: </label>
                  <div class="col-sm-10">
                    <select class="form-control" name="bank_name">
                      <option value="SBI Bank">SBI Bank</option>
                      <option value="HDFC Bank">HDFC Bank</option>
                      <option value="Axis Bank">Axis Bank</option>
                      <option value="Bank of India">Bank of India</option>
                      <!-- Add more options as needed -->
                    </select>
                  </div>
                </div>

                <div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">Account Number <span style="color:red; font-size:18px;">*</span>: </label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="account_number" placeholder="Enter account number!">

                  </div>
                </div>
                <div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">Account Type <span style="color:red; font-size:18px;">*</span>: </label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="payment_type" placeholder="Enter account type!">

                  </div>
                </div>
                <div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">IFSC Code <span style="color:red; font-size:18px;">*</span>: </label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="ifsc_code" placeholder="Enter IFSC code!">

                  </div>
                </div>


                <div class="form-group row offset-sm-2">
                  <div class="offset-sm-0 col-sm-3">
                    <button type="submit" class="btn btn-dark" name="submit" style="width:100%;margin-top: 16%;">Submit</button>
                  </div>

                </div>

              </form>


            </div><!-- /.card-body -->
          </div>


        </div>
        <!-- /.card -->


      </div>

    </div>

    <!-- /.row -->

    <!-- /.container-fluid -->
  </section>
  <section class="content">
    <div class="container-fluid">
      <div class="row">

        <div class="col-md-12">

          <!-- general form elements -->

          <div class="card card-secondary">
            <div class="card-header">
              <h3 class="card-title">View Bank Details</h3>
              <ol class="breadcrumb float-sm-right">
                <li class="breadcrumb-item">Setting</li>
                <li class="breadcrumb-item active">Payment Setting</li>
              </ol>
            </div>
            <!-- /.card-header -->
            <div class="card-body">

              <table id="example1" class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>Date</th>
                    <th>Holder Name</th>
                    <th>Bank Name</th>
                    <th>Account Number</th>
                    <th>Account Type</th>
                    <th>IFSC Code</th>
                    <th>Edit</th>

                  </tr>
                </thead>
                <tbody>
                  <?php
                  include('connection.php');
                  $uname = $_SESSION['username'];
                  $sql = "SELECT * FROM bank_details WHERE added_by='$uname' ORDER BY date_time ";
                  $res = mysqli_query($conn, $sql);
                  while ($row = mysqli_fetch_assoc($res)) {

                  ?>

                    <tr>
                      <td><?php echo $row['date_time'];  ?></td>
                      <td><?php echo $row['holder_name'];  ?></td>
                      <td><?php echo $row['bank_name'];  ?></td>
                      <td><?php echo $row['payment_type'];  ?></td>
                      <td><?php echo $row['account_number'];  ?></td>
                      <td><?php echo $row['ifsc_code'];  ?></td>
                      <td>
                        <button type="button" class="btn btn-link" style="color:blue;font-weight:600;" data-toggle="modal" data-target="#exampleModalCenter_<?php echo $row['id']; ?>">
                          <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
                      </td>
                    </tr>

                  <?php
                  }
                  ?>
                  <!-- Modal -->
                  <?php
                  $sql = "SELECT * FROM bank_details";
                  $res = mysqli_query($conn, $sql);

                  while ($row = mysqli_fetch_array($res)) {
                  ?>
                    <div class="modal fade" id="exampleModalCenter_<?php echo $row['id']; ?>" 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">Modal title</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                              <span aria-hidden="true">&times;</span>
                            </button>
                          </div>
                          <div class="modal-body">
                            <form action="bank_details_update.php" method="post">

                              <div class="form-group row">
                                <label for="inputName" class="col-sm-4 col-form-label">Holder Name <span style="color:red; font-size:18px;">*</span> :</label>
                                <div class="col-sm-8">
                                  <input type="text" class="form-control" maxlength="20" name="holder_name" value="<?php echo $row['holder_name'];  ?>"placeholder="Enter account holder name!">
                                  <input type="hidden" class="form-control" maxlength="20" name="id" value="<?php echo $row['id'];  ?>" placeholder="Enter account holder name!">

                                </div>
                              </div>
                              <div class="form-group row">
                                <label for="inputName" class="col-sm-4 col-form-label">Bank Name <span style="color:red; font-size:18px;">*</span>: </label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="bank_name">
                                        <?php
                                        // Define an array of bank names
                                        $bankNames = ["SBI Bank", "HDFC Bank", "Axis Bank", "Bank of India"]; // Add more options as needed

                                        // Loop through the array and generate the options
                                        foreach ($bankNames as $option) {
                                            // Check if the current option matches the database value
                                            $isSelected = ($row['bank_name'] == $option) ? 'selected' : '';

                                            // Output the option element with the selected attribute if needed
                                            echo "<option value='$option' $isSelected>$option</option>";
                                        }
                                        ?>
                                    </select>
                                </div>
                            </div>

                              <div class="form-group row">
                                <label for="inputName" class="col-sm-4 col-form-label">Account Number <span style="color:red; font-size:18px;">*</span>: </label>
                                <div class="col-sm-8">
                                  <input type="text" class="form-control" name="account_number" value="<?php echo $row['account_number'];  ?>" placeholder="Enter account number!">

                                </div>
                              </div>
                              <div class="form-group row">
                                <label for="inputName" class="col-sm-4 col-form-label">Account Type <span style="color:red; font-size:18px;">*</span>: </label>
                                <div class="col-sm-8">
                                  <input type="text" class="form-control" name="payment_type" value="<?php echo $row['payment_type'];  ?>" placeholder="Enter account type!">

                                </div>
                              </div>
                              <div class="form-group row">
                                <label for="inputName" class="col-sm-4 col-form-label">IFSC Code <span style="color:red; font-size:18px;">*</span>: </label>
                                <div class="col-sm-8">
                                  <input type="text" class="form-control" name="ifsc_code" value="<?php echo $row['ifsc_code'];  ?>"  placeholder="Enter IFSC code!">

                                </div>
                              </div>


                              <div class="form-group row offset-sm-2">
                                <div class="offset-sm-0 col-sm-3">
                                  <button type="submit" class="btn btn-dark" name="update" style="width:100%;margin-top: 16%;">Submit</button>
                                </div>

                              </div>

                            </form>


                            </form>
                          </div>

                        </div>
                      </div>
                    </div>
                  <?php } ?>
                  <!-- modal end -->
                </tbody>

              </table>

            </div><!-- /.card-body -->
          </div>


        </div>
        <!-- /.card -->


      </div>

    </div>

    <!-- /.row -->

    <!-- /.container-fluid -->
  </section>
  <!-- /.content -->
</div>
<!-- for searching -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Sweet Alert  start-->
<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 1) { ?>
  <script>
    Swal.fire(
      'Good job!',
      ' Added Successfully!!',
      'success'
    ).then(() => {
      window.location.href = "bank_details.php";
    });
  </script>
<?php } ?>

<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 2) { ?>
  <script>
    Swal.fire(
      'Oops...',
      'Something went wrong!!',
      'error'
    ).then(() => {
      window.location.href = "bank_details.php";
    });
  </script>
<?php } ?>

<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 3) { ?>
  <script>
    Swal.fire(
      'Oops...',
      'Already Added This Bank Name',
      'error'
    ).then(() => {
      window.location.href = "bank_details.php";
    });
  </script>
<?php } ?>
<?php
require("footer.php")
?>