<?php
header("Content-type: text/html; charset=utf8");

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

include("config.inc.php");
include("Forms_DataGrid_Archive.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");

mysql_query("SET NAMES 'utf8'"); 
mysql_query('SET CHARACTER SET utf8'); 

/*$querylog="SELECT FI_Delivery as loginaccess, FI_SalesVAT from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
*/

$query = "select archive_path from setup";
$res = mysql_query($query,$connection);
$row = mysql_fetch_row($res);
$archive_path = $row[0];

class tabs {
	var $name;
	var $tabs;
	var $active;
	var $current;
function start($name){
		if (empty($this->active)){ $this->active = $name; }
		$this->current = $name;
		ob_start();
	}
	function end(){
		$this->tabs[$this->current] = ob_get_contents();
		ob_end_clean();
	}
	function run(){
	
	
	
		if (count($this->tabs) > 0){
			echo "<DIV CLASS='tabs'>\n";
			$jsClear = "";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				$jsClear .= "\tdocument.getElementById('$tabid').className = 'tab_inactive';\n";
				$jsClear .= "\tdocument.getElementById('$contentid').style.display = 'none';\n";
			}
			echo "<script type=\"text/javascript\">\n";
			echo "function tab_".$this->name."(id,fieldname){\n";
			echo "$jsClear";
			
			echo "\tdocument.getElementById('tab_".$this->name."_'+id).className = 'tab_active';\n";
			echo "\tdocument.getElementById('tabcontent_".$this->name."_'+id).style.display = '';\n";
			
			echo"	
				//alert(fieldname);
				if(fieldname!='' && fieldname!=undefined)
					
					document.clientdt[fieldname].focus();
				";
			echo "}\n";
			echo "</script>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV CLASS='";
				if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
				echo "' ID='$tabid' ";
				echo "onClick=\"tab_".$this->name."('$tabname');\">$tabname</DIV>\n";
			}
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
				if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
				echo ";'>$tabcontent</DIV>\n";
			}
			echo "</DIV>\n";
			echo "<DIV STYLE='clear: both;'></DIV>\n";
		}}
}	

$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mainaction = $_POST["mainaction"]; if ($mainaction == ""){$mainaction = $_GET["mainaction"];}   
$archive_id = $_POST["archive_id"]; if ($archive_id == ""){$archive_id = $_GET["archive_id"];}   
$chkdate	= $_POST["chkdate"]; 	if ($chkdate == ""){$chkdate = $_GET["chkdate"];}   
$chkdate2	= $_POST["chkdate2"]; 	if ($chkdate2 == ""){$chkdate2 = $_GET["chkdate2"];}   

if (empty($mainaction))	$mainaction = 'insert';
if($chkdate=='') $chkdate=0;
if($chkdate2=='') $chkdate2=0;
if($chkdetail=='') $chkdetail=0;

if($fromdate=='') $fromdate=date('d/m/Y');
if($todate=='') $todate=date('d/m/Y');


if($archive_issuedate == '') $archive_issuedate = date('d/m/Y');
$message = ereg_replace("'"," ",$message);

$queryper = "select distinct period from archiving ;";
$resper = mysql_query($queryper, $connection);
$rwp = mysql_fetch_row($resper);
//if($period_id == '') $period_id = $rwp[0];
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">
<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
<script type="text/javascript" language="javascript">

function SetNextPage(startrange,perpage, parameters){
	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('[BRK]');
			document.getElementById("filterGrid").innerHTML='';
			document.getElementById("filterGrid").innerHTML=data[1];	
							
		}
	}
	
	xmlhttp.open("GET",'Form_Archive_Action.php?actionmode=SetPage&startrange='+startrange+'&perpage='+perpage+'&parameters='+parameters);
	xmlhttp.send();
}
function SetLastPage(perpage,totalrows,parameters){
	var result=totalrows % perpage;
	if (result == 0) result = perpage;
	startrange=totalrows-result;
	
	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('[BRK]');
			document.getElementById("filterGrid").innerHTML='';
			document.getElementById("filterGrid").innerHTML=data[1];	
							
		}
	}
	
	xmlhttp.open("GET",'Form_Archive_Action.php?actionmode=SetPage&startrange='+startrange+'&perpage='+perpage+'&parameters='+parameters);
	xmlhttp.send();
}


function SetPrvPage(startrange,perpage,parameters){

	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('[BRK]');
			document.getElementById("filterGrid").innerHTML='';
			document.getElementById("filterGrid").innerHTML=data[1];	
							
		}
	}
	
	xmlhttp.open("GET",'Form_Archive_Action.php?actionmode=SetPage&startrange='+startrange+'&perpage='+perpage+'&parameters='+parameters);
	xmlhttp.send();
}
function SetFirstPage(startrange,perpage,parameters){
	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('[BRK]');
			document.getElementById("filterGrid").innerHTML='';
			document.getElementById("filterGrid").innerHTML=data[1];	
							
		}
	}
	
	xmlhttp.open("GET",'Form_Archive_Action.php?actionmode=SetPage&startrange='+startrange+'&perpage='+perpage+'&parameters='+parameters);
	xmlhttp.send();
}

function printpreview(exp){

	
	var x = document.archives;
	var archive_company	= encodeURIComponent(x.archive_company.value);
	var archive_clearing = encodeURIComponent(x.archive_clearing.value);
	var archive_ForwarderL = encodeURIComponent(x.archive_ForwarderL.value);
	var archive_ForwarderB = encodeURIComponent(x.archive_ForwarderB.value);
	var archive_container = encodeURIComponent(x.archive_container.value);
	var archive_docnumber = encodeURIComponent(x.archive_docnumber.value);
	var archive_shipper = encodeURIComponent(x.archive_shipper.value);
	var archive_producttype = encodeURIComponent(x.archive_producttype.value);
	var archive_freight = encodeURIComponent(x.archive_freight.value);
	var archive_loading = encodeURIComponent(x.archive_loading.value);
	var archive_consigned = encodeURIComponent(x.archive_consigned.value);
	var archive_issuedate = encodeURIComponent(x.archive_issuedate.value);
	var userfile1 = encodeURIComponent(x.userfile1.value);
	var advfield = encodeURIComponent(x.advfield.value);
	var period_id = x.period_id.value;
	var chkdetail=x.chkdetail.value;
	
	var groupby=x.groupby.value;
	var chkdate=x.chkdate.value;
	var chkdate2=x.chkdate2.value;
	var filterflag=x.filterflag.value;
	var advfilterflag=x.advfilterflag.value;
	var chkor=x.chkor.value;
	var orderby=x.orderby.value;
	var perpage=x.perpage.value;
	var startrange=x.startrange.value;
	
	window.open('Form_Archive_Report.php?archive_company='+archive_company+'&archive_clearing='+archive_clearing+
	'&archive_ForwarderL='+archive_ForwarderL+'&archive_ForwarderB='+archive_ForwarderB+
	'&archive_container='+archive_container+'&archive_docnumber='+archive_docnumber+
	'&archive_shipper='+archive_shipper+'&archive_producttype='+archive_producttype+
	'&archive_freight='+archive_freight+'&archive_loading='+archive_loading+
	'&archive_consigned='+archive_consigned+'&archive_issuedate='+archive_issuedate+
	'&userfile1='+userfile1+'&period_id='+period_id+'&advfield='+advfield+'&groupby='+groupby+
	'&chkdate='+chkdate+'&chkor='+chkor+'&chkdate2='+chkdate2+'&chkdetail='+chkdetail+
	'&advfilterflag='+advfilterflag+'&filterflag='+filterflag+'&orderby='+orderby+
	'&perpage='+perpage+'&startrange='+startrange+'&exp='+exp);


}

function saveProduct(product_id){
	if(product_id == '')
		actionmode = 'insertproduct';
	else actionmode = 'updateproduct';
	if(document.archives.product_name.value==''){
		alert("Product Name should not be Empty!");
		return 0;
	} else {
		var product_name  = encodeURIComponent(document.archives.product_name.value);
		
		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('[BRK]');
				document.getElementById("divproduct").innerHTML='';
				document.getElementById("divproduct").innerHTML=data[0];	
				document.getElementById("divallproduct").innerHTML='';					
				document.getElementById("divallproduct").innerHTML=data[1];					
			}
		}
	    
		xmlhttp.open("GET",'Form_Archive_Action.php?actionmode='+actionmode+'&product_id='+product_id+'&product_name='+product_name);
		xmlhttp.send();

	}
}

function deleteProduct(product_id){
		
	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('[BRK]');
			document.getElementById("divproduct").innerHTML=" ";
			document.getElementById("divproduct").innerHTML=data[0];
			document.getElementById("divallproduct").innerHTML='';	
			document.getElementById("divallproduct").innerHTML=data[1];					
		}
	}
	    
	xmlhttp.open("GET",'Form_Archive_Action.php?actionmode=deleteproduct&product_id='+product_id);
	xmlhttp.send();
}
function editProduct(product_id){
	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('[BRK]');
			document.getElementById("divproduct").innerHTML=" ";
			document.getElementById("divproduct").innerHTML=data[0];
			document.getElementById("divallproduct").innerHTML='';	
			document.getElementById("divallproduct").innerHTML=data[1];					
		}
	}
	    
	xmlhttp.open("GET",'Form_Archive_Action.php?actionmode=editProduct&product_id='+product_id);
	xmlhttp.send();
}
function PostChanges(){
	var x = document.archives;
	if(x.archive_shipper.value==''){
		alert("Shipper Value is Empty!");
		return 0;
	} else if(x.archive_company.value==''){
		alert("Company Name is Empty!");
		return 0;
	} 
	else {
		x.action = "Form_Archive_Action.php";
		x.submit();
	}
	
}

function SearchPage(){
	win = window.open('Form_ArchiveSearch.php', 'Form_ArchiveSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=950,height=600,top=100');		
	win.creator = self;
	win.focus();	
}

function FilterResult(){
	document.archives.filterflag.value=1;
	document.archives.advfilterflag.value=0;
	document.archives.submit();
}

function AdvFilterResult(){
	document.archives.filterflag.value=0;
	document.archives.advfilterflag.value=1;
	document.archives.submit();
}

function ClearPage(){
	var x = document.archives;
	x.actionmode.value='';
	x.mainaction.value='';
	x.archive_id.value='';
	x.filterflag.value='';
	x.advfilterflag.value='';
	x.archive_company.value='';
	x.archive_issuedate.value='';
	x.archive_consigned.value='';
	x.archive_loading.value='';
	x.archive_freight.value='';
	x.archive_producttype.value='';
	x.archive_shipper.value='';
	x.archive_docnumber.value='';
	x.archive_container.value='';
	x.archive_ForwarderL.value='';
	x.archive_ForwarderB.value='';
	x.archive_clearing.value='';
	x.userfile1.value='';
	x.period_id.value='';
	x.groupby.value='';
	x.chkdate.value='';
	x.chkdate2.value='';
	x.advfield.value='';
	x.chkdetail.value='';
	x.archive_fullpage.value='';
	x.orderby.value='';
	x.submit();
}
function setOr(){
	if(document.getElementById("chkor").checked)
		document.getElementById("chkor").value=1;
	else document.getElementById("chkor").value=0;
}
function setDetail(){
	if(document.getElementById("chkdetail").checked)
		document.getElementById("chkdetail").value=1;
	else document.getElementById("chkdetail").value=0;
}
function setchk(){
	if(document.getElementById("chkdate").checked){
		document.getElementById("chkdate").value=1;
		document.getElementById("chkdate2").value=0;
		document.getElementById("chkdate2").checked=false;
	}
	else document.getElementById("chkdate").value=0;
}
function setchk2(){
	if(document.getElementById("chkdate2").checked){
		document.getElementById("chkdate2").value=1;
		document.getElementById("chkdate").value=0;
		document.getElementById("chkdate").checked=false;
	}
	else document.getElementById("chkdate2").value=0;
}
function viewPage(id,tablename){
	str='form_FulPageText.php?id='+id+'&tbname='+tablename;
	window.open(str,'mywindow','width=865,height=680,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
</script>
<style>
.style111 {
	font-size: 11px;
}
</style>
<title>Archives</title>
</head>
<body >
<form name='archives' method='post' action=''  enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='archive_id' value='$archive_id'>
<input type='hidden' name='filterflag' value='$filterflag'>
<input type='hidden' name='advfilterflag' value='$advfilterflag'>
<input type='hidden' name='archive_path' value='$archive_path'>
<input type='hidden' name='message' value='$message' size='200'>

HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'><input type='hidden' id='txtSaDiscount_Temp'  name='txtSaDiscount_Temp' value='$txtSaDiscount_Temp'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>Archives</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";

echo" <button type='button' id='btnClear' name='btnClear' onclick=\"ClearPage();return false;\" title='Clear Page'><span><span>Clear Page</span></span></button>";
echo" <button type='button' id='btnPost' name='btnPost' onclick=\"PostChanges();return false;\" title='Save Changes'><span><span>Save</span></span></button>";
echo" <button type='button' id='btnSearch' name='btnSearch' onclick=\"SearchPage();return false;\" title='Search'><span><span>Search</span></span></button>";
echo" <button type='button' id='btnFilter' name='btnFilter' onclick=\"FilterResult();return false;\" title='Filter'><span><span>Filter</span></span></button>";
echo" <button type='button' id='btnFilter' name='btnFilter' onclick=\"AdvFilterResult();return false;\" title='Advanced Filter'><span><span>Advanced Filter</span></span></button>";

echo" <button type='button' id='preview' name='preview' onclick=\"printpreview();return false;\" title='preview'><span><span>Preview</span></span></button>";
echo" <button type='button' id='export_excel' name='export_excel' onclick=\"exportexcel();return false;\" title='Export Excel'><span><span>Export Excel</span></span></button>";
echo"</td></tr></table>";
echo"</td></tr>";				

if($archive_id != ''){
	$query ="select companyname,date_format(Check_DateFormat(issuedate),'%d/%m/%Y'), vessel, consigned,portofloading,	portofdischarge,freight,producttype, shipper, filename, documentnumber, fullpage,containertype,ForwarderL, 
			ForwarderB,clearingtime
			from archiving where auto=$archive_id;";//echo $query;
	$res = mysql_query($query,$connection);
	$row = mysql_fetch_row($res);
	
	$archive_company = $row[0];
	$archive_issuedate = $row[1];
	$archive_vessel = $row[2];
	$archive_consigned = $row[3];
	$archive_loading = $row[4];
	$archive_discharge = $row[5];
	$archive_freight = $row[6];
	$archive_producttype = $row[7];
	$archive_shipper = $row[8];
	$archive_docnumber = $row[10];
	$archive_fullpage = $row[11];
	$archive_container = $row[12];
	$archive_ForwarderL = $row[13];
	$archive_ForwarderB = $row[14];
	$archive_clearing = $row[15];
	
}	
echo"<tr><td id='content-body'>";

$tabs = new tabs("Archives");	
	
$tabs->start("Main Page");

echo"	<table border='0'  align='left' valign='top' class='tablecontent'>
			<col width=100%>";
echo"   	<tr bgcolor='#F7F7F7' height='10' ><td valign='top'>";
echo "<table align='left'  border='0' width='1099px' bgcolor='999999' ><col width=80px><col width=100px><col width=100px><col width=100px><col width=180px><col width=100px><col width=100px><col width=100px><col width=100px>";

echo "<tr><td><span class='style1'>Group By: </span></td>";
echo"<td><select name='groupby' style='width: 120px;'>";
echo"<option value='0' ".($groupby=='0'?'selected':'')."></option>";
echo"<option value='1' ".($groupby=='1'?'selected':'').">Date</option>";
echo"<option value='2' ".($groupby=='2'?'selected':'').">Company</option>";
echo"</select></td>";
echo "<td colspan='1'><input type='checkbox' name='chkdate2' id='chkdate2' value='$chkdate2' ".($chkdate2==1?'checked':'')." onclick=\"setchk2();\"> 
	<span class='style1'>Issue Date </span></td>";
echo "<td colspan='1'><input type='checkbox' name='chkdate' id='chkdate' value='$chkdate' ".($chkdate==1?'checked':'')." onclick=\"setchk();\">
	<span class='style1'>From/To Date</span></td>";
echo "<td colspan='1'><input type='checkbox' name='chkor' id='chkor' value='$chkor' ".($chkor==1?'checked':'')." onclick=\"setOr();\"> <span class='style1'> OR as a Separator</span></td>";
echo"<td colspan='2'><span class='style1'>From Date</span>";
echo"<input type='text' name='fromdate' id='fromdate' value='$fromdate' style='width:80px' readonly>
	<a href='#' onclick=\"displayCalendar(document.archives.fromdate,'dd/mm/yyyy',this); return false;\" name='anchor1' id='anchor1'><img src=\"./img/cal.gif\" border='0' align='top'></a>
	</td>";
echo"<td colspan='2'><span class='style1'>To Date </span>";
echo"<input type='text' name='todate' id='todate' value='$todate'  style='width:80px' readonly>
	<a href='#' onclick=\"displayCalendar(document.archives.todate,'dd/mm/yyyy',this); return false;\" name='anchor1' id='anchor1'><img src=\"./img/cal.gif\" border='0' align='top'></a>
	</td></tr>";
echo "<tr><td><span class='style1'>Order By </span></td><td colspan='1'><select name='orderby' id='orderby' style='width: 120px;'>";
echo "<option value='' ".($orderby==''?'selected':'')."></option>";
echo "<option value='1' ".($orderby=='1'?'selected':'').">Document Number</option>";
echo "</select></td>
	<td colspan='1' align='right'><span class='style1'>Advanced</span></td><td colspan='1'><textarea name='advfield' id='advfield' col='40' row='1'>$advfield</textarea></td>";
echo "<td colspan='2'><input type='checkbox' name='chkdetail' id='chkdetail' value='$chkdetail' ".($chkdetail==1?'checked':'')." onclick=\"setDetail();\"> <span class='style1'>Include Detailed Results</span></td></tr>";
		
echo"</table>";





echo"   	<tr bgcolor='#F7F7F7' height='10' ><td valign='top'>";	 
echo" 			<table border='0' style='table-layout:fixed' align='left' width='1000px' valign='top' >
					<col width=100px>
					<col width=150px>
					<col width=20px>
					<col width=100px>
					<col width=150px>
					<col width=20px>
					<col width=100px>
					<col width=150px>
					<col width=20px>
					<col width=100px>
					<col width=150px>";

				
					
echo "<tr height='30px'>
		<td><span class='style1'>Company</span></td>
		<td><input type='text' name='archive_company' id='archive_company' value='$archive_company' style='font-size:12px; width:160px;height:25px;'></td>
		 <td></td>
		 <td><span class='style1'>Document Number</span></td>
		<td><textarea name='archive_docnumber' id='archive_docnumber' cols='20' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_docnumber)."</textarea></td>
        
		<td></td>
		<td><span class='style1'>Shipper</span></td>
		<td><textarea  name='archive_shipper' id='archive_shipper'  cols='20' rows='1' style='font-size:12px;' >".htmlspecialchars($archive_shipper)."</textarea></td>
		<td></td>
		<td><span class='style1'>Port of Loading</span></td>
		<td><textarea name='archive_loading' id='archive_loading' cols='20' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_loading)."</textarea></td>
		
	</tr>";
echo "<tr>
		<td><span class='style1'>Consigned</span></td>
		<td><textarea name='archive_consigned' id='archive_consigned' cols='20' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_consigned)."</textarea></td>
		<td></td>
		<td><span class='style1'>Freight</span></td>
		<td><textarea name='archive_freight' id='archive_freight' cols='20' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_freight)."</textarea></td>
		<td></td>
		<td><span class='style1'>Issue Date</span></td>
		<td><input type='text' name='archive_issuedate' id='archive_issuedate' value='$archive_issuedate' style='font-size:12px; width:125px;' readonly>
		<a href='#' onclick=\"displayCalendar(document.archives.archive_issuedate,'dd/mm/yyyy',this); return false;\" name='anchor1' id='anchor1'><img src=\"./img/cal.gif\" border='0' align='top'></a></td>
		";
echo "<td></td>
		<td><span class='style1'>Period</span></td>
		<td><select name='period_id' id='period_id' style='width:100px;font-size:12px;'>";
		echo "<option value='' ".($period_id == ''?'selected':'')."></option>";	
		$queryper = "select period_id, period_description from periods ";
		$resper = mysql_query($queryper, $connection);
		while($rwper = mysql_fetch_row($resper)){
			echo "<option value='$rwper[0]' ".($period_id == $rwper[0]?'selected':'').">$rwper[1]</option>";	
		}
		echo "	</select></td>
		
		
	</tr>";	
echo "<tr><td colspan='11'><hr></td></tr>";
echo "<tr>
		<td><span class='style1'>Forwarder Loading</span></td>
		<td><textarea name='archive_ForwarderL' id='archive_ForwarderL' cols='20' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_ForwarderL)."</textarea></td>
		<td></td>
		<td><span class='style1'>Forwarder Discharge</span></td>
		<td><textarea name='archive_ForwarderB' id='archive_ForwarderB' cols='20' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_ForwarderB)."</textarea></td>
		<td></td>
		<td><span class='style1'>File</span></td>
		<td><input type='file'  name='userfile1' id='userfile1' style='width:200px;'></td>
	</tr>";	
	
echo "<tr>
		<td><span class='style1'>Container Type</span></td>
		<td><textarea name='archive_container' id='archive_container' cols='20' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_container)."</textarea></td>
		<td></td>
		<td><span class='style1'>Product Type</span></td>
		<td><textarea name='archive_producttype' id='archive_producttype' cols='20' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_producttype)."</textarea></td>
	    <td></td>
		<td><span class='style1'>Clearing Time</span></td>
		<td><textarea name='archive_clearing' id='archive_clearing' cols='20' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_clearing)."</textarea></td>

	</tr>";		
echo "<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>	
	</tr>";
echo "<tr>
		
		<td><span class='style1'>Full Page</span></td>
		<td colspan='7'><textarea name='archive_fullpage' id='archive_fullpage' cols='130' rows='3' style='font-size:12px;' >".htmlspecialchars($archive_fullpage)."</textarea></td>
	</tr>";

echo "<tr height='5px'></tr>";	
echo "</table>";


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


$ndate=explode("/",$fromdate);
$fromdate=$ndate[2]."-".$ndate[1]."-".$ndate[0];
$ndate=explode("/",$todate);
$todate=$ndate[2]."-".$ndate[1]."-".$ndate[0];
$ndate=explode("/",$archive_issuedate);
$archive_issuedate=$ndate[2]."-".$ndate[1]."-".$ndate[0];
$parameters = array();

$parameters['fromdate'] 			= $fromdate;
$parameters['todate'] 				= $todate;
$parameters['filterflag'] 			= $filterflag;
$parameters['advfilterflag'] 		= $advfilterflag;
$parameters['chkdetail'] 			= $chkdetail;
$parameters['chkor'] 				= $chkor;
$parameters['archive_company'] 		= $archive_company;
$parameters['archive_consigned'] 	= $archive_consigned;
$parameters['archive_loading'] 		= $archive_loading;
$parameters['archive_freight'] 		= $archive_freight;
$parameters['archive_shipper'] 		= $archive_shipper;
$parameters['archive_docnumber'] 	= $archive_docnumber;
$parameters['archive_discharge'] 	= $archive_discharge;
$parameters['archive_producttype'] 	= $archive_producttype;
$parameters['archive_container'] 	= $archive_container;
$parameters['archive_ForwarderL'] 	= $archive_ForwarderL;
$parameters['archive_ForwarderB'] 	= $archive_ForwarderB;
$parameters['archive_clearing'] 	= $archive_clearing;
$parameters['period_id'] 			= $period_id;
$parameters['chkdate'] 				= $chkdate;
$parameters['chkdate2'] 			= $chkdate2;
$parameters['advfield'] 			= $advfield;
$parameters['orderby'] 				= $orderby;
$parameters['archive_path'] 		= $archive_path;
$parameters['archive_issuedate']    = $archive_issuedate;
echo" <tr bgcolor='999999' height='25' ><td valign='top'><div id='filterGrid' style='overflow-x: scroll;overflow-y: scroll;height:500px;width:1100px'>";
$perpage = 1000;$startrange=0;
filterGrid($parameters, $perpage, $startrange, $connection);
echo"</div></td></tr>";
echo "</table>";


$tabs->end();
				
$tabs->start("Products");
echo"	<table border='0'  align='left' valign='top' class='tablecontent'>
			<col width=65%>";
echo" <tr bgcolor='#F7F7F7' height='25' ><td valign='top'>";	 			
echo "<div id='divproduct' style='width: 600px;height: 100px;float: left;'>";
	getProductGrid($product_id,$connection);
echo "</div>";
echo "<div id='divallproduct' style='width: 340px;float: left;'>";
	getAllProductGrid($product_id,$connection);
echo "</div>";
echo "</td></tr>";
echo "</table>";

$tabs->end();				
$tabs->run();
echo"   </td></tr>"; 

echo"  <tr height='30'><td align='center' id='content-bottom' ></td></tr>";  

echo" </table>  ";//end of last table menu
	if($vTabFocus!=''){
	echo'<script type="text/javascript" language="javascript">';
	echo"tab_('$vTabFocus','');";
	echo'</script>';	
}	

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

HERE;

?>