<?php
header("Content-Type: application/vnd.ms-excel"); 
header('Content-Disposition: attachment; filename="yearlydata.xls"');
?>
<html>
<head>

<title>Fish landing data management system</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
#wrapper {
		border: 1px solid black;
		background-color: #E0E0EF;
		color:#FFFFFF;
		padding:10px;
        height:800px;
        width:1024px;
		text-align:center;
    }
.stylewhite {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	font-weight: bold;
	color: #FFFFFF;
}
.stylewhitesmall {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #FFFFFF;
}
.stylegreen {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #00661F;
}
.styleblack {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #000000;
}
.styleblacklarge {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	font-weight: bold;
	color: #000000;
}
a:link {
	color: #FFFFFF;
	text-decoration: none;
}
a:visited {
	color: #FFFFFF;
	text-decoration: none;
}
a:hover {
	color: #FF0000;
	text-decoration: none;
}
a:active {
	color: #FFFFFF;
	text-decoration: none;
}
.style1 {color: #FF0000}
-->
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="500" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
  <tr bgcolor="#FFFFFF" class="stylewhite">
    <td colspan="3"><div align="center" class="styleblacklarge">Yearly Catch Data (in kg.)</div></td>
  </tr>
  <tr bgcolor="#FFFFFF" class="styleblacklarge">
    <td><div align="center">Year</div></td>
    <td><div align="center">Fishing Sector</div></td>
    <td><div align="center">Total Weight(kg.)</div></td>
  </tr>
  <?
		  include "connect.inc.php";
		  $sqlgetrptYearly = "SELECT year(DepartureDate) as yy,sector,sum(Weight) as sw FROM catch";
		  $sqlgetrptYearly = $sqlgetrptYearly." INNER JOIN fishspecies ON catch.spid = fishspecies.spid";
		  $sqlgetrptYearly = $sqlgetrptYearly." INNER JOIN fishoperation ON fishoperation.Optid = catch.Optid";
		  $sqlgetrptYearly = $sqlgetrptYearly." INNER JOIN ship ON fishoperation.VesselId = ship.ShipName";
		  $sqlgetrptYearly = $sqlgetrptYearly." INNER JOIN shiptype ON ship.fishsector = shiptype.shptid";
		  $sqlgetrptYearly = $sqlgetrptYearly." INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
		  $sqlgetrptYearly = $sqlgetrptYearly." GROUP BY year(DepartureDate),fishingsector.sid";
		  $sqlgetrptYearly = $sqlgetrptYearly." ORDER BY fishingsector.sid, year(DepartureDate)";
		  //echo  $sqlgetrptYearly;
		  $qryRptYearly = mysql_query($sqlgetrptYearly) or die(mysql_error());
		  $numRptYearly = mysql_num_rows($qryRptYearly);
		  for($i=1;$i<=$numRptYearly;$i++)
		  { 
		   $resRptYearly = mysql_fetch_array($qryRptYearly);
		   $dby = $resRptYearly["yy"];
		   $dbsector = $resRptYearly["sector"];
		   $dbweight = $resRptYearly["sw"];
		  ?>
  <tr bgcolor="#FFFFFF" class="styleblack">
    <td class="stylewhitesmall"><div align="center" class="styleblack"><? echo $dby; ?></div></td>
    <td class="stylewhitesmall"><div align="center" class="styleblack"><? echo $dbsector; ?></div></td>
    <td class="stylewhitesmall"><div align="center" class="styleblack"><? echo $dbweight; ?></div></td>
  </tr>
  <?
		  }
		  ?>
</table>
</body>
</html>