<? session_start();
$brcode = $_SESSION['brcode'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("../opendb.php");
$submit = $_REQUEST['submit'];
$dist = $_REQUEST['dist'];
$state = $_REQUEST['state'];
if($submit)
{
 if(strlen($dist)<=0)
  {
     print "<script> alert('In sufficient entry'); history.back(1);  </script>";
     return;
  }

$chk=mysqli_query($db,"select * from dist_master where dist='$dist' and brcode='$brcode'");

 if(mysqli_num_rows($chk)>0)
 {
    print "<script> alert('Duplicate Entry'); history.back(1); </script>";
    return;
 }

 $code=substr($dist,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);

 $sql="insert into dist_master values('$code','$dist','$state','$brcode')";
 mysqli_query($db,$sql) or die(mysqli_error());
 print "<font color='Green'> Data has been saved</font>";
}
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>

<CENTER>
<BR>
<form action='<?print $PHP_SELF?>' method='post'>
<table cellspacing=1 cellpadding=1 bgcolor=green>
<tr><td align=center>
<table>
<tr><td colspan=2 align=center>DISTRICT MASTER</TD></TR>
<tr><td><font color=red>District Name </td><td><input type=text name='dist' size=40></td></tr>
<tr><td>State </td><td><input type=text name='state' size=40></td></tr>
<TR><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT  name='submit' VALUE='  SAVE  '></TD></TR>

</table>
</td></tr>
</table>
</form>
<br>
<?
$result=mysqli_query($db,"select * from dist_master where brcode='$brcode' order by dist")or die(mysqli_error());
print "<table cellspacing=1 cellpadding=1 border=1>";
print "<th> No.<th>District <th>State <th>Edit";

$i=1;
while($row=mysqli_fetch_row($result))
{
 print "<tr><td>".$i++."</td><td>$row[1]</td><td>$row[2]</td><td><a href='editdist.php?code=$row[0]'> <img src='../img/signit.gif' border=0></a> </td> </tr>";
}
?>
</table>
