<?
session_start();
include("../opendb.php");
include("../test.php");
if($sv)
{
 $re=mysqli_query($db,"select * from txtypemast where ttype='$ttype'");
 if(mysqli_num_rows($re)>0)
 {
  print "<script> alert('Duplicate Entry');</script>";
  return;
 }
 else
  mysqli_query($db,"insert into txtypemast values('$ttype','$head','$foot')");
}
if($del)
{
 mysqli_query($db,"delete from txtypemast where ttype='$ttype'");
 print '<font color=red>Record has been deleted</font>';
}
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
tr{background-color:white}
th{background-color:steelblue;color:white}
</style>
<script>
 function valid()
 {
   if(document.f1.ttype.value.length<=0)
   {
     alert('Invalid Invoice Type');
     document.f1.ttype.focus();
     return false;
   }
}
 function delfun(x)
 {
  if(confirm('Do you want to delete '+x))
  {
	document.location='<?print $PHP_SELF?>?del=del&ttype='+x;
  }
}
</script>

<center>
<form action='<?print $PHP_SELF?>' name='f1' method='get' onSubmit="return valid()">
<table cellspacing=1 cellpadding=5>
<th colspan=2> INVOICE TYPE MASTER</th>
<tr><td>Invoice Type</td><td><input type=text name='ttype'></td></tr>
<tr><td>Header</td><td><input type=text name='head' size=40></td></tr>
<tr><td>Footer</td><td><input type=text name='foot' size=40></td></tr>
<th colspan=2 align=center><input type=submit value='Add' name='sv'></th>
</table>
</form>
<fieldset>
<legend> Existing Records</legend>
<?
 $re=mysqli_query($db,"select * from txtypemast");
 if(mysqli_num_rows($re)>0)
 {
 $i=1;
?>
<table cellspacing=1 cellpadding=4 bgcolor='silver'>
<th>No <th>Invoice Type <th>Header <th>Footer <th>Del
<?
  while($row=mysqli_fetch_array($re))
  {
    print "<tr><td>".$i++."</td><td><center>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
    print "\n<td><input type=button value='Del' onClick=delfun('$row[0]')></td></tr>";
 }
}
?>
</table>
<script>

</script>

