<?
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">
<link rel="stylesheet" href="autocomplete.css" type="text/css" media="screen">
<script src="jquery.js" type="text/javascript"></script>
<script src="dimensions.js" type="text/javascript"></script>
<script src="autocomplete.js" type="text/javascript"></script>

<script type="text/javascript">
	$(function(){
	    setAutoComplete("searchField", "results", "autocomplete.php?part=");
	});
</script>
<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"];
	  
				?>
                <br>
        </span>
        <table width="99%" 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">Species anual yearly report</span></td>
          </tr>
        <tr bordercolor="#FFFFFF">
          <td colspan="14" bgcolor="#006666" class="stylewhite"><span class="stylewhitesmall">Species/Local name: 
            
          <?php ;
		  	$localsp = $_POST["searchField"];
			require_once("sp_function.inc.php");
			$rptSpid = getspeciesid($localsp);
			require_once("sp_function.inc.php");
			$rptSp = getspname($rptSpid); 
			echo $rptSp;
			?></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 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>
        <tr bgcolor="#000000" class="stylewhitesmall">
            <td width="16%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Year</span></div></td>
            <td width="6%" class="stylewhitesmall"><div align="center"><span class="stylewhitesmallk">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>
        <?
       
		$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($i=0;$i<count($_POST["chkYear"]);$i++) 
		 { 
	
         	if($_POST["chkYear"][$i] != "") 
        	{ 
			$rptyear = $_POST["chkYear"][$i];
			//if(count($_POST["chkYear"]) == 1)
			//{
				//$str_y =$rptyear;
			//}
			//else
			//{
				$lastarray = count($_POST["chkYear"]);
				//echo "count=".$lastarray;
				if($i == 0)
				{
					$str_y = $rptyear;
				}
				else
				{
					$str_y = $str_y.",".$rptyear;
				}
				
			//}
			require_once("NewReport.inc.php");
			$catchJan = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid ,1);
			$ttjan = $ttjan+$catchJan;
			
			require_once("NewReport.inc.php");
			$catchFeb = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,2);
			$ttfeb = $ttfeb+$catchFeb;
			require_once("NewReport.inc.php"); 
			$catchMar = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,3);
			$ttmar = $ttmar+$catchMar; 
			require_once("NewReport.inc.php"); 
			$catchApr = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,4);
			$ttapr = $ttapr+$catchApr; 
			require_once("NewReport.inc.php"); 
			$catchMay = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,5);
			$ttmay = $ttmay+$catchMay; 
			require_once("NewReport.inc.php"); 
			$catchJun = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,6);
			$ttjun = $ttjun+$catchJun; 
			require_once("NewReport.inc.php"); 
			$catchJul = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,7);
			$ttjul = $ttjul+$catchJul; 
			require_once("NewReport.inc.php"); 
			$catchAug = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,8);
			$ttaug = $ttaug+$catchAug;
			require_once("NewReport.inc.php"); 
			$catchSep = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,9);
			$ttsep = $ttsep+$catchSep; 
			require_once("NewReport.inc.php"); 
			$catchOct = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,10);
			$ttoct = $ttoct+$catchOct; 
			require_once("NewReport.inc.php"); 
			$catchNov = getCatchDataSp($rptyear,$subgear,$rptZone,$rptSpid,11);
			$ttnov = $ttnov+$catchNov; 
			require_once("NewReport.inc.php"); 
			$catchDec = getCatchDataSp($rptyear,$subgear,$rptZone,$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"> <div align="center"><span class="styleblack"><? echo $rptyear; ?> </span></div></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="NewSpeciesAnualReport_excel.php?lstsp=<? echo $rptSpid; ?>&lstgear=<? echo $_POST["lstgear"]; ?>&chkYear=<? echo $str_y; ?>&local=<? echo $_POST["searchField"]; ?>"><img src="images/excel_4.jpg" width="35" height="29" border="0">&nbsp;&nbsp; </a></span></div>
	    <p class="styleblack">
	      <?
				
        	} 
    	 }
	  ?>
	      
        </p>
	    <form action="NewSpeciesAnualReport.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">Species Annual Yearly 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">Local name</span>&nbsp; </div></td>
              <td height="14" bgcolor="#ADCE4C"><div id="auto"><input name="searchField" type="text" class="styleblack" id="searchField" />
                  <input type="hidden" name="hiddenField" id="hiddenField" />
              </div></td>
            </tr>
            <tr>
              <td height="14" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right" class="stylegreen">Fishing Gear&nbsp; </div></td>
              <td height="14" bgcolor="#ADCE4C" class="styletextbox">
                <select name="lstgear" class="styleblack" id="lstgear">
                  <?php
				   include "connect.inc.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>