<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($user)<=0)
{
 print "<script> alert('Invalid Login'); document.location='ind.php' ; </script>";
 return;
}
$led=$_REQUEST['led'];
$grp=$_REQUEST['grp'];
$op=$_REQUEST['op'];
$drcr=$_REQUEST['drcr'];
$led=trim($led);
if(strlen($led)<=0 || strlen($grp)<=0)
{
 print "<script>alert('Insufficient Entry'); history.back(1);</script>";
 return;
}
/*if(ereg("[&']",$led))
{
 print "<script> alert('Please avoid & and \''); history.back(1);</script>";
 return;
}*/
$code=substr($led,0,3).substr(time(),7,3);
$code=str_replace(' ','-',$code);

/*$link=mysqli_connect("localhost.localdomain","root");
mysqli_select_db("alpdb") or die ("<h3> Error:Database could not be connected-".mysqli_error());
*/
 include("opendb.php");
$re=mysqli_query($db,"select * from ledger where led='$led' and brcode='$brcode'");
if(mysqli_num_rows($re)>0)
{
 print "<script>alert('Duplicate Entry'); history.back(1); </script>";
 return;
}
if($op<='')
{
   $op=0; 
}

$sql="insert into ledger values('$led','$grp','$op','$drcr','$code','$brcode')";
mysqli_query($db,$sql) or die(mysqli_error());

log_entry($brcode,$user,$REMOTE_ADDR,"ledger Creation-$led",$db);
include("ledge.php");
?>
