<?
session_start();
$brcode = $_SESSION['brcode'];
$user = $_SESSION['user'];
include("test.php");
include("opendb.php");
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='ind.php' </script>";
  return;
}
$us=mysqli_query($db,"select level from bruser where username='$user'")or die(mysqli_error());
$r=mysqli_fetch_row($us);
$user_level=$r[0];
 print "User Level:".$user_level;
?>
<head>
<script>
 function sh()
 {
  window.open('prnledger.php');
 }
</script>
</head>
<style>
 td{font-family:arial ;font-size:13;color:black;}
 th{font-family:aria narrow;font-size:14;color:white;background-color:#5b5858}
 body{background-color:ivory}
</style>
</center>
<body>
<table border=0 width=100%>
<tr><td>
<font face=verdana size=3 color='dark brown'>Current Ledgers</b></font>
</td><td align=right width=30 bgcolor=silver><a href='javascript:sh()'><img src='Type001.gif' border=0></a> </td></tr>
<tr><td colspan=2 bgcolor=green></td></tr>
<tr><td colspan=2>
<table border=0 cellspacing=1 cellpadding=1 bgcolor=black width=>
<tr bgcolor='silver'><td width=5><center><b>No.</td><td width=300><center><b>Ledger Name </td><td><center><b>Under Group</td><td><center><b>Op Balance<td><center><b>Dr/Cr</td>

<?
$sea = $_REQUEST['sea'];
$num_rows = $_REQUEST['num_rows'];
if($user_level=='4')
 print "<td align=center><b>Action</td>";
print "</tr>";

$cnt=mysqli_query($db,"select * from ledger where brcode='$brcode'")or die(mysqli_error());
$num_rows=mysqli_num_rows($cnt);

if($num_rows>25)
{
 print "Page ";
 for($k=0;$k<=$num_rows/25;$k++)
 {
   print "<a href='listledgers2.php?pg=".($k)."'>".($k+1)."</a> ";
 }
}

print "<form name='f1' action='$PHP_SELF'><input type=text name='sea' > <input type=submit value='Search' name='sealed'></form><br>&nbsp;";
print "Current page:".($pg+1);
if($sealed||strlen($sea)>0)
 $sq="select * from ledger where led like '%$sea%' and brcode='$brcode' order by led";
else
 $sq="select * from ledger where brcode='$brcode' order by led limit ".($pg*25).",25";
$result=mysqli_query($db,$sq)or die(mysqli_error());

$i=$pg*25+1;
while($row=mysqli_fetch_array($result))
{
 if($row[0]=='Cash' || $row[0]=='Petty Cash')
{
print"\n<form action='editledger.php'><input type=hidden name=ledg value='$row[0]'>";
print "\n<tr bgcolor='#fffcd6' onMouseOver=bgColor='#f7dbd4'; onMouseOut=bgColor='#fffcd6'>";
print "<td>".$i++."</td><td><a href='vmledger-test-scru1.php?cd=".str_replace('&','-',$row[0])."'>$row[0]</a></td><td>$row[1]</td><td align=right>".putComa($row[2])."</td><td align=right>$row[3]</td>";
if($user_level=='4')
 print "\n<td colspan=2><input type=submit value='Edit' style={width:37}></td></tr> </form>";
}
else
{
//print"<form action='editledger.php'><input type=hidden name=ledg value='$row[0]'>";
print"\n<form action='editledger.php'><input type=hidden name=ledg value='$row[0]'>";
print "\n<tr bgcolor='#fffcd6' onMouseOver=bgColor='#f7dbd4'; onMouseOut=bgColor='#fffcd6'>";
print "<td>".$i++."</td><td><a href='vmledger-test-scru1.php?cd=".str_replace('&','~',$row[0])."&sea=$sea'>$row[0]</a></td><td>$row[1]</td><td align=right>".putComa($row[2])."</td><td align=right>$row[3]</td>";
 if($user_level=='4')
print "\n<td><input type=submit value='Edit' style={width:37}> <input type=button value='Delete' onClick=delfun('".$row['code']."'); style={width:52}></td></tr></form>";
}
print "</tr>";
}
?>
</table>
<script>
function delfun(x)
{
 document.location='delledger.php?code='+x;
}
</script>
