<?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 offer_path from setup";
$res = mysql_query($query,$connection);
$row = mysql_fetch_row($res);
$offer_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"];}   
$offer_id 	= $_POST["offer_id"]; 	if ($offer_id == ""){	$offer_id 	= $_GET["offer_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($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);

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 exportexcel(){
		var x = document.archives;
	var groupbylist=x.groupbylist.value;
	
	
	
	
		var archive_offer	=x.archive_offer.value;
	var archive_account= x.archive_account.value;
	var archive_POL =x.archive_POL.value;
	var archive_POD= x.archive_POD.value;
	var archive_FOD= x.archive_FOD.value;
	var archive_type= x.archive_type.value;
	var archive_issue_date= x.archive_issue_date.value;
	var archive_expire_date= x.archive_expire_date.value;
	//var archive_size1= x.archive_size1.value;
	//var archive_size2=x.archive_size2.value;
	//var groupbylist=x.groupbylist.value;
	var fromdateo=x.fromdateo.value;
	var todateo=x.todateo.value;
	var checkdateissue=x.checkdateissue.value;
	var checkdateexpire=x.checkdateexpire.value;
	var filterflago=x.filterflago.value;
	var confirmed=x.confirmed.value;
	
	//if(filterflago==1)
	window.open('Form_offer_Excel.php?archive_offer='+archive_offer+'&archive_account='+archive_account+'&archive_POL='+archive_POL+'&archive_POD='+archive_POD+'&archive_FOD='+archive_FOD
	+'&archive_type='+archive_type+'&archive_issue_date='+archive_issue_date+'&archive_expire_date='+archive_expire_date+'&confirmed='+confirmed
	+'&groupbylist='+groupbylist+'&fromdateo='+fromdateo+'&todateo='+todateo+'&checkdateissue='+checkdateissue+'&checkdateexpire='+checkdateexpire);

		//else window.open("Form_offer_Excel.php?groupbylist="+groupbylist);
}



function PostChangesoffer(){
	var x = document.archives;
	
	if (x.archive_offer.value==''){
		alert("Offer Code is Empty!");
	}
	else {
		x.action = "Form_offer_Action.php";
		x.submit();
	}
}


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

function AdvFilterResulto(){
	document.archives.filterflago.value=0;
	document.archives.advfilterflago.value=1;
	document.archives.submit();
}

function FilterResulto(){
	
	document.archives.filterflago.value=1;
	
	document.archives.advfilterflago.value=0;
	
	document.archives.submit();
	
}
function printpreview(){
	
	var x = document.archives;
	var archive_offer	=x.archive_offer.value;
	var archive_account= x.archive_account.value;
	var archive_POL =x.archive_POL.value;
	var archive_POD= x.archive_POD.value;
	var archive_FOD= x.archive_FOD.value;
	var archive_type= x.archive_type.value;
	var archive_issue_date= x.archive_issue_date.value;
	var archive_expire_date= x.archive_expire_date.value;
	//var archive_size1= x.archive_size1.value;
	//var archive_size2=x.archive_size2.value;
	var groupbylist=x.groupbylist.value;
	var fromdateo=x.fromdateo.value;
	var todateo=x.todateo.value;
	var checkdateissue=x.checkdateissue.value;
	var checkdateexpire=x.checkdateexpire.value;
	var filterflago=x.filterflago.value;
	var confirmed=x.confirmed.value;
	//if(filterflago==1)
	window.open('Form_offer_Report.php?archive_offer='+archive_offer+'&archive_account='+archive_account+'&archive_POL='+archive_POL+'&archive_POD='+archive_POD+'&archive_FOD='+archive_FOD
	+'&archive_type='+archive_type+'&archive_issue_date='+archive_issue_date+'&archive_expire_date='+archive_expire_date
	+'&groupbylist='+groupbylist+'&fromdateo='+fromdateo+'&todateo='+todateo+'&checkdateissue='+checkdateissue+'&checkdateexpire='+checkdateexpire+'&confirmed='+confirmed);

//else window.open('Form_offer_Report.php?groupbylist='+groupbylist);

}





function ClearPageoffer(){
	var x = document.archives;
	x.offer_id.value='';
	x.actionmode.value='';
	x.mainaction.value='';
	x.archive_offer.value='';
	x.archive_account.value='';
	x.archive_POL.value='';
	x.archive_POD.value='';
	x.archive_FOD.value='';
	x.archive_type.value='';
	x.archive_issue_date.value='';
	x.archive_expire_date.value='';
	//x.archive_size1.value='';
	//x.archive_size2.value='';
	x.filterflago.value='';
	x.advfilterflago.value='';
	x.archive_offer2.value='';
	x.freedt.value = '';
	x.submit();
}




function setchk(){
	
	if(document.getElementById("checkdateexpire").checked)
		document.getElementById("checkdateexpire").value=1;
	else document.getElementById("checkdateexpire").value=0;
	
}
function setchk2(){
	
	if(document.getElementById("checkdateissue").checked)
		document.getElementById("checkdateissue").value=1;
	else document.getElementById("checkdateissue").value=0;
}
function setchk3(){
	
	if(document.getElementById("confirmed").checked)
		document.getElementById("confirmed").value=1;
	else document.getElementById("confirmed").value=0;
	//alert(document.getElementById("confirmed").value);
	
}

function getClientCode(str){
	win = window.open("list_client.php?str="+str, "Client_List",'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=500,top=100');
	win.focus();
}

function submitDetails(index, offerdt_id){
	// header
	var archive_offer 		= encodeURIComponent(document.getElementById('archive_offer').value);
	var archive_issue_date 	= document.getElementById('archive_issue_date').value;
	var archive_expire_date = document.getElementById('archive_expire_date').value;
	var archive_POL			= encodeURIComponent(document.getElementById('archive_POL').value);
	var archive_POD 		= encodeURIComponent(document.getElementById('archive_POD').value);
	var archive_FOD 		= encodeURIComponent(document.getElementById('archive_FOD').value);
	var archive_account 	= encodeURIComponent(document.getElementById('archive_account').value);
	var archive_type 		= encodeURIComponent(document.getElementById('archive_type').value);
	var txtclientcode 		= encodeURIComponent(document.getElementById('txtclientcode').value);
	var freedt 				= encodeURIComponent(document.getElementById('freedt').value);
	
	//Details
	
	var itemcode 			= document.getElementById('itemcode['+index+']').value;
	var txtdescription 		= encodeURIComponent(document.getElementById('txtdescription['+index+']').value);
	var txtamount 			= document.getElementById('txtamount['+index+']').value;
	var txtcurrency_code 	= document.getElementById('txtcurrency_code['+index+']').value;
	var txtqty 				= document.getElementById('txtqty['+index+']').value;
	var txtdiscount 		= document.getElementById('txtdiscount['+index+']').value;
	
	var offer_id = document.archives.offer_id.value;
	if ( offerdt_id == '')
		var mainaction = 'inserdt';
	else var mainaction = 'editdt';
	
	
	if ( archive_offer == ''){
		alert('Please Fill the Offer Code First!');
		document.getElementById('archive_offer').focus();
		return 0;
	} else if ( itemcode == '' ){
		alert('Please Select an Item Code First!');
		document.getElementById('itemcode['+index+']').focus();
		return 0;
	} else if ( txtamount == '' ){
		alert('Amount Should not be Empty!');
		document.getElementById('txtamount['+index+']').focus();
		return 0;
	} else if ( txtcurrency_code == '' ){
		alert('Currency Should not be Empty');
		document.getElementById('txtcurrency_code['+index+']').focus();
		return 0;
	} else if ( txtqty == '' ){
		alert('Quantity Should not be Empty');
		document.getElementById('txtqty['+index+']').focus();
		return 0;
	} else {
		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]");
		
			 if (data[1] != ''){
				alert(data[1]);
			} else {
				if ( offer_id == ''){
					document.archives.offer_id.value = data[2];
					var index2 = parseInt(index)+1;
					document.getElementById('itemcode['+index2+']').focus();
					document.archives.submit();
				} else {
					
					document.getElementById('offerdtGrid').innerHTML=data[3]; 
					var index2 = parseInt(index)+1; 
					document.getElementById('itemcode['+index2+']').focus();
				}	
					
				
			}
		}
	  }
		
		xmlhttp.open("GET","Form_offer_Action.php?mainaction="+mainaction+"&offer_id="+offer_id+"&offerdt_id="+offerdt_id+"&archive_offer="+archive_offer+"&archive_issue_date="+archive_issue_date+"&archive_expire_date="+archive_expire_date+
				"&archive_POL="+archive_POL+"&archive_POD="+archive_POD+"&archive_FOD="+archive_FOD+"&archive_account="+archive_account+"&archive_type="+archive_type+"&txtclientcode="+txtclientcode+"&freedt="+freedt+
				"&itemcode="+itemcode+"&txtdescription="+txtdescription+"&txtamount="+txtamount+"&txtcurrency_code="+txtcurrency_code+"&txtqty="+txtqty+"&txtdiscount="+txtdiscount,true);
		xmlhttp.send();
	}
}

function DeleteRecord(index, offerdt_id){
	if (confirm ( "Are you sure you want to Delete this Record " + "?")){
		var offer_id = document.archives.offer_id.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]");
			if (data[1] != '') alert(data[1]);
			document.getElementById('offerdtGrid').innerHTML=data[2]; 
			document.getElementById('itemcode['+index+']').focus();
		}
	  }
		xmlhttp.open("GET","Form_offer_Action.php?mainaction=deletedt&offer_id="+offer_id+"&offerdt_id="+offerdt_id);
		xmlhttp.send();
	}
}
function setOffer(){
	document.getElementById('archive_offer2').value = document.getElementById('archive_offer').value;
}

function setItemInfo(index){
	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('itemdesc['+index+']').value = data[1];
	}
  }
  var itemcode = document.getElementById('itemcode['+index+']').value;
  
xmlhttp.open("GET","Form_offer_Action.php?mainaction=setItemInfo&itemcode="+itemcode,true);

xmlhttp.send();
}
</script>
<style>
.style111 {
	font-size: 11px;
}
</style>
<title>Offre</title>
</head>
<body >
<form name='archives' method='post' action=''  enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='vTabFocus' value='$vTabFocus'>
<input type='hidden' name='mainaction' value='$mainaction'>

 <input type='hidden' name='offer_id' value='$offer_id'>

<input type='hidden' name='filterflago' value='$filterflago'>
<input type='hidden' name='advfilterflago' value='$advfilterflago'>
<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'>Offer</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

$saveDisabled = "";
if($offer_id != ''){
	$query ="select auto, Offer_code, issuedate, account, POL, POD, Expiredate, FOD, type, filename, ifnull(CONFIRMED,0), freetimedetention
			from archivingoffer where auto='$offer_id';";
	$res = mysql_query($query,$connection);
	$row = mysql_fetch_Array($res);
	
	$auto 				= $row[0];
	$archive_offer 		= $row[1];
	$archive_issue_date = $row[2];
	$archive_account 	= $row[3];
	$archive_POL 		= $row[4];
	$archive_POD 		= $row[5];
	$archive_expire_date = $row[6];
	$archive_FOD 		= $row[7];
	$archive_type 		= $row[8];
	$freedt 			= $row[11];
	
	$ndate = explode("-", $archive_issue_date);
	$archive_issue_date = $ndate[2]."/".$ndate[1]."/".$ndate[0];
	
	$ndate = explode("-", $archive_expire_date);
	$archive_expire_date = $ndate[2]."/".$ndate[1]."/".$ndate[0];
	$offer_confirmed 	= $row[10]; 
	if ($offer_confirmed == 1) $saveDisabled = "disabled";
}	
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=\"ClearPageoffer();return false;\" title='Clear Page'><span><span>Clear Page</span></span></button>";
echo" <button type='button' id='btnPost' name='btnPost' onclick=\"PostChangesoffer();return false;\" title='Save Changes' $saveDisabled><span><span>Save</span></span></button>";
echo" <button type='button' id='btnSearch' name='btnSearch' onclick=\"SearchPageoffre();return false;\" title='Search'><span><span>Search</span></span></button>";
echo" <button type='button' id='btnFilter' name='btnFilter' onclick=\"FilterResulto();return false;\" title='Filter'><span><span>Filter</span></span></button>";
echo" <button type='button' id='btnFilter' name='btnFilter' onclick=\"AdvFilterResulto();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>";				


echo"<tr><td id='content-body'>";

$tabs = new tabs("Offers");	
$tabs->start("Offre");

echo"	<table border='0'  align='left' valign='top'  class='tablecontent'>
			<col width=100%>";
			echo "<tr>";
				//<td width='30'  height='34'>&nbsp;</td>
				echo "<td valign='middle' height='34' width='720px' align='left'>";

echo"</td></tr>";
echo"   	<tr bgcolor='#F7F7F7' height='10' ><td valign='top'>";
echo "<table align='left'  border='0' width='1099px' bgcolor='999999' >
<col width=70px><col width=80px><col width=60px><col width=80px><col width=90px><col width=60px><col width=100px><col width=100px><col width=120px><col width=120px>";

//<col width=80px><col width=70px><col width=80px><col width=70px><col width=30px><col width=120px><col width=100px><col width=120px>



echo "<tr><td><span class='style1'>Group By: </span></td>";

//echo $groupbylist;
echo"<td><select name='groupbylist' >";
echo"<option value=''></option>";
echo"<option value='offer_code'";   if ($groupbylist=='offer_code') echo "selected ";
echo ">Offer Code</option>";
echo"<option value='issuedate'" ;  if ($groupbylist=='issuedate') echo "selected ";
echo ">Issue Date</option>";
echo"<option value='expiredate'" ;  if ($groupbylist=='expiredate') echo "selected ";
echo ">Expire Date</option>";
echo"<option value='account'" ;  if ($groupbylist=='account') echo "selected ";
echo ">Account</option>";
echo"<option value='pol'" ;  if ($groupbylist=='pol') echo "selected ";
echo ">POL</option>";
echo"<option value='pod'";   if ($groupbylist=='pod') echo "selected ";
echo ">POD</option>";
echo"<option value='fod' "  ; if ($groupbylist=='fod') echo "selected ";
echo ">FOD</option>";
echo"<option value='type' " ;  if ($groupbylist=='type') echo "selected ";
echo ">Type</option>";


echo"</select></td>";
echo "<td colspan='2'><input type='checkbox' name='checkdateissue' id='checkdateissue' value='$checkdateissue' ";
if ($checkdateissue==1) echo "checked ";
echo "onclick=\"setchk2();\">
	<span class='style1'>Filter By Issue Date</span></td>";
	echo "<td colspan='2'><input type='checkbox' name='checkdateexpire' id='checkdateexpire' value='$checkdateexpire'";
if ($checkdateexpire==1) echo "checked ";
	echo "onclick=\"setchk();\">
	
	<span class='style1'>Filter By Expire Date</span></td>";
	echo "<td><input type='checkbox' name='confirmed' id='confirmed' value='$confirmed'";
	if ($confirmed==1) echo "checked ";
	echo "onclick=\"setchk3();\">";
	echo "<span class='style1' >confirmed</span></td>";
/*echo "<td colspan='2'><input type='checkbox' name='checkdateexpire' id='checkdateexpire' value='$checkdateexpire' onclick=\"setchk();\">
	<span class='style1'>Filter By From/To Date</span></td>";*/
echo"<td align='right'><span class='style1'>From Date</span></td>";
echo"<td><input type='text' name='fromdateo' id='fromdate' value='$fromdateo' style='width:90px' readonly>
	<a href='#' onclick=\"displayCalendar(document.archives.fromdateo,'dd/mm/yyyy',this); return false;\" name='anchor1' id='anchor1'><img src=\"./img/cal.gif\" border='0' align='top'></a>
	</td>";
echo"<td align='right'><span class='style1' >To Date</span></td>";
echo"<td><input type='text' name='todateo' id='todateo' value='$todateo'  style='width:90px' readonly>
	<a href='#' onclick=\"displayCalendar(document.archives.todateo,'dd/mm/yyyy',this); return false;\" name='anchor1' id='anchor1'><img src=\"./img/cal.gif\" border='0' align='top'></a>
	</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=220px>
					<col width=20px>
					<col width=20px>
					<col width=100px>
					<col width=220px>
					<col width=20px>
					<col width=20px>
					<col width=100px>
					<col width=220px>";

				
					

			
	echo "<tr height='25'><td ><span class='style1' > auto:</span></td><td><span class='style1' > $auto </span> </td></tr>";
	echo "<td ><span class='style1' >Offer code</span></td>
		<td align='left'><textarea name='archive_offer' id='archive_offer' cols='31' rows='1' onkeyup=\"setOffer();\" style='font-size:12px;'>".htmlspecialchars($archive_offer)."</textarea></td>
        <td></td><td></td>
		<td><span class='style1'  >Issue Date</span></td>
		<td align='left'><input type='text' name='archive_issue_date' id='archive_issue_date' value='$archive_issue_date' style='font-size:12px; width:90px;' readonly>
		<a href='#' onclick=\"displayCalendar(document.archives.archive_issue_date,'dd/mm/yyyy',this); return false;\" name='anchor1' id='anchor1'><img src=\"./img/cal.gif\" border='0' align='top'></a><td></td>
		<td></td>
		<td align='left'><span class='style1'>Expire Date</span></td>
		<td align='left'><input type='text' name='archive_expire_date' id='archive_expire_date' value='$archive_expire_date' style='font-size:12px; width:90px;' readonly>
		<a href='#' onclick=\"displayCalendar(document.archives.archive_expire_date,'dd/mm/yyyy',this); return false;\" name='anchor1' id='anchor1'><img src=\"./img/cal.gif\" border='0' align='top'></a><td></td>
		
	</tr>";
/*echo "<tr>

		
		
		<td><span class='style1'>size1</span></td>
		<td><input type='text' name='archive_size1' id='archive_size1' cols='31' rows='1' style='font-size:12px;' value=".htmlspecialchars($archive_size1)."></td>
		<td></td>
	<td><span class='style1'>size2</span></td>
		<td><input type='text' name='archive_size2' id='archive_size2' cols='31' rows='1' style='font-size:12px;'  value=".htmlspecialchars($archive_size2)."></td>
		
		
	echo "</tr>";*/
echo "<tr>
<td><span class='style1'>POL</span></td>
		<td><textarea name='archive_POL' id='archive_POL' cols='31' rows='1' style='font-size:12px;' >".htmlspecialchars($archive_POL)."</textarea></td>
	<td></td>
	<td></td>
		<td><span class='style1'>POD</span></td>
		<td><textarea name='archive_POD' id='archive_POD' cols='31' rows='1' style='font-size:12px;'>".htmlspecialchars($archive_POD) ."</textarea></td>
		<td></td><td></td>
		<td><span class='style1'>FOD</span></td>
		<td><textarea name='archive_FOD' id='archive_FOD' cols='31' rows='1' style='font-size:12px;'>". htmlspecialchars($archive_FOD)."</textarea></td>
		
		</tr>";	

echo "<tr>
<td><span class='style1'>Account</span></td>
		<td><textarea name='archive_account' id='archive_account' cols='31' rows='1' style='font-size:12px;' >".htmlspecialchars($archive_account)."</textarea></td>
        <td></td>";
		echo "<td></td>";
		echo "
		<td><span class='style1'>type</span></td>
		<td><select name='archive_type' id='archive_type'><option value=''></option>
		
		<option value='IMPORT'"; 
		if(htmlspecialchars($archive_type)=='IMPORT') echo "selected";
		echo ">Import</option>
		<option value='EXPORT'";
		if(htmlspecialchars($archive_type)=='EXPORT') echo "selected";
		echo ">Export</option>
		</select></td>
		<td></td>
		<td></td>
		<td colspan='2' align='center' ><input type='file' name='offerfile' id='offerfile' style='width:400px;' ></td>
	    <td></td>
		
	</tr>";	
	
echo "<tr>
		<td><span class='style1'>Client</span></td>
		<td colspan='4'><input type='text' name='txtclientcode' id='txtclientcode' value='$txtclientcode' style='width:120px;'>
			<input type='text' name='txtclientname' id='txtclientname' value='$txtclientname' style='width:180px;'>
			<input type='image' src='img/btnopen.jpg' title='Select client ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" onclick=\"getClientCode('1'); return false;\" style='cursor: pointer;'>
		</td>
		<td colspan='3'></td>
		<td><span class='style1'>Detention Free Time</span></td>
		<td><input type='text' name='freedt' id='freedt' value='$freedt'  onkeypress=\"return ((event.charCode >= 48 && event.charCode <= 57) || event.charCode == 46);\" style='width:100px;'></td>
		
	</tr>";

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


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

$ndate=explode("/",$fromdateo);
$fromdateo=$ndate[2]."-".$ndate[1]."-".$ndate[0];
$ndate=explode("/",$todateo);
$todateo=$ndate[2]."-".$ndate[1]."-".$ndate[0];
$ndate=explode("/",$archive_issue_date);
$archive_issue_date=$ndate[2]."-".$ndate[1]."-".$ndate[0];
$ndate=explode("/",$archive_expire_date);
$archive_expire_date=$ndate[2]."-".$ndate[1]."-".$ndate[0];

if($filterflago == 1 || $advfilterflago == 1 ){
echo" <tr  height='25' ><td valign='top'><div style='overflow-x: scroll;overflow-y: scroll;height:500px;width:1100px'>";
echo "<table border='1' style='table-layout:fixed' align='left' width='1270px' valign='top' > ";
echo "<col width='70px'><col width='70px'><col width='50px'><col width='150px'><col width='150px'><col width='150px'><col width='150px'><col width='150px'><col width='150px'><col width='150px'>
	<col width='150px'><col width='150px'><col width='150px'>";
	$querysearch = "select auto, Offer_code, issuedate, account, POL, POD, Expiredate, FOD, type, filename, ifnull(confirmed,0) as offerconfirmed, freetimedetention
					from archivingoffer where 1=1 ";
				

if($filterflago == 1){
	if($archive_offer != '') $querysearch = $querysearch." and ifnull(offer_code,'') like ('%".$archive_offer."%') ";
	if($archive_account != '') $querysearch = $querysearch." and ifnull(account,'') like ('%".$archive_account."%') ";
	if($archive_POL != '') $querysearch = $querysearch." and ifnull(POL,'') like ('%".$archive_POL."%') ";
	if($archive_POD != '') $querysearch = $querysearch." and ifnull(POD,'') like ('%".$archive_POD."%') ";
	if($archive_FOD != '') $querysearch = $querysearch." and ifnull(FOD,'') like ('%".$archive_FOD."%') ";
	if($archive_type != '') $querysearch = $querysearch." and ifnull(type,'') like ('%".$archive_type."%') ";
	if($archive_size1 != '') $querysearch = $querysearch." and ifnull(size1,'') like ('%".$archive_size1."%') ";
	if($archive_size2 != '') $querysearch = $querysearch." and ifnull(size2,'') like ('%".$archive_size2."%') ";
	if($freedt != '') $querysearch = $querysearch." and ifnull(freetimedetention,'') like ('%".$freedt."%') ";
	
	
	//echo $checkdateexpire."ddd";
	if($checkdateissue == 1) 
		$querysearch = $querysearch." and ( issuedate between '$fromdateo' and '$todateo' ) ";
	 if($checkdateexpire == 1) 
		$querysearch = $querysearch." and ( expiredate between '$fromdateo' and '$todateo' ) ";
	 if($confirmed == 1) 
		$querysearch = $querysearch." and ( confirmed =1 ) ";
	 
 if($groupbylist !='') 
	$querysearch = $querysearch." order by  $groupbylist,auto desc  ";
	else 
	$querysearch = $querysearch." order by  auto desc  ";
	

} 

$resultsearch = mysql_query($querysearch,$connection);
$numrow = mysql_num_rows($resultsearch);


echo "<tr bgcolor='999999' height='30'>
		<td><span class='style1'>document</span></td>
		<td><span class='style1'>confirmed</span></td>
		
		<td><span class='style1'>Auto</span></td>
		<td><span class='style1'>Offer Code</span></td>
		<td><span class='style1'>Account </span></td>
		<td><span class='style1'>Issue Date</span></td>
		<td><span class='style1'>Expire Date</span></td>
		<td><span class='style1'>Type</span></td>";
		//<td><span class='style1'>Size1</span></td>
		//<td><span class='style1'>Size2</span></td>
		echo "<td><span class='style1'>POD</span></td>
		<td><span class='style1'>POL</span></td>
		<td><span class='style1'>FOD</span></td>
		
	  </tr>";
echo "<tr><td colspan='16'><hr></td></tr>";

	  $i = 0;
	while($rows = mysql_fetch_array($resultsearch)){
		extract($rows);
		
	if($i%2) $bgcolor = "bgcolor = '#E6E6E6'";
		else $bgcolor = "bgcolor = '#F7F7F7'";
		
	echo "<tr $bgcolor>
	";
	echo "<td><span class='style111'>";
	$pathname= $offer_path."\\".$filename;
if ($filename!= '')	echo "<a href='../$pathname' download><img src='./icon/open-folder.png' height='20' width='20' ></a>";
	echo"</span></td>";
	echo "<td align='center'><span class='style111'>";
	if ($offerconfirmed==1)
		echo "<img src='./img/confirmorder.png' height='20' width='20' ></span></td>";
	else echo "<img src='./img/unconfirmorder.png' height='20' width='20' ></span></td>";
	
	echo "<td><span class='style111'>$auto</span></td>";
	echo "	<td><span class='style111'>$Offer_code</span></td>
	        <td><span class='style111'>$account</span></td>
			<td><span class='style111'>$issuedate</span></td>
			<td><span class='style111'>$Expiredate</span></td>
			<td><span class='style111'>$type</span></td>";
		
			echo "<td><span class='style111'>$POD</span></td>
			<td><span class='style111'>$POL</span></td>
			<td><span class='style111'>$FOD</span></td>"; 
echo "</tr>";	
	$i++;
	}
	

echo "</table></td></tr>";}
echo "</table>";
$tabs->end();
$tabs->start("Details");	
$archive_offer2 = $archive_offer;
echo "<table align='left'  border='0' width='1000px' >
	<col width='20px'><col width='30px'><col width='150px'><col width='180px'><col width='200px'><col width='100px'>
	<col width='60px'><col width='80px'><col width='80px'><col width='50px'>";
echo "<tr height='30px'>";
echo "<td colspan='10' align='left'><span class='style1'>Offer: </span><input type='text' name='archive_offer2' id='archive_offer2' value='$archive_offer2' style='font-size:12px;' readonly></td>";
echo "</tr>";
echo "<tr height='30px' bgcolor='999999'>
		<td></td><td></td>
		<td align='center'><span class='style1'>Item Code</span></td><td align='center'><span class='style1'>Item Name</span></td>
		<td align='center'><span class='style1'>Description</span></td><td align='center'><span class='style1'>Amount</span></td>
		<td align='center'><span class='style1'>Currency</span></td><td align='center'><span class='style1'>Quatity</span></td>
		<td align='center'><span class='style1'>Rebate</span></td><td></td>
	  </tr>";
echo "<tr><td colspan='10'><div id='offerdtGrid' style='width:1010px;height:400px;overflow-x: hidden; overflow-y:scroll;'>";
	offerdtGrid($offer_id, $connection);
echo "</div></td></tr>";
echo "</table>";	
	

$tabs->end();

$tabs->run();
echo "</div><div>";
echo "<div style='clear: both;'></div>";
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;

?>