<? session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include("opendb.php");
$code=$_REQUEST['code'];
if(isset($_POST['edit']))
{
$brname=$_REQUEST['brname'];
$addr=$_REQUEST['addr'];
$brcity=$_REQUEST['brcity'];
$brphone=$_REQUEST['brphone'];
$tin=$_REQUEST['tin'];
$brstate=$_REQUEST['brstate'];
$pin=$_REQUEST['pin'];
$cst=$_REQUEST['cst'];
 $sql="update branch set brname='$brname',braddr='$addr',brcity='$brcity',brphone='$brphone', tin='$tin',brstate='$brstate', pupass2='$pin',cstno='$cst' where brcode='$code'";
 mysqli_query($db,$sql)or die(mysqli_error($db));
include("branch.php");
return;
}

$result=mysqli_query($db,"select * from branch where  brcode='$code'");
$row=mysqli_fetch_array($result);
?>
<script>
function valid()
{
  submitOK="true";

 if(document.f1.brname.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Branch name');
 }

  if(submitOK=="true")
   return true;
  else
   return false;
}
function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
}
</script>
<title></title>
    <script type="text/javascript" src="scripts/jquery-latest.js"></script>
	<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7}
.mnu{margin-left:5}
</style>
<body background="back_ground.jpg">
<?php include('includes/top.php'); ?>				
<br>
<div id='container'>

<br><br><br>

<CENTER>
<BR>
<form name='f1' action='<? print $PHP_SELF?>' method='Post' onSubmit="return valid()">
<input  type=hidden name='code' value='<?print $code?>'>
<table cellspacing=1 cellpadding=1 bgcolor=green>
<tr><td align=center>
<table class=form>
<tr><td colspan=2 align=center>EDIT BRANCH DETAILS</TD></TR>
<tr><td><font color=red>Branch Name </td><td>
<input type=text name='brname' readonly size=30 value='<?print $row[brname]?>' onKeyDown=chkey(this)>
</td></tr>
<tr><td>Address </td><td><input type=text name='addr' size=40 value='<?print $row[braddr]?>'></td></tr>
<tr><td>City </td><td><input type=text name='brcity' size=40 value='<?print $row[brcity]?>'></td></tr>
<tr><td>State </td><td><input type=text name='brstate' size=40 value='<?print $row[brstate]?>'></td></tr>
<tr><td>Phone </td><td><input type=text name='brphone' size=40 value='<?print $row[brphone]?>'></td></tr>
<tr><td>Pin No </td><td><input type=text name='pin' size=40 value='<?print $row[pupass2]?>'></td></tr>
<tr><td>Tin </td><td><input type=text name='tin' size=40 value='<?print $row[tin]?>'></td></tr>
<tr><td>Cst No </td><td><input type=text name='cst' size=40 value='<?print $row[cstno]?>'></td></tr>
<TR><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT name='edit' VALUE='  Update  '>
<input type=button value='Cancel' onClick=history.go(-1)></TD></TR>

</table>
</td></tr>
</table>
</form>
<br>
<script>
 function fn(x,y)
 {
  if(confirm('Do you want to edit branch '+x+ ' ?'))
   document.location='editbrname.php?na='+x+'&code='+y;
 }
</script>

