<?php ob_start(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
<?php   require_once 'head_link.php'; ?>

</head>

<body>
 
<?php   require_once 'header1.php'; ?> 

<?php
	
	if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
	{
		$id = $_GET['edit_id'];
		$stmt_edit = $DB_con->prepare('SELECT * FROM bank_money 
		Left JOIN bank_name ON bank_name.id = bank_money.bank_id
		WHERE bank_money.bank_id =:uid');
		$stmt_edit->execute(array(':uid'=>$id));
		$edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
		extract($edit_row);
	}
	else
	{
		header("Location: bank-account");
	}
	
	if(isset($_POST['btn_save_updates']))
	{
		
		//$BName = $_POST['BName'];
		$Prev = $_POST['Prev'];
		$Today = $_POST['Today'];
		$RecAmt = $_POST['RecAmt'];
		$Reff = $_POST['Reff'];
		$Purpose = $_POST['Purpose'];
		
		// if no error occured, continue ....
		if(!isset($errMSG))
		{
			$stmt = $DB_con->prepare('UPDATE bank_money 
									     SET  previous_amt=:Prev,
										      today_amt=:Today,
											  recent_amt=:RecAmt, 
										      refer=:Reff, 
										      cuses=:Purpose 
										     
											 
								       WHERE  bank_id = :uid');
			
		
			
			
			$stmt->bindParam(':Prev',$Prev);
			$stmt->bindParam(':Today',$Today);
			$stmt->bindParam(':RecAmt',$RecAmt);
			$stmt->bindParam(':Reff',$Reff);
			$stmt->bindParam(':Purpose',$Purpose);
			
			$stmt->bindParam(':uid',$id);
			
			if($stmt->execute()){
				?>
               
				<script>
				  document.addEventListener('DOMContentLoaded', function () {
					const modalEl = document.getElementById('successModal');
					const progressBar = document.getElementById('progressBar');

					const modal = new bootstrap.Modal(modalEl, {
					  backdrop: 'static',
					  keyboard: false
					});

					modal.show();

					// Ensure animation runs after modal is fully visible
					modalEl.addEventListener('shown.bs.modal', function () {
					  progressBar.style.transition = 'width 3s ease-in-out';
					  progressBar.style.width = '100%';
					});

					// Redirect after 3 seconds
					setTimeout(() => {
					  window.location.href = 'bank-account';
					}, <?= $MsgDuration; ?>);  // This seeting are in session.php 
				  });
				</script>
                <?php
			}
			else{
				$errMSG = "Sorry Data Could Not Updated !";
			}
		
		}
		
						
	}
	
?>


<?php  require_once 'sidebar.php'; ?>

  <main id="main" class="main">

    <div class="pagetitle">
      <h1> Bank Money Edit </h1> <hr>
    </div> 
	
    <section class="section">
      <div class="row">
        <div class="col-lg-6">

          <div class="card">
            <div class="card-body">
              <h5 class="card-title">
			  <?php
	if(isset($errMSG)){
			?>
            <div class="alert alert-danger">
            	<span class="glyphicon glyphicon-info-sign"></span> <strong><?php echo $errMSG; ?></strong>
            </div>
            <?php
	}
	else if(isset($successMSG)){
		?>
        <div class="alert alert-success">
              <strong><span class="glyphicon glyphicon-info-sign"></span> <?php echo $successMSG; ?></strong>
        </div>
        <?php
	}
	?>  
			  
</h5>
			  
<form method="post" enctype="multipart/form-data" class="form-horizontal"> 
    <?php
	if(isset($errMSG)){
		?>
        <div class="alert alert-danger">
          <span class="glyphicon glyphicon-info-sign"></span> &nbsp; <?php echo $errMSG; ?>
        </div>
        <?php
	}
	?>
   
    
	<table class="table table-hover table-responsive">
	
<tr>
    	<td><label class="control-label">Bank Name</label></td>
		<td><input class="form-control" type="text" name="BName" placeholder="Bank Name" value="<?php echo $name; ?>" readonly></td>
    </tr>
	
	<tr>
    	<td><label class="control-label">Previous</label></td>
		<td><input class="form-control" type="text" name="Prev" placeholder="Bank Name" value="<?php echo $previous_amt; ?>"></td>
    </tr>
	
	<tr>
    	<td><label class="control-label">Today</label></td>
		<td><input class="form-control" type="text" name="Today" placeholder="Bank Name" value="<?php echo $today_amt; ?>"></td>
    </tr>
	
	<tr>
    	<td><label class="control-label">Current Deposit</label></td>
        <td> <input class="form-control" type="text" id="RecAmt" name="RecAmt" placeholder="Current Deposit" value="<?php echo $recent_amt; ?>"  ></td>
    </tr>
	 
	 
	 <tr>
    	<td><label class="control-label">Reference</label></td>
		<td><input class="form-control" type="text" name="Reff" placeholder="Bank Name" value="<?php echo $refer; ?>"></td>
    </tr>
	
	<tr>
    	<td><label class="control-label">Purpose</label></td>
		<td><input class="form-control" type="text" name="Purpose" placeholder="Bank Name" value="<?php echo $cuses; ?>"></td>
    </tr>
    
	
    </table>
	
	<tr>
        <td colspan="2"><button type="submit" name="btn_save_updates" class="btn-sm btn-primary" title="Click for Update                                                             ">
        <span class="bi bi-check-circle"></span> Update
        </button>
        
        <a class="btn-sm btn-danger" href="bank-account" title="Click for Cancel"> <span class="bi bi-x-circle"></span> Cancel </a>
        
        </td>
    </tr>
    
</form> 
			  
			  
            </div>
          </div>

          
        </div>

       
    </section>

  </main> 

    <?php  require_once 'footer1.php'; ?>