<?
session_start();
ob_start();
?>
<html>
<head>
<script language="JavaScript"> 
function onInsert()
{ 
		if(form1.txttotalcatch.value =="")
		{
			alert("You not fill total catch!");
			form1.txttotalcatch.focus();
			return false;
		}
		else
		{
			return true; 
		}	 
} 
function onInsert2()
{ 
		if(form2.searchField.value =="")
		{
			alert("You not fill species!");
			form2.searchField.focus();
			return false;
		}
		if(form2.txtweight.value =="")
		{
			alert("You not fill weight!");
			form2.txtweight.focus();
			return false;
		}
		else
		{
			return true; 
		}	 
} 
function onInsert3()
{ 
		if(form3.searchField.value =="")
		{
			alert("You not fill species!");
			form3.searchField.focus();
			return false;
		}
		if(form3.txtweight2.value =="")
		{
			alert("You not fill weight!");
			form3.txtweight2.focus();
			return false;
		}
		else
		{
			return true; 
		}	 
} 
</script>
<title>Fish landing data management system</title>

<script type="text/javascript" src="calendarDateInput.js">

/***********************************************
* Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
* Script featured on and available at http://www.dynamicdrive.com
* Keep this notice intact for use.
***********************************************/

</script>
<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; }
.style36 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #FFFFFF; }
.style37 {color: #FFFFFF}
.styleblacklargered {font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	font-weight: bold;
	color:#FF0000;
}
-->
</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" colspan="2" bgcolor="#ADCE4C" class="stylewhite">&nbsp;Fish Landing Data Management System</td>
  </tr>
	<tr class="stylewhitesmall">
	  <td height="20" colspan="2" 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"> Sampling Port </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="report.php">Report</a> |<span class="style1"> <a href="logout.php">Logout</a></span></td>
  </tr>
	<tr>
	  <td width="379" height="705" valign="top" bgcolor="#CCCCCC"><p align="center"><span class="stylewhite">
	    <?
if($_POST[submit])
{
		
	include "usr_function.php"; //for Check null
	require_once("fishing_function.inc.php");
	//($optid,$sector,$vessel,$fg,$zoneid,$district,$port,$ddate,$adate,$fishingtime,$bdepth,$gdepth,$hual,$totalcatch,$recorder)
	$insoptid = $_POST["hdoptid"];
	$inssector = $_POST["lstsector"];
	$insvessel = $_POST["lstvessel"];
	$insfg = $_POST["lstfg"];
	$inszone = $_POST["lstzone"];
	$insdistrict = $_POST["lstdistrict"];
	$insport = $_POST["lstport"];
	$inssdate = $_POST["samplingdate"];
	$insddate = $_POST["departure"];
	$insadate = $_POST["arrival"];
	$insfishingtime = $_POST["lstfishingtime"];
	$insbdepth = chknull($_POST["txtbottomdepth"]);
	$insgdepth = chknull($_POST["txtfishingdepth"]);
	$inshual = chknull($_POST["txthual"]);
	$instotalcatch = 0;
	$insrecorder = $_POST["txtrecord"];
	EditOpt($insoptid,$inssector,$insvessel,$insfg,$inszone,$insdistrict,$insport,$inssdate,$insddate,$insadate,$insfishingtime,$insbdepth,$insgdepth,$inshual,$instotalcatch,$insrecorder);
	$tlog = "Add Fishing Operation ".$optid;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	
}
if($_POST[submit2])
{
	$insoptid = $_POST["hdoptid2"];
	$inssortno = 1;
	require_once("sp_function.inc.php");
	$insspid = getspeciesid($_POST[searchField]);
	$insweight = $_POST["txtcatchweight"];
	require_once("fishing_function.inc.php");
	InsertCatch($insoptid,$inssortno,$insspid,$insweight);
	$tlog = "Add Primary Sorting ".$optid." ".$_POST[searchField];
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	
}
if($_POST[submit3])
{
	$insoptid = $_POST["hdoptid3"];
	$inssortno = 2;
	require_once("sp_function.inc.php");
	$insspid = getspeciesid($_POST[searchField]);
	$insweight = $_POST["txtcatchweight2"];
	require_once("fishing_function.inc.php");
	InsertCatch($insoptid,$inssortno,$insspid,$insweight);
	$tlog = "Add Secondary Sorting ".$optid." ".$_POST[searchField];
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
if($_POST[submit4])
{
	$insoptid = $_POST["hdoptid4"];
	require_once("fishing_function.inc.php");
	DeleteOpt($insoptid);
	$tlog = "Add Secondary Sorting ".$optid." ".$_POST[searchField];
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
?>
	  </span></p>        
        <table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
          <tr>
            <td colspan="4" bgcolor="#000000"><div align="center"><span class="stylewhite">
                <?
if($_POST[submit])
{
		
	include "usr_function.php"; //for Check null
	require_once("fishing_function.inc.php");
	//($optid,$sector,$vessel,$fg,$zoneid,$district,$port,$ddate,$adate,$fishingtime,$bdepth,$gdepth,$hual,$totalcatch,$recorder)
	$insoptid = $_POST["hdoptid"];
	$insvessel = $_POST["lstvessel"];
	$insport = $_POST["lstport"];
	$insddate = $_POST["departure"];
	$insadate = $_POST["arrival"];
	$insfishingtime = $_POST["lstfishingtime"];
	$insbdepth = chknull($_POST["txtbottomdepth"]);
	$insgdepth = chknull($_POST["txtfishingdepth"]);
	$inshual = chknull($_POST["txthual"]);
	$insfdulation = chknull($_POST["txtfdulation"]);
	$insrecorder = $_POST["txtrecord"];
	//Expence
	/*
	$insfuel = chknull($_POST["txtfuel"]);
	$insice = chknull($_POST["txtice"]);
	$insfood = chknull($_POST["txtfood"]);
	$insrepair = chknull($_POST["txtrepair"]);
	$insmantenance = chknull($_POST["txtmaintenance"]);
	$insmis = chknull($_POST["txtmis"]);
	*/
	//set null
	$insfuel = "";
	$insice = "";
	$insfood = "";
	$insrepair = "";
	$insmantenance = "";
	$insmis = "";
	
	Insertopt($insoptid,$insvessel,$insport,$insddate,$insadate,$insfishingtime,$insbdepth,$insgdepth,$inshual,$insfdulation,$insrecorder,$insfuel,$insice,$insfood,$insrepair,$insmantenance,$insmis);
	$tlog = "Add Fishing Operation ".$insoptid;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	
}
if($_POST[submit2])
{
	$insoptid = $_POST["hdoptid2"];
	$inssortno = 1;
	require_once("sp_function.inc.php");
	$insspid = getspeciesid($_POST[searchField]);
	$insweight = $_POST["txtcatchweight"];
	require_once("fishing_function.inc.php");
	InsertCatch($insoptid,$inssortno,$insspid,$insweight);
	$tlog = "Add Primary Sorting ".$optid." ".$_POST[searchField];
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	
}
if($_POST[submit3])
{
	$insoptid = $_POST["hdoptid3"];
	$inssortno = 2;
	require_once("sp_function.inc.php");
	$insspid = getspeciesid($_POST[searchField]);
	$insweight = $_POST["txtcatchweight2"];
	require_once("fishing_function.inc.php");
	InsertCatch($insoptid,$inssortno,$insspid,$insweight);
	$tlog = "Add Secondary Sorting ".$optid." ".$_POST[searchField];
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
?>
              Catch Data</span></div></td>
          </tr>
          <tr class="stylewhitesmall">
            <td width="27%" bgcolor="#000000" class="stylewhitesmall">Vessel Name</td>
            <td width="41%" bgcolor="#000000"><div align="center">Departure Date</div></td>
            <td width="17%" bgcolor="#000000"><div align="center">Edit</div></td>
            <td width="15%" bgcolor="#000000"><div align="center">Delete</div></td>
          </tr>
          <div align="center"> <span class="stylegreen">
            <?
	  include "connect.inc.php";
	  $sqlgetyear = "select Optid,VesselId,DepartureDate from fishoperation order by VesselId,DepartureDate";
	  //echo  $sqlgetyear;
	  $qrygetyear = mysql_query($sqlgetyear);
	  $numgetyear = mysql_num_rows($qrygetyear);
	   for($i=1;$i<=$numgetyear;$i++)
		{
			$resgetyear = mysql_fetch_array($qrygetyear);
			$dboptid = $resgetyear["Optid"];
			$dbddate= $resgetyear["DepartureDate"];
			$dbvessel= $resgetyear["VesselId"];
			$encodeoptid = base64_encode($dboptid);
			?>
            </span>
              <tr>
                <td align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $dbvessel; ?></td>
                <td align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $dbddate; ?></td>
                <td align="center" bgcolor="#006666" class="styleblack"><a href="fishoperationsector.php?editoptid=<? echo $encodeoptid; ?>"><img src="images/document_edit.png" width="20" height="20" border="0" /></a></td>
                <td align="center" bgcolor="#006666" class="styleblack"><a href="fishoperationsector.php?deloptid=<? echo $encodeoptid; ?>"><img src="images/close.png" width="20" height="20" border="0" /></a></td>
              </tr>
              <span class="stylegreen">
              <?
        }
      ?>
            </span></div>
          <tr>
            <td colspan="4" bgcolor="#000000"><div align="right"><span class="stylewhitesmall"><a href="fishingzone.php"><img src="images/add.png" width="24" height="24" border="0" /></a><a href="catchdata.php">+Add ...</a></span><span class="styleblack">&nbsp;&nbsp;&nbsp; </span></div></td>
          </tr>
        </table>
      <p align="center">&nbsp; </p>        <p align="center">&nbsp;</p></td>
      <td width="639" valign="top" bgcolor="#CCCCCC"><?
	  	//
		 if(isset($_GET["deloptid"]))
	  	{
		  $decodeid = base64_decode($_GET["deloptid"]);
	  	?>
	  <br>
	  <form action="fishoperationsector.php?y=<? echo $_GET["y"]; ?>" method="post" name="form4" id="form4">
        <table width="82%" height="86" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="100%" height="19" background="images/index_01.gif"><div align="center"><span class="stylewhite">Delete Catch Data</span></div>
                <div align="right"></div></td>
          </tr>
          <tr>
            <td height="25" bgcolor="#ADCE4C" class="style1"><label>
                <br>
              <div align="center" class="stylewhite"><span class="styleblack">
                <input type="hidden" name="hdoptid4" id="hdpid3" value="<? echo $decodeid; ?>">
                  </span>&nbsp; Are you sure to delete this catch data?</div></td>
          </tr>
          <tr>
            <td height="34" bgcolor="#ADCE4C"><label>
                <div align="center">
                  <input name="submit4" type="submit" class="styleblack" id="submit4" value="Confirm" />
                </div>
              </label></td>
          </tr>
          <tr>
            <td height="19" bgcolor="#6B716F"><div align="right"></div></td>
          </tr>
        </table>
	    </form>
	  <?
	  }
		//
	  if(isset($_GET[editoptid]))
	  {
	  $decodeid = base64_decode($_GET["editoptid"]);
	  $sqlgetoperation = "select VesselId,LandingPort,DepartureDate,ArrivalDate,Duration,FishingTime,BottomDepth,FishingGearDepth,HualPerTrip,TotalCatch,Recorder,fishinggear,portname,province,zoneid,fishsector,fishingdulation from  fishoperation inner join ship on fishoperation.VesselId = ship.ShipName left join gearandmethod on ship.GearType =  gearandmethod.fgid  inner join fishingport on fishingport.portid = fishoperation.LandingPort inner join district on  fishingport.province = district.disid where Optid = '$decodeid'";
	//  echo $sqlgetoperation;
	  $qrygetoperation = mysql_query($sqlgetoperation) or die(mysql_error());
	  $numgetoperation = mysql_fetch_array($qrygetoperation);
	  $dbsector = $numgetoperation["Sector"];
	  $dbvessel =  $numgetoperation["VesselId"];
	  $dbgearid =  $numgetoperation["ShipGearId"];
	  $dbgearname = $numgetoperation["fishinggear"];
	  $dbgearmethod = $numgetoperation["fishmethod"];
	  $dbfishingzone =  $numgetoperation["zoneid"];
	  $dbdistrict = $numgetoperation["District"];
	  $dbdisname = $numgetoperation["disname"];
	  $dbportid2 = $numgetoperation["LandingPort"];
	  $dbportname2 = $numgetoperation["portname"];
	  $dbportprovince2 = $numgetoperation["province"];
	  $dbsamplingdate = $numgetoperation["SamplingDate"];
	  $dbdeparturedate = $numgetoperation["DepartureDate"];
	  $dbarrivaldate = $numgetoperation["ArrivalDate"];
	  $dbduration = $numgetoperation["Duration"];
	  $dbfishingtime = $numgetoperation["FishingTime"];
	  $dbbottomdepth = $numgetoperation["BottomDepth"];
	  $dbfishingdepth = $numgetoperation["FishingGearDepth"];
	  $dbhual = $numgetoperation["HualPerTrip"];
	  $dbtotalcatch = $numgetoperation["TotalCatch"];
	  $dbrecorder = $numgetoperation["Recorder"];
	  $dbddate = $numgetoperation["DepartureDate"];
	  $dbtotalcatchpri = $numgetoperation["catchprimary"];
	  $dbfishsector = $numgetoperation["fishsector"];
	  $dbfishdulation = $numgetoperation["fishingdulation"];
	  ?>
	  <form action="fishoperationsector.php?editoptid=<? echo $optid; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
          <table width="70%" height="155" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="19" colspan="2" background="images/index_01.gif"><div align="center"><span class="stylewhite">Catch Data </span></div>
                  <div align="right"></div></td>
            </tr>
            <tr>
              <td height="14" colspan="2" bgcolor="#ADCE4C" class="style1"><label> </label>
                  <div align="left">&nbsp; <span class="stylewhite">Edit</span><span class="styleblack">
                    <input type="hidden" name="hdoptid" id="hdgid2" value="<? echo  $decodeid; ?>">
                </span></div></td>
            </tr>
            <tr>
              <td width="37%" height="12" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Vessel Name</span>&nbsp; </div></td>
              <td width="63%" height="12" bgcolor="#ADCE4C"><label><span class="styletextbox">
                <select name="lstvessel" class="styleblack" id="select4">
                  <?php
		include "connect.inc.php";
		echo "<option value='$dbvessel'>$dbvessel</option>";
	  $sqlgetship = "SELECT ShipId,ShipName  FROM ship where ShipName != '$dbvessel' order by ShipName";
	  //echo $sqlgetship;
	  $qrygetship = mysql_query($sqlgetship);
	  $numgetship = mysql_num_rows($qrygetship);
	   for($i=1;$i<=$numgetship;$i++)
		{
			$resgetship = mysql_fetch_array($qrygetship);
			$dbshipid = $resgetship["ShipId"];
			$dbshipname = $resgetship["ShipName"];
				echo "<option value='$dbshipname'>$dbshipname</option>";
			  }
			  ?>
                </select>
              </span></label></td>
            </tr>
            <tr>
              <td height="6" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Fishing Zone</span>&nbsp; </div></td>
              <td bgcolor="#ADCE4C"><input name="txtzone" type="text" disabled="disabled" class="styleblack" id="txtzone" value="<? echo $dbfishingzone; ?>"/></td>
            </tr>
            <tr>
              <td height="3" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Fishing Gear&nbsp; </div></td>
              <td bgcolor="#ADCE4C"><input name="txtgear" type="text" disabled="disabled" class="styleblack" id="txtgear" value="<? echo $dbgearname; ?>"/></td>
            </tr>
            <tr>
              <td height="4" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Fishing Sector</div></td>
              <td bgcolor="#ADCE4C"><input name="txtsector" type="text" class="styleblack" id="txtsector" disabled="disabled" value="<? echo $dbfishsector; ?>"/></td>
            </tr>
            <tr>
              <td height="3" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Landing port&nbsp; </div></td>
              <td height="0" bgcolor="#ADCE4C"><span class="styletextbox">
                <select name="lstport" class="styleblack" id="select7">
                  <?php
				echo "<option value='$dbportid2'>$dbportname2</option>";
		 include "connect.inc.php";
	  $sqlgetport = "select portid,portname,province from fishingport order by portid";
	  $qrygetport = mysql_query($sqlgetport);
	  $numgetport = mysql_num_rows($qrygetport);
	   for($i=1;$i<=$numgetport;$i++)
		{
			$resgetport = mysql_fetch_array($qrygetport);
			$dbportid = $resgetport["portid"];
			$dbportname = $resgetport["portname"];
			$dbprovince = $resgetport["province"];
			echo "<option value='$dbportid'>$dbportname</option>";
			  }
			  ?>
                </select>
              </span></td>
            </tr>
            <tr>
              <td height="7" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Departure date&nbsp; </div></td>
              <td height="1" bgcolor="#ADCE4C"><Script language="JavaScript">DateInput('departure', true, 'YYYY-MM-DD','<? echo $dbdeparturedate; ?>')</script></td>
            </tr>
            <tr>
              <td height="7" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Arrival date&nbsp; </div></td>
              <td height="1" bgcolor="#ADCE4C"><Script language="JavaScript">DateInput('arrival', true, 'YYYY-MM-DD','<? echo $dbarrivaldate; ?>')</script></td>
            </tr>
            <tr>
              <td height="1" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Dulation (Days)&nbsp; </div></td>
              <td height="0" bgcolor="#ADCE4C"><span class="styleblack">
                <input name="txtdulation" type="text" class="styleblack" id="txtdulation" disabled="disabled" value="<? echo $dbduration; ?>"/>
              <?  ?></span></td>
            </tr>
            <tr>
              <td height="2" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Fishing time&nbsp; </div></td>
              <td height="2" bgcolor="#ADCE4C"><select name="lstfishingtime" class="styleblack" id="lstfishingtime">
                <?
			  if($dbfishingtime == "Day")
			  {
			  ?>
                <option value="Day">Day</option>
                <option value="Night">Night</option>
                <option value="Day and Night">Day and Night</option>
                <?
				 }
				 else if($dbfishingtime == "Night")
				 {
				 ?>
                <option value="Night">Night</option>
                <option value="Day and Night">Day and Night</option>
                <option value="Day">Day</option>
                <?
				 }
				 else
				 {
				 ?>
                <option value="Day and Night">Day and Night</option>
                <option value="Night">Night</option>
                <option value="Day">Day</option>
                <?
				 }
				 ?>
              </select></td>
            </tr>
            <tr>
              <td height="3" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Bottom depth&nbsp; </div></td>
              <td height="0" bgcolor="#ADCE4C"><input name="txtbottomdepth" type="text" class="styleblack" id="txtbottomdepth2" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10" value="<? echo $dbbottomdepth; ?>"></td>
            </tr>
            <tr>
              <td height="2" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Fishing gear depth&nbsp; </div></td>
              <td height="0" bgcolor="#ADCE4C"><input name="txtfishingdepth" type="text" class="styleblack" id="txtfishingdepth4" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10" value="<? echo $dbfishingdepth; ?>"></td>
            </tr>
            <tr>
              <td height="1" valign="top" bgcolor="#ADCE4C" class="stylegreen"><p align="right">No. of haul per trip&nbsp; </p></td>
              <td height="0" bgcolor="#ADCE4C"><input name="txthual" type="text" class="styleblack" id="txthual" onKeyPress="if (event.keyCode&lt;48||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10" value="<? echo $dbhual; ?>"></td>
            </tr>
            <tr>
              <td height="1" align="right" valign="middle" bgcolor="#ADCE4C" class="stylegreen">&nbsp;
                Fishing Duration(hours)&nbsp; </td><td height="1" bgcolor="#ADCE4C"><input name="txtfdulation" type="text" class="styleblack" id="txtbottomdepth" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10" value="<? echo $dbfishdulation; ?>" /></td>
            </tr>
            <tr>
              <td height="7" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Recorder&nbsp; </div></td>
              <td height="0" bgcolor="#ADCE4C"><input name="txtrecord" type="text" class="styleblack" id="txtrecord" size="30" maxlength="30" value="<? echo $dbrecorder; ?>"></td>
            </tr>
            <tr>
              <td height="7" valign="top" bgcolor="#ADCE4C" class="style1">&nbsp;</td>
              <td height="7" bgcolor="#ADCE4C">&nbsp;</td>
            </tr>
            <tr>
              <td height="34" colspan="2" bgcolor="#ADCE4C"><label> </label>
                  <div align="center">
                    <input name="submit" type="submit" class="styleblack" id="submit2" value="Edit" />
                </div></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <?
	

         if(!isset($_GET["secondcatchoptid"]))
	  	{
		?>
        <form action="fishoperationsector.php?y=<? echo $_GET["y"]; ?>&catchoptid=<? echo $_GET["optid"]; ?>&optid=<? echo $_GET["optid"]; ?>" method="post" enctype="multipart/form-data" name="form2" id="form2" onSubmit="return onInsert2();">
          <?
	  //$decodeid = base64_decode($_GET["optid"]);
	  $sqlgetoperation = "select Sector,VesselId,ShipGearId,FishingZone,District,LandingPort,DepartureDate, ArrivalDate,Duration,FishingTime,BottomDepth,FishingGearDepth,HualPerTrip,TotalCatch,Recorder,catchprimary from  fishoperation where Optid = '$decodeid'";
	  $qrygetoperation = mysql_query($sqlgetoperation);
	  $numgetoperation = mysql_fetch_array($qrygetoperation);
	  $dbvessel =  $numgetoperation["VesselId"];
	  $dbddate = $numgetoperation["DepartureDate"];
	  $dbtotalcatch = $numgetoperation["catchprimary"];
	  $sqlgetbycatch = "select sum(weight) as sw from catch where SortNo=1 and Optid = $decodeid group by Optid ";
	 // echo  $sqlgetbycatch;
	  $qrygetbycatch = mysql_query($sqlgetbycatch);
	  $resgetbycatch = mysql_fetch_array($qrygetbycatch);
	  $totalprimary = $resgetbycatch["sw"];
	  require_once("fishing_function.inc.php");
	  $totalbycatch = $dbtotalcatch-$totalprimary;
	  updatetotalcatch($decodeid, $totalprimary,$totalbycatch);
	  ?>
          <br>
          <table width="70%" height="119" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="9" colspan="2" background="images/index_01.gif"><div align="center"><span class="stylewhite">Edit Catch Data</span></div>
              <div align="right"></div></td>
            </tr>
            <?
		   include "connect.inc.php";
	  $sqlgetcatch = "select scientific,catch.spid,Weight from catch inner join fishspecies on catch.spid = fishspecies.spid where Optid='$decodeid' and SortNo = 1";
	  //echo $sqlgetcatch;
	  $qrygetcatch = mysql_query($sqlgetcatch);
	  $numgetcatch = mysql_num_rows($qrygetcatch);
	  
		  ?>
            <tr>
              <td height="2" colspan="2" bgcolor="#ADCE4C"><span class="styleblack">
              <input type="hidden" name="hdoptid2" id="hdoptid2" value="<? echo $decodeid; ?>">
              </span></td>
            </tr>
            <tr>
              <td height="3" colspan="2" bgcolor="#ADCE4C"><span class="styleblack"> &nbsp;</span></td>
            </tr>
            <tr>
              <td height="5" colspan="2" bgcolor="#ADCE4C">&nbsp;<span class="styleblack">Total catch = <? echo $totalprimary; ?> kg.</span></td>
            </tr>
            <tr>
              <td height="7" colspan="2" bgcolor="#ADCE4C" class="style1"><label> </label>
                  <div align="left"> <br>
                      <table width="80%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
                        <tr bgcolor="#000000" class="styleblack">
                          <td width="11%" class="stylewhitesmall"><div align="center">No</div></td>
                          <td width="31%" class="stylewhitesmall"><div align="left">Species</div></td>
                          <td width="22%" class="stylewhitesmall"><div align="center">Weight(kg.)</div></td>
                          <td width="16%" class="stylewhitesmall"><div align="center">Edit</div></td>
                          <td width="20%" class="stylewhitesmall"><div align="center">
                            <p>Delete</p>
                            </div></td>
                        </tr>
                        <?
               for($j=1;$j<=$numgetcatch;$j++)
				{
    				$resgetcatch = mysql_fetch_array($qrygetcatch);
					$dbspid = $resgetcatch["spid"];
					$dbspname = $resgetcatch["scientific"];
					$dbweight = $resgetcatch["Weight"];
				?>
                        <tr class="styleblack">
                          <td bgcolor="#006666" class="styleblack"><div align="center"><span class="style37"><? echo $j; ?></span></div></td>
                          <td bgcolor="#006666" class="styleblack"><span class="style37"><? echo $dbspname; ?></span></td>
                          <td align="center" bgcolor="#006666" class="styleblack"><span class="style37"><? echo $dbweight; ?></span></td>
                          <td align="center" bgcolor="#006666" class="styleblack"><a href="fishoperationsector.php?editoptid=<? echo $encodeoptid; ?>"><img src="images/document_edit.png" width="20" height="20" border="0" /></a></td>
                          <td align="center" bgcolor="#006666" class="styleblack"><a href="fishoperationsector.php?deloptid=<? echo $encodeoptid; ?>"><img src="images/close.png" width="20" height="20" border="0" /></a></td>
                        </tr>
                        <?
			  }
			  ?>
                        <tr class="styleblack">
                          <td colspan="5" bgcolor="#000000" class="stylewhitesmall">&nbsp;</td>
                        </tr>
                      </table>
                    <br>
                </div></td>
            </tr>
            <tr>
              <td height="3" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Vessel Name&nbsp; </div></td>
              <td height="3" bgcolor="#ADCE4C" class="styleblack"><? echo $dbvessel; ?></td>
            </tr>
            <tr>
              <td height="4" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Departure Date&nbsp; </div></td>
              <td height="4" bgcolor="#ADCE4C" class="styleblack"><? echo $dbddate; ?></td>
            </tr>
            <tr>
              <td width="37%" height="3" valign="top" bgcolor="#ADCE4C" class="styleblack"><div align="right">Species&nbsp; </div></td>
              <td width="63%" height="0" bgcolor="#ADCE4C" class="styleblack"><p id="auto">
                <input name="searchField" type="text" class="styleblack" id="searchField" />
              </p></td>
            </tr>
            <tr>
              <td height="4" valign="top" bgcolor="#ADCE4C" class="styleblack"><div align="right">Weight&nbsp; </div></td>
              <td width="63%" height="0" bgcolor="#ADCE4C" class="styleblack"><span class="style36">
                <input name="txtcatchweight" type="text" class="styleblack" id="txtcatchweight" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" value="" size="7" maxlength="7" />
              </span></td>
            </tr>
            <tr>
              <td height="7" valign="top" bgcolor="#ADCE4C" class="style1">&nbsp;</td>
              <td width="63%" height="7" bgcolor="#ADCE4C">&nbsp;</td>
            </tr>
            <tr>
              <td height="34" colspan="2" bgcolor="#ADCE4C"><label> </label>
                  <div align="center">
                    <input name="submit2" type="submit" class="styleblack" id="submit" value="Insert" />
                </div></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <?
		}
		
		else
		{
		?>
        
        <form action="fishoperationsector.php?y=<? echo $_GET["y"]; ?>&secondcatchoptid=<? echo $_GET["optid"]; ?>&optid=<? echo $_GET["optid"]; ?>" method="post" enctype="multipart/form-data" name="form3" id="form3" onSubmit="return onInsert3();">
        
		  <?
	  $decodeid = base64_decode($_GET["secondcatchoptid"]);
	  $sqlgetoperation = "select Sector,VesselId,ShipGearId,FishingZone,District,LandingPort,DepartureDate, ArrivalDate,Duration,FishingTime,BottomDepth,FishingGearDepth,HualPerTrip,TotalCatch,Recorder from  fishoperation where Optid = '$decodeid'";
	  $qrygetoperation = mysql_query($sqlgetoperation);
	  $numgetoperation = mysql_fetch_array($qrygetoperation);
	  $dbvessel =  $numgetoperation["VesselId"];
	  $dbddate = $numgetoperation["DepartureDate"];
	  $dbtotalcatch = $numgetoperation["TotalCatch"];
	  $sqlgetbycatch = "select sum(weight) as sw from catch where SortNo=1 and Optid = $decodeid group by Optid ";
	 // echo  $sqlgetbycatch;
	  $qrygetbycatch = mysql_query($sqlgetbycatch);
	  $resgetbycatch = mysql_fetch_array($qrygetbycatch);
	  $totalprimary = $resgetbycatch["sw"];
	  $sqlgetsambycatch = "select sum(weight) as swb from catch where SortNo=2 and Optid = $decodeid group by Optid ";
	 // echo $sqlgetsambycatch;
	 // echo  $sqlgetbyca
	   $qrygetsambycatch = mysql_query($sqlgetsambycatch);
	  $resgetsambycatch = mysql_fetch_array($qrygetsambycatch);
	  $totalsecondary = $resgetsambycatch["swb"];
	  $totalbycatch =  $dbtotalcatch-$totalprimary;
	  if($totalsecondary != 0)
	  {
	  $rais = $totalbycatch/$totalsecondary;
	   require_once("fishing_function.inc.php");
	  updateraisingfact($decodeid,$totalsecondary,$rais);
	  }
	  ?>
          <br>
          <table width="90%" height="120" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="9" colspan="2" background="images/index_01.gif"><div align="center"><span class="stylewhite">Catch Data </span><span class="stylewhite"> (Secondary Sorting)</span></div>
                  <div align="right"></div></td>
            </tr>
            <?
		   include "connect.inc.php";
	  $sqlgetcatch = "select scientific,catch.spid,Weight,Weight*raisingfact as estotalcatch from catch inner join fishspecies on catch.spid = fishspecies.spid inner join fishoperation on catch.Optid = fishoperation.Optid where catch.Optid='$decodeid' and SortNo = 2";
	//echo $sqlgetcatch;
	  $qrygetcatch = mysql_query($sqlgetcatch);
	  $numgetcatch = mysql_num_rows($qrygetcatch);
	  
		  ?>
            <tr>
              <td height="2" colspan="2" bgcolor="#ADCE4C">&nbsp; <span class="stylewhite">Edit</span><span class="styleblack">
                <input type="hidden" name="hdoptid3" id="hdoptid" value="<? echo $decodeid; ?>">
                <br>
                <br>
              </span></td>
            </tr>
            <tr>
              <td height="3" colspan="2" bgcolor="#ADCE4C"><span class="styleblack"> &nbsp; Total catch=<? echo $dbtotalcatch; ?> kg. </span></td>
            </tr>
            <tr>
              <td height="5" colspan="2" bgcolor="#ADCE4C"><span class="styleblack">&nbsp; Total weight of primary sorting=<? echo $totalprimary; ?> kg.</span></td>
            </tr>
            <tr>
              <td height="5" colspan="2" bgcolor="#ADCE4C"><span class="styleblack">&nbsp; By catch = <? echo number_format($totalbycatch,'2','.',''); ?> kg.</span></td>
            </tr>
            <tr>
              <td height="5" colspan="2" bgcolor="#ADCE4C"> &nbsp;<span class="styleblack"> Total Sampling weight (Secondary sorting)= <? echo number_format($totalsecondary,'2','.',''); ?> kg.</span></td>
            </tr>
            <tr>
              <td height="7" colspan="2" bgcolor="#ADCE4C" class="style1"><label> </label>
                  <div align="left"> <br>
                      <table width="90%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
                        <tr bgcolor="#000000" class="styleblack">
                          <td width="7%" class="stylewhitesmall"><div align="center">No</div></td>
                          <td width="24%" class="stylewhitesmall"><div align="left">Species</div></td>
                          <td width="15%" class="stylewhitesmall"><div align="center">Sampling<br>Weight(kg.)</div></td>
                          <td width="17%" class="stylewhitesmall"><div align="center">Estimate<br>Total catch(kg.)</div></td>
                          <td width="20%" class="stylewhitesmall"><div align="center">Total weight<br>
                          Primary sorting(kg.)</div></td>
                          <td width="17%" class="stylewhitesmall"><div align="center">Species<br>
                          composition</div></td>
                        </tr>
                        <?
               for($j=1;$j<=$numgetcatch;$j++)
				{
    				$resgetcatch = mysql_fetch_array($qrygetcatch);
					$dbspid = $resgetcatch["spid"];
					$dbspname = $resgetcatch["scientific"];
					$dbweight = $resgetcatch["Weight"];
					$dbestimate = $resgetcatch["estotalcatch"];
				?>
                        <tr class="styleblack">
                          <td bgcolor="#006666" class="styleblack"><div align="center"><span class="style37"><? echo $j; ?></span></div></td>
                          <td bgcolor="#006666" class="styleblack"><span class="style37"><? echo $dbspname; ?></span></td>
                          <td align="center" bgcolor="#006666" class="styleblack"><span class="style37"><? echo $dbweight; ?></span></td>
                          <td align="center" bgcolor="#006666" class="styleblack"><? echo $dbestimate; ?></td>
                          <td align="center" bgcolor="#006666" class="styleblack"><span class="stylewhitesmall">
                            <?
						 require_once("fishing_function.inc.php");
                         $totalweight = getprimarytotalspid($decodeid,$dbspid);
						 echo $totalweight;
						 $totalcomposition = $dbestimate+$totalweight;
						 $percent = ($totalcomposition*100)/$dbtotalcatch;
						?>
                          </span></td>
                          <td align="center" bgcolor="#006666" class="styleblack"><span class="stylewhitesmall"><? echo $totalcomposition."(".$percent." %)"; ?></span></td>
                        </tr>
                        <?
			  }
			  ?>
                        <tr class="styleblack">
                          <td colspan="6" bgcolor="#000000" class="stylewhitesmall"><div align="right"><a href="fishoperationsector.php?s=<? echo $_GET["s"]; ?>&y=<? echo $_GET["y"]; ?>&catchoptid=<? echo $_GET["optid"]; ?>&optid=<? echo $_GET["optid"]; ?>">Add Primary Sorting ..</a></div>
                              <div align="center"></div></td>
                        </tr>
                      </table>
                    <br>
                </div></td>
            </tr>
            <tr>
              <td height="3" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Vessel Name&nbsp; </div></td>
              <td height="3" bgcolor="#ADCE4C" class="styleblack"><? echo $dbvessel; ?></td>
            </tr>
            <tr>
              <td height="4" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Departure Date&nbsp; </div></td>
              <td height="4" bgcolor="#ADCE4C" class="styleblack"><? echo $dbddate; ?></td>
            </tr>
            <tr>
              <td width="37%" height="3" valign="top" bgcolor="#ADCE4C" class="styleblack"><div align="right">Species&nbsp; </div></td>
              <td width="63%" height="0" bgcolor="#ADCE4C" class="styleblack"><p id="auto">
                  <input name="searchField" type="text" class="styleblack" id="searchField" />
              </p></td>
            </tr>
            <tr>
              <td height="4" valign="top" bgcolor="#ADCE4C" class="styleblack"><div align="right">Sampling Weight&nbsp; </div></td>
              <td width="63%" height="0" bgcolor="#ADCE4C" class="styleblack"><span class="style36">
                <input name="txtcatchweight2" type="text" class="styleblack" id="txtcatchweight2" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" value="" size="7" maxlength="7" />
              </span></td>
            </tr>
            <tr>
              <td height="7" valign="top" bgcolor="#ADCE4C" class="style1">&nbsp;</td>
              <td width="63%" height="7" bgcolor="#ADCE4C">&nbsp;</td>
            </tr>
            <tr>
              <td height="34" colspan="2" bgcolor="#ADCE4C"><label> </label>
                  <div align="center">
                    <input name="submit3" type="submit" class="styleblack" id="submit3" value="Insert" />
                </div></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <p>&nbsp;</p>
      <?
	  }
	  }
	 
      ?></td>
  </tr>
	<tr>
	  <td colspan="2" bgcolor="#006666"><div align="right"><span class="styleblack">@SEAFDEC 2012</span></div></td>
  </tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>