
<link rel="stylesheet" href="style.css" type="text/css" />
<style>
 a{color:brown}
</style>
<center>
<b>I.P ADMISSION </B>
<form action='<?print $PHP_SELF?>'>
<table border=1>
<tr><td>Reg. No.</td><td><input type=text name='regno' size=10></td>
 <td>Room No.</td><td>
<select name='rno'>
<option></option>
<?
include("opendb.php");
$sql= "select * from room order by roomno";
$result =mysqli_query($db,$sql) or die(mysqli_error());
while($row=mysqli_fetch_array($result))
{
print"<option>$row[roomno]</option>";
}
?>

</select>

</td></tr>
<tr> <td>Admission Type</td><td><input type=text name='admtype'></td>
 <td>Doctor</td><td>
<select name='dr'>
<option></option>
<?
include("opendb.php");
$sql= "select * from dr";
$result =mysqli_query($db,$sql) or die(mysqli_error());
while($row=mysqli_fetch_array($result))
{
print"<option>$row[name]</option>";
}
?>
</select>
<tr><td>Admission Date</td><td colspan=3><input type=text name='admdate' value='<?print date('d-m-Y',time())?>' size=9> Advance Rs. <input type=text name='adv' size=8>
<input name='submit' type=submit value='Save'></td></tr>
</table>
</form>
<hr>
<?
include("test.php");

if ($submit)
{
$dt=date("Y-m-d",time());
 $result=mysqli_query($db,"select * from regn where regno='$regno'") or die(mysqli_error());
 if(mysqli_num_rows($result)<=0 )
  {
    print "<script> alert('Reg. No. does not exist'); history.back(1); </script>";
    return;
  }
 if(strlen($rno)<=0||strlen($regno)<=0)
  {
    print "<script> alert('Insufficient Entry'); history.back(1); </script>";
    return;
  }
 $re=mysqli_query($db,"select * from ipreg where regno='$regno'");
 if(mysqli_num_rows($re)>0 )
  {
    print "<script> alert('Duplicate Entry'); history.back(1); </script>";
    return;
  }
 $re=mysqli_query($db,"select * from ipreg where rno='$rno'");
 if(mysqli_num_rows($re)>0 )
  {
    print "<script> alert('Room is occupied'); history.back(1); </script>";
    return;
  }

 $sql="insert into ipreg values('$regno','$rno','$admtype','$dr','".parsedate($admdate)."','$adv')";

 mysqli_query($db,$sql);
if($adv>0)
{
$acsq="insert into actrans values('$regno','I.P Advance','Liabilities','$regno','$dt', 'I.P Advance Recvd.','$adv','0','Being i.P. Advance received.','Cash','Cash','I.P Advance Recvd.','$adv')";
	  mysqli_query($db,$acsq)or die(mysqli_error());
}
 print "<font color=green face=verdana> Data has been saved</font>";
 print "<script>window.open('prnipregrece.php?reg=$regno'); </script>";
}


$sql="select a.regno,a.rno,a.admtype,a.dr,a.admdate,a.advance,b.name,b.house,b.adr from ipreg a, regn b where a.regno=b.regno";
$result= mysqli_query($db,$sql)or die(mysqli_error());
?>
<table border=1
<th>Reg No<th>Name
<th>House <th> Address <th>Room No<th>Admn type<th>Doctor<th>Admn Date<th>Adv.
<?
while($row=mysqli_fetch_array($result))
{
print"<tr onMouseOver=bgColor='lightsteelblue'; onMouseOut=bgColor='EBF0DB'>";
print "<td><a href='editipreg.php?code=$row[regno]' title='Edit/Delete'>";
printf("%d",$row[regno]);
print"</a></td><td>$row[name]</td><td>$row[house]</td><td>$row[adr]</td>";
print "<td>$row[rno]</td><td>$row[admtype]</td><td>$row[dr]</td>";
print "<td>".datetohtml($row[admdate])."<td align=right>$row[advance]</td></td></tr>";
}
?>
</table>
