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

include("config.inc.php");
include("function.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");
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 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
	extract($rows);
}

$item   	= $_GET['item']; 		if ($item == ""){		$item 		= $_POST["item"];}
$frm	   	= $_GET['frm']; 		if ($frm == ""){		$frm 		= $_POST["frm"];}
$index		= $_GET['index']; 		if ($index == "") 		$index 		= $_POST['index'];
$PCode  	= $_POST["PCode"]; 		if ($PCode == ""){		$PCode 		= $_GET["PCode"];}
$PDesc  	= $_POST["PDesc"]; 		if ($PDesc == ""){		$PDesc 		= $_GET["PDesc"];}

if ($frm == 1)
	$title = "Services";
else if ($frm == 2)
	$title = "Dealer";
else if ($frm == 3)
	$title = "Team";
else if ($frm == 4)
	$title = "Ship Co";
else if ($frm == 5)
	$title = "Terminal";
else if ($frm == 6)
	$title = "Destination";
else if ($frm == 7)
	$title = "Tranporter";
else if ($frm == 8)
	$title = "Pick Up";

 
	
if($_GET['lcode']!=""){
	
	// Readon from Logistic_Services
	if ($frm == 1)
	$query1=" select service_id as code1, service_code as code2, service_description as code3, ifnull(service_seqId,0)+1 as code4 from Logistic_Services ".
			" where service_id ='".$_GET['lcode']."'";
	
	// Readon from Logistic_Dealer		
	if ($frm == 2)
	$query1=" select Dealer_Id as code1, Dealer_Code as code2, Dealer_Description as code3 from Logistic_Dealer ".
			" where Dealer_Id ='".$_GET['lcode']."'";
	
	// Readon from Logistic_Team		
	if ($frm == 3)
	$query1=" select Team_Id as code1, Team_Code as code2, Team_Description as code3 from Logistic_Team ".
			" where Team_Id ='".$_GET['lcode']."'";
	
	// Readon from Logistic_ShipCo		
	if ($frm == 4)
	$query1=" select Ship_Id as code1, Ship_Code as code2, Ship_Description as code3 from Logistic_ShipCo ".
			" where Ship_Id ='".$_GET['lcode']."'";
	
	// Readon from Logistic_Terminal		
	if ($frm == 5)
	$query1=" select Terminal_Id as code1, Terminal_Code as code2, Terminal_Description as code3 from Logistic_Terminal ".
			" where Terminal_Id ='".$_GET['lcode']."'";
	
	// Readon from Logistic_Destination
	if ($frm == 6)
	$query1=" select Destination_Id as code1, Destination_Code as code2, Destination_Description as code3 from logistic_destination ".
			" where Destination_Id ='".$_GET['lcode']."'";
	
	// Readon from logistic_transporter
	if ($frm == 7)
	$query1=" select Transporter_Id as code1, Transporter_Code as code2, Transporter_Description as code3 from logistic_transporter ".
			" where Transporter_Id ='".$_GET['lcode']."'";
	
	// Readon from logistic_pickup
	if ($frm == 8)
	$query1=" select PickUp_Id as code1, PickUp_Code as code2, PickUp_Description as code3 from logistic_pickup ".
			" where PickUp_Id ='".$_GET['lcode']."'";
					  
	$result1=mysql_query($query1,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result1)){
		extract($rows);

	}

	$_GET['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 <?php echo $title;?></title>
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>

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

function clearform()
{
	var vFrm = document.form1.frm.value;	
	var vitem = document.form1.item.value;	
	var vindex = document.form1.index.value;	
	document.form1.PCode.value='';
	document.form1.PDesc.value='';
	document.form1.action='List_LogisticOpSetup.php?frm='+vFrm+'&item='+vitem+'&index='+vindex;
	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; font-size: 13px;}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="800" border="0" cellspacing="1" align="center">
	<col width='200'><col width='200'><col width='350'><col width='50px'>
    <tr>
      <th colspan="5" bgcolor="#DDDDDD"><span class="style1"> List of <?php echo $title;?> </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for <?php echo $title;?></span></td>
      <td bgcolor="#DDDDDD"><input type="text" name="PCode" value="<?php echo $PCode; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $code1; ?>">
        <input name="code2" type="hidden" id="code2"  value="<?php echo $code2; ?>">
        <input name="code3" type="hidden" id="code3"  value="<?php echo $code3; ?>">
        <input name="code4" type="hidden" id="code4"  value="<?php echo $code4; ?>">
      <td bgcolor="#DDDDDD">
		<input type="text" name="PDesc" value="<?php echo $PDesc; ?>"  />
         <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="item" type="hidden" id="item" value="<?php echo $item; ?>" />
		<input name="frm" type="hidden" id="frm" value="<?php echo $frm; ?>" />
		<input name="index" type="hidden" id="index" value="<?php echo $index; ?>" />
	 </td>
    </tr>
<?php if($_GET['post']=="1") { ?>
<script type="text/javascript" language="javascript">
var FormOption = document.form1.frm.value;
var FormItem   = document.form1.item.value;
var FormIndex   = document.form1.index.value;

if (FormOption == 1) {
	if (FormItem == 1) {
		opener.document.getElementById('olServiceTypeId').value	= document.form1.code1.value;
		opener.document.getElementById('olServiceType').value	= document.form1.code2.value;
		opener.document.getElementById('olServiceSeqId').value	= document.form1.code2.value+'-'+document.form1.code4.value;
	}
}	
else if (FormOption == 2) {
	if (FormItem == 1) {
		opener.document.getElementById('olDealerId').value	= document.form1.code1.value;
		opener.document.getElementById('olDealer').value	= document.form1.code2.value;
	}
}
else if (FormOption == 3) {
	if (FormItem == 1) {
		opener.document.getElementById('olTeamId').value	= document.form1.code1.value;
		opener.document.getElementById('olTeam').value		=	document.form1.code2.value;
	}
}
else if (FormOption == 4) {
	if (FormItem == 1) {
		opener.document.getElementById('olShipCoId').value	= document.form1.code1.value;
		opener.document.getElementById('olShipCo').value	= document.form1.code2.value;
	}
}
else if (FormOption == 5) {
	if (FormItem == 1) {
		opener.document.getElementById('olTerminalId').value	= document.form1.code1.value;
		opener.document.getElementById('olTerminal').value		= document.form1.code2.value;
	}
	if (FormItem == 2) {
		opener.document.getElementById('tlTerminalId').value	= document.form1.code1.value;
		opener.document.getElementById('tlTerminal').value		= document.form1.code2.value;
	}
}
else if (FormOption == 6) {
	if (FormItem == 1) {
		opener.document.getElementById('olDestinationId').value	= document.form1.code1.value;
		opener.document.getElementById('olDestination').value	= document.form1.code2.value;
	}
	if (FormItem == 2) {
		opener.document.getElementById('tlDestinationId').value	= document.form1.code1.value;
		opener.document.getElementById('tlDestination').value	= document.form1.code2.value;
	}
}
else if (FormOption == 7) {
	if (FormItem == 1) {
		opener.document.getElementById('tlTransporterId'+FormIndex).value	= document.form1.code1.value;
		opener.document.getElementById('tlTransporter'+FormIndex).value	= document.form1.code2.value;
	}
}
else if (FormOption == 8) {
	if (FormItem == 1) {
		opener.document.getElementById('tlPickUpPntId'+FormIndex).value	= document.form1.code1.value;
		opener.document.getElementById('tlPickUpPnt'+FormIndex).value	= document.form1.code2.value;
	}
}
self.close();

</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td ><span class="style2">Code </span></td>
      <td colspan='2'><span class="style2">Description</span></td>
      <td ><span class="style3"></span></td>
    </tr>
<?php
	if ($frm == 1)
		$query = " select service_id as LogOp_id, service_code as LogOp_code, service_description as LogOp_desc from Logistic_Services 
				where if('$PCode' != '', service_code like '$PCode%', 1=1) and if('$PDesc' != '', service_description like '$PDesc%', 1=1)
				order by service_code ";
	else if ($frm == 2)
		$query = " select Dealer_Id as LogOp_id, Dealer_Code as LogOp_code, Dealer_Description as LogOp_desc from Logistic_Dealer 
				where if('$PCode' != '', Dealer_Code like '$PCode%', 1=1) and if('$PDesc' != '', Dealer_Description like '$PDesc%', 1=1)
				order by Dealer_Code ";
	else if ($frm == 3)
		$query = " select Team_Id as LogOp_id, Team_Code as LogOp_code, Team_Description as LogOp_desc from Logistic_Team 
				where if('$PCode' != '', Team_Code like '$PCode%', 1=1) and if('$PDesc' != '', Team_Description like '$PDesc%', 1=1)
				order by Team_Code ";
	else if ($frm == 4)
		$query = " select Ship_Id as LogOp_id, Ship_Code as LogOp_code, Ship_Description as LogOp_desc from Logistic_ShipCo 
				where if('$PCode' != '', Ship_Code like '$PCode%', 1=1) and if('$PDesc' != '', Ship_Description like '$PDesc%', 1=1)
				order by Ship_Code ";
	else if ($frm == 5)
		$query = " select Terminal_Id as LogOp_id, Terminal_Code as LogOp_code, Terminal_Description as LogOp_desc from Logistic_Terminal 
				where if('$PCode' != '', Terminal_Code like '$PCode%', 1=1) and if('$PDesc' != '', Terminal_Description like '$PDesc%', 1=1)
				order by Terminal_Code ";	
	else if ($frm == 6)
		$query = " select Destination_Id as LogOp_id, Destination_Code as LogOp_code, Destination_Description as LogOp_desc from logistic_destination 
				where if('$PCode' != '', Destination_Code like '$PCode%', 1=1) and if('$PDesc' != '', Destination_Description like '$PDesc%', 1=1)
				order by Destination_Code ";	
	else if ($frm == 7)
		$query = " select Transporter_Id as LogOp_id, Transporter_Code as LogOp_code, Transporter_Description as LogOp_desc from logistic_transporter 
				where if('$PCode' != '', Transporter_Code like '$PCode%', 1=1) and if('$PDesc' != '', Transporter_Description like '$PDesc%', 1=1)
				order by Transporter_Code ";	
	else if ($frm == 8)
		$query = " select PickUp_Id as LogOp_id, PickUp_Code as LogOp_code, PickUp_Description as LogOp_desc from logistic_pickup 
				where if('$PCode' != '', PickUp_Code like '$PCode%', 1=1) and if('$PDesc' != '', PickUp_Description like '$PDesc%', 1=1)
				order by PickUp_Code ";	
	
	$result = mysql_query($query, $connection);

while($rows=mysql_fetch_array($result)){
	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"><span class="style3"><a href="List_LogisticOpSetup.php?lcode=<?php echo $LogOp_id; ?>&frm=<?php echo $frm; ?>&item=<?php echo $item; ?>&index=<?php echo $index; ?>"><?php echo $LogOp_code; ?></a></span></td>
      <td colspan="2"><span class="style3"><a href="List_LogisticOpSetup.php?lcode=<?php echo $LogOp_id; ?>&frm=<?php echo $frm; ?>&item=<?php echo $item; ?>&index=<?php echo $index; ?>"><?php echo $LogOp_desc; ?></a></span></td>
      <td>&nbsp;</td>
    </tr>
<?php
	}
?>
  </table>
</form>
</body>
</html>
