<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
ini_set('max_execution_time', $config['ReportTimeExecution']);

$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");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

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

}


$post  = $_GET['post'];if ($post == ""){$post = $_POST["post"];}

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

$frm = $_GET['frm'];
$vIndex = $_GET['vIndex'];

if($_GET['icode']!=""){

$query1="select itemOption_code as itemOpt_code, item_description, itemOption_qty as qty from item_option
		inner join items on items.item_code = itemOption_code 
		where itemOption_code='".$_GET['icode']."'";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}
$post="1";
}

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Select Items</title>

<script type="text/javascript" language="javascript">

function clearform()
{
  document.form1.PItem_Description.value='';
  document.form1.PItem_Code.value='';
  document.form1.SCode.value='';

}
</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;
	font-size: 12px;
}
.style3 {color: #999999}
.style4{
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="100%" border="0" align="center">
    <tr>
      <th colspan="6" bgcolor="#DDDDDD"><span class="style1">Search for Item </span></th>
    </tr>
  
   <tr>
   <td bgcolor="#DDDDDD" > <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Item  <br> Code / Desc.</span></td>
     
      
      <th bgcolor="#DDDDDD" align='left' colspan='5'>
	  <input type="text" name="PItem_Code" value="<?php echo $PItem_Code; ?>"  />
		<input name="code1" type="hidden" id="code1"  value="<?php echo $itemCode; ?>">
		<input type="hidden" name="field1" id='field1' value="<?php echo $itemOpt_code; ?>"  />
		<input name="field2" type="hidden" id="field2" value="<?php echo $item_description; ?>" />
		<input name="field3" type="hidden" id="field3"  value="<?php echo $qty; ?>">
		<input name="frm" type="hidden" id="frm"  value="<?php echo $frm; ?>">
		<input name="vIndex" type="hidden" id="vIndex"  value="<?php echo $vIndex; ?>">
		<input type="text" name="PItem_Description"  value="<?php echo $PItem_Description; ?>" size='35'/>
		<input type="submit" name="Submit" value="Find" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
		</td><th>
        
	  </th>
      
    </tr>

	
	              			
      
			

	
<?php if($post=="1") { ?>
<script type="text/javascript" language="javascript">
x=document.form1;
frm = x.frm.value;
index = x.vIndex.value;
if(frm=="1"){
	opener.document.getElementById('itemcode['+index+']').value=document.form1.field1.value;
	opener.document.getElementById('itemdescription['+index+']').value=document.form1.field2.value;
	//opener.document.getElementById('prddtquantity['+index+']').value=document.form1.field3.value;
	//opener.document.getElementById('prddtquantity['+index+']').onkeyup();
	self.close();
}

if(frm=="2"){
	opener.document.getElementById('itemcode['+index+']').value=document.form1.field1.value;
	opener.document.getElementById('itemdescription['+index+']').value=document.form1.field2.value;
	//opener.document.getElementById('prddtquantity['+index+']').value=document.form1.field3.value;
	//opener.document.getElementById('prddtquantity['+index+']').onkeyup();
	self.close();
}

</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="110"><span class="style2">Item Code </span></td>
      <td width="411" colspan="2"><span class="style2">Item Description </span></td>
      <td width="108"><span class="style2">Quantity</span></td>
    </tr>
<?php

$query1 = "select itemOption_code as Item_Code, item_description, itemOption_qty as qty from item_option
			inner join items on items.item_code = itemOption_code where item_option.item_code = '$itemCode'"; //echo $query1;
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

$ct+=1;

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

?>
    <tr <?php echo $Color; ?>>
      <td align="left"><a href="List_itemOption.php?frm=<?php echo $_GET['frm']; ?>&vIndex=<?php echo $_GET['vIndex']; ?>&icode=<?php echo $Item_Code; ?>&itemCode=<?php echo $itemCode; ?>"><span class="style4"><?php echo $Item_Code; ?></span></a></td>
      <td colspan="2"><a href="List_itemOption.php?frm=<?php echo $_GET['frm']; ?>&vIndex=<?php echo $_GET['vIndex']; ?>&icode=<?php echo $Item_Code; ?>&itemCode=<?php echo $itemCode; ?>"><span class="style4"><?php echo $item_description; ?></span></a></td>
      <td><span class="style4"><?php echo $qty; ?></span></td>
    </tr>
<?php
}
?>
  </table>
</form>
</body>
</html>
