<? session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
if($submit)
{
 if(strlen($finname)<=0)
  {
     print "<script> alert('In sufficient entry'); history.back(1);  </script>";
     return;
  }
 $rrs=mysqli_query($db,"select * from fin_master where finname='$finname' and branch='$brcode'");
 if(mysqli_num_rows($rrs)>0)
  {
     print "<script> alert('Duplicate Financer'); history.back(1);  </script>";
     return;
  }

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

 $sql="insert into fin_master values('$code','$finname','$addr1','$addr2','$city','$dist', '$stat','$pin','$phone1','$phone2','$email','$brcode')";
 mysqli_query($db,$sql)or die(mysqli_error());
}
?>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
th{background-color:green; color:ivory}
.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 bgcolor='green'><font color='ivory'><STRONG>FINANCIER  MASTER</TD></TR>
<tr style={background:yellow}><td>Name <BR>
 <FONT SIZE=1 color=red>(Non editable)</font></td><td><input type=text name='finname' size=40 onKeyDown=chkey(this); style={color:red} title='As it will create A/c head, it cannot be edited'></td></tr>
<tr><td>Address1 </td><td><input type=text name='addr1' size=40></td></tr>
<tr><td>Address2 </td><td><input type=text name='addr2' size=40></td></tr>
<tr><td>City </td><td><input type=text name='city' size=40></td></tr>
<tr><td>District </td><td><select name='dist'>
<?
$re=mysqli_query($db,"select * from dist_master where brcode='$brcode' order by dist");
while($row=mysqli_fetch_row($re))
{
 print "<option>$row[1]</option>";
}
?>
 </select></td></tr>
<tr><td>State </td><td><input type=text name='stat' size=40></td></tr>
<tr><td>Pin No </td><td><input type=text name='pin' size=40></td></tr>
<tr><td>Phone1 </td><td><input type=text name='phone1' size=40></td></tr>
<tr><td>Phone2 </td><td><input type=text name='phone2' size=40></td></tr>
<tr><td>Email_id </td><td><input type=text name='email' 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 fin_master where branch='$brcode' order by finname")or die(mysqli_error());
print "<table cellspacing=1 cellpadding=1 border=1>";
print "<th> No.<th>Name <th>Addr1 <th>Addr 2 <th>City <th>Dist. <th>State <th>Pin <th>Phone1 <th>Phone 2";
print " <th>Email <th>Edit";
$i=1;
while($row=mysqli_fetch_row($result))
{
 print "<tr><td>".$i++."</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td>";
 print "<td>$row[4]</td><td>$row[5]</td><td>$row[6]</td><td>$row[7]</td><td>$row[8]</td>";
 print "<td>$row[9]</td><td>$row[10]</td><td align=center>\n<a href='editfine_mast.php?code=$row[0]' title='Edit Entry' onMouseOver='window.status=''; return true'><img src='../img/edit.gif' border=0></a></td></tr>";
}
?>
</table>
<script>
function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
}
</script>
