<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);

if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.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);
}

$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}

$query_login="select login_belongstogrp,ifNull(FI_SalesmenDel,0),ifNull(FI_SalesmenMod,0) from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlogin=mysql_query($query_login,$connection) or die(mysql_error());

$row_login=mysql_fetch_row($resultlogin);
$belongstogroup=$row_login[0];
$FI_Salesman_Del=$row_login[1];
$FI_Salesman_Mod=$row_login[2];


//// Delete   Edit 
$DeleteMode=' ';
if($FI_Salesman_Del==0)
$DeleteMode ='disabled';

$EditMode=' ';
if($FI_Salesman_Mod==0)
$EditMode = ' disabled ';

$str = $_GET['str'];

print <<<HERE
<head>
<link rel="stylesheet" href="default.css" type="text/css" />
<title>Search Manifest</title>
<script type="text/javascript" language="javascript">

function clearform()
{
	
  document.search.action='Form_ManifestsOnlySearch.php';
  document.search.submit();

}

function LoadForm() 
{
	x=document.search;
	x.PRef.focus();
	

}

function SetNextPage(startrange,perpage){
	document.search.action='Form_ManifestsOnlySearch.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetPrvPage(startrange,perpage){
	document.search.action='Form_ManifestsOnlySearch.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function set_limit(){

	perpage=document.search.perpage.value;
	document.search.action='Form_ManifestsOnlySearch.php?perpage='+perpage;
	document.search.submit();
}


function Choosemanifest(manifest_auto, bl){
	var str = document.search.str.value;
	if (str == '1'){
		opener.document.containertrace.BL_number.value = bl;
	} else {
		opener.document.fromcr.manifest_auto.value = manifest_auto;
		opener.document.fromcr.showinfo.value = "1";
		opener.document.fromcr.submit();
	}
self.close();
}

function refreshSearch(){
	document.search.submit();
}

</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}

</style>

</head>
<body onLoad='LoadForm();'>
<form name='search' id='search' method='post' action=''>
<input type='hidden' name=vessel_auto value='$vessel_auto'>
<input type='hidden' name='str' id='str' value='$str'>
HERE;

echo"<table border='0' style='table-layout:fixed'>
	  <col width=20>
	  <col width=25>
	  <col width=25>
	  <col width=25>
	  <col width=25>
	  <col width=25>
	  
	  <col width=100>
	  <col width=150>
	  <col width=350>
	  <col width=350>
	  <col width=100>
	 
		     
	  <tr bgcolor='#DDDDDD'>
	    <td align='center' colspan='11'><span class='style16'>List of Manifest</span></td></tr>
	  <tr bgcolor='#DDDDDD' height=30px>
	    <td align='left' colspan='4'><span class='style11'>Search by Id</span></td>
		<td align='left' colspan=5><span class='style11'><input type='text' name='PRef' id='PRef' value='$PRef' size='15' maxlength='30'/>
			<input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
		    <input type='button' name='button' value='Find' onclick=\"refreshSearch();\" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
			<input type='button' name='btnCancel' value='Cancel' onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>
		<td align='left' colspan=2 valign='center'><span class='style25'>Result per page </span><span class='style11'>
		<select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
              


        if ($perpage==20)
			$s20 = 'selected';
		else if ($perpage==30)
			$s30 = 'selected';
		else if ($perpage==40)
			$s40 = 'selected';
		else if ($perpage==50)
			$s50 = 'selected';

			
				
        echo'<option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s40.' value="40">40</option>
			 <option '.$s50.' value="50">50</option>
			 </select></span>';

		echo "</td>";
			 

$querysearch = " select agent_id,BOL_identification,manifest_auto,consignee1,shipper1,Portofloading,voyage_number,received_date,client_code,ifnull(manifest_confirm,0),
				delivery_id,manifest_auto,voyage_year
				from manifest ";

$querysearch=$querysearch." WHERE ( ( agent_id like"."('%".$PRef."%') or BOL_identification like"."('%".$PRef."%')) ";
$querysearch=$querysearch." OR  ( voyage_year like"."('%".$PRef."%') or voyage_number like"."('%".$PRef."%')) ";
$querysearch=$querysearch." or ( consignee1 like"."('%".$PRef."%') or shipper1 like"."('%".$PRef."%')) ";
$querysearch=$querysearch." or ( voyage_bolnumber like"."('%".$PRef."%')) or ( manifest_confirm like"."('%".$PRef."%')) )  ";
if($manifeststatus != '')
	$querysearch=$querysearch." and ifnull(manifest_confirm,0) = '$manifeststatus' ";
$querysearch=$querysearch." order by manifest_auto desc";
//echo $querysearch;
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
echo" </tr>
	  <tr bgcolor='#DDDDDD'>
		<td height='15' align='center' colspan='18'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	
	  <tr bgcolor='#CCD8E6'>
		<td  height='25' align='center'><span class='style25'>&nbsp;</span></td>
		<td  height='25' align='left'><span class='style25'>JV Ref</span></td>
		<td  height='25' align='left'><span class='style25'>Inv Ref </span></td>
		<td  height='25' align='left'><span class='style25'>Manifest id </span></td>
		<td  height='25' align='left'><span class='style25'>voyage year </span></td>
		<td  height='25' align='center' ><span class='style25'>Voyage Number </span></td>
		<td  height='25' align='left'><span class='style25'>Agent Id </span></td>
		<td  height='25' align='center' ><span class='style25'>Bill Of lading </span></td>
		<td  height='25' align='center' ><span class='style25'>Consignee </span></td>
		<td  height='25' align='center' ><span class='style25'>Shipper </span></td>
		
		<td  height='25' align='center' ><span class='style25'>Status </span></td>
		
		
		
	  </tr>";

	
if ($startrange=='')
	$startrange = 0;
if ($perpage=='')
	$perpage = 20;
		
$querysearch = $querysearch." limit ".$startrange.",".$perpage;
echo"<input type='hidden' name='startranger' id='startranger' value='$startrange'>";

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		


while($rows=mysql_fetch_array($resultsearch)){
	
	$port_carrier='';
	$jv='';
	$reference='';
	
	$port="select port_carrier from port where port.port_name='$rows[5]'";
	$result=mysql_query($port,$connection) or die(mysql_error());
	$row=mysql_fetch_row($result);
	$port_carrier=$row[0];

	extract($rows);
	
	$delivery="select Journal_refgovernment,delivery_reference,delivery_id from deliveries left join journal on deliveries.journal_id=journal.journal_id where delivery_id=' $rows[10]'";
//echo $delivery;
	$querydeliv=mysql_query($delivery,$connection) or die(mysql_error());		
	$ref=mysql_fetch_row($querydeliv);
	$jv=$ref[0];
	$reference=$ref[1];
	$delivery_id=$ref[2];

	
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
			

	echo'<tr '.$Color.'>';




print<<<HERE
	


HERE;
	if ($rows[9]==1)$confirm="confirmed";
else if ($rows[9]==0)$confirm="not confirmed";
	
	$id=ereg_replace(" ","",$rows[0]);	
	$identification=ereg_replace(" ","",$rows[1]);	
	$auto=ereg_replace(" ","",$rows[2]);	

print<<<HERE
	<td align=center width='3%' ><img border='0' src='img/button_edit.png' width='9' height='10' title='Select Manifest' onmouseover=\"this.style.cursor='pointer'\" OnClick="Choosemanifest('$rows[2]','$identification');"></td>
	<td><font face='Arial' size='2' color='#186194'><span class='style15'>$jv</span></td>
	<td><font face='Arial' size='2' color='#186194'><span class='style15'>$reference</span></td>
	<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[11]</span></td>
	<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[12]</span></td>
	<td ><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[6]</span></font></td>

<td><font face='Arial' size='2' color='#186194'>

HERE;


print<<<HERE
<span class="style15">$id</span>

HERE;


echo"</font></td><td ><font face='Arial' size='2' color='#186194'><span class='style15'>$identification</span></font></td>";
echo"</font></td>";
echo "<td ><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[3]</span></font></td>";
echo"</font></td>";
echo "<td ><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[4]</span></font></td>";
echo"</font></td>";

echo "<td align='center' ><font face='Arial' size='2' color='#186194'><span class='style15'>$confirm</span></font></td>";
echo"</font></td>";

echo"</tr>";


}
			
		
echo"   <tr><td colspan='11'>&nbsp;</td></tr>
		<tr><td colspan=11><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td width='150' align='center'>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td><td width='170'>&nbsp;</td></tr>";
		echo"<table>";

echo"</td></tr></table>";
	


          

		  

print <<<HERE
</form>
</body>

HERE;

?>