<?php
session_start();

include("config.inc.php");
include("Functions_UserAccess.php");
include("function.inc.php");

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

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']);
mysql_select_db($_SESSION['dbName'],$connection);

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






	$filename = "OfferList" . date('Ymd') . ".xls";

	header("Content-Disposition: attachment; filename=\"$filename\"");
	header("Content-Type: application/vnd.ms-excel");



print <<< HERE
<script language="JavaScript" type="text/javascript">
</script>
HERE;

 echo"</head><body>";

	$groupbylist	 	= $_POST["groupbylist"]; 	 	if ($groupbylist == ""){		$groupbylist 		 = $_GET["groupbylist"];} 
//echo $groupbylist;
	
	
	$offer_id 			= $_POST["offer_id"]; 		    if ($offer_id == ""){			$offer_id 		     = $_GET["offer_id"];}  
$archive_offer	 	= $_POST["archive_offer"]; 	 	if ($archive_offer == ""){		$archive_offer 		 = $_GET["archive_offer"];} 
$archive_issue_date	= $_POST["archive_issue_date"]; if ($archive_issue_date == ""){	$archive_issue_date  = $_GET["archive_issue_date"];} 
$archive_expire_date= $_POST["archive_expire_date"];if ($archive_expire_date == ""){$archive_expire_date = $_GET["archive_expire_date"];} 
$archive_account	= $_POST["archive_account"]; 	if ($archive_account == ""){	$archive_account 	 = $_GET["archive_account"];} 
$archive_size1	 	= $_POST["archive_size1"]; 	 	if ($archive_size1 == ""){		$archive_size1 		 = $_GET["archive_size1"];} 
$archive_size2	 	= $_POST["archive_size2"]; 		if ($archive_size2 == ""){		$archive_size2 	 	 = $_GET["archive_size2"];} 
$archive_POL	 	= $_POST["archive_POL"]; 	 	if ($archive_POL == ""){		$archive_POL 	 	 = $_GET["archive_POL"];} 
$archive_POD	 	= $_POST["archive_POD"]; 	 	if ($archive_POD == ""){		$archive_POD 		 = $_GET["archive_POD"];} 
$archive_FOD	 	= $_POST["archive_FOD"]; 	 	if ($archive_FOD == ""){		$archive_FOD 		 = $_GET["archive_FOD"];} 
$archive_type	 	= $_POST["archive_type"]; 	 	if ($archive_type == ""){		$archive_type 		 = $_GET["archive_type"];} 
$fromdateo	 	= $_POST["fromdateo"]; 	 	if ($fromdateo == ""){		$fromdateo 		 = $_GET["fromdateo"];} 
$todateo	 	= $_POST["todateo"]; 	 	if ($todateo == ""){		$todateo 		 = $_GET["todateo"];} 
$checkdateissue	 	= $_POST["checkdateissue"]; 	 	if ($checkdateissue == ""){		$checkdateissue 		 = $_GET["checkdateissue"];} 
$checkdateexpire	 	= $_POST["checkdateexpire"]; 	 	if ($checkdateexpire == ""){		$checkdateexpire 		 = $_GET["checkdateexpire"];} 


	
		$querysearch="select auto, Offer_code, Date_Format(issuedate,'%d/%m/%Y'), account, POL, POD, Date_Format(Expiredate,'%d/%m/%Y'), FOD, size1, size2, type,confirmed from archivingoffer where 1=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($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  ";
	
	
$result=mysql_query($querysearch,$connection) or die(mysql_error());






	

		
echo"<table border=0 align='left' cellpadding='0' cellspacing='0' class = 'width:700' >";	
echo"<col width='100'><col width='100'>
	<col width='350'>
	<col width='100'>
	<col width='350'>
	<col width='100'>
	<col width='100'>
	<col width='100'>
	<col width='100'>
	
	<col width='100'>
	";
	echo "<tr height='10px'><td></td></tr>";
	
	echo"<tr>
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>confirmed</th>
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>Auto</th>
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>Offer Code</th>
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>Issue Date</th>
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'> Account</th>
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'> POL</th>
		
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>POD</th>
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>Expire Date</th>
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>FOD</th>
		
		
		<th style='font-size:16px;border-top: #A8A8A8 solid 1px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>type </th></tr>
		";

	
	$i=0;
	while($row=mysql_fetch_array($result)){
	
		if($i%2) $bgcolor = "bgcolor = '#E6E6E6'";
		else $bgcolor = "bgcolor = '#F7F7F7'";
	echo"<tr $bgcolor>";
	echo "
	<td style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'  >";
	if ($row[10]==1)
		echo "yes </td>";
	else echo "No</td>";
	echo "<td style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'  >$row[0]</td>
	<td style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;' >$row[1]</td>
	<td style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>$row[2]</td>
	<td  style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>$row[3]</td>
	<td style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>$row[4]</td>
	<td style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;' >$row[5]</td>
	<td style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>$row[6]</td>
	<td  style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>$row[7]</td>
	<td style='font-size:14px;padding-left:5px;border-bottom: #A8A8A8 solid 1px;border-right: #A8A8A8 solid 1px;'>$row[10]</td>
	
	</tr>";



$i++;
	

}	

echo"</table></body></html>"; 
?>