<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$level=$_SESSION['level'];
include("../opendb.php");
include("../test.php");
$source=$_REQUEST['source'];
$code=$_REQUEST['code'];

if(isset($_POST['del']))
{
 $q="delete from inqsource where code='$code'";
 mysqli_query($db,$q);
}


if(isset($_POST['save']))
{
 $re1=mysqli_query($db,"select * from inqsource where source='$source'")or die(mysqli_error($db));
 if(mysqli_num_rows($re1)>0)
  {
   print "<font color=red>Duplicate Entry</font>";
  }
 else{
 mysqli_query($db,"insert into inqsource (source) values('$source')");

 }
}
?>
<head>
<?php include('top.php'); ?>
<script>
 function valid()
 {
   if(document.f1.source.value.length<=0)
   {
    alert("Insufficient entry");
    return false;
   }
}

</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 method='post' name='f1' action='<?print $PHP_SELF?>' onSubmit='return valid()'>
<table border=1>
<th COLSPAN=3>ADD SOURCE</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 inqsource order by source")or die(mysqli_error($db));
 $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 "<form method='post' name='f2'><tr><td>".$i++."</td><td>$row[1]</td><td align=center><input type=hidden name='code' value=$row[0]><input type=submit value='Del' name='del' ></td></tr></form>";

}
?>
</table>