<?
session_start();
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fish landing data management system</title>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
	window.onload = function(){
		new JsDatePick({
			useMode:2,
			target:"departure",
			dateFormat:"%Y-%m-%d",
			limitToToday:true
			/*selectedDate:{				This is an example of what the full configuration offers.
				day:5,						For full documentation about these settings please see the full version of the code.
				month:9,
				year:2006
			},
			yearsRange:[1978,2020],
			limitToToday:false,
			cellColorScheme:"beige",
			dateFormat:"%m-%d-%Y",
			imgPath:"img/",
			weekStartDay:1*/
		});
		new JsDatePick({
			useMode:2,
			target:"arrival",
			dateFormat:"%Y-%m-%d"
			/*selectedDate:{				This is an example of what the full configuration offers.
				day:5,						For full documentation about these settings please see the full version of the code.
				month:9,
				year:2006
			},
			yearsRange:[1978,2020],
			limitToToday:false,
			cellColorScheme:"beige",
			dateFormat:"%m-%d-%Y",
			imgPath:"img/",
			weekStartDay:1*/
		});
		new JsDatePick({
			useMode:2,
			target:"departure2",
			dateFormat:"%Y-%m-%d",
			limitToToday:true
			/*selectedDate:{				This is an example of what the full configuration offers.
				day:5,						For full documentation about these settings please see the full version of the code.
				month:9,
				year:2006
			},
			yearsRange:[1978,2020],
			limitToToday:false,
			cellColorScheme:"beige",
			dateFormat:"%m-%d-%Y",
			imgPath:"img/",
			weekStartDay:1*/
		});
		new JsDatePick({
			useMode:2,
			target:"arrival2",
			dateFormat:"%Y-%m-%d"
			/*selectedDate:{				This is an example of what the full configuration offers.
				day:5,						For full documentation about these settings please see the full version of the code.
				month:9,
				year:2006
			},
			yearsRange:[1978,2020],
			limitToToday:false,
			cellColorScheme:"beige",
			dateFormat:"%m-%d-%Y",
			imgPath:"img/",
			weekStartDay:1*/
		});
	};
</script>

<script language="JavaScript"> 
function onInsert()
{ 

		if(form1.lstvessel.value == 0)
		{
			alert("select vessel name");
			return false;
		}
		else if(form1.departure.value =="")
		{
			alert("You not fill departure date!");
			form1.departure.focus();
			return false;
		}
		else if(form1.arrival.value =="")
		{
			alert("You not fill arrival date!");
			form1.arrival.focus();
			return false;
		}
		else
		{
			return true; 
		}	 
} 
function onUpdate()
{ 
		
		
		if(form7.lstvessel2.value == 0)
		{
			alert("select vessel name");
			return false;
		}
		else if(form7.departure2.value =="")
		{
			alert("You not fill departure date!");
			form7.departure2.focus();
			return false;
		}
		else if(form7.arrival2.value =="")
		{
			alert("You not fill arrival date!");
			form7.arrival2.focus();
			return false;
		}
		else
		{
			return true; 
		}	 
} 
function onInsert2()
{ 
		if(form2.searchField.value =="")
		{
			alert("You not fill species!");
			form2.searchField.focus();
			return false;
		}
		if(form2.txtcatchweight.value =="")
		{
			alert("You not fill weight!");
			form2.txtcatchweight.focus();
			return false;
		}
		else
		{
			return true; 
		}	 
} 
function onUpdateCatch()
{ 
		if(form4.txtcatchweight3.value =="")
		{
			alert("You not fill weight!");
			form4.txtcatchweight3.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>
<?
	include "connect.inc.php";
?>

<script language="JavaScript">
	function resutName(CusID)
	{
		switch(CusID)
		{
			<?
			//$strSQL = "SELECT * FROM ship ORDER BY ShipName ASC";
			$strSQL = "SELECT ShipId,ShipName,sector,fishinggear";
		$strSQL = $strSQL." from ship inner join gearandmethod on ship.GearType =gearandmethod.fgid inner join shiptype on ship.fishsector = shiptype. Shptid inner join fishingsector on shiptype .sid = fishingsector.sid";
		//echo $strSQL;
			$objQuery = mysql_query($strSQL);
			while($objResult = mysql_fetch_array($objQuery))
			{
			?>
				case "<?=$objResult["ShipName"];?>":
				form1.txtsector.value = "<?=$objResult["sector"];?>";
				form1.txtgear.value = "<?=$objResult["fishinggear"];?>";
				break;
			<?
			}
			?>
			default:
				form1.txtzone.value = "";
				form1.txtsector.value = "";
				form1.txtgear.value = "";
				break;
		}
	}
</script>
<script language="JavaScript">
	function resutName2(CusID)
	{
		switch(CusID)
		{
			<?
			//$strSQL = "SELECT * FROM ship ORDER BY ShipName ASC";
			$strSQL2 = "SELECT ShipId,ShipName,Owner,ShipLength,EngineType,EngineHP,ShipWidth,ShipDepth,GrossTon,TypeofHull,DateBuild,PlaceBuilt,NumberofCrew,OwnerAddress,OwnerContactNumber,email,District,disname,GearType,fishinggear,NetLength,NetWidth,MeshSize,NoHook,PicShip,ship.fishsector,fishingsector.sector,gearlicence,expiredate,ship.zoneid,hooksize,nounit";
		$strSQL2 = $strSQL2." FROM ship left join district on district.disid = ship.District left join gearandmethod on ship.GearType =  gearandmethod.fgid left join shiptype on ship.fishsector = shiptype.shptid inner join fishingsector on shiptype.sid = fishingsector.sid";
		//echo $strSQL;
			$objQuery2 = mysql_query($strSQL2);
			while($objResult2 = mysql_fetch_array($objQuery2))
			{
			?>
				case "<?=$objResult2["ShipName"];?>":
				form7.txtzone2.value = "<?=$objResult2["zoneid"];?>";
				form7.txtsector2.value = "<?=$objResult2["sector"];?>";
				form7.txtgear2.value = "<?=$objResult2["fishinggear"];?>";
				break;
			<?
			}
			?>
			default:
				form7.txtzone2.value = "";
				form7.txtsector2.value = "";
				form7.txtgear2.value = "";
				break;
		}
	}
</script>
<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}
.style38 {
	color: #CC0000;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	font-weight: bold;
}
.stylebodywhite {font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color:#FFFFFF;
	font-weight: bold;
}
-->
</style>
</head>
<body>
<?
if($_POST[submit])
{
	include "usr_function.php"; //for Check null
	require_once("fishing_function.inc.php");
	include "connect.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"];
	$inszone = $_POST["lstzone"];
	$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"]);
	//chk
	$sqlchk = "select * from  fishoperation where VesselId = '$insvessel' and  DepartureDate='$insddate'";
	//echo $sqlchk;
	$qrychk = mysql_query($sqlchk);
	if(mysql_num_rows($qrychk) != 0){ 
	echo "<script>alert('vessel and date is duplicate');history.back();</script>"; 
	exit();
	}
	else
	{ 
	Insertopt($insoptid,$insvessel,$insport,$insddate,$insadate,$insfishingtime,$insbdepth,$insgdepth,$inshual,$insfdulation,$insrecorder,$insfuel,$insice,$insfood,$insrepair,$insmantenance,$insmis,$inszone);
	$tlog = "Add Fishing Operation ".$insoptid;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	}
}
if($_POST[submit2])
{
	include "usr_function.php"; //for Check null
	$insoptid = $_POST["hdoptid2"];
	$inssortno = 1;
	require_once("sp_function.inc.php");
	$insspid = getspeciesid($_POST[searchField]);
	$insweight = $_POST["txtcatchweight"];
	$instray = chknull($_POST["txttray"]);
	$insprice = chknull($_POST["txtprice"]);
	require_once("fishing_function.inc.php");
	InsertCatch($insoptid,$inssortno,$insspid,$insweight,$instray,$insprice);
	$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"];
	$instray = chknull($_POST["txttray2"]);
	$insprice = chknull($_POST["txtprice2"]);
	require_once("fishing_function.inc.php");
	InsertCatch($insoptid,$inssortno,$insspid,$insweight,$instray,$insprice);
	$tlog = "Add Secondary Sorting ".$optid." ".$_POST[searchField];
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
if($_POST["submit5"])
{
	$delspoptid = $_POST["hddelopt"];
	$delspspid = $_POST["hddelsp"];
	require_once("fishing_function.inc.php");
	DeleteCatch($delspoptid,1,$delspspid);
	
}
if($_POST["submit4"])
{
	include "usr_function.php"; //for Check null
	$edtspoptid = base64_decode($_GET["catchoptid"]);
	$edtspspid = $_POST["hdedtsp"];
	$edtnewweight = $_POST["txtcatchweight3"];
	$edttray = chknull($_POST["txttray2"]);
	$edtprice = chknull($_POST["txtprice2"]);
	$edtupcatch = $_POST["tdupcatch"];
	require_once("fishing_function.inc.php");
	EditCatch($edtspoptid,1,$edtspspid,$edtnewweight,$edttray,$edtprice,$edtupcatch);
}
if($_POST["submit6"])
{
$deloptid = $_POST["hddelid"];
require_once("fishing_function.inc.php");
DeleteOpt($deloptid);
}
if($_POST["submit7"])
{
		
	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)
	$edtoptid = $_POST["hdoptid2"];
	$edtvessel = $_POST["lstvessel2"];
	$edtport = $_POST["lstport2"];
	$edtddate = $_POST["departure"];
	$edtadate = $_POST["arrival"];
	$edtfishingtime = $_POST["lstfishingtime2"];
	$edtbdepth = chknull($_POST["txtbottomdepth2"]);
	$edtgdepth = chknull($_POST["txtfishingdepth2"]);
	$edthual = chknull($_POST["txthual2"]);
	$edtfdulation = chknull($_POST["txtfdulation2"]);
	$edtrecorder = $_POST["txtrecord2"];
	$edtzone = $_POST["lstzone2"];
	//Expence
	
	$edtfuel = chknull($_POST["txtfuel2"]);
	$edtice = chknull($_POST["txtice2"]);
	$edtfood = chknull($_POST["txtfood2"]);
	$edtrepair = chknull($_POST["txtrepair2"]);
	$edtmantenance = chknull($_POST["txtmaintenance2"]);
	$edtmis = chknull($_POST["txtmis2"]);
	
	//chk
	$sqlchk = "select * from  fishoperation where VesselId = '$edtvessel' and  DepartureDate='$edtddate' and Optid != $edtoptid ";
	//echo $sqlchk;
	$qrychk = mysql_query($sqlchk);
	if(mysql_num_rows($qrychk) != 0){ 
	echo "<script>alert('vessel and date is duplicate');history.back();</script>"; 
	exit();
	}
	else
	{ 
	//EditOpt($optid,$vessel,$port,$ddate,$adate,$fishingtime,$bdepth,$gdepth,$hual,$fdulation,$recorder,$fuel,$ice,$food,$repair,$maintemance,$miscel)
	EditOpt($edtoptid,$edtvessel,$edtport,$edtddate,$edtadate,$edtfishingtime,$edtbdepth,$edtgdepth,$edthual,$edtfdulation,$edtrecorder,$edtfuel,$edtice,$edtfood,$edtrepair,$edtmantenance,$edtmis,$edtzone);
	$tlog = "Add Fishing Operation ".$insoptid;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	}
}
?>
<table width="1024" height="799" align="center" bordercolor="#FFFFFF">
  <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> | <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 width="428" height="705" valign="top" bgcolor="#CCCCCC"><br />
    <?
	 if(isset($_GET["catchoptid"]))
	{
		include "connect.inc.php";
		$decodeid = base64_decode($_GET["catchoptid"]);
		$dd = $_GET['d'];
	  
	  ?>
	  <form action="catchdata.php?catchoptid=<? echo $_GET["catchoptid"]; ?>" method="post" enctype="multipart/form-data" name="form7" id="form7" onsubmit="return onUpdate();">
          <table width="95%" height="155" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="19" colspan="2" bgcolor="#000000"><div align="center"><span class="stylewhite">Fishing Operation</span></div>
              <div align="right"></div></td>
            </tr>
            <tr>
              <td height="14" colspan="2" bgcolor="#990000" class="style1"><label> </label>
                  <div align="left"><span class="styleblack">
                  <?
				  $sqlgetoperation = "select VesselId,LandingPort,DepartureDate,ArrivalDate,Duration,FishingTime,BottomDepth,FishingGearDepth,HualPerTrip,TotalCatch,Recorder,fishinggear,portname,province,fishoperation.zoneid,fishsector,fishingdulation,sector from  fishoperation inner join ship on fishoperation.VesselId = ship.ShipName inner join gearandmethod on ship.GearType =  gearandmethod.fgid  inner join fishingport on fishingport.portid = fishoperation.LandingPort left join district on  fishingport.province = district.disid inner join shiptype on ship.fishsector = shiptype.Shptid inner join fishingsector on shiptype.sid = fishingsector.sid 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["sector"];
	  $dbfishdulation = $numgetoperation["fishingdulation"];
				  ?>
                  <input type="hidden" name="hdoptid2" id="hdoptid2" value="<? echo  $decodeid; ?>">
                </span></div></td>
            </tr>
            <tr>
              <td width="37%" height="12" valign="top" bgcolor="#990000" class="stylewhitesmall"><div align="right" class="stylewhitesmall"><span class="stylewhitesmall">Vessel Name</span>&nbsp; </div></td>
        <td width="63%" height="12" bgcolor="#990000"><label><span class="styletextbox">
                <select name="lstvessel2" class="styleblack" id="lstvessel2"  onchange="resutName2(this.value);">
                  <?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="#990000" class="stylewhitesmall"><div align="right"><span class="stylewhitesmall">Fishing area</span>&nbsp; </div></td>
              <td bgcolor="#990000">                <span class="styleblack"><span class="styletextbox">
              <select name="lstzone2" class="styleblack" id="select6">
                  <?php
				  echo "<option value='$dbfishingzone'>$dbfishingzone</option>";
		 include "connect.inc.php";
	  $sqlgetzone = "select zone,description from fishingzone where zone != '$dbfishingzone' order by zone";
	  $qrygetzone = mysql_query($sqlgetzone);
	  $numgetzone = mysql_num_rows($qrygetzone);
	   for($i=1;$i<=$numgetzone;$i++)
		{
			$resgetzone = mysql_fetch_array($qrygetzone);
			$dbzone = $resgetzone["zone"];
				echo "<option value='$dbzone'>$dbzone</option>";
			  }
			  ?>
                </select>
              </span></span></td>
            </tr>
            <tr>
              <td height="3" valign="top" bgcolor="#990000" class="stylewhitesmall"><div align="right">Fishing Gear&nbsp; </div></td>
              <td bgcolor="#990000"><input name="txtgear2" type="text" disabled="disabled" class="styleblack" id="txtgear2" value="<? echo $dbgearname; ?>"/></td>
            </tr>
            <tr>
              <td height="4" valign="top" bgcolor="#990000" class="stylewhitesmall"><div align="right">Fishing Sector</div></td>
              <td bgcolor="#990000"><input name="txtsector2" type="text" class="styleblack" id="txtsector2" disabled="disabled" value="<? echo $dbfishsector; ?>"/></td>
            </tr>
            <tr>
              <td height="3" valign="top" bgcolor="#990000" class="stylewhitesmall"><div align="right">Landing port&nbsp; </div></td>
            <td height="0" bgcolor="#990000"><span class="styletextbox">
          <select name="lstport2" 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="#990000" class="stylewhitesmall"><div align="right">Departure date&nbsp; </div></td>
              <td height="1" bgcolor="#990000">
              <input name="departure" type="text" class="styleblack" id="departure" size="12" value="<? echo $dbdeparturedate; ?>" /></td>
            </tr>
            <tr>
              <td height="7" valign="top" bgcolor="#990000" class="stylewhitesmall"><div align="right">Arrival date&nbsp; </div></td>
              <td height="1" bgcolor="#990000">
                <span class="styleblack">
                <input name="arrival" type="text" class="styleblack" id="arrival" size="12" value="<? echo $dbarrivaldate; ?>" />
              </span></td>
            </tr>
            <tr>
              <td height="1" valign="top" bgcolor="#990000" class="stylewhitesmall"><div align="right">Dulation (Days)&nbsp; </div></td>
            <td height="0" bgcolor="#990000"><span class="styleblack">
              <input name="txtdulation2" type="text" class="styleblack" id="txtdulation2" disabled="disabled" value="<? echo $dbduration; ?>"/>
              <?  ?></span></td>
            </tr>
            <tr>
              <td height="2" valign="top" bgcolor="#990000" class="stylewhitesmall"><div align="right">Fishing time&nbsp; </div></td>
              <td height="2" bgcolor="#990000"><select name="lstfishingtime2" class="styleblack" id="lstfishingtime2">
                <?
			  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="#990000" class="stylewhitesmall"><div align="right">Bottom depth&nbsp; </div></td>
              <td height="0" bgcolor="#990000"><input name="txtbottomdepth2" 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="#990000" class="stylewhitesmall"><div align="right">Fishing gear depth&nbsp; </div></td>
              <td height="0" bgcolor="#990000"><input name="txtfishingdepth2" 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="#990000" class="stylewhitesmall"><p align="right">No. of haul per trip&nbsp; </p></td>
              <td height="0" bgcolor="#990000"><input name="txthual2" type="text" class="styleblack" id="txthual2" 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="#990000" class="stylewhitesmall">&nbsp;
                Fishing Duration(hours)&nbsp; </td>
              <td height="1" bgcolor="#990000"><input name="txtfdulation2" 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="#990000" class="stylewhitesmall"><div align="right">Recorder&nbsp; </div></td>
              <td height="0" bgcolor="#990000"><input name="txtrecord2" type="text" class="styleblack" id="txtrecord2" size="30" maxlength="30" value="<? echo $dbrecorder; ?>"></td>
            </tr>
            <tr>
              <td height="7" valign="top" bgcolor="#990000" class="style1">&nbsp;</td>
              <td height="7" bgcolor="#990000">&nbsp;</td>
            </tr>
            <tr>
              <td height="34" colspan="2" bgcolor="#990000"><label> </label>
                  <div align="center">
                    <input name="submit7" type="submit" class="styleblack" id="submit7" value="Update" />
                    <input name="Button" type="button" class="styleblack" id="button" value="Cancel" onClick="window.location='catchdata.php';" />
              </div></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#000000"><div align="right"></div></td>
            </tr>
          </table><br />
        <span class="stylebodywhite">
        </span>
    <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">Catch Data For '<? echo $dbvessel; ?>'</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">Arrival 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";
	  $sqlgetyear2 = "select Optid,VesselId,ArrivalDate from fishoperation where VesselId =  '$dbvessel' order by ArrivalDate ";
	 // echo  $sqlgetyear2;
	  $qrygetyear2 = mysql_query($sqlgetyear2);
	  $numgetyear2 = mysql_num_rows($qrygetyear2);
	   for($j=1;$j<=$numgetyear2;$j++)
		{
			$resgetyear2 = mysql_fetch_array($qrygetyear2);
			$dboptid2 = $resgetyear2["Optid"];
			$dbddate2= $resgetyear2["ArrivalDate"];
			$dbvessel2= $resgetyear2["VesselId"];
			$encodeoptid2 = base64_encode($dboptid2);
			$encodevessel = base64_encode($dbvessel2);
			if($dbarrivaldate == $dbddate2)
			{
				$colcolors = "#990000";
			}
			else
			{
				$colcolors = "#006666";
			}
			
			?>
              </span>
                <tr>
                  <td align="center" bgcolor="<? echo $colcolors; ?>" class="stylewhitesmall"><? echo $dbvessel2; ?></td>
                  <td align="center" bgcolor="<? echo $colcolors; ?>" class="stylewhitesmall"><? echo $dbddate2; ?></td>
                  <td align="center" bgcolor="<? echo $colcolors; ?>" class="styleblack"><a href="catchdata.php?catchoptid=<? echo $encodeoptid2; ?>&d=<? echo $dbddate2; ?>"><img src="images/document_edit.png" width="20" height="20" border="0" /></a></td>
                  <td align="center" bgcolor="<? echo $colcolors; ?>" class="styleblack"><a href="catchdata.php?deloptid=<? echo $encodeoptid2; ?>&v=<? echo $dbvessel2; ?>&d=<? echo $dbddate2; ?>"><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"><a href="catchdata.php"></a><a href="catchdata.php?vid=<? echo $encodevessel; ?> "><img src="images/add.png" width="24" height="24" border="0" /></a></div></td>
            </tr>
        </table>
        <p>&nbsp;</p>
	  </form>
      <?
	}
	else
	{
	?>
    <table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
<tr>
            <td colspan="3" bgcolor="#000000"><div align="center"><span class="stylewhite">
                
              Catch Data</span></div></td>
        </tr>
          <tr class="stylewhitesmall">
            <td width="56%" bgcolor="#000000" class="stylewhitesmall"><div align="center">Vessel Name</div></td>
            <td width="24%" bgcolor="#000000"><div align="center">No. of operation</div></td>
            <td width="20%" bgcolor="#000000"><div align="center">Edit</div></td>
          </tr>
         
        <div align="center"> <span class="stylegreen">
            <?
	  include "connect.inc.php";
	  $sqlgetyear = "select VesselId,min(ArrivalDate) as mindate,count(Optid) AS countopt from fishoperation group by VesselId order by ArrivalDate";
	  //echo  $sqlgetyear;
	  $qrygetyear = mysql_query($sqlgetyear);
	  $numgetyear = mysql_num_rows($qrygetyear);
	   for($i=1;$i<=$numgetyear;$i++)
		{
			$resgetyear = mysql_fetch_array($qrygetyear);
			
			$dbcountoptid = $resgetyear["countopt"];
			$dbddate= $resgetyear["mindate"];
			$dbvessel = $resgetyear["VesselId"];
			$sqlgetopt = "select Optid from fishoperation where VesselId='$dbvessel' and ArrivalDate='$dbddate'";
			$qrygetopt = mysql_query($sqlgetopt);
			$resgetopt = mysql_fetch_array($qrygetopt);
			$dboptid = $resgetopt["Optid"];
			$encodeoptid = base64_encode($dboptid);
			
			?>
            </span>
              <tr>
            <td align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $dbvessel; ?></td>
            <td align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $dbcountoptid; ?></td>
            <td align="center" bgcolor="#006666" class="styleblack"><a href="catchdata.php?catchoptid=<? echo $encodeoptid; ?>"><img src="images/monthForward_down.gif" width="20" height="20" border="0" /></a></td>
          </tr>
              <span class="stylegreen">
              <?
        }
      ?>
            </span></div>
          <tr>
            <td colspan="3" bgcolor="#000000"><div align="right"><a href="catchdata.php"></a><a href="catchdata.php"><img src="images/add.png" width="24" height="24" border="0" /></a>&nbsp; </div></td>
        </tr>
      </table>
      <?
		}
		?>
      <p align="center">&nbsp; </p>
      <p align="center">&nbsp;</p></td>
  <td width="584" valign="top" bgcolor="#CCCCCC"><?
		include "connect.inc.php";
			  	$sqlgetid = "select max(Optid) as gmax from fishoperation";
				//echo $sqlgetid;
				$qrygetid = mysql_query($sqlgetid);
				$numgetresult = mysql_num_rows($qrygetid);
				if($numgetresult == 0)
				{
				$gid = 1;
				}
				else
				{ 
				$resultgetid = mysql_fetch_array($qrygetid);
				$maxId = $resultgetid["gmax"];
				$gid = $maxId+1;
				}
				//echo "Operation no ".$gid;
			  
	  if(!isset($_GET["catchoptid"]) && !isset($_GET["secondcatchoptid"]) && !isset($_GET["deloptid"]))
	  {
	  $encodegid = base64_encode($gid);
	  					
	  ?>
<form action="catchdata.php?catchoptid=<? echo $encodegid; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return onInsert();"><br />
          <table width="80%" height="127" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="19" colspan="2" background="images/index_01.gif"><div align="center" class="stylewhite">New Fishing Operation</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="styleblack">
                    <input type="hidden" name="hdoptid" id="hdgid2" value="<? echo $gid; ?>" />
                </span></div></td>
            </tr>
            <tr>
              <td width="41%" height="6" valign="middle" bgcolor="#ADCE4C" class="style1"><div align="left"><span class="stylegreen">&nbsp; Vessel Name </span>&nbsp; </div></td>
              <td height="6" bgcolor="#ADCE4C"><span class="styletextbox">
                <select name="lstvessel" class="styleblack" id="select4" onchange="resutName(this.value);">
                <?
				if(isset($_GET["vid"]))
				{
					$encodevid = base64_decode($_GET["vid"]);
					$strgetship = "SELECT ShipId,ShipName,sector,fishinggear";
					$strgetship = $strgetship." FROM ship inner join gearandmethod on ship.GearType =  gearandmethod.fgid left join shiptype on ship.fishsector = shiptype.shptid inner join fishingsector on shiptype.sid = fishingsector.sid where ShipName='$encodevid'";
					//echo $strgetship;
					$qrygetship = mysql_query($strgetship);
					$numgetship = mysql_num_rows($qrygetship);
					$resgetship = mysql_fetch_array($qrygetship);
					
					$sector = $resgetship["sector"];
					$gear = $resgetship["fishinggear"];
					
				?>
                
                  <option value="<? echo $encodevid; ?>"><? echo $encodevid; ?></option>
                <?	
				}
				else
				{
				?>
                <option value="0"><< Select Vessel >></option>
                <?
            
                  }
		include "connect.inc.php";
	  $sqlgetship = "SELECT ShipId,ShipName  FROM ship 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);
			$dbshipname = $resgetship["ShipName"];
			?>
                  <option value="<?=$dbshipname;?>">
                    <?=$dbshipname;?>
                  </option>
                  <?
              }
			  ?>
                </select>
              </span></td>
            </tr>
            <tr>
              <td height="2" valign="middle" bgcolor="#ADCE4C" class="stylegreen">&nbsp; Fishing area </td>
            <td height="2" bgcolor="#ADCE4C"><span class="styletextbox">
              <select name="lstzone" class="styleblack" id="lstzone">
                <?php
		 include "connect.inc.php";
	  $sqlgetzone = "select zone,description from fishingzone order by zone";
	  
	  $qrygetzone = mysql_query($sqlgetzone);
	  $numgetzone = mysql_num_rows($qrygetzone);
	   for($i=1;$i<=$numgetzone;$i++)
		{
			$resgetzone = mysql_fetch_array($qrygetzone);
			$dbzone = $resgetzone["zone"];
			$dbdesc = $resgetzone["description"];
				echo "<option value='$dbzone'>$dbzone</option>";
			  }
			  ?>
              </select>
            </span></td>
            </tr>
            <tr>
              <td height="2" valign="middle" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Landing site&nbsp; </div></td>
              <td height="2" bgcolor="#ADCE4C"><span class="styletextbox">
                <select name="lstport" class="styleblack" id="select7">
                  <?php
		 include "connect.inc.php";
	  $sqlgetport = "select portid,portname,province,disname from fishingport left join district on district.disid = fishingport.province 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["disname"];
			echo "<option value='$dbportid'>$dbportname</option>";
			  }
			  ?>
                </select>
              </span></td>
            </tr>
            <tr>
              <td height="7" valign="middle" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Departure date&nbsp; </div></td>
              <td height="7" bgcolor="#ADCE4C"><input name="departure" type="text" class="styleblack" id="departure" size="12" /></td>
            </tr>
            <tr>
              <td height="3" valign="middle" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Arrival date&nbsp; </div></td>
              <td height="3" bgcolor="#ADCE4C"><span class="styleblack">
                <input name="arrival" type="text" class="styleblack" id="arrival" size="12" />
              </span></td>
            </tr>
            <tr>
              <td height="7" valign="middle" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Fishing time&nbsp; </div></td>
              <td height="7" bgcolor="#ADCE4C"><select name="lstfishingtime" class="styleblack" id="lstfishingtime">
                  <option value="Day">Day</option>
                  <option value="Night">Night</option>
                  <option value="Day and Night">Day and Night</option>
              </select></td>
            </tr>
            <tr>
              <td height="3" valign="middle" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Bottom depth(meter)&nbsp; </div></td>
              <td height="3" 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" /></td>
            </tr>
            <tr>
              <td height="2" valign="middle" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Fishing gear depth(meter)&nbsp; </div></td>
              <td height="2" 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" /></td>
            </tr>
            <tr>
              <td height="1" valign="middle" bgcolor="#ADCE4C" class="stylegreen">&nbsp; No. of haul per trip</td>
              <td height="1" 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" /></td>
            </tr>
            <tr>
              <td height="1" valign="middle" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Fishing Duration(hours)</div></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" /></td>
            </tr>
            <tr>
              <td height="3" valign="middle" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Recorder&nbsp; </div></td>
              <td height="3" bgcolor="#ADCE4C"><input name="txtrecord" type="text" class="styleblack" id="txtrecord" size="30" maxlength="30" /></td>
            </tr>
            <tr>
              <td height="4" valign="middle" bgcolor="#ADCE4C" class="stylegreen">&nbsp;</td>
              <td height="4" bgcolor="#ADCE4C">&nbsp; </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="Insert" />
                    <input name="Reset" type="reset" class="styleblack" id="Reset" value="Cancel" />
                  </div>
              </div></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
      </form>
   
        <?
      }
	  
	  if(isset($_GET["deloptid"]))
	{
	$encodedelid = base64_decode($_GET["deloptid"]);
	?>
     <br>
	  <form action="catchdata.php" method="post" name="form6" id="form6">
        <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 Fishing Operation Data</span></div>
                <div align="right"></div></td>
          </tr>
          <tr>
            <td height="25" bgcolor="#990000" class="style1"><label>
                <br>
              <div align="center" class="stylewhite"><span class="styleblack">
                <input type="hidden" name="hddelid" id="hddelid" value="<? echo $encodedelid; ?>">
            </span>&nbsp; Are you sure to delete catch data <br /> 
            from '<? echo $_GET["v"]; ?>' and Date '<? echo $_GET["d"]; ?>'</div></td>
          </tr>
          <tr>
            <td height="34" bgcolor="#990000"><label>
              <div align="center">
                  <input name="submit6" type="submit" class="styleblack" id="submit6" value="Confirm" />
                  <input name="button" type="button" class="styleblack" id="button2" value="Cancel" onclick="window.location='catchdata.php';" />
              </div>
              </label></td>
          </tr>
          <tr>
            <td height="19" bgcolor="#6B716F"><div align="right"></div></td>
          </tr>
        </table>
      </form>
  <?
	}
	  
	  
	  
	  
	  
	  
	  
	 if(isset($_GET["catchoptid"]))
	  {
       if(isset($_GET["editcatch"]))
	   {
	   ?>
        <form action="catchdata.php?catchoptid=<? echo $_GET["catchoptid"]; ?>" method="post" enctype="multipart/form-data" name="form4" id="form4" onsubmit="return onUpdateCatch();">
          <?
	  $decodeid = base64_decode($_GET["catchoptid"]);
	  $decodespid = base64_decode($_GET["editcatch"]);
	  $sqlgetoperation = "select VesselId,ArrivalDate,Duration,TotalCatch from  fishoperation where Optid = '$decodeid'";
	  $qrygetoperation = mysql_query($sqlgetoperation);
	  $numgetoperation = mysql_fetch_array($qrygetoperation);
	  $dbvessel =  $numgetoperation["VesselId"];
	  $dbddate = $numgetoperation["ArrivalDate"];
	  $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"];
	  require_once("fishing_function.inc.php");
	  $totalbycatch = $dbtotalcatch-$totalprimary;
	  updatetotalcatch($decodeid, $totalprimary,$totalbycatch);
	  ?>
          <br />
          <table width="90%" height="74" 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,Tray,Price from catch inner join fishspecies on catch.spid = fishspecies.spid where Optid='$decodeid' and SortNo = 1 and catch.spid != $decodespid";
	  //echo $sqlgetcatch;
	  $qrygetcatch = mysql_query($sqlgetcatch);
	  $numgetcatch = mysql_num_rows($qrygetcatch);
	  $ttw = 0;
	  
		  ?>
            <tr>
              <td height="7" colspan="2" bgcolor="#ADCE4C" class="style1"><label> </label>
                  <div align="left"> <br />
                      <table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
                        <tr bgcolor="#000000" class="styleblack">
                          <td width="7%" class="stylewhitesmall"><div align="center">No</div></td>
                          <td width="49%" class="stylewhitesmall"><div align="left">Species</div></td>
                          <td class="stylewhitesmall"><div align="center">Weight(kg.)</div></td>
                        </tr>
                        <?
               for($j=1;$j<=$numgetcatch;$j++)
				{
    				$resgetcatch = mysql_fetch_array($qrygetcatch);
					$dbspid = $resgetcatch["spid"];
					$dbspname = $resgetcatch["scientific"];
					$dbweight = $resgetcatch["Weight"];
					 $ttw =  $ttw+$dbweight;
					$dbtray = $resgetcatch["Tray"];
					$dbprice = $resgetcatch["Price"];
					$encodesp = base64_encode($dbspid);
				?>
                        <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; ?>
                            <input type="hidden" name="hdedtoptid" id="hdedtoptid" value="<? echo $decodeid; ?>" />
                          </span></td>
                          <td align="center" bgcolor="#006666" class="styleblack"><span class="style37"><? echo $dbweight; ?></span></td>
                        </tr>
                        <?
			  }
			  $sqlgetcatch2 = "select scientific,catch.spid,Weight,Tray,Price from catch inner join fishspecies on catch.spid = fishspecies.spid where Optid='$decodeid' and SortNo = 1 and catch.spid = $decodespid";
	  //echo $sqlgetcatch;
	  $qrygetcatch2 = mysql_query($sqlgetcatch2);
	  $resgetcatch2 = mysql_fetch_array($qrygetcatch2);
	  $catchdbsp2 = $resgetcatch2["scientific"];
	  $catchdbweight2 = $resgetcatch2["Weight"];
	  $catchdbtray2 = $resgetcatch2["Tray"];
	  $catchdbprice2 = $resgetcatch2["Price"];
			  ?>
                        <tr class="styleblack">
                          <td colspan="3" bgcolor="#000000" class="stylewhitesmall">&nbsp;Total catch  = <? echo $ttw; ?> <input type="hidden" name="tdupcatch" id="tdupcatch" value="<? echo $ttw; ?>" />
                          kg.</td>
                        </tr>
                      </table>
                    <br />
                </div></td>
            </tr>
            <tr>
              <td width="37%" height="1" valign="top" bgcolor="#ADCE4C" class="styleblack"><div align="right">Species&nbsp; </div></td>
              <td width="63%" height="0" bgcolor="#ADCE4C" class="styleblack"><div id="auto2">
               <? echo $catchdbsp2; ?>
                <span class="style37">
                <input type="hidden" name="hdedtsp" id="hdedtsp" value="<? echo $decodespid; ?>" />
                </span></div></td>
            </tr>
            <tr>
              <td height="4" valign="top" bgcolor="#ADCE4C" class="styleblack"><div align="right">Weight (kg.)&nbsp; </div></td>
              <td width="63%" height="0" bgcolor="#ADCE4C" class="styleblack"><span class="style36">
                <input name="txtcatchweight3" type="text" class="styleblack" id="txtcatchweight3" onkeypress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" value="<? echo $catchdbweight2; ?>" size="7" maxlength="7" />
              </span></td>
            </tr>
            <tr>
              <td height="34" colspan="2" bgcolor="#ADCE4C"><label> </label>
                  <div align="center">
                    <input name="submit4" type="submit" class="styleblack" id="submit4" value="Edit" />
                    <input name="button2" type="button" class="styleblack" id="button3" value="Cancel" onclick="window.location='catchdata.php?catchoptid=<? echo $_GET["catchoptid"]; ?>';" />
                </div></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
      </form>
      <?
	  
	   }
	   elseif(isset($_GET["deletecatch"]))
	   {
	   ?>
       
       <form action="catchdata.php?catchoptid=<? echo $_GET["catchoptid"]; ?>" method="post" enctype="multipart/form-data" name="form4" id="form5" onsubmit="return onInsert2();">
         <?
	  $decodeid = base64_decode($_GET["catchoptid"]);
	  $decodespid = base64_decode($_GET["deletecatch"]);
	  $sqlgetoperation = "select VesselId,DepartureDate,Duration,TotalCatch 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"];
	  require_once("fishing_function.inc.php");
	  $totalbycatch = $dbtotalcatch-$totalprimary;
	  updatetotalcatch($decodeid, $totalprimary,$totalbycatch);
	  ?>
         <br />
         <table width="90%" height="69" border="0" align="center" cellpadding="0" cellspacing="0">
           <tr>
             <td width="100%" height="9" background="images/index_01.gif"><div align="center"><span class="stylewhite">Delete Catch Data</span></div>
                 <div align="right"></div></td>
           </tr>
           <?
		   include "connect.inc.php";
	  $sqlgetcatch3 = "select scientific,catch.spid,Weight,Tray,Price from catch inner join fishspecies on catch.spid = fishspecies.spid where Optid='$decodeid' and SortNo = 1 and catch.spid = $decodespid";
	 // echo $sqlgetcatch3;
	  $qrygetcatch3 = mysql_query($sqlgetcatch3);
	  $numgetcatch3 = mysql_num_rows($qrygetcatch3);
	  
		  ?>
           <tr>
             <td height="7" bgcolor="#ADCE4C" class="style1"><label> </label>
                 <div align="left"> <br />
                     <table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
                       <tr bgcolor="#000000" class="styleblack">
                         <td width="7%" class="stylewhitesmall"><div align="center">No</div></td>
                         <td width="49%" class="stylewhitesmall"><div align="left">Species</div></td>
                         <td class="stylewhitesmall"><div align="center">Weight(kg.)</div></td>
                       </tr>
                       <?
               for($j=1;$j<=$numgetcatch3;$j++)
				{
    				$resgetcatch3 = mysql_fetch_array($qrygetcatch3);
					$dbspid = $resgetcatch3["spid"];
					$dbspname = $resgetcatch3["scientific"];
					$dbweight = $resgetcatch3["Weight"];
					$dbtray = $resgetcatch3["Tray"];
					$dbprice = $resgetcatch3["Price"];
					$encodesp = base64_encode($dbspid);
				?>
                       <tr class="styleblack">
                         <td bgcolor="#990000" class="styleblack"><div align="center"><span class="style37"><? echo $j; ?></span></div></td>
                         <td bgcolor="#990000" class="styleblack"><span class="style37"><? echo $dbspname; ?>
                             <input type="hidden" name="hddelopt" id="hdoptid4" value="<? echo $decodeid; ?>" />
                           <input type="hidden" name="hddelsp" id="hddelsp" value="<? echo $decodespid; ?>" />
                         </span></td>
                         <td align="center" bgcolor="#990000" class="styleblack"><span class="style37"><? echo $dbweight; ?></span></td>
                       </tr>
                       <?
			  }
			  ?>
                       <tr class="styleblack">
                         <td colspan="3" bgcolor="#000000" class="stylewhitesmall">&nbsp;</td>
                       </tr>
                     </table>
                   <br />
               </div></td>
           </tr>


           <tr>
             <td height="34" bgcolor="#ADCE4C"><label> </label>
                 <div align="center">
                   <input name="submit5" type="submit" class="styleblack" id="submit5" value="Delete" />
                   <input name="button3" type="button" class="styleblack" id="button4" value="Cancel" onclick="window.location='catchdata.php?catchoptid=<? echo $_GET["catchoptid"]; ?>';" />
               </div></td>
           </tr>
           <tr>
             <td height="19" bgcolor="#6B716F"><div align="right"></div></td>
           </tr>
         </table>
      </form>
       <?
	   }
	   else
	   {
	   ?>
  <form action="catchdata.php?catchoptid=<? echo $_GET["catchoptid"]; ?>" method="post" enctype="multipart/form-data" name="form2" id="form2" onsubmit="return onInsert2();">
          <?
	  $decodeid = base64_decode($_GET["catchoptid"]);
	  $sqlgetoperation = "select VesselId,DepartureDate,Duration,TotalCatch 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"];
	  require_once("fishing_function.inc.php");
	  $totalbycatch = $dbtotalcatch-$totalprimary;
	  updatetotalcatch($decodeid, $totalprimary,$totalbycatch);
	  ?>
          <br />
          <table width="90%" height="76" 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></div>
              <div align="right"></div></td>
            </tr>
            <?
		   include "connect.inc.php";
	  $sqlgetcatch = "select scientific,catch.spid,Weight,Tray,Price,DepartureDate from catch inner join fishspecies on catch.spid = fishspecies.spid inner join fishoperation on fishoperation.Optid = catch.Optid where catch.Optid='$decodeid' and SortNo = 1";
	  //echo $sqlgetcatch;
	  $qrygetcatch = mysql_query($sqlgetcatch);
	  $numgetcatch = mysql_num_rows($qrygetcatch);
	  
		  ?>
            <tr>
              <td height="2" colspan="2" bgcolor="#ADCE4C">&nbsp;<span class="styleblack">
                <input type="hidden" name="hdoptid2" id="hdoptid2" value="<? echo $decodeid; ?>" />
              </span></td>
            </tr>
            <tr>
              <td height="7" colspan="2" bgcolor="#ADCE4C" class="style1"><label> </label>
                  <div align="left"> <br />
                      <table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
                        <tr bgcolor="#000000" class="styleblack">
                          <td width="7%" class="stylewhitesmall"><div align="center">No</div></td>
                          <td width="49%" class="stylewhitesmall"><div align="left">Species</div></td>
                          <td class="stylewhitesmall"><div align="center">Weight(kg.)</div></td>
                          <td width="7%" class="stylewhitesmall"><div align="center">Edit</div></td>
                          <td width="9%" class="stylewhitesmall"><div align="center">Delete</div></td>
                        </tr>
                        <?
               for($j=1;$j<=$numgetcatch;$j++)
				{
    				$resgetcatch = mysql_fetch_array($qrygetcatch);
					$dbspid = $resgetcatch["spid"];
					$dbspname = $resgetcatch["scientific"];
					$dbweight = $resgetcatch["Weight"];
					$dbtray = $resgetcatch["Tray"];
					$dbprice = $resgetcatch["Price"];
					$dbddate =  $resgetcatch["DepartureDate"];
					$encodesp = base64_encode($dbspid);
				?>
                        <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="catchdata.php?catchoptid=<? echo $_GET['catchoptid']; ?>&editcatch=<? echo $encodesp; ?>&sortno=1&d=<? echo  $dbddate; ?>"><img src="images/document_edit.png" width="20" height="20" border="0" /></a></td>
                          <td align="center" bgcolor="#006666" class="styleblack"><a href="catchdata.php?catchoptid=<? echo $_GET['catchoptid']; ?>&deletecatch=<? echo $encodesp; ?>&sortno=1&d=<? echo  $dbddate; ?>"><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;Total catch  = <? echo $totalprimary; ?>
                            <?
							require_once("fishing_function.inc.php");
							$ttbycatch = 0-$ttprimary;
							updatetotalcatch($optid,$ttprimary,$ttbycatch);
							?>
                          kg.</td>
                        </tr>
                      </table>
                    <br />
                </div></td>
            </tr>
            <tr>
              <td width="37%" height="1" valign="top" bgcolor="#ADCE4C" class="styleblack"><div align="right">Species&nbsp; </div></td>
              <td width="63%" height="0" bgcolor="#ADCE4C" class="styleblack"><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="4" valign="top" bgcolor="#ADCE4C" class="styleblack"><div align="right">Weight (kg.)&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="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>
      <?
	  }
      }
	  if(isset($_GET["secondcatchoptid"]))
	  {
	  ?>
        <form action="catchdata.php?secondcatchoptid=<? echo $_GET["secondcatchoptid"]; ?>" 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;
	  $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">+ Add</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="10" colspan="2" bgcolor="#ADCE4C"><span class="styleblack">&nbsp; By catch = <? echo number_format($totalbycatch,'2','.',''); ?> kg.</span></td>
            </tr>
            <tr>
              <td height="7" colspan="2" bgcolor="#ADCE4C" class="style1"><label> </label>
                  <div align="left"> <br />
                      <table width="85%" 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="17%" class="stylewhitesmall"><div align="center">Sampling<br />
                            Weight(kg.)</div></td>
                          <td width="21%" class="stylewhitesmall"><div align="center">Estimate<br />
                            Total catch (kg.)</div></td>
                          <td width="17%" class="stylewhitesmall"><div align="center">Total weight(kg.)<br />
                            Primary sorting</div></td>
                          <td width="14%" class="stylewhitesmall"><p align="center">Species<br />
                            composition</p></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="stylewhitesmall"><?
						//$estimatetotal =  number_format($dbweight*$rais,2,'.',''); 
						echo $dbestimate;
						?></td>
                          <td align="center" bgcolor="#006666" class="stylewhitesmall"><?
						 require_once("fishing_function.inc.php");
                         $totalweight = getprimarytotalspid($decodeid,$dbspid);
						 echo $totalweight;
						 $totalcomposition = $dbestimate+$totalweight;
						 $percent = ($totalcomposition*100)/$dbtotalcatch;
						?></td>
                          <td align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $totalcomposition."(".$percent." %)"; ?></td>
                        </tr>
                        <?
			  }
			  ?>
                        <tr class="styleblack">
                          <td colspan="6" bgcolor="#000000" class="stylewhitesmall"><div align="right"><a href="fishoperation.php?catchoptid=<? echo $_GET["secondcatchoptid"]; ?>">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(kg.)&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>
    </td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#006666"><div align="right"><span class="styleblack">@SEAFDEC 2012</span></div></td>
  </tr>
</table>
</body>
</html>
