<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
$cng=$_REQUEST['cng'];
if($cng)
{
    $newled=$_REQUEST['newled'];
    $ledna=$_REQUEST['ledna'];
 $re=mysqli_query($db,"select * from ledger where led='$newled' and brcode='$brcode'")or die(mysqli_error($db));
 if(mysqli_num_rows($re)>0)
 {
   print "<script> alert('Duplicate Ledger'); history.back(1); </script>";
   return;
 }
 mysqli_query($db,"update ledger set led='$newled' where led='$ledna' ")or die(mysqli_error($db));

 mysqli_query($db,"update bnkpay set partic='$newled' where partic='$ledna'  and brcode='$brcode'")or die(mysqli_error($db));
 mysqli_query($db,"update bnkrec set partic='$newled' where partic='$ledna'  and brcode='$brcode'")or die(mysqli_error($db));
 mysqli_query($db,"update cshpay set partic='$newled' where partic='$ledna' and brcode='$brcode'")or die(mysqli_error($db));
 mysqli_query($db,"update journal2 set partic='$newled' where partic='$ledna' ")or die(mysqli_error($db));

print "<font color=green>Ledger name has been changed</font>";
}
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<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='';
  }
 if(yy.indexOf('&')>-1) 
  {
    alert("\& is not allowed");
    abc.value='';
  }

}
function valid()
{
if(document.f1.ledna.selectedIndex<=0)
{alert('Invalid Ledger Selection'); return false;}

if(document.f1.newled.value.length<=0)
{alert('Invalid Ledger Name'); return false;}
}
function ss()
{
 document.f1.newled.value=document.f1.ledna.options[document.f1.ledna.selectedIndex].text;
}
</script>


<center>
<form action='<?print $PHP_SELF?>' name='f1' onSubmit="return valid()">
<table>
<?
if($user=='anoop'||$user=='joy')
{
?>

<th colspan=3> Edit Ledger Name</th>
<tr><td> Select Ledger </td><td>
<select name='ledna' onChange=ss()>
<option></option>
<?
$re=mysqli_query($db,"select code,led from ledger where brcode='$brcode' and grp !='Cash in hand' and grp !='Sundry Debtors' and grp !='Sundry Creditors' order by led");
while($row=mysqli_fetch_row($re))
{
 print "<option>$row[1]</option>";
}
?>
</select> </td></tr>
<tr><td>Enter New Name </td><td><input type=text name='newled' size=50 maxlength=45 onKeyDown=chkey(this)></td></tr>
<tr><td colspan=2 align=center height=29>
<input type=button value='Cancel' onClick='window.close();'>
<input type=submit value='Change' name='cng'>
</td></tr>
<?
}
?>

</table>
</form>

