<?php
header("Content-Type: application/vnd.ms-excel"); 
header('Content-Disposition: attachment; filename="monthlydata.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}
.styletextbox {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color:#000000; }
-->
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (Untitled-1) -->
<span class="styleblack">
<? 
	  
	  $subsector = $_GET["lstsector"];
	  $subgear = $_GET["lstgear"];
	  $rptyear = $_GET["chkYear"];

				?>
<br>
</span>
<table width="95%" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#000000" bgcolor="#000000" class="stylewhite">
  <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <td colspan="14" class="stylewhite"><div align="center"><span class="styleblacklarge">Monthly Catch Data (kg.)</span></div></td>
  </tr>
  <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <td colspan="14" class="stylewhite"><span class="styleblack">Year : <? echo $rptyear;?></span></td>
  </tr>
  <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <td colspan="14" class="stylewhite"><span class="styleblack">Fishing Sector :
          <?
		  require_once("NewReport.inc.php");
		  echo getSectorName($subsector); 
		  ?>
    </span></td>
  </tr>
  <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <td colspan="14" class="stylewhite"><span class="styleblack">Fishing Gear :
          <?
		  require_once("NewReport.inc.php");
		  echo getGearName($subgear); 
		  ?>
    </span></td>
  </tr>
  <?
		include "connect.inc.php";
		$sqlgetzone = "SELECT distinct fishoperation.zoneid FROM catch";
		$sqlgetzone = $sqlgetzone." INNER JOIN fishspecies ON catch.spid = fishspecies.spid";
		$sqlgetzone = $sqlgetzone." INNER JOIN fishoperation ON fishoperation.Optid = catch.Optid";
		$sqlgetzone = $sqlgetzone." INNER JOIN ship ON fishoperation.VesselId = ship.ShipName";
		$sqlgetzone = $sqlgetzone." INNER JOIN shiptype ON ship.fishsector = shiptype.shptid";
		$sqlgetzone = $sqlgetzone." INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
		$sqlgetzone = $sqlgetzone." INNER JOIN gearandmethod ON ship.GearType = gearandmethod.fgid";
		$sqlgetzone = $sqlgetzone." WHERE year(DepartureDate) = '$rptyear' and shiptype.shptid = $subsector and ship.GearType=$subgear";
      // echo $sqlgetzone;
		$qrygetzone = mysql_query($sqlgetzone);
		$numgetzone = mysql_num_rows($qrygetzone);
		if($numgetzone == 0)
		{
		?>
  <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <td colspan="14" class="stylewhite"><span class="styleblack">No data</span></td>
  </tr>
  <?
		}
		else
		{
		for($j=1;$j<=$numgetzone;$j++)
		{
			$resgetzone = mysql_fetch_array($qrygetzone);
			$rptZone = $resgetzone["zoneid"];
			
		  ?>
  <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <td colspan="14" class="stylewhite"><span class="styleblack">Fishing Area: <? echo $rptZone; ?></span></td>
  </tr>
  <?
       // include "connect.inc.php";
		$sqlgetship = "SELECT distinct fishoperation.VesselId FROM catch";
		$sqlgetship = $sqlgetship." INNER JOIN fishspecies ON catch.spid = fishspecies.spid";
		$sqlgetship = $sqlgetship." INNER JOIN fishoperation ON fishoperation.Optid = catch.Optid";
		$sqlgetship = $sqlgetship." INNER JOIN ship ON fishoperation.VesselId = ship.ShipName";
		$sqlgetship = $sqlgetship." INNER JOIN shiptype ON ship.fishsector = shiptype.shptid";
		$sqlgetship = $sqlgetship." INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
		$sqlgetship = $sqlgetship." INNER JOIN gearandmethod ON ship.GearType = gearandmethod.fgid";
		$sqlgetship = $sqlgetship." WHERE year(DepartureDate) = '$rptyear' and shiptype.shptid = $subsector and ship.GearType=$subgear and fishoperation.zoneid='$rptZone'";
        //echo $sqlgetship;
		$qrygetship = mysql_query($sqlgetship);
		$numgetship = mysql_num_rows($qrygetship);
		for($k=1;$k<=$numgetship;$k++)
		{
			$resgetship = mysql_fetch_array($qrygetship);
			$rptShip = $resgetship["VesselId"];
		?>
  <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <td colspan="14" class="stylewhite"><span class="styleblack">Vessel Name : <? echo $rptShip; ?> </span></td>
  </tr>
  <tr bgcolor="#FFFFFF" class="styleblack">
    <td width="16%" class="stylewhitesmall"><div align="center" class="styleblack">Species</div></td>
    <td width="6%" class="stylewhitesmall"><div align="center" class="styleblack">Jan<br>
    </div></td>
    <td width="5%" class="stylewhitesmall"><div align="center" class="styleblack">Feb<br>
    </div></td>
    <td width="8%" class="stylewhitesmall"><div align="center" class="styleblack">Mar<br>
    </div></td>
    <td width="5%" class="stylewhitesmall"><div align="center" class="styleblack">Apr<br>
    </div></td>
    <td width="7%" class="stylewhitesmall"><div align="center" class="styleblack">May<br>
    </div></td>
    <td width="6%" class="stylewhitesmall"><div align="center" class="styleblack">Jun<br>
    </div></td>
    <td width="6%" class="stylewhitesmall"><div align="center" class="styleblack">July<br>
    </div></td>
    <td width="7%" class="stylewhitesmall"><div align="center" class="styleblack">Aug<br>
    </div></td>
    <td width="7%" class="stylewhitesmall"><div align="center" class="styleblack">Sep<br>
    </div></td>
    <td width="6%" class="stylewhitesmall"><div align="center" class="styleblack">Oct<br>
    </div></td>
    <td width="7%" class="stylewhitesmall"><div align="center" class="styleblack">Nov<br>
    </div></td>
    <td width="5%" class="stylewhitesmall"><div align="center" class="styleblack">Dec<br>
    </div></td>
    <td width="9%" class="stylewhitesmall"><div align="center" class="styleblack">Total</div></td>
  </tr>
  <?
        $sqlgetsp = "SELECT distinct scientific,catch.spid FROM catch";
		$sqlgetsp = $sqlgetsp." INNER JOIN fishspecies ON catch.spid = fishspecies.spid";
		$sqlgetsp = $sqlgetsp." INNER JOIN fishoperation ON fishoperation.Optid = catch.Optid";
		$sqlgetsp = $sqlgetsp." INNER JOIN ship ON fishoperation.VesselId = ship.ShipName";
		$sqlgetsp = $sqlgetsp." INNER JOIN shiptype ON ship.fishsector = shiptype.shptid";
		$sqlgetsp = $sqlgetsp." INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
		$sqlgetsp = $sqlgetsp." INNER JOIN gearandmethod ON ship.GearType = gearandmethod.fgid";
		$sqlgetsp = $sqlgetsp." WHERE year(DepartureDate) = '$rptyear' and shiptype.shptid = $subsector and ship.GearType=$subgear and fishoperation.zoneid='$rptZone' and fishoperation.VesselId ='$rptShip'";
        //echo $sqlgetsp;
		$qrygetsp = mysql_query($sqlgetsp);
		$numgetsp = mysql_num_rows($qrygetsp);
		$ttjan = 0;
		$ttfeb = 0;
		$ttmar = 0;
		$ttapr = 0;
		$ttmay = 0;
		$ttjun = 0;
		$ttjul = 0;
		$ttaug = 0;
		$ttsep = 0;
		$ttoct = 0;
		$ttnov = 0;
		$ttdec = 0;
		$tts = 0;
		for($l=1;$l<=$numgetsp;$l++)
		{
			$resgetsp = mysql_fetch_array($qrygetsp);
			$rptSpid = $resgetsp["spid"];
			$rptSp = $resgetsp["scientific"];
			
			require_once("NewReport.inc.php");
			$catchJan = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,1);
			$ttjan = $ttjan+$catchJan;
			require_once("NewReport.inc.php");
			$catchFeb = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,2);
			$ttfeb = $ttfeb+$catchFeb;
			require_once("NewReport.inc.php"); 
			$catchMar = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,3);
			$ttmar = $ttmar+$catchMar; 
			require_once("NewReport.inc.php"); 
			$catchApr = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,4);
			$ttapr = $ttapr+$catchApr; 
			require_once("NewReport.inc.php"); 
			$catchMay = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,5);
			$ttmay = $ttmay+$catchMay; 
			require_once("NewReport.inc.php"); 
			$catchJun = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,6);
			$ttjun = $ttjun+$catchJun; 
			require_once("NewReport.inc.php"); 
			$catchJul = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,7);
			$ttjul = $ttjul+$catchJul; 
			require_once("NewReport.inc.php"); 
			$catchAug = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,8);
			$ttaug = $ttaug+$catchAug;
			require_once("NewReport.inc.php"); 
			$catchSep = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,9);
			$ttsep = $ttsep+$catchSep; 
			require_once("NewReport.inc.php"); 
			$catchOct = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,10);
			$ttoct = $ttoct+$catchOct; 
			require_once("NewReport.inc.php"); 
			$catchNov = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,11);
			$ttnov = $ttnov+$catchNov; 
			require_once("NewReport.inc.php"); 
			$catchDec = getCatchData($rptyear,$subsector,$subgear,$rptZone,$rptShip,$rptSpid ,12);
			$ttdec = $ttdec+$catchDec; 
			$tty = $catchJan+$catchFeb+$catchMar+$catchApr+$catchMay+$catchJun+$catchJul+$catchAug+$catchSep+$catchOct+$catchNov+$catchDec;
			$tts = $tts+$tty;
		?>
  <tr bgcolor="#FFFFFF" class="styleblack">
    <td> <? echo $rptSp; ?> </td>
    <td align="center"><? echo $catchJan; ?> </td>
    <td align="center"><? echo $catchFeb; ?></td>
    <td align="center"><? echo $catchMar; ?></td>
    <td align="center"><? echo $catchApr; ?></td>
    <td align="center"><? echo $catchMay; ?></td>
    <td align="center"><? echo $catchJun; ?></td>
    <td align="center"><? echo $catchJul; ?></td>
    <td align="center"><? echo $catchAug; ?></td>
    <td align="center"><? echo $catchSep; ?></td>
    <td align="center"><? echo $catchOct; ?></td>
    <td align="center"><? echo $catchNov; ?></td>
    <td align="center"><? echo $catchDec; ?></td>
    <td align="center" class="styleblack"><? echo number_format($tty,2,'.',''); ?></td>
  </tr>
  <?
		}
		?>
  <tr bgcolor="#FFFFFF" class="stylewhitesmall">
    <td align="center"><span class="styleblack">Total </span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttjan,2,'.',''); ?> </span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttfeb,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttmar,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttapr,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttmay,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttjun,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttjul,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttaug,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttsep,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttoct,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttnov,2,'.',''); ?></span></td>
    <td align="center"><span class="styleblack"><? echo number_format($ttdec,2,'.',''); ?></span></td>
    <td align="center" class="stylewhitesmall"><span class="styleblack"><? echo number_format($tts,2,'.',''); ?></span></td>
  </tr>
  <?
		}
		}
		}
		?>
</table>
<!-- End ImageReady Slices -->
</body>
</html>