<?php
session_start();
include "connect.php";

$currentpage=1;
$activepage="BANK";
if(!isset($_SESSION['admin_login'])){ header("location:index.php");}
$limit = 20;
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };  
$start_from = ($page-1) * $limit;  

$q_sql="SELECT * FROM bank_details ORDER BY id DESC";
$q_query=mysqli_query($conn,$q_sql);
	
	
	if(isset($_POST['bank_details']) && $_POST['bank_details']=='BANK')
	{
		$bank_name=$_POST['bank_name'];
		$acc_name=$_POST['acc_name'];
		$acc_no=$_POST['acc_no'];
		$ifsccode=$_POST['ifsccode'];
		$checkLogin=mysqli_query($conn,"INSERT INTO `bank_details`(`id`, `bank_name`, `acc_name`, `acc_no`, `ifsccode`)
		VALUES (NULL,'$bank_name','$acc_name','$acc_no','$ifsccode')");
		if($checkLogin){
					
				echo "<script> window.location = 'add_bank.php?success'; </script>";			
		}else{
			 header("location:add_bank.php?err");			 
		}
	}
$success='<div class="alert alert-success alert-dismissible" role="alert" style="margin-top: -18px; padding: 10px;"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true" style="margin-left:-50px; color:white;">&times;</span><span class="sr-only">Close</span></button><strong>Success!</strong> Insert is successfull.</div>';
$err='<div class="alert alert-danger alert-dismissible" role="alert" style="margin-top: -18px; padding: 10px;"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true" style="margin-left:-50px; color:white;">&times;</span><span class="sr-only">Close</span></button><strong>Wrong!</strong> Invalid credentials.</div>';

if (isset($_REQUEST['idd']) && $_REQUEST['delete'] == 'true') {
    $query_service = "DELETE FROM `bank_details` WHERE id ='".$_REQUEST['idd']."'";
     
        $result_service = mysqli_query($conn,$query_service);
		
		if($result_service){
			echo "<script>alert('you deleted successfully. ');   window.location = 'add_bank.php'; </script>";
			// header("location:view_branch.php");
		}
}
if (isset($_REQUEST['id']) && $_REQUEST['edit'] == 'true'){
    $query_service = "SELECT * FROM `bank_details`  WHERE id ='".$_REQUEST['id']."'";

        $result_service = mysqli_query($conn,$query_service);
		$row_service = mysqli_fetch_assoc($result_service);
} 
if (isset($_POST['btnedit']) && $_POST['btnedit'] == 'Modify'){
	    $bank_name=$_POST['bank_name'];
		$acc_name=$_POST['acc_name'];
		$acc_no=$_POST['acc_no'];
		$ifsccode=$_POST['ifsccode'];
	
	
	
	$query_service1 = "UPDATE `bank_details` SET `bank_name`='$bank_name',
	`acc_name`='$acc_name',`acc_no`='$acc_no',
	`ifsccode`='$ifsccode' WHERE id = '".$_REQUEST['id']."'";
//echo $query_service1; die;
        $result_service1 = mysqli_query($conn,$query_service1);
		if($result_service1){
			 header("location:add_bank.php");
		}else{
			 header("location:add_bank.php?err");			
		}
		
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>:: Right Choices | Bank ::</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<?php include "common/CSS_link.php";?> 
<link rel="stylesheet" href="js/jquery.com_ui.css">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="js/jquery.com_ui.css">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<style>

/*.frmSearch {border: 1px solid #a8d4b1;background-color: #c6f7d0;margin: 2px 0px;padding:40px;border-radius:4px;}*/
#country-list{float:left;list-style:none;margin-top:-3px;padding:0;width:90%;position: absolute; z-index:800;}
#country-list li{padding: 10px; background: #008B8B; color:#fff; border-bottom: #bbb9b9 1px solid;}
#country-list li:hover{background:#f39c12;cursor: pointer; color:#000;}
#search-box{padding: 10px;border: #a8d4b1 1px solid;border-radius:4px;}
</style>


<script>
$( function() {
$( ".datepicker1" ).datepicker({ dateFormat: 'dd/mm/yy' });
} );

$( function() {
$( ".datepicker2" ).datepicker({ dateFormat: 'yy-mm-dd' });
} );
</script>
<script>
function ff(url) {
  var txt;
  var r = confirm("Are you want to delete this?");
  if (r == true) {
    window.location = url;
  } else {
    
  }
  document.getElementById("demo").innerHTML = txt;
}
</script>

 <style>
[class*=" pe-7s-"], [class^=pe-7s-] {
    display: inline-block;
    font-family: Pe-icon-7-stroke;
    speak: none;
    font-style: normal;
    font-weight: 400;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
user agent stylesheet
i, cite, em, var, address, dfn {
    font-style: italic;
}
.content-header .header-icon {
    font-size: 55px;
    color: #37a000;
    width: 68px;
    float: left;
    margin-top: -4px;
    line-height: 0;
}

</style>
<script>
 
  function isNumber(evt) {
        var iKeyCode = (evt.which) ? evt.which : evt.keyCode
        if (iKeyCode != 46 && iKeyCode > 31 && (iKeyCode < 48 || iKeyCode > 57)){
            return false;
		}
        return true;
    }	

</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#referral_id").keyup(function(){
       var txt = $("#referral_id").val();
	   if(txt !="" ){
      $.post("fetch_ajax_value.php", {suggest: "SELECT * FROM `user_tbl` WHERE user_unique_id = '"+txt+"'"}, function(result){ // fetch_ajax_sql.php
           $("#referral_name").val(result);
       });
	   }
   }); 
  
   
	

 
 $('#pan_no').on('blur' , function() {
var panVal = $('#pan_no').val();
var regpan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;
if(panVal !="" ){
if(regpan.test(panVal)){
  // valid pan card number
} else {
  alert('invalid pan card number .'); // invalid pan card number
  //$("#pan_no").focus();
}
}	
 });

	
    $("#acc_no").keypress(function (e) {
     //if the letter is not digit then display error and don't type anything
     if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        //display error message
        alert('Enter numerical numbers only.');
	   return false;
            
    }
   });
   
   $('#ifsccode').on('blur' , function() {
var panVal = $('#ifsccode').val();
var regpan = /^([a-zA-Z]){4}([a-zA-Z0-9]){7}$/;
if(panVal !="" ){
if(regpan.test(panVal)){
  // valid pan card number
} else {
  alert('invalid IFSC CODE number .'); // invalid pan card number
}	
}
 });
   
   $(function() {
    $('#email_id').on('blur' , function() {
        // Your code here
		 if($('#email_id').val() != ""){
		validmail();
		 }
    });
  });
  $(function() {
    $('#cpassword').on('blur' , function() {
        // Your code here
		 if($('#cpassword').val() != ""){
			 if($('#password').val() != $('#cpassword').val()){
				 alert('password does not match with confirm password !!!');
				 $('#cpassword').val('');
			 }
		
		 }
    });
  });
 
 
   	
});


function validmail(){
	var txt =  document.getElementById("email_id").value; 
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt))
  {
    return (true);
  }else{
    alert("You have entered an invalid email address!")
    //$("#email_id").focus();
  }
}  

</script>  
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
  <header class="main-header">
    <?php include "common/header.php";?>
  </header> 
  <aside class="main-sidebar">    
    <section class="sidebar">
      <?php include "common/LEFT_sidebar.php";?>
  </aside>  
  <div class="content-wrapper">    
     <section class="content-header">
      <div class="header-icon">
		<i class="fa fa-file-text-o" style="color:#37a000; font-size:50px;"></i>
	   </div>
      <h1 style="fonyt-family:'Alegreya Sans',sans-serif; margin: 0; font-size: 24px">Add Bank<br><span style="font-size: 13px; display: inline-block; padding-left: 4px; font-weight: 600; color: #7a7a7a;">Add Bank</span></h1>
      <ol class="breadcrumb">
        <li><a href="home.php"><i class="fa fa-dashboard"></i>Home</a></li>        
        <li class="active" style="color:#37a000; font-weight:bold;">Add Bank </li>
      </ol>
    </section>       
    <section class="invoice">           
      <div class="row">
	  <div class="col-xs-8">
		<div class="modal-body" style="">
			<div id='msg'><?php if(isset($_GET['success'])){ echo $success; echo "<script> setTimeout(\"window.location = 'add_bank.php'\",4000); </script>"; } ?><?php if(isset($_GET['err'])){ echo $err; echo "<script> setTimeout(\"window.location = 'add_bank.php'\",4000); </script>"; } ?></div>                        
			<form class="form-horizontal" role="form" id="addSalHead" action="" method="POST" >
			<?php if (isset($_REQUEST['id']) && $_REQUEST['edit'] == 'true'){ ?>  
			<input type="hidden" name="btnedit" value="Modify" />
			<?php }else{ ?>
				<input type="hidden" name="bank_details" value="BANK" />
			<?php } ?>
				<div class="form-group">					
					<div class="col-sm-6">
						<label class="control-label" id="text_chnge1">Bank Name <span style="color:red;">*</span></label>						
						<input value="<?php echo isset($row_service['bank_name']) ? $row_service['bank_name'] : ""; ?>" type="text" class="form-control" name="bank_name" id="bank_name" placeholder="Bank Name" autocomplete="off" required>
					</div><div class="col-sm-6">
						<label class="control-label" id="text_chnge1">Account Name <span style="color:red;">*</span></label>						
						<input value="<?php echo isset($row_service['acc_name']) ? $row_service['acc_name'] : ""; ?>" type="text" class="form-control" name="acc_name" id="acc_name" placeholder="Account Name" autocomplete="off" required>
					</div>
					
				</div>
				<div class="form-group">					
					<div class="col-sm-6">
						<label class="control-label" id="text_chnge1">IFSC Code <span style="color:red;">*</span></label>						
						<input value="<?php echo isset($row_service['ifsccode']) ? $row_service['ifsccode'] : ""; ?>" type="text" class="form-control" name="ifsccode" id="ifsccode" placeholder="IFSC Code" autocomplete="off" required>
					</div><div class="col-sm-6">
						<label class="control-label" id="text_chnge1">Account No<span style="color:red;">*</span></label>						
						<input value="<?php echo isset($row_service['acc_no']) ? $row_service['acc_no'] : ""; ?>" type="text" class="form-control" name="acc_no" id="acc_no" placeholder="Account No" autocomplete="off" required>
					</div>
					
				</div>				
				  	
			  <div class="form-group">
					<!--<div class="col-sm-6">
					<label class="control-label">Created Date <span style="color:red;">*</span></label>
						<input type="text" class="form-control datepicker2" name="doj" id="doj" value="<?php //echo date("Y-m-d");?>" autocomplete="off" required>
					</div>-->
					<div class="col-sm-6">
					<div class=" col-sm-12">
					<label class="control-label">&nbsp;&nbsp;&nbsp;	</label>
					<label class="control-label">&nbsp;&nbsp;&nbsp;	</label> </div>
					  <button type="submit" class="btn btn-success" name="submit" id="submit">Submit</button>
					</div>				
				</div>
				
					
			</form>
		</div>
                    
	  </div>
        <div class="col-xs-4 table-responsive">
		<div id="result" style="margin:15px 0;"></div>
          <table class="table table-bordered table-sm">
            <thead>
            <tr style="fonyt-family:sans; background:#008B8B; color:#fff;">
			  <th>Sl</th>
			  <th class="text-center">Bank Name</th>
              <th class="text-left">Account Name</th>            
              <th class="text-left">Account No</th>            
              <th class="text-left">IFSC Code</th>            
              <th class="text-center">Action</th>
            </tr>
            </thead>
            <tbody id="user_data">
			<?php $sno = 1; ?>
            <?php
				$bg_color="#FFF";
				while($row=mysqli_fetch_array($q_query)){
				
				$bank_name=$row['bank_name'];
				$acc_name=$row['acc_name'];
				$acc_no=$row['acc_no'];
				$ifsccode=$row['ifsccode'];
				
				if($bg_color=="#FFF") $bg_color="#fff";
					else $bg_color="#FFF";
			?>
            <tr bgcolor="<?php echo $bg_color;?>">
              <td style="font-size:11px;"><?php echo $sno; ?></td>
			  <td class="text-center" style="font-size:11px;"><?php echo $bank_name; ?></td>   
              <td class="text-left" style="font-size:11px;"><?php echo $acc_name; ?></td>           
              <td class="text-left" style="font-size:11px;"><?php echo $acc_no; ?></td>           
              <td class="text-left" style="font-size:11px;"><?php echo $ifsccode; ?></td>           
              <td class="text-center"> <div> 
				<a href="add_bank.php?edit=true&id=<?php echo $row['id']; ?>" ><i class="fa fa-edit"></i></a>
				<span onclick=ff("add_bank.php?delete=true&idd=<?php echo $row['id']; ?>"); title="Delete"><i class="glyphicon glyphicon-remove" style="color:red; cursor:pointer;"></i></span>
			
			</div></td>
            </tr>			
				<?php $sno = $sno+1;  } ?>
            </tbody>
          </table>	
			<div class="pull-right no-print" style="text-align: center">
			
			
			</div>		  
        </div>        
      </div>  
    </section>
    <div class="clearfix"></div>
  </div>
  <div class="modal fade" id="modal-container-666931" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header" style="background:#605ca8; color:#FFF;">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="color:#FFF;">×</button>
				<h4 class="modal-title" id="myModalLabel">Edit Salary Head : (<span id="edit123"style="font-weight:bold;"></span>)</h4>
			</div>
			<div class="modal-body">
				<div id='ajax_edit'></div>                        
				<form class="form-horizontal" role="form" id="editSalHead" action="ajax/master.php" method="POST" enctype="multipart/form-data" >
					<input type="hidden" name="edit_sal_head" value="EditSalaryHead" />
				
				<div class="form-group">					
					<div class="col-sm-6">
						<label class="control-label" id="text_chnge1">Salary Head Name <span style="color:red;">*</span></label>						
						<input type="text" class="form-control" name="salary_head_name" id="salary_head_name123" placeholder="Salary Head Name" autocomplete="off" required>
					</div>
					<div class="col-sm-6">
					<label class="control-label">Created Date <span style="color:red;">*</span></label>
						<input type="text" class="form-control datepicker2" name="created" id="created123" value="" autocomplete="off" required>
					</div>
				</div>
				
				<input type="hidden" name="id" id="u_id" value=""/>
				
				<div class="form-group">
					<div class="col-sm-6">
					<div class=" col-sm-12">
					<label class="control-label">&nbsp;&nbsp;&nbsp;	</label>
					<label class="control-label">&nbsp;&nbsp;&nbsp;	</label> </div>
					  <button type="submit" class="btn btn-success" name="submit" id="submit">Update</button>
					</div>				
				</div>
			</form>
			</div>
			</div>                    
		</div>
	</div>       
       
  <footer class="main-footer">
    <?php include "common/footer.php";?>
  </footer>
</body>
</html>     
 <script>  	
		/*$(document).ready(function (e){
		$("#addSalHead").on('submit',(function(e){
			e.preventDefault();
			var url = $(this).attr('action');
			
			console.log(url);
				$.ajax({
					url: url,
					type: "POST",
					data:  new FormData(this),
					contentType: false,
					cache: false,
					processData:false,
						success: function(data){
						$('#msg').html(data);	                  
						$('#addSalHead')[0].reset();
						setTimeout('window.location.reload();',4000);
						},
					error: function(){} 	        
				});
			}));
		});*/
</script>
<script>
$("#modal-container-666931").on('hidden.bs.modal', function(e){window.location.reload();});
</script>
<script>
function get_Data(id){
	$.ajax({
		type: "POST",
		url: "ajax/master.php",
		data: { id: id, get_salHeadData: "SalaryHead"} ,
		success: function(data){
			var res=data.split("#");
			document.getElementById('u_id').value=res[0];
			document.getElementById('edit123').innerHTML=res[1];
			document.getElementById('salary_head_name123').value=res[1];
			document.getElementById('created123').value=res[2];
			
		}		
	});
}
function delete_sal_head(id){
	var url = "ajax/master.php";	
	var msg = confirm("Are you sure?");	
	if (msg == true) { 
		$.ajax({
			url: url,
			type:"POST",
			data:'id='+id+'&delete_sal_head=DeleteSalaryHead'
			}).done(function(data){					
			$("#msg").html(data);
			setTimeout('document.location.href="add_salary_head.php"',2000);			
			
		});
	}else{
	 return false;
	}
}
 $("#item-search").on('click', function (e){
    e.preventDefault();
    var item = $("#item").val();	
    console.log(item);	
        $.ajax({
            type:'POST',
            url:'ajax/client.php',
            data:'q='+item
        }).done(function (data){
            $("#response-table").html(data);			
        });
    
});


	$(function(){
        $( "#editSalHead" ).submit(function( event ) {
           event.preventDefault();
            var url = $(this).attr('action');
            console.log(url);            
            $.ajax({
                url: url,
                data: $("#editSalHead").serialize(),
                type: $(this).attr('method')
              }).done(function(data) {
                   $("#ajax_edit").html(data);
				   setTimeout('window.location.href="add_salary_head.php"',4000);             
              });
            
        });
    });
</script>
<script>
  $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="assets/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="assets/bower_components/raphael/raphael.min.js"></script>
<script src="assets/bower_components/morris.js/morris.min.js"></script>
<script src="assets/bower_components/jquery-sparkline/dist/jquery.sparkline.min.js"></script>
<script src="assets/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="assets/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="assets/bower_components/jquery-knob/dist/jquery.knob.min.js"></script>
<script src="assets/bower_components/moment/min/moment.min.js"></script>
<script src="assets/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="assets/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<script src="assets/bower_components/fastclick/lib/fastclick.js"></script>
<script src="assets/dist/js/adminlte.min.js"></script>
<script src="assets/dist/js/pages/dashboard.js"></script>
<script src="assets/dist/js/demo.js"></script>
