<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
?>
<head>
<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='';
  }
}
</script>
</head>
<?
if(isset($_POST['add']))
{
    $itmcod=$_REQUEST['cus'];
    $grpnm=$_REQUEST['grp'];
    if(strlen($grpnm)>0)
    {
        $sql=mysqli_query($db,"select count(item_code) from prod_invoice where item_code='$itmcod' and brcode='$brcode'");
        $row=mysqli_fetch_array($sql);
        if($row[0]>0)
        {
            $query="update prod_invoice set gname='$grpnm' where item_code='$itmcod' and brcode='$brcode'";
            mysqli_query($db,$query);
        }
        $sql1=mysqli_query($db,"select count(item_code) from brtransferin where item_code='$itmcod' and brcode='$brcode'");
        $row1=mysqli_fetch_array($sql1);
        if($row1[0]>0)
        {
            $query1="update brtransferin set gname='$grpnm' where item_code='$itmcod' and brcode='$brcode'";
            mysqli_query($db,$query1);
        }
        
        $sql2=mysqli_query($db,"select count(item_code) from brtransferout where item_code='$itmcod' and brcode='$brcode'");
        $row2=mysqli_fetch_array($sql2);       
        if($row2[0]>0)
        {         
            $query2="update brtransferout set gname='$grpnm' where item_code='$itmcod' and brcode='$brcode'";            
            mysqli_query($db,$query2);             
        }    
       
        $sql3=mysqli_query($db,"select count(itemcode) from stockverification where itemcode='$itmcod' and brcode='$brcode'");
        $row3=mysqli_fetch_array($sql3);
        if($row3[0]>0)
        {
            $query3="update stockverification set gname='$grpnm' where itemcode='$itmcod' and brcode='$brcode'";
            mysqli_query($db,$query3);
        }
        
        $sql4=mysqli_query($db,"select count(itemcode) from sparestock where itemcode='$itmcod' and brcode='$brcode'");
        $row4=mysqli_fetch_array($sql4);
        if($row4[0]>0)
        {
            $query4="update sparestock set item_grp='$grpnm' where itemcode='$itmcod' and brcode='$brcode'";
            mysqli_query($db,$query4);
        }
        
       $sql5=mysqli_query($db,"select count(partcode) from partmaster where partcode='$itmcod'");
        $row5=mysqli_fetch_array($sql5);
        if($row5[0]>0)
        {
            $query5="update partmaster set gname='$grpnm' where partcode='$itmcod'";
            mysqli_query($db,$query5);
        }          
            print "<script> alert('Data has been updated'); </script>";            
  		
    }
}

?>
<title>Demo</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="scripts/jquery-latest.js"></script>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
<script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      

</script>
<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;

}
</style>
<style>
th{background-color:steelblue;color:white}
</style>
<body background="back_ground.jpg">
<?php //include('logo2.php'); ?>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()" method='post'>
<table class="container"><tr><td>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Utility >> Group Name Change</font>
<center>

<table class="form" ><tr><th colspan='2'>
<h3><font color='black'>Group Name Change</font></h3></td></tr>
<form action='<?print $PHP_SELF?>'>
    <?
    $sql="SELECT * FROM partmaster order by partcode asc";
$result = mysqli_query($db,$sql);
?>

<tr><td>Item Code</td>
    <td  id="to_new_customerTD">
        <select name='cus' id='cus' onchange='showregister(this.value)' style='width:260px;border:1px solid grey; border-style:dotted;' >
            <option value="">--select--</option>
            <?
            while($row=mysqli_fetch_array($result))
{
?>
<option value="<? echo $row['partcode'] ?>"><? echo $row['partcode'] ?></option>
<?
}
?>
</select>
        </td></tr>
  
<tr> <td>Group Name </td>
<td id="to_new_registerTD"><input type=text name='cusnwnm' size=40 onKeyUp=chkey(this) onKeyPress="return handleEnter(this, event)"></td>
</tr>
<tr> <th colspan='2' align='center'><input type=submit value='Update' name='add'></th></tr>
</table>
</form>
<script type="text/javascript">
function showregister(str)
{
//var str="hello";
//alert (str);
if (str=="")
  {
  document.getElementById("to_new_registerTD").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("to_new_registerTD").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","showitems.php?cname="+str,true);
xmlhttp.send();

}
</script>