<?php
$pgMod="bank";
$pgAct="add";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);


if($_POST)
{
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;
	if(!isset($_POST['account']) || trim($_POST['account'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter account no.");
	}elseif(!isset($_POST['bank']) || trim($_POST['bank'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Bank name.");
	}
	if($flgEr!=TRUE && $pgAct=="add")
	{$data = array(	
					 'bank'=>$_POST["bank"],
					 'account'=>$_POST["account"],
					 'address'=>$_POST["address"],
					 "school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"],
					 'ifsc'=>$_POST["ifsc"],);
		$flgIn = $db->insertAry("bank",$data);
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			sms($LinksDetails["DirectorNumber"],"Dear sir, Income Amount of Rs. ".$_POST["amount"]." from ".$_POST["mode"]." is Successfully Deposited in ".$LinksDetails["site_name"]." account","Income_Expense");
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Account", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
}else
if($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete("bank","where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
	if(!is_null($res)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Account", "page_id"=>$pgMod)));
}
if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
//echo $_SESSION["admin"]["session"];
if($_GET["action"]=="add"){
?>
<!-- Forms --> 
	<div class="row-fluid">
        <form method="post" action="">
			<!-- Forms: Box -->
			<div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i> Create Bank</h3>
				</div>
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content --> 
				<div class="well no-padding">

						<div class="control-group">
							<label class="control-label" for="mode">Bank name</label>
							<div class="controls">
								<input type="text" id="bank" name="bank" class="input-block-level" value="<?php if($_POST)echo $_POST["bank"]; ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="idate">Account No</label>
							<div class="controls">
								<input type="text" id="account" name="account" class="input-block-level" value="<?php if($_POST)echo $_POST["account"]; ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="detail">Bank IFSC Code</label>
							<div class="controls">
								<input type="text" id="ifsc" name="IFSC" class="input-block-level" value="<?php if($_POST)echo $_POST["ifsc"]; ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="idate">Address</label>
							<div class="controls">
								<input type="text" id="address" name="address" class="input-block-level" value="<?php if($_POST)echo $_POST["address"]; ?>">
							</div>
						</div>
						<div class="form-actions">
							<button type="submit" class="btn btn-primary"> Save</button>
							<button type="button" class="btn"> Cancel</button>
						</div>
                        
				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->

        </form>
	</div>
<!-- / Forms -->
<!-- / Forms -->
<?php 
}else{

	?>
<div class="row-fluid">
  <div class="span12">
    <div class="top-bar">
      <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
      <div style="float:right; margin-top:5px">
                	<button style="float:right; margin-top:5px" onclick="window.location='./?src=Account&page_id=<?php echo $pgMod; ?>&action=add'" class="btn" type="button">Add <?php echo $pgMod; ?></button>
                </div>
    </div>
    <div class="well no-padding">
      <?php
	$aryPgAct=array("src"=>"Account", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("select * from bank  where school_id='".$_SESSION["admin"]["school_id"]."'");
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
      <table class="table" id="example">
        <thead>
          <tr>
            <th></th>
            <th>Name</th>
            <th>Account NO</th>
            <th>IFSC</th>
            <th>Address</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];
            ?>
          <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
            <td><?php echo $i; ?></td>
            <td><?php echo $clist["bank"] ?></td>
            <td><?php echo $clist["account"] ?></td>
            <td><?php echo $clist["ifsc"] ?></td>
            <td><?php echo $clist["address"] ?></td>
            <td><?php $aryPgAct['action']="delete"; ?>
              <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>">
              <button type="button" class="btn btn-info">delete</button>
              </a></td>
          </tr>
          <?php } ?>
        </tbody>
        <tfoot>
          <tr>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th colspan="2"></th>
          </tr>
        </tfoot>
      </table>
      <?php
	}
	else{
		?>
      <div class="alert alert-info"> <a class="close" data-dismiss="alert">×</a> <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i> </div>
      <?php
	}
	?>
    </div>
  </div>
</div>
<?php
}?>
<script>
function hide_underof(valu)
{
	if(valu=='1'){
		$('#paymode').hide('slow');
		$("#chque").val('');$("#backname").val('');
	}else 
	if(valu=='2'){
		$('#paymode').show('slow');
	}
}
</script>