<?php
header("Content-type: text/html; charset=windows-1256");
session_start();

include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");


$query1="select grid_color1,grid_color2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}


$str   = $_GET['str']; if ($str == ""){		$str 	= $_POST["str"];}
$mode  = $_GET['mode'];if ($mode == ""){	$mode 	= $_POST["mode"];}
$post  = $_GET['post'];if ($post == ""){	$post 	= $_POST["post"];}
$index = $_GET['index']; if ($index == "") 	$index 	= $_POST['index'];
$PRef  = $_POST["PRef"]; if ($PRef == ""){	$PRef 	= $_GET["PRef"];}

$group_code1  = $_POST["group_code1"]; if ($group_code1 == ""){$group_code1 = $_GET["group_code1"];}
$group_name1  = $_POST["group_name1"]; if ($group_name1 == ""){$group_name1 = $_GET["group_name1"];}

if($mode=='insert'){
  
  $query = "insert into grouping(group_code,group_name,group_creationdate) values('".$group_code1."','".$group_name1."',now())";
  $result=mysql_query($query,$connection);
  $message  = mysql_error($connection); 
  $mode='';
  $PRef = $group_code1;
  $group_code1 = '';
  $group_name1 = '';
  
}




?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>List of Groups</title>
<script type="text/javascript" language="javascript">
function submitrecord(){
  
  document.form1.mode.value='insert';
  document.form1.action='List_Grouping.php';
  document.form1.submit();


}
function clearform()
{
  document.form1.PRef.value='';
  document.form1.action='List_Grouping.php';
  document.form1.submit();

}
</script>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style1 {
	color: #333333;
	font-weight: bold;
}
.style2 {
	color: #999999;
	font-weight: bold;
}
.style3 {color: #999999}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="800" border="0" align="center">
    <tr>
      <th colspan="2" bgcolor="#DDDDDD"><span class="style1"> Groups</span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Group <br> Code / Name</span></td>
      <td bgcolor="#DDDDDD"><input type="text" name="PRef" value="<?php echo $PRef; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $_GET['lcode']; ?>">
	   <input name="str" type="hidden"   value="<?php echo $str; ?>">
	   <input name="mode" type="hidden"   value="<?php echo $mode; ?>">
	   <input name="index" type="hidden" value="<?php echo $index; ?>">
     
        <input name="desc1" type="hidden" id="desc1" value="<?php echo $_GET['desc1']; ?>" />
	    <input type="submit" name="Submit" value="Find" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
		<input type="button" name="cancelbtn" value="Cancel" onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>
   
    </tr>
<?php if($post=="1") { ?>
	
		
<script type="text/javascript" language="javascript">


var vIndex	   = document.form1.index.value; 

if(document.form1.str.value=='1'){
	opener.document.SubGroup.group_code.value=document.form1.code1.value;
	opener.document.SubGroup.group_name.value=document.form1.desc1.value;
}

else if(document.form1.str.value=='2'){
	opener.document.items.group_code.value=document.form1.code1.value;
	opener.document.items.group_name.value=document.form1.desc1.value;
}

else if(document.form1.str.value=='3'){
	opener.document.salesman.group_codedt.value=document.form1.code1.value;
	opener.document.salesman.group_namedt.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='4'){
	opener.document.useraccess.group_code.value=document.form1.code1.value;
	opener.document.useraccess.group_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='5'){
	opener.document.items.item_packgroupcode.value=document.form1.code1.value;
	opener.document.items.item_packgroupname.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='6'){
	opener.document.clientdt.group_code.value=document.form1.code1.value;
	opener.document.clientdt.group_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='7'){
	if (opener.document.form1.fromgroup)
		opener.document.form1.fromgroup.value=document.form1.code1.value; 
	
	if (opener.document.form1.fromgroup_code)
		opener.document.form1.fromgroup_code.value=document.form1.code1.value; 
	
	opener.document.form1.fromgroup_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='8'){
	if (opener.document.form1.togroup)
		opener.document.form1.togroup.value=document.form1.code1.value;
	
	if (opener.document.form1.togroup_code)
		opener.document.form1.togroup_code.value=document.form1.code1.value;
	
	opener.document.form1.togroup_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='9'){
	opener.document.production.group_code.value=document.form1.code1.value;
}
else if(document.form1.str.value=='10'){
	opener.document.getElementById("group_code["+vIndex+"]").value=document.form1.code1.value;
}
else if(document.form1.str.value=='11'){
	opener.document.supplierdt.group_code.value=document.form1.code1.value;
	opener.document.supplierdt.group_name.value=document.form1.desc1.value;
} else if(document.form1.str.value=='12'){
	opener.document.supplierdt.supplier_groupcode.value=document.form1.code1.value;
	opener.document.supplierdt.supplier_groupname.value=document.form1.desc1.value;
} 
else if(document.form1.str.value=='13'){
	opener.document.getElementById('group').value=document.form1.code1.value;
	opener.document.getElementById('groupname').value=document.form1.desc1.value;
}
else if(document.form1.str.value=='14'){
	opener.document.getElementById('fromgroup').value 		= document.form1.code1.value;
	opener.document.getElementById('fromgroupname').value 	= document.form1.desc1.value;
	
	if (opener.document.getElementById('togroup').value == ''){
		opener.document.getElementById('togroup').value 	= document.form1.code1.value;
		opener.document.getElementById('togroupname').value = document.form1.desc1.value;
	}
}
else if(document.form1.str.value=='15'){
	opener.document.getElementById('togroup').value 	= document.form1.code1.value;
	opener.document.getElementById('togroupname').value = document.form1.desc1.value;
}
	else if(document.form1.str.value=='16'){
	opener.document.getElementById('group_code').value 	= document.form1.code1.value;
}
else if(document.form1.str.value=='17'){
	opener.document.form1.fromgroup.value=document.form1.code1.value;
	opener.document.form1.fromgroup_name.value=document.form1.desc1.value;
	opener.document.form1.togroup.value=document.form1.code1.value;
	opener.document.form1.togroup_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='18'){
	opener.document.form1.togroup.value=document.form1.code1.value;
	opener.document.form1.togroup_name.value=document.form1.desc1.value;
}
self.close();

</script>

<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="136"><span class="style2">Group Code </span></td>
      <td width="411" colspan="1"><span class="style2">Group Name </span></td>
  
    </tr>
	
	   <tr bgcolor="#E5E5E5">
      <td width="136"><span class="style2"><input type='text' name='group_code1' id='group_code1' style='width:100px' value='<?php echo $group_code1; ?>'></span></td>
      <td width="411" colspan="1"><span class="style2"><input type='text' name='group_name1' id='group_name1' value='<?php echo $group_name1; ?>'></span>
	  <input type='button' name='add' value='Save New Group' onclick='submitrecord()'><?php echo "<font color=red size=2>".$message."</font>"; ?>
	  </td>
  
    </tr>
	
<?php
$query1=" select Group_Code,Group_Name ".
		" from grouping";
		
		$query1=$query1." where (Group_Code like"."('%".$PRef."%') or Group_Name like"."('%".$PRef."%')) ";
if($str == 16) $query1 .= " and ifnull(sale_group,0) = 1 ";		
		$query1.= " order by Group_Code";
	

		
//echo$query1;
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){


$ct+=1;

if($ct%2==0)
{
	$Color="style='color:#0000FF;background-color:".$grid_color1."'";
	
	}else{
		
	$Color="style='color:#0000FF;background-color:".$grid_color2."'";	
}

?>
    <tr <?php echo $Color; 
	
	
	?>>
	
	 <?php
		$groupcode = $rows[0];
		$desc = $rows[1];
		$rows[1]=ereg_replace("'","%27",$rows[1]);
		
		$rows[0] = rawurlencode($rows[0]);
		$rows[1] = rawurlencode($rows[1]);
		?>
		
		
      <td align="left"><a href="List_Grouping.php?str=<?php echo $str; ?>&post=1&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo $desc; ?>&index=<?php echo $index; ?>"><?php echo $groupcode; ?></a></td>
      <td colspan="1"><a href="List_Grouping.php?str=<?php echo $str; ?>&post=1&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo $desc; ?>&index=<?php echo $index; ?>"><?php echo $desc; ?></a></td>

    </tr>
	
<?php }?>
  </table>
</form>
</body>
</html>
