<?php
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($HTTP_SESSION_VARS['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);

}

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

	$query1=" select distinct costcent_code, costcent_name from costcent ".
	        " where costcent_code ='".$_GET['lcode']."'";
					  
	$result1=mysql_query($query1,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result1)){
		extract($rows);

	}

	$post="1";

}

?>

<!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=iso-8859-1" />
<title>List of Costcenters</title>
<script type="text/javascript" language="javascript">

function clearform()
{
  document.form1.PCostcent_Code.value='';
  document.form1.PCostcent_Name.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;
}
.style3 {color: #999999}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="800" border="0" align="center">
    <tr>
      <th colspan="5" bgcolor="#DDDDDD"><span class="style1"> COSTCENTERS </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Costcent  <br> Code / Name</span></td>
      <td bgcolor="#DDDDDD"><input type="text" name="PCostcent_Code" value="<?php echo $PCostcent_Code; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $costcent_code; ?>">
      <td bgcolor="#DDDDDD"><input type="text" name="PCostcent_Name"  value="<?php echo $PCostcent_Name; ?>" size='35'/>
        <input name="desc1" type="hidden" id="desc1" value="<?php echo $costcent_name; ?>" />
	    <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>
      <td bgcolor="#DDDDDD">
		<input name="item1" type="hidden" id="item1" value="<?php echo $_GET['item']; ?>" />
		<input name="frm1" type="hidden" id="frm1" value="<?php echo $_GET['frm']; ?>" />
	  </td>
    </tr>
<?php if($post=="1") { ?>
<script type="text/javascript" language="javascript">

var vItem = document.form1.item1.value;
var vFrm = document.form1.frm1.value;

if (vFrm == 2 && vItem == 1) {
	opener.document.invoices.fromcostcent.value=document.form1.code1.value;
	opener.document.invoices.fromcostcentname.value=document.form1.desc1.value;
}
else if (vFrm == 2 && vItem == 2) {
	opener.document.invoices.tocostcent.value=document.form1.code1.value;
	opener.document.invoices.tocostcentname.value=document.form1.desc1.value;
}
else {
	opener.document.form1.fromcostcent.value=document.form1.code1.value;
}


self.close();

</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="136"><span class="style2">Costcent Code </span></td>
      <td width="411" colspan="2"><span class="style2">Costcent Name </span></td>
      <td width="57"><span class="style3"></span></td>
    </tr>
<?php
		
				  
//Costcenter List
$querycostcent=" select distinct costcent.costcent_code as costcent_code, costcent_name as costcent_name".
               " from costcent left join ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on costcent.costcent_code like concat(loginstk.costcent_code,'%') ".
 			   " where user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
			   " and costcent.costcent_code like '".$PCostcent_Code."%' ".
			   " and costcent_name like '%".$PCostcent_Name."%' ".
 			   " order by costcent.costcent_code";
			  
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentrows   = mysql_num_rows($costcentresult);
if ($costcentrows == 0)
    $querycostcent=" select distinct costcent_code, costcent_name from costcent ".
	               " where costcent_code like '".$PCostcent_Code."%' ".
				   " and costcent_name like '%".$PCostcent_Name."%' ".
				   " order by costcent_code ";			  
$resultcostcent=mysql_query($querycostcent,$connection) or die(mysql_error());				  
			  
while($rows=mysql_fetch_array($resultcostcent)){
extract($rows);

$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; ?>>
      <td align="left"><a href="List_Costcenter_Reports.php?lcode=<?php echo $costcent_code; ?>&item=<?php echo $_GET['item']; ?>&frm=<?php echo $_GET['frm']; ?>"><?php echo $costcent_code; ?></a></td>
      <td colspan="2"><a href="List_Costcenter_Reports.php?lcode=<?php echo $costcent_code; ?>&item=<?php echo $_GET['item']; ?>&frm=<?php echo $_GET['frm']; ?>"><?php echo $costcent_name; ?></a></td>
      <td>&nbsp;</td>
    </tr>
<?php
}
?>
  </table>
</form>
</body>
</html>
