<link href="../css/form.css" type="text/css" rel="stylesheet" media="screen"  />
<html>
<body >

<?
session_start();
include("../opendb.php");
include("../test.php");
if($code&&$act=='del')
{
 $q="delete from ussage where code='$code' and brcode='$brcode'";
 mysqli_query($db,$q);
}
if($save)
{
 $re1=mysqli_query($db,"select * from ussage where source='$source'")or die(mysqli_error());
 if(mysqli_num_rows($re1)>0)
  {
   print "<font color=red>Duplicate Entry</font>";
  }
 else{
 mysqli_query($db,"insert into ussage (source,brcode) values('$source','$brcode')");
 }
}
?>
<head>
<script>
 function valid()
 {
   if(document.f1.source.value.length<=0)
   {
    alert("Insuffient entry");
    return false;
   }
}
function del(x)
{
 if(confirm('Do you want to delete this item ?'))
  document.location='<?print $PHP_SELF?>?code='+x+'&act=del';
}
</script>

<style>
tr{font-family:arial;font-size:13;background-color:white}
TH{COLOR:WHITE;BACKGROUND-COLOR:STEELBLUE}
</style>

<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<center>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit='return valid()'>
<table border=1>
<th COLSPAN=3>ADD USAGE</TH>
<tr><td>Source </td><td><input type=text name='source' size=40></td>
  <td><input type=submit value='Add' name='save'></td></tr>
</table>
</form>
<?
 $re=mysqli_query($db,"select * from ussage where brcode='$brcode' order by source")or die(mysqli_error());
 $i=1;  
 print "<table cellspacing=1 cellpadding=3 bgcolor='gray'>";
 print "<th width=20>No <th>Source<th>Del";
while($row=mysqli_fetch_array($re))
{
 print "<tr><td>".$i++."</td><td>$row[1]</td><td align=center>";
?>
<input type=button value='Del' onClick=del('<?print $row[0]?>')></td></tr>
<?
}
?>
</table>

