<?php session_name('CAKEPHP'); session_start();
$PageSecurity = 4;
$PageName = 'Add Items';
include('includes/DefinePOClass.php');
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/DefineSuppTransClass.php');
//include('includes/header.inc');
include('includes/function_lib.php');
?>
<script> 
function getdata1(str)
{  	
var xmlhttp;
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)
    {
	 var data=xmlhttp.responseText.split("__");	 
	document.getElementById("ItemListDiv").innerHTML=data[1];
	document.getElementById("subcategory1").innerHTML=data[0];
		
    }
  }
  xmlhttp.open("GET","item_list_ajax.php?site="+str,true);
xmlhttp.send();
//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

}	function getItems(str)
	{		
		//var arr=document.getElementById("arr").value;
		//alert(arr);
		
		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("ItemListDiv").innerHTML=xmlhttp.responseText;
    	
        		}}
        		var arr=document.getElementById('start').value;
        		
xmlhttp.open("GET","item_list_ajax.php?q="+str+"&start="+arr,true);
xmlhttp.send();
	}
	
	
	function getItems1(str)
	{		
		//var arr=document.getElementById("arr").value;
		//alert(arr);
		
		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("ItemListDiv").innerHTML=xmlhttp.responseText;
    	
        		}}
xmlhttp.open("GET","item_list_ajax.php?q="+str,true);
xmlhttp.send();
	}
	
	
function ExitWindow()
{
	opener.window.location="index.php?route=POModule/direct_purchase_order&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewRequisition=Yes";self.close();
}
</script>

 <h2 align="center">Search ITEMS</h2>
 <?php 
if($_REQUEST['Select'] != '')
{
	$item_array=array();
	$item_array=$_REQUEST['row_id'];
	if(empty($_SESSION['itemdetails']))
	{
		$_SESSION['itemdetails']=$item_array;
	}
	else if(!empty($_SESSION['itemdetails']))
	{ if(!empty($_REQUEST['row_id']))
		{ 
		$_SESSION['IntermediateList']=$_REQUEST['row_id'];
		$_SESSION['itemdetails']=array_unique(array_merge($_SESSION['itemdetails'],$_SESSION['IntermediateList']));
		}
	}
	if(!empty($_SESSION['itemdetails']))
	{
	//print_r($_SESSION['ACGRequisition-ItemList']);
	$itemlist=implode("#",$_SESSION['itemdetails']);
	$_SESSION['itemdetails_1']=$itemlist;
	}
	print_r($_SESSION['itemdetails']); 
if($_REQUEST['Reset']!='')
{
	unset($_SESSION['itemdetails']);
	unset($_SESSION['itemdetails_1']);
	unset($_SESSION['IntermediateList']);
}
}
?>
<form name="form1" action="" method="post">
	<input type="hidden" value="<?php print_r($_SESSION['itemdetails']);?>" id="arr" />
<table width="100%" border="0">
	<tr><td><input style="margin:0px 0px 10px 0px;" type="submit" name="Select" id="Select" value="Add To List"><input style="margin:0px 0px 10px 0px;" type="submit" name="Reset" id="Reset" value="Reset"></td>
		<td><div align="right"><input style="margin:0px 0px 10px 0px;" type="button" name="Exit" id="Exit" value="Exit" onclick="ExitWindow()" ></div>
		</td>
	</tr></table>
  <table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
        <tr>
          <th width="13%"><strong>SELECT</strong></th>
          <th width="30%"><strong>ITEM CODE</strong></th>
          <th width="34%"><strong>ITEM NAME</strong></th>
            <th width="34%"><strong>ITEM No</strong></th>
          <th width="23%"><strong>UNIT</strong></th>
        </tr></table>
<?php
$i=0;
  	if($i%2==0)
	{$bg="#CCCCCC";}
	else
	$bg="#C8BECB";
 	$sql=DB_query("Select * from item_master",$db); 	
	?>
	<div style="overflow: scroll; height: 300px" id="ItemListDiv"><table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
	<?php 
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
	  		$parameter=$myrow['StockID'];
			$c='';
			for($x=0;$x<count($_SESSION['itemdetails']);$x++)
			{
				if($parameter==$_SESSION['itemdetails'][$x])
				$c="checked";
			}
  ?>
 <tr bgcolor="<?php echo $bg;?>">
      <td width="13%"><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"	<?php echo $c;?> /></td>
      <td width="32%"><strong><?php echo $myrow['StockID'];?></strong></td>
      <td width="34%"><?php echo $myrow['item_name'];?></td>
      <td width="34%"><?php echo $myrow['item_no'];?></td>
       <td width="21%"><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); echo $unit;?></td>
     
    </tr>
<?php $i++;
		} 
}?>
<input type="hidden" name="row_sount" id="row_count" value="<?php echo $i;?>">
</table></div>
</form>

