<? session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
if($edit)
{
 if(strlen($newacname)<=0)
  {
     print "<script> alert('In sufficient entry'); history.back(1);  </script>";
     return;
  }
$r=mysqli_query($db,"select * from ledger where led= trim('$newacname') and brcode='$brcode'");
if(mysqli_num_rows($r)>0)
  {
     print "<script> alert('Duplicate Ledger name'); history.back(1);  </script>";
     return;
  }

$r=mysqli_query($db,"select * from ledger where led='$oldname' and brcode='$brcode'")or die(mysqli_error());

if(mysqli_num_rows($r)<=0)
  {
     print "<script> alert('Ledger does not exist'); history.back(1);  </script>";
    return;
  }

 $sql="update ledger set led='".trim($newacname)."' where led='$oldname' and brcode='$brcode'";
 mysqli_query($db,$sql) or die('ledger Err:'.mysqli_error());

 $sql="update journal2 set partic='".trim($newacname)."' where partic='$oldname' and brcode='$brcode'";
 mysqli_query($db,$sql) or die('Journal Err:'.mysqli_error());

 $sql="update cust_master set acname='".trim($newacname)."' where code='$code' and branch='$brcode'";
  mysqli_query($db,$sql) or die('Cust_master Err:'.mysqli_error());

 $sql="update orderform set cust='".trim($newacname)."' where formno='$ofno' and brcode='$brcode'";
 mysqli_query($db,$sql) or die('Order form Err:'.mysqli_error());
log_entry($brcode,$user,$REMOTE_ADDR,"Edit customer Ledger $oldname");
}
$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;

if($user_level>='4'||$user=='admin')
{  
 $re=mysqli_query($db,"select * from cust_master where code='$code'");
 $row=mysqli_fetch_array($re);
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<script>
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='';
  }

}
</script>
<form action='<?print $PHP_SELF?>'>
<table border=1>
<input type=hidden name='oldname' value='<?print $row[acname]?>'>
<input type=hidden name='code' value='<?print $code?>'>
<input type=hidden name='ofno' value='<?print $row[ofno]?>'>


<tr><td colspan=2 align=center><b><font color=red>EDIT CUSTOMER NAME (LEDGER)</td></tr>
<tr><td>Customer Name</td><td><?print $row[custname]?> </td></tr>
<tr><td>Ledger /Display Name</td><td><?print $row[acname]?> </td></tr>
<tr><td>Order Form No.</td><td><?print $row[ofno]?> </td></tr>
<tr><td>Address</td><td><?print $row[addr1].'<br>'.$row[addr2]?> </td></tr>
<tr><td>New Display Name</td><td><input type=text name='newacname' size=40 onKeyDown=chkey(this);> </td></tr>
<tr><td colspan=2 align=center> <input type=submit name='edit' value=' SAVE '> <input type=button value=' Cancel ' onClick=document.location='cust-mast.php'></td></tr>
</table>
</form>

<?
}
else
 print "<font color=red>You are not authorised</font>";
?>
