<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($bcode)<=0 && strlen($user)<=0)
{
 print "<script> alert('Please login again'); parent.document.location='ind.php'; </script>";
 return;
}
include("test.php");
include("opendb.php");
$us=mysqli_query($db,"select level from bruser where username='$user'")or die(mysqli_error());
$r=mysqli_fetch_row($us);
$level=$r[0];
if($level<=3)
{
 print "<center><font color=red><b>You are not authorised to create ledger";
return;
}
?>

<style>
 td{font-family:verdana;font-size:14;color:black;}
 th{font-family:verdana;font-size:14;color:white;background-color:#5b5858}
 body{background-color:silver;}
 select
  {border-style:ridge;
   border-color:black;
   height:25px;
   border-size=1;
   font-family:verdana;
   color:black;
  }
 input
  {border-style:ridge;
   border-color:#22437f;
   background-color:white;
   height:25px;
   font-weight:bold;
   border-size=1;
   font-family:sans-serif;
   color:BLACK;
  }
</style>
<script>
 var dr_cr=[];
function showNature()
{
 var nature=dr_cr[document.f1.grp.selectedIndex];
 if(nature=='Assets'||nature=='Expenses')
    document.f1.drcr.value='Dr';
 else if(nature=='Liabilities'||nature=='Income')
    document.f1.drcr.value='Cr';
 else
   document.f1.drcr.value='';
}

function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
 if(yy.indexOf("'")>-1) 
  {
    alert("\' is not allowed");
    abc.value='';
  }
 if(yy.indexOf('"')>-1) 
  {
    alert("\" is not allowed");
    abc.value='';
  }
 if(yy.indexOf('&')>-1) 
  {
    alert("\& is not allowed");
    abc.value='';
  }
}

function valid()
{ 
 subOK="false";
 x=confirm("Do you want to save?");
 if(x)
  subOK="true";
   if(subOK=="true")
     return true;
   else
     return false;
} 

</script>
<?
if($level>2)
{?>
<body>
<center>
<form name=f1 action="svled.php" method=post onSubmit="return valid()">
<table width=90%>
<tr><td colspan=2 bgcolor=#5b5858 align=center><font color=white size=3>LEDGER CREATION</font></tr></td>
<tr><td>Ledger Name</td><td><input type=text name=led size=40 onKeyDown=chkey(this)></td></tr>
<tr><td>Under Sub Group</td><td>
<select name=grp onChange=showNature();>
<option></option>
<?

$i=1;
$result=mysqli_query($db,"select gname,nature,headgroup from acgroups where gname !='-' order by headgroup") or die(mysqli_error());
while($row=mysqli_fetch_row($result))
{
 print "\n<option value='$row[0]'>$row[0] - $row[2]</option>";
 print "\n<script>dr_cr[$i]='$row[1]'</script>";
 $i++;
}

?>
</select> </tr></td>
<tr><td>Opening Balance </td><td><input type=text name=op > 
Type <input type=text readonly name=drcr size=4 style={background:silver}>
<!--
<select name=drcr>
<option>Dr</option>
<option>Cr</option>
<select>
-->
</td></tr>
<tr><td colspan=2 bgcolor=#5b5858 align=center>
<input type=submit value="Add"> <input type=button value="Cancel" onClick=document.location='blank.html'> <input type=reset value='Clear'>
</tr></td>
</table>
</form>
<?
}
?>
