<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$code=$_REQUEST['code'];
if(isset($_POST['submit']))
{
        $re12=mysqli_query($db,"select brgroup from branch where brcode ='$brcode'")or die(mysqli_error($db));
	$row12=mysqli_fetch_array($re12);
	$brman=$_REQUEST['brman'];
	$braddr=$_REQUEST['braddr'];
	$brcity=$_REQUEST['brcity'];
	$brphone=$_REQUEST['brphone'];
	$brname=$_REQUEST['brname'];
	$brtype=$_REQUEST['brtype'];
	$tin=$_REQUEST['tin'];
	$cst=$_REQUEST['cst'];
	$brstate=$_REQUEST['brstate'];
	$code=$_REQUEST['code'];
	$sql="update branch set brname='$brname',brman='$brman',braddr='$braddr',brcity='$brcity',brphone='$brphone',brtype='$brtype',tin='$tin',cstno='$cst',brstate='$brstate',brgroup='$row12[0]' where brcode='$code'";
	mysqli_query($db,$sql) or die(mysqli_error($db));
	//$sql="update branch set pupass2='$pupass2',sapass2='$sapass2',jopass2='$jopass2',acpass2='$acpass2',otpass2='$otpass2'";
	//mysqli_query($db,$sql) or die(mysqli_error($db));
	print("<script>document.location='createbr.php';</script>");
}
$result=mysqli_query($db,"select * from branch where brcode='$code'");
$row=mysqli_fetch_array($result)or die(mysqli_error($db));
?>
<script>
resizeTo(500,550);
</script>
<link rel="stylesheet" href="css/form.css" type="text/css" />
<script>
function validate()
{
	var p1=document.f1.brpass1.value
	var p2=document.f1.brpass2.value
	submit="true";
 	if(document.f1.brname.value.length<3)
  	{submit="false"; alert('Invalid branch name');}
	if(document.f1.brpass1.value.length<=0)
  	{submit="false"; alert('Invalid Password');}

 if(document.f1.brpass2.value.length<=0)
  {submit="false"; alert('Invalid Password2');}
 if(p1!=p2)
  {submit="false"; alert('Passwords does not match');}

 if(submit=="false")
  return false;
}
</script>

<body bgcolor=fcfff1>
<font color=green>
<h3>Branch Updation</h3></font>
<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return validate()">
<input type=hidden name=code value='<?print $code?>'>
<table border=1  cellspacing=2 cellpadding=5 class=form>
<tr><td>Branch Name</td><td><input type=text name='brname' size=40 value='<?print $row[brname]?>'></td></tr>
<tr><td>Branch Type </td><td><select name='brtype'>
<option><?print $row[brtype]?></option>
<option>HO</option>
<option>BR</option>
</select></td></tr>
<tr><td>Branch Manager</td><td><input type=text name='brman' size=40 value='<?print $row[brman]?>'></td></tr>
<tr><td>Address</td><td><input type=text name='braddr' 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>
<select name='brstate'>
<option><?print $row[brstate]?></option>
<option>Kerala</option>
<option>Karnataka</option>
</select>
</td></tr>
<tr><td>Phone</td><td><input type=text name='brphone' size=40 value='<?print $row[brphone]?>'></td></tr>
<tr><td>Tin No.</td><td><input type=tex 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='submit' value='  S A V E  '> <input type=button value='C A N C E L' onClick='window.location="createbr.php"'></td></tr>
</table>
</form>


