<?
session_start();
ob_start();
?>
<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}
.style38 {	color: #CC0000;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	font-weight: bold;
}
.style37 {color: #FFFFFF}
.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"><a href="main.php">Home</a><span class="style1">&nbsp;</span> | <a href="usr.php">User</a> |<span class="style1"> <a href="fishingzone.php">Fishing Area |</a> <a href="district.php">State/Province </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">
	  <?
	  
				
				
				
	  	  if($_POST["submit"])
		  {
		  $yy = $_POST["lstyear"];
		  if($_POST["lstunit"] == 0.1)
		  {
		  	$unt = "CM";
		  }
		  else
		  {
		  	$unt = "MM";
		  }
		  if($_POST["lstlength"] == "tl")
		  {
		  $typeoflength = "Total Length";
		  }
		  elseif ($_POST["lstlength"] == "bl")
		  {
		  $typeoflength = "Body Length";
		  }
		   elseif ($_POST["lstlength"] == "fl")
		  {
		  $typeoflength = "Fork Length";
		  }
		   elseif ($_POST["lstlength"] == "sl")
		  {
		  $typeoflength = "Standard Length";
		  }
		  
		  require_once("reportlenght.inc.php");
		  $spname = getspname($_POST["lstsp"]);
	  ?>	  
      <br> <br>
      <table width="95%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
        <tr bgcolor="#000000">
          <td colspan="15" bgcolor="#6B716F" class="stylewhitesmall"> <div align="left" class="stylewhite"> Length Frequency </div>            <div align="left"></div></td>
        </tr>
        <tr bgcolor="#000000">
          <td colspan="15" bgcolor="#6B716F" class="stylewhitesmall">Year : <? echo $yy; ?></td>
        </tr>
        <tr bgcolor="#000000">
          <td colspan="15" bgcolor="#6B716F" class="stylewhitesmall">Species : <? echo  $spname; ?>  </td>
        </tr>
        <tr bgcolor="#000000">
          <td colspan="15" bgcolor="#6B716F" class="stylewhitesmall">Length : <? echo $typeoflength; ?></td>
        </tr>
        <tr class="styleblack">
          <td width="13%" class="stylegreen"><div align="center">Lower Limit<br><? echo $unt; ?></div></td>
          <td width="13%" class="stylegreen"><div align="center">Upper Limit<br><? echo $unt; ?> </div></td>
          <td width="13%" class="stylegreen"><div align="center">Mid Length<br><? echo $unt; ?> </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Jan<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Feb<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Mar<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Apr<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">May<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Jun<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">July<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Aug<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Sep<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Oct<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Nov<br>
    </div></td>
          <td bgcolor="#000000" class="stylewhitesmall"><div align="center">Dec<br>
    </div></td>
        </tr>
        <?
		 $interval = $_POST["txtinterval"];
		 $interval2 = $interval-1;
		 $lowerlimit = $_POST["txtlower"];
		 $modlower =  $lowerlimit%$interval;
		 $min = $lowerlimit-$modlower; 
		 require_once("reportlenght.inc.php");
		 $tlen = $_POST["lstlength"];
		 //echo "type of length =".$tlen;
		 $max = maxlength($tlen,$yy,$ss);
		 $minimum = $min;
		 $maximum = $max; 
		 $unit = $_POST["lstunit"];
						for($b=$minimum;$b<=$maximum;$b=$b+$interval)
						{
						$lower = $b;
						$upper = $b+$interval2;
						$showlower = $lower*$unit;
						$showupper = $upper*$unit;
						$midlength = ($b+($b+$interval2))/2;
						$showmid = $midlength*$unit;
						 require_once("reportlenght.inc.php");
						$ljan = getlength($tlen,$yy,1,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$lfeb = getlength($tlen,$yy,2,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$lmar = getlength($tlen,$yy,3,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$lapr = getlength($tlen,$yy,4,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$lmay = getlength($tlen,$yy,5,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$ljun = getlength($tlen,$yy,6,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$ljul = getlength($tlen,$yy,7,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$laug = getlength($tlen,$yy,8,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$lsep = getlength($tlen,$yy,9,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$loct = getlength($tlen,$yy,10,$_POST["lstsp"],$lower,$upper);
						 require_once("reportlenght.inc.php");
						$lnov = getlength($tlen,$yy,11,$_POST["lstsp"],$lower,$upper );
						 require_once("reportlenght.inc.php");
						$ldec = getlength($tlen,$yy,12,$_POST["lstsp"],$lower,$upper );
						?>
        <tr align="center" class="styleblack">
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $showlower; ?></td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $showupper; ?></td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $showmid; ?></td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $ljan; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $lfeb; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $lmar; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $lapr; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $lmay; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $ljun; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $ljul; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $laug; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $lsep; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $loct; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $lnov; ?>&nbsp;</td>
          <td height="17" bgcolor="#ADCE4C" class="styleblack"><? echo $ldec; ?>&nbsp;</td>
        </tr>
        <?
						}
						?>
        <tr bgcolor="#006666" class="styleblack">
          <td height="8" colspan="3" class="stylewhitesmall"><div align="right">
            <p align="center">Total number of fishes
              <?  
		   require_once("reportlenght.inc.php");
						$sjan = getsumlength($tlen,$yy,1,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$sfeb = getsumlength($tlen,$yy,2,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$smar = getsumlength($tlen,$yy,3,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$sapr = getsumlength($tlen,$yy,4,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$smay = getsumlength($tlen,$yy,5,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$sjun = getsumlength($tlen,$yy,6,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$sjul = getsumlength($tlen,$yy,7,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$saug = getsumlength($tlen,$yy,8,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$ssep = getsumlength($tlen,$yy,9,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$soct = getsumlength($tlen,$yy,10,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$snov = getsumlength($tlen,$yy,11,$_POST["lstsp"]);
						 require_once("reportlenght.inc.php");
						$sdec = getsumlength($tlen,$yy,12,$_POST["lstsp"]);
		  ?>
          </p> 
			</div>          </td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $sjan; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $sfeb; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $smar; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $sapr; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $smay; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $sjun; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $sjul; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $saug; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $ssep; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $soct; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $snov; ?>&nbsp;</td>
		  <td height="17" align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $sdec; ?>&nbsp;</td>
        </tr>
        <tr class="styleblack">
          <td height="9" colspan="15" bgcolor="#6B716F" class="stylewhitesmall"><div align="right">Export <a href="length_excel.php?y=<? echo $yy; ?>&lstsp=<? echo $_POST["lstsp"]; ?>&lstunit=<? echo $_POST["lstunit"]; ?>&lstlength=<? echo $_POST["lstlength"]; ?>&txtinterval=<? echo $_POST["txtinterval"]; ?>&txtlower=<? echo $_POST["txtlower"]; ?>"><img src="images/excel_4.jpg" width="35" height="29" border="0"></a></div></td>
        </tr>
      </table>
      <?
	  }
	  ?>
	  <form name="form1" method="post" action="">
	    <div align="center"><br>
	      <table width="43%" height="29" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="4" colspan="2" align="right" bgcolor="#6B716F"><div align="left"><span class="stylewhite">Length Frequency</span></div></td>
            </tr>
            <tr>
              <td width="38%" height="0" align="right" bgcolor="#ADCE4C" class="styleblack">Year&nbsp; </td>
              <td width="62%" align="right" bgcolor="#ADCE4C" class="styleblack">
                <div align="left">
                  <select name="lstyear" class="styleblack" id="lstsector">
                    <?
			  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 fishingsector.sid, 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"];
			echo "<option value='$dbyear'>$dbyear</option>";
		}
		?>
                  </select>
</div></td>
            </tr>
            <tr>
              <td width="38%" height="0" align="right" bgcolor="#ADCE4C" class="styleblack">Length&nbsp;&nbsp;</td>
              <td align="right" bgcolor="#ADCE4C" class="styleblack"><div align="left">
                <select name="lstlength" class="styleblack" id="lstlength">
                    <?
				  $yy = $_GET["y"];
				$ss = $_GET["s"];
				  ?>
                    <option value="tl">TL
                    <? require_once("reportlenght.inc.php"); echo "Min=".minlength('tl')." mm."; require_once("reportlenght.inc.php"); echo " Max=".maxlength('tl')." mm."; ?>
                    </option>
                    <option value="bl">BL
                    <? require_once("reportlenght.inc.php"); echo "Min=".minlength('bl')." mm."; require_once("reportlenght.inc.php"); echo " Max=".maxlength('bl')." mm."; ?>
                    </option>
                    <option value="fl">FL
                    <? require_once("reportlenght.inc.php"); echo "Min=".minlength('fl')." mm."; require_once("reportlenght.inc.php"); echo " Max=".maxlength('fl')." mm."; ?>
                    </option>
                    <option value="sl">SL
                    <? require_once("reportlenght.inc.php"); echo "Min=".minlength('sl')." mm."; require_once("reportlenght.inc.php"); echo " Max=".maxlength('sl')." mm."; ?>
                    </option>
                </select>
              </div></td>
            </tr>
            <tr>
              <td width="38%" height="0" align="right" bgcolor="#ADCE4C" class="styleblack">Species&nbsp; </td>
              <td align="left" bgcolor="#ADCE4C" class="styleblack"><?
			 
			 include "connect.inc.php";
			  $sqlgetcatch = "select distinct(biology.spid),fishspecies.scientific from biology inner join fishspecies on biology.spid = fishspecies.spid  inner join fishoperation on biology.Optid = fishoperation.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";
				//echo $sqlgetcatch;
				$qrygetcatch = mysql_query($sqlgetcatch);
				$numgetcatch = mysql_num_rows($qrygetcatch);
				?>                <select name="lstsp" class="styleblack" id="lstsp">
                <?
				
				for($i=1;$i<=$numgetcatch;$i++)
				{
				$resgetcatch = mysql_fetch_array($qrygetcatch);
				$dbspid = $resgetcatch["spid"];
				$dbspname = $resgetcatch["scientific"];
				echo "<option value='$dbspid'>$dbspname</option>";
				}
				?>
                            </select></td>
            </tr>
            <tr>
              <td width="38%" height="0" align="right" bgcolor="#ADCE4C" class="styleblack">Lower Limit Length&nbsp; </td>
              <td align="left" bgcolor="#ADCE4C" class="styleblack"><input name="txtlower" type="text" class="styleblack" id="txtlower" onKeyPress="if (event.keyCode&lt;48||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10"></td>
            </tr>
            <tr>
              <td width="38%" height="1" align="right" bgcolor="#ADCE4C" class="styleblack">Class Interval&nbsp; </td>
              <td align="left" bgcolor="#ADCE4C" class="styleblack"><input name="txtinterval" type="text" class="styleblack" id="txtinterval" onKeyPress="if (event.keyCode&lt;48||event.keyCode&gt;57) event.returnValue=false" size="3" maxlength="3"> </td>
            </tr>
            <tr>
              <td height="3" align="right" bgcolor="#ADCE4C" class="styleblack">Unit&nbsp; </td>
              <td height="3" align="right" bgcolor="#ADCE4C" class="styleblack"><div align="left">
                <select name="lstunit" class="styleblack" id="lstunit">
                  <option value="1">MM</option>
                  <option value="0.1">CM</option>
                </select>
              </div></td>
            </tr>
            <tr>
              <td height="9" colspan="2" align="right" bgcolor="#6B716F"><div align="center">
                <input name="submit" type="submit" class="styleblack" id="submit" value="Submit">
              </div></td>
            </tr>
          </table>
        </div>
	  </form></td>
  </tr>
	<tr>
	  <td bgcolor="#006666"><div align="right"><span class="styleblack">@SEAFDEC 2012</span></div></td>
  </tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>