<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('42','edits','R');     
$_SESSION['cuPages']='ban_accountlist.php';   
$cuPage='ban_accountlist.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];     
}else{
header('Location:../index.php');
exit;    
}
$mhead='bank';
$menuh='Bank';
$phead='acclist';
$page='Account Record';
$dtnow = date("Y-m-d h:i:s", time());
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>
<?php 
if(isset($_POST['update_account'])){
    $acid = remove_junk(escape($_POST['acid']));
	$acno = remove_junk(escape($_POST['acno']));
    $title = remove_junk(escape($_POST['title']));
    $bank = remove_junk(escape($_POST['bank']));
    $branch = remove_junk(escape($_POST['branch']));
    $code = remove_junk(escape($_POST['code']));
    $location = remove_junk(escape($_POST['location']));
	
	if(isset($_POST['acno'])){
	$ducode = mysqli_query($con,"SELECT * FROM tbl_bacount WHERE acno = '$acno' AND id!='$acid'");
	}
	
	if($ducode->num_rows > 0) {
		save_msg('i','Account Number alrady used! Plz try another');
		echo "<script>window.location='ban_accountlist.php'</script>";
	}else{
    $sql="UPDATE tbl_bacount SET bid='$bank',branch='$branch',acno='$acno',title='$title',location='$location',brcode='$code' WHERE id='$acid'";    
	$result = mysqli_query($con,$sql) or die(mysqli_error($con));	
    if($result){
    $act =remove_junk(escape('Account No: '.$acno));    
    write_activity($aid,'ACC','Account no has been Updated',$act);    
    }
    save_msg('s','Data Successfully Update!');
    echo "<script>window.location='ban_accountlist.php'</script>";  
	}  
}
?>
<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">

<div class="row">
<div class="col-md-8">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Edit Account</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>  
<form action="ban_accountedit.php" onsubmit="return validate()" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="col-md-12 popup_details_div">
<div class="col-md-1"></div>
<div class="col-md-10">
<?php 
if(isset($_POST['editacc'])){
$ids = $_POST['editacc'];
$sql="SELECT * FROM tbl_bacount WHERE id='".$ids."' ORDER BY id ASC LIMIT 1";    
$admin=mysqli_query($con,$sql) or die(mysqli_error($con));    
while ($adm=mysqli_fetch_array($admin)){
?>     
<div class="row">
<div class="col-md-5">
<div class="form-group">
<label>Account No</label>
<div class="input-group">
<span class="input-group-addon">AC</span>   
<input type="text" class="form-control" maxlength="25" name="acno" id="acno" value="<?php echo $adm['acno'];?>" placeholder="Account No" required="" autocomplete="off">
</div>
<input type="hidden" maxlength="11" value="<?php echo $adm['id'];?>" class="form-control" name="acid" autocomplete="off" readonly>    
</div>
</div>
<div class="col-md-7">
<div class="form-group">
<label>Account Title</label>
<div class="input-group">
<span class="input-group-addon">AT</span>   
<input type="text" class="form-control" maxlength="45" name="title" id="title" value="<?php echo $adm['title'];?>" placeholder="Account Title" required="" autocomplete="off">
</div>    
</div>
</div>    
</div>
<div class="row">
<div class="col-md-5">
<div class="form-group" >
<label for="inputName" class="control-label mb-10">Select Bank</label>
<div class="input-group">
<span class="input-group-addon">BA</span>
<select class="form-control select2" name="bank" id="bank" required>
<option value="">-Select-</option>
<?php									
$queryd=mysqli_query($con,"SELECT * FROM tbl_bank ORDER BY id ASC")or die(mysqli_error($con));
while ($rowd=mysqli_fetch_array($queryd)){
?>
<?php if($rowd['id']==$adm['bid']){ ?>
<option selected value="<?php echo $rowd['id'];?>"><?php echo $rowd['name'];?></option>
<?php }else{?>    
<option value="<?php echo $rowd['id'];?>"><?php echo $rowd['name'];?></option>
<?php } ?> 
<?php } ?>     
</select>
</div>
</div>    
</div>
<div class="col-md-7">
<div class="form-group">
<label>Branch Name</label>
<div class="input-group">
<span class="input-group-addon">BN</span>   
<input type="text" class="form-control" maxlength="45" name="branch" id="branch" value="<?php echo $adm['branch'];?>" placeholder="Branch Name" required="" autocomplete="off">
</div>    
</div>    
</div>    
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>Branch Code</label>
<div class="input-group">
<span class="input-group-addon">BC</span>   
<input type="text" class="form-control" maxlength="6" name="code" id="code" value="<?php echo $adm['brcode'];?>" onkeypress="return isNumberKey(event)" placeholder="Branch Code" required="" autocomplete="off">
</div>    
</div>    
</div>
<div class="col-md-9">
<div class="form-group">
<label>Branch Location</label>
<div class="input-group">
<span class="input-group-addon">BL</span>   
<input type="text" class="form-control" maxlength="250" name="location" id="location" value="<?php echo $adm['location'];?>" placeholder="Branch Location" required="" autocomplete="off">
</div>    
</div>    
</div>    
</div>    
<?php }} ?>
</div>    
<div class="col-md-1"></div>
</div>
    
<div class="clearfix" ></div>
<div class="col-md-12 nopadding widgets_area"></div>    
<div class="row"style="margin-top: 15px" >
<div class="col-md-8"></div>
<div class="col-md-4 text-right" >
<input type="submit" name="update_account" id="submit" class="btn btn-flat bg-purple btn-sm " value="Update"/> <a href="ban_accountlist.php" class="btn btn-flat bg-gray  ">Close</a>
</div> 
</div>     
</form>    
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php if($_SESSION['access']=='1'){echo read_activity($aid,'ACC','A');}else{echo read_activity($aid,'ACC','U');}?>
</div>
</div>
</div>
</div>
</div>
</div>

<?php include('../layout/quick.php');?>    
</section>
<!-- /.main content -->    
</div>

<?php 
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function () {  
var acno = new LiveValidation('acno');
acno.add(Validate.Presence);
var title = new LiveValidation('title');
title.add(Validate.Presence);
var bank = new LiveValidation('bank');
bank.add(Validate.Presence);
var branch = new LiveValidation('branch');
branch.add(Validate.Presence);    
});
</script>    
<!-- /page script -->
</html>    