<? session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='ind.php'; </script>";
 return;
}
include("opendb.php");
if($cng)
{
 $re=mysqli_query($db,"select * from ledger where led='$newled'")or die(mysqli_error());
 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' and brcode='$brcode'")or die(mysqli_error());
 mysqli_query($db,"update advcollection set type='$newled' where type='$ledna'  and brcode='$brcode'")or die(mysqli_error());
 mysqli_query($db,"update bnkpay set partic='$newled' where partic='$ledna'  and brcode='$brcode'")or die(mysqli_error());
 mysqli_query($db,"update bnkrec set partic='$newled' where partic='$ledna'  and brcode='$brcode'")or die(mysqli_error());
 mysqli_query($db,"update cshpay set partic='$newled' where partic='$ledna' and brcode='$brcode'")or die(mysqli_error());
 mysqli_query($db,"update cshrec set partic='$newled' where partic='$ledna' and brcode='$brcode'")or die(mysqli_error());
 mysqli_query($db,"update dbnote set partic='$newled' where partic='$ledna' and brcode='$brcode'")or die(mysqli_error());
 mysqli_query($db,"update journal2 set partic='$newled' where partic='$ledna' and brcode='$brcode'")or die(mysqli_error());
 mysqli_query($db,"update receipts set cus_ac='$newled' where cus_ac='$ledna'")or die(mysqli_error());
 mysqli_query($db,"update veh_purchase set ledger='$newled' where ledger='$ledna' and brcode='$brcode'")or die(mysqli_error());
 mysqli_query($db,"update veh_salereturn set retfrom='$newled' where retfrom='$ledna' and brcode='$brcode'")or die(mysqli_error());
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>
<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=document.location='blank.html'> 
<input type=submit value='Change' name='cng'>
</td></tr>
</table>
</form>

