<?php

include("includes/header.php"); 
include("includes/sidebar.php");

if(isset($_GET['detailid'])){
    
    $id = $_GET['detailid'];
    
    $details = $db_handle->runBaseQuery("SELECT * FROM bank_details WHERE id = $id");
    
    $bank_name = $details[0]['bank_name'];
    $acc_no = $details[0]['acc_no'];
    $acc_name = $details[0]['acc_name'];
    
}

if(isset($_POST['edit'])){
    if (!isset($_POST['csrf_token']) || !$csrf->validateToken($_POST['csrf_token'])) {
        die("CSRF token validation failed!");
    }
    $bank_name = $db_handle->sanitize($_POST['bank_name']);
    $acc_no = $db_handle->sanitize($_POST['acc_no']);
    $acc_name = $db_handle->sanitize($_POST['acc_name']);
    $date = date("d-m-Y h:i:sa");

   

    $update = $db_handle->update("UPDATE bank_details SET bank_name = ?,acc_no = ?, acc_name = ? WHERE id = ?","sssi",array($bank_name,$acc_no,$acc_name,$id));

if($update){

$_SESSION['msg-s'] = "Bank Details added successfully";
}else{
$_SESSION['msg-e'] = "Could not add bank details";
}
}

 ?>
 <div class="main-content app-content">
<div class="container-fluid">
                            
                            <!--Modal: order-modal-->
                            <div class="modal fade" id="order-modal" tabindex="-1" role="dialog"
                                aria-labelledby="exampleModalLabel" aria-hidden="true">
                                <div class="modal-dialog modal-notify modal-info" role="document">
                                    <div class="modal-content text-center">
                                        <div class="modal-header d-flex justify-content-center">
                                            <p class="heading">Be up to date</p>
                                        </div>
                                        <div class="modal-body"><i class="fa fa-bell fa-4x animated rotateIn mb-4"></i>
                                            <p>New order arrived</p>
                                        </div>
                                        <div class="modal-footer flex-center">
                                            <a role="button" class="btn btn-outline-secondary-modal waves-effect"
                                                onClick="window.location.reload();"
                                                data-bs-dismiss="modal">Okay</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                                <h5 class="text-uppercase">
        Edit Bank Details</h5>
    <div class="row settings mt-3">

        

        <?php if (isset($_SESSION['msg-s'])) { ?>
        <div class="alert alert-success alert-dismissible">
                    <button type="button" class="close" data-bs-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-check"></i> Success!</h4> <?php echo $_SESSION['msg-s']; ?>
                </div>
<?php unset($_SESSION['msg-s']); } ?>

<?php if (isset($_SESSION['msg-e'])) { ?>
        <div class="alert alert-danger alert-dismissible" role="alert">
                    <button type="button" class="close" data-bs-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-check"></i> Error!</h4> <?php echo $_SESSION['msg-e']; ?>
                </div>
<?php unset($_SESSION['msg-e']); } ?>
        
        <div class="col-xl-12">
            <div id="settingmenuContent">
                
                                <div id="editprofile">
                    <div class="row mb-5">
                        <div class="col-12">
                            <div class="card border-0 box-shadow">
                                <div class="card-body pb-0">
                                    <div class="d-flex align-items-center mb-3">
                                        <h5 class="text-uppercase">Edit Bank Details</h5>
                                    </div>
                                    <form method="POST"
                                        action=""
                                        enctype="multipart/form-data">
                                         <?php echo $csrf->csrfInput(); ?>                                    <div class="row">
                                            <div class="form-group col-sm-6">
                                                <label class="form-label">Bank Name<span
                                                        class="text-danger"> * </span></label>
                                                <input type="text" class="form-control" name="bank_name"
                                                    value="<?php echo $bank_name; ?>"
                                                    placeholder="Bank Name" required>

                                            </div>
                                            
                                            <div class="form-group col-sm-6">
                                                <label class="form-label">Account Number<span
                                                        class="text-danger"> * </span></label>
                                                <input type="text" class="form-control" name="acc_no"
                                                    value="<?php echo $acc_no; ?>"
                                                    placeholder="Account Number" required>

                                            </div>

                                            <div class="form-group col-sm-6">
                                                <label class="form-label">Account Name<span
                                                        class="text-danger"> * </span></label>
                                                <input type="text" class="form-control" name="acc_name"
                                                    value="<?php echo $acc_name; ?>"
                                                    placeholder="Account Name" required>

                                            </div>
                                                 
                                               
                                                
                                                                                        <div class="form-group text-end">
                                                <button
                                                    class="btn btn-secondary  "
                                                     type="submit" name="edit" value="1" >Edit Bank Details</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
               



                                                                                                                                                                                                                                                                                                    <div id="delete_profile">
                        
                    </div>
                  
                               

            </div>
        </div>
    </div>
    
    
                        </div>
                    </div>
                </div>
  <?php

include("includes/footer.php"); 
 ?>