<?
session_start();
if(strlen($user)<=0)
{
 print "<script> alert('You are not logged in') </script>";
 include("../logout.php");
 return;
}

include("../opendb.php");
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
th{color:white}
</style>
<center>
<form action='<?print $PHP_SELF?>' method='post'>
<table>
<tr><td bgcolor='c1d799' align=center>SEARCH ITEM</td></tr>
<tr><td>Item Name <input type=text name='itname' size=40> 
 	<input type=submit value='Search' name='sea'>
</td></tr>
<tr><td bgcolor='lightsteelblue'></td></tr>
</table>
</form>

<?
if($sea)
{

 $re=mysqli_query($db,"select distinct a.brcode,b.brname,date_format(a.upddate,'%W %d-%m-%Y %r') from dailyspare a,branch b where a.brcode=b.brcode") or die(mysqli_error());
 while($brrow=mysqli_fetch_row($re))
 {
 $result=mysqli_query($db,"select * from dailyspare where item like '%$itname%' and brcode='$brrow[0]'");
 if(mysqli_num_rows($result)<=0)
 {
   print "<font color=red>Item does not exist</font>";
 }
 else
 {
  print "Search result of <font color=blue>$itname <br>&nbsp;</font><fieldset> <legend>Stock at $brrow[1] as on $brrow[2]</legend>";
  print "<table cellspacing=1 cellpadding=5 bgcolor='steelblue' width=95%>";
  print "<th>No <th>Item <th>Qty <th>Rate <th>Amount";
  $i=1;
  while($row=mysqli_fetch_array($result))
  {
    print "<tr bgcolor=white onMouseOver=bgColor='c1d799' onMouseOut=bgColor='white'><td>".$i++."</td><td>$row[0]</td><td>$row[1]</td>";
    print "<td align=right>$row[2]</td><td align=right>$row[3]</td>";
  }
 print "</table></fieldset>";
 } // end else
 } // end while
} // end if
?>
<br>&nbsp;
