<?php
$PageSecurity = 5;
global $db;
 include('includes/session.inc');
//$title = _('Search VendorCode ');
   echo '<link href="'.$rootpath. '/css/'. $_SESSION['Theme'] .'/default.css" rel="stylesheet" type="text/css" />';

if($_REQUEST['submit'])
{
	$filter = array();
	$sql = "Select vendor_code, vendor_name from suppliers";
 	if(isset($_POST['code']) && $_POST['code'] != '')
	$filter[] = "vendor_code LIKE '%".$_POST['code']."%'";
	if(isset($_POST['name']) && $_POST['name'] != '')
	$filter[] = "vendor_name LIKE '%".$_POST['name']."%'";
 	if(count($filter)>0) 
	{
		$sql = $sql." where ".implode(" and ",$filter);
	}
	else{
		$sql = $sql." where 1=1";
	}
	 
}
else{
$sql = "Select vendor_code, vendor_name from suppliers";
}
$result = DB_query($sql, $db);
?>
<form action="" method="post">
<table align="center">
<tr><td colspan="4"><div align="center"><strong>SEARCH</strong></div></td></tr>
<tr>
<td><strong>Vendor Code</strong></td>
<td><input type="text" name="code" value="<?php echo $_POST['code'];?>" /></td>
<td><strong>Vendor Name</strong></td>
<td><input type="text" name="name" value="<?php echo $_POST['name'];?>" /></td>
<td><input type="submit" name="submit" value="Search" /></td>
</tr>
</table>
 
</form>
 
<form action="" method="post">
  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    
     
   
    
    <tr>
      <td><table width="100%" border="1" align="center" cellpadding="2">
        <tr bgcolor="#CCCCCC">
        
          <th width="50%" align="center"><strong>VENDOR NAME</strong></th>
          <th width="50%" align="center"><strong>VENDOR CODE</strong></th>
          </tr>
        <?php while($myrow = DB_fetch_array($result))
{ ?>
        <tr>
          
          <td><?php echo $myrow['vendor_name'];?></td>
          <td><a href="javascript:loadValue('<?php echo $myrow['vendor_code'].",".$myrow['vendor_name'];?>')"><?php echo $myrow['vendor_code'];?></a></td>
          </tr>
        <?php } ?>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>

<script type="text/javascript">
function loadValue(i)
{   
	var name1;
	var name2;
	var spl = i.split(",");
	name1 = spl[0];
	name2 = spl[1];
	window.opener.document.getElementById('VendorCodeSearch').value = name1;
	window.opener.document.getElementById('VendorNameSearch').value = name2;
	window.close();
}
</script>

 