<?
session_start();
ob_start();
?>
<html>
<head>
<script language="JavaScript">
	function ClickCheckAll(vol)
	{
	
		var i=1;
		for(i=1;i<=document.frmMain.hdnCount.value;i++)
		{
			if(vol.checked == true)
			{
				eval("document.frmMain.chkYear"+i+".checked=true");
			}
			else
			{
				eval("document.frmMain.chkYear"+i+".checked=false");
			}
		}
	}

	function onDelete()
	{
		if(confirm('Do you want to delete ?')==true)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
</script>
<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) -->
<table width="1024" height="799" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#F3F3F3" id="Table_01">
<tr>
		<td height="50" bgcolor="#ADCE4C" class="stylewhite">&nbsp;Fish Landing Data Management System</td>
  </tr>
	<tr class="stylewhitesmall">
	  <td height="20" bgcolor="#006666"><span class="styleblack">&nbsp;</span><a href="main.php">Home</a><span class="style1">&nbsp;</span> |&nbsp;<a href="usr.php">User</a> |<span class="style1"> <a href="fishingzone.php">Fishing Zone |</a> <a href="district.php">District</a> </span>|<a href="samplingport.php"> Landing Site </a>| <a href="fgmethod.php">Fishing Gear and Method</a> | <a href="vessel.php">Fishing Vessel</a> | <a href="species.php">Fish Species</a> | <a href="catchdata.php">Catch Data </a> | <a href="biology.php">Biology Data</a> | <a href="report.php"> </a><a href="report.php">Report</a> |<span class="style1"> <a href="logout.php">Logout</a></span></td>
  </tr>
	<tr>
	  <td height="705" valign="top" bgcolor="#CCCCCC"><br>	    
        <span class="styleblack">
        <? 
	  
	  if($_POST[submit])
	  {
	  $subsector = $_POST["lstsector"];
	  $subgear = $_POST["lstgear"];
	  for($i=0;$i<count($_POST["chkYear"]);$i++) 
		 { 
	
         	if($_POST["chkYear"][$i] != "") 
        	{ 
				$rptyear = $_POST["chkYear"][$i];
				?>
                <br>
        </span>
        <table width="95%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#FFFFFF" class="stylewhite">
        <tr bordercolor="#FFFFFF">
          <td colspan="14" bgcolor="#006666" class="stylewhite"><span class="stylewhitesmall">Catch composition report (kg.)</span></td>
          </tr>
        <tr bordercolor="#FFFFFF">
          <td colspan="14" bgcolor="#006666" class="stylewhite"><span class="stylewhitesmall">Year : <? echo $rptyear;?></span></td>
        </tr>
        <tr bordercolor="#FFFFFF">
          <td colspan="14" bgcolor="#006666" class="stylewhite"><span class="stylewhitesmall">Fishing Sector : 
            <?
		  require_once("NewReport.inc.php");
		  echo getSectorName($subsector); 
		  ?>
          </span></td>
        </tr>
        <tr bordercolor="#FFFFFF">
          <td colspan="14" bgcolor="#006666" class="stylewhite"><span class="stylewhitesmall">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">
          <td colspan="14" bgcolor="#ADCE4C" 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">
          <td colspan="14" bgcolor="#006666" class="stylewhite"><span class="stylewhitesmall">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">
          <td colspan="14" bgcolor="#006666" class="stylewhite"><span class="stylewhitesmall">Vessel Name : <? echo $rptShip; ?> </span></td>
        </tr>
        <tr bgcolor="#000000" class="styleblack">
            <td width="16%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Species</span></div></td>
            <td width="6%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Jan<br>
            </span></div></td>
            <td width="5%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Feb<br>
            </span></div></td>
            <td width="8%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Mar<br>
            </span></div></td>
            <td width="5%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Apr<br>
            </span></div></td>
            <td width="7%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">May<br>
            </span></div></td>
            <td width="6%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Jun<br>
            </span></div></td>
            <td width="6%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">July<br>
            </span></div></td>
            <td width="7%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Aug<br>
            </span></div></td>
            <td width="7%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Sep<br>
            </span></div></td>
            <td width="6%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Oct<br>
            </span></div></td>
            <td width="7%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Nov<br>
            </span></div></td>
            <td width="5%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Dec<br>
            </span></div></td>
            <td width="9%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Total</span></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 class="styleblack">
            <td bgcolor="#ADCE4C"> <span class="styleblack"><? echo $rptSp; ?> </span></td>
            <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchJan; ?> </span></td>
            <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchFeb; ?></span></td>
            <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchMar; ?></span></td>
            <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchApr; ?></span></td>
          <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchMay; ?></span></td>
          <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchJun; ?></span></td>
          <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchJul; ?></span></td>
          <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchAug; ?></span></td>
          <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchSep; ?></span></td>
          <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchOct; ?></span></td>
          <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchNov; ?></span></td>
          <td align="center" bgcolor="#ADCE4C"><span class="styleblack"><? echo $catchDec; ?></span></td>
            <td align="center" bgcolor="#ADCE4C" class="styleblack"><span class="styleblack"><? echo number_format($tty,2,'.',''); ?></span></td>
          </tr>
        <?
		}
		?>
        <tr class="stylewhitesmall">
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall">Total </span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttjan,2,'.',''); ?> </span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttfeb,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttmar,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttapr,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttmay,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttjun,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttjul,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttaug,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttsep,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttoct,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttnov,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666"><span class="stylewhitesmall"><? echo number_format($ttdec,2,'.',''); ?></span></td>
            <td align="center" bgcolor="#006666" class="stylewhitesmall"><span class="stylewhitesmall"><? echo number_format($tts,2,'.',''); ?></span></td>
          </tr>
        <tr bgcolor="#A8C47A" class="stylewhitesmall">
          <td colspan="14" align="center"><div align="right"></div>            <div align="right"></div></td>
          </tr>
        <?
		}
		}
		}
		?>
        </table>
        <div align="right"><span class="styleblack">Export <a href="NewCatchVesselReport_excel.php?lstsector=<? echo $_POST["lstsector"]; ?>&lstgear=<? echo $_POST["lstgear"]; ?>&chkYear=<? echo $rptyear; ?>"><img src="images/excel_4.jpg" width="35" height="29" border="0"></a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div>
	    <p class="styleblack">
	      <?
				
        	} 
    	 }
	  ?>
	      <?
		 }
		 ?>
        </p>
	    <form action="NewCatchVesselReport.php" method="post" name="frmMain" id="frmMain">
          <table width="50%" height="159" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="19" colspan="2" background="images/index_01.gif"><div align="center" class="stylewhite">Select Report </div>
                  <div align="right"></div></td>
            </tr>
            <tr>
              <td width="27%" height="14" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Fishing Sector </span>&nbsp; </div></td>
              <td height="14" bgcolor="#ADCE4C"><label><span class="styletextbox">
              <select name="lstsector" class="styleblack" id="lstsector">
                <?php
				include "connect.inc.php";
		 $sqlgetgeart = "SELECT shptid,manpower,sector FROM shiptype inner join fishingsector on fishingsector.sid = shiptype.sid where shptid=1 or shptid=2";
	  	$qrygetgeart = mysql_query($sqlgetgeart);
	  	$numgetgeart = mysql_num_rows($qrygetgeart);
	   for($gt=1;$gt<=$numgetgeart;$gt++)
		{
			$resgetgeart = mysql_fetch_array($qrygetgeart);
			$dbfgtid = $resgetgeart["shptid"];
			$dbmanpower = $resgetgeart["manpower"];
			$dbsector = $resgetgeart["sector"];
			$fsector = $dbsector;
			//$fsector = $dbsector." (".$dbmanpower.")";
			echo "<option value='$dbfgtid'>$fsector</option>";
			  }
			  ?>
              </select>
              </span></label></td>
            </tr>
            <tr>
              <td height="14" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right" class="stylegreen">Fishing Gear</div></td>
              <td height="14" bgcolor="#ADCE4C" class="styletextbox">
                <select name="lstgear" class="styleblack" id="lstgear">
                  <?php
		 $sqlgetgear = "select fgid,fishinggear from gearandmethod order by fgid";
	  
	  $qrygetgear = mysql_query($sqlgetgear);
	  $numgetgear = mysql_num_rows($qrygetgear);
	   for($i=1;$i<=$numgetgear;$i++)
		{
			$resgetgear = mysql_fetch_array($qrygetgear);
			$dbfgid = $resgetgear["fgid"];
			$dbgear = $resgetgear["fishinggear"];
			echo "<option value='$dbfgid'>$dbgear</option>";
			  }
			  ?>
                </select>              </td>
            </tr>
            <tr>
              <td height="6" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right" class="stylegreen">Year </div></td>
              <td bgcolor="#ADCE4C" class="styleblack">
              <?
			  //include "connect.inc.php";
	  $sqlgetyear = "SELECT distinct year(DepartureDate) as yy FROM catch INNER JOIN fishspecies ON catch.spid = fishspecies.spid INNER JOIN fishoperation ON fishoperation.Optid = catch.Optid INNER JOIN ship ON fishoperation.VesselId = ship.ShipName INNER JOIN shiptype ON ship.fishsector = shiptype.shptid INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid ORDER BY year(DepartureDate)";
	  //echo $sqlgetship;
	  $qrygetyear = mysql_query($sqlgetyear);
	  $numgetyear = mysql_num_rows($qrygetyear);
	   for($i=1;$i<=$numgetyear;$i++)
		{
			$resgetyear = mysql_fetch_array($qrygetyear);
			$dbyear= $resgetyear["yy"];
			 if($i%5 == 0 && $i>1)
			 {
			 	echo "<br>";
			 }
			
			  ?>
                <input type="checkbox" name="chkYear[]" id="chkYear<?=$i;?>" value="<?=$dbyear;?>" /> <? echo $dbyear; ?>
                <? 
				}
				?>
              <br><input name="CheckAll" type="checkbox" id="CheckAll" value="Y" onClick="ClickCheckAll(this);">
              ALL</td>
        </tr>
            
            <tr class="stylegreen">
              <td height="34" colspan="2" bgcolor="#ADCE4C"><div align="right">
                  <label> </label>
                  <div align="center">
                    <input name="submit" type="submit" class="styleblack" id="submit2" value="Select Report" />
                  <input type="hidden" name="hdnCount" value="<?=$i;?>"></div>
              </div></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>       <p>&nbsp;</p>
        <p>&nbsp;</p>
      <p>&nbsp;</p></td>
  </tr>
	<tr>
	  <td bgcolor="#006666"><div align="right"><span class="styleblack">@SEAFDEC 2012</span></div></td>
  </tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>