<?
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*/
		});
	};
</script>

<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>
<?
	mysql_connect("localhost","root","bittersweet") or die(mysql_error());
	mysql_select_db("fishlanding");
?>

<script language="JavaScript">
	function resutName(CusID)
	{
		switch(CusID)
		{
			<?
			//$strSQL = "SELECT * FROM ship ORDER BY ShipName ASC";
			$strSQL = "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";
		$strSQL = $strSQL." FROM ship left join district on district.disid = ship.District left join gearandmethod on ship.GearType =  gearandmethod.fgid left join fishingsector on ship.fishsector = fishingsector.sid";
			$objQuery = mysql_query($strSQL);
			while($objResult = mysql_fetch_array($objQuery))
			{
			?>
				case "<?=$objResult["ShipName"];?>":
				form1.txtzone.value = "<?=$objResult["zoneid"];?>";
				form1.txtdistrict.value = "<?=$objResult["District"];?>";
				form1.txtsector.value = "<?=$objResult["sector"];?>";
				form1.txtgear.value = "<?=$objResult["fishinggear"];?>";
				break;
			<?
			}
			?>
			default:
				form1.txtzone.value = "";
				form1.txtdistrict.value = "";
				form1.txtsector.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;
}
-->
</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="fishoperation.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="226" height="705" valign="top" bgcolor="#CCCCCC"><p align="left"><br>
	  </p>        
        <table width="95%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
          <tr>
            <td 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"];
	$inssector = $_POST["lstsector"];
	$insvessel = $_POST["lstvessel"];
	$insfg = $_POST["lstfg"];
	$inszone = $_POST["lstzone"];
	$insdistrict = $_POST["lstdis"];
	$insport = $_POST["lstport"];
	$inssamplingdate = $_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"];
	Insertopt($insoptid,$inssector,$insvessel,$insfg,$inszone,$insdistrict,$insport,$inssamplingdate,$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);
}
?>        
Fishing Operation </span></div></td>
          </tr>
          <tr>
            <td bgcolor="#000000"><span class="stylewhitesmall"><a href="fishoperationsector.php?y=<? echo $dbyear; ?>"><span class="style38">Click 'Year' to see all operation</span></a></span></td>
          </tr>
          <div align="center"> <span class="stylegreen">
            <?
	  include "connect.inc.php";
	  $sqlgetyear = "select distinct year(DepartureDate) as dyear from fishoperation order by dyear";
	  //echo $sqlgetship;
	  $qrygetyear = mysql_query($sqlgetyear);
	  $numgetyear = mysql_num_rows($qrygetyear);
	   for($i=1;$i<=$numgetyear;$i++)
		{
			$resgetyear = mysql_fetch_array($qrygetyear);
			$dbyear= $resgetyear["dyear"];
			?>
            </span>
              <tr class="styleblack">
                <td align="center" bgcolor="#006666" class="stylewhitesmall"><span class="stylewhitesmall">
				<a href="fishoperationsector.php?y=<? echo $dbyear; ?>"><? 
				echo $dbyear;
				require_once("fishing_function.inc.php");
				echo " (".getNumYear($dbyear)." operations) ";
				
				?></a></span><br>
				</td> 
            </tr>
              <span class="stylegreen">
			 
              <?
        }
      ?>
            </span></div>
          <tr>
            <td bgcolor="#000000"><div align="right"><span class="stylewhitesmall"><a href="fishoperation.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="792" 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"]))
	  {
	  $encodegid = base64_encode($gid);
	  					
	  ?>
      
      <form action="fishoperation.php?catchoptid=<? echo $encodegid; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
	  	
        <table width="80%" height="170" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="19" colspan="4" background="images/index_01.gif"><div align="center" class="stylewhite">Add Fishing Operation</div>
                <div align="right"></div></td>
          </tr>
          <tr>
            <td height="14" colspan="4" 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="27%" height="6" valign="top" bgcolor="#ADCE4C" class="style1"><div align="left"><span class="stylegreen">&nbsp; Vessel Name </span>&nbsp; </div></td>
            <td width="23%" height="1" bgcolor="#ADCE4C"><span class="styletextbox">
              <select name="lstvessel" class="styleblack" id="select4" OnChange="resutName(this.value);">
                <?php
		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);
			$dbshipid = $resgetship["ShipId"];
			$dbshipname = $resgetship["ShipName"];
			?>
			<option value="<?=$dbshipname;?>"><?=$dbshipname;?></option>
			  <?
              }
			  ?>
              </select>
            </span></td>
            <td width="16%" bgcolor="#ADCE4C" class="stylegreen">&gt;&gt; Fishing zone</td>
            <td width="34%" bgcolor="#ADCE4C"><input name="txtzone" type="text" class="styleblack" id="txtfishingdepth" disabled="disabled"/></td>
          </tr>
          <tr>
            <td height="3" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Landing site&nbsp; </div></td>
            <td height="0" 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>
            <td height="0" bgcolor="#ADCE4C" class="stylegreen">&gt;&gt; Fishing gear</td>
            <td height="0" bgcolor="#ADCE4C"><input name="txtgear" type="text" class="styleblack" id="txtfishingdepth3" disabled="disabled"/></td>
          </tr>
          <tr>
            <td height="7" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Departure date&nbsp; </div></td>
            <td height="1" bgcolor="#ADCE4C">
              <input name="departure" type="text" class="styleblack" id="departure" size="12" /></td>
            <td height="1" bgcolor="#ADCE4C" class="stylegreen">&gt;&gt; Fishing sector</td>
            <td height="1" bgcolor="#ADCE4C"><input name="txtsector" type="text" class="styleblack" id="txtsector" disabled="disabled"/></td>
          </tr>
          <tr>
            <td height="3" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Arrival date&nbsp; </div></td>
            <td height="1" bgcolor="#ADCE4C">
              <span class="styleblack">
              <input name="arrival" type="text" class="styleblack" id="arrival" size="12" />
              </span></td>
            <td height="1" bgcolor="#ADCE4C" class="stylegreen">&gt;&gt; District</td>
            <td height="1" bgcolor="#ADCE4C"><input name="txtdistrict" type="text" class="styleblack" id="txtfishingdepth2" disabled="disabled"/></td>
          </tr>
          <tr>
            <td height="7" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Fishing time&nbsp; </div></td>
            <td height="3" 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>
            <td height="1" bgcolor="#ADCE4C" class="stylegreen">&nbsp;</td>
            <td height="1" bgcolor="#ADCE4C">&nbsp;</td>
          </tr>
          <tr>
            <td height="3" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Bottom depth(meter)&nbsp; </div></td>
            <td height="0" colspan="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="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Fishing gear depth(meter)&nbsp; </div></td>
            <td height="0" colspan="3" 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="top" bgcolor="#ADCE4C" class="stylegreen"><p align="left">&nbsp; No. of haul per trip&nbsp; </p></td>
            <td height="0" colspan="3" 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="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Fishing Duration(hours)</div></td>
            <td height="0" colspan="3" bgcolor="#ADCE4C"><input name="txtbottomdepth2" 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="7" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Recorder&nbsp; </div></td>
            <td height="0" colspan="3" bgcolor="#ADCE4C"><input name="txtrecord" type="text" class="styleblack" id="txtrecord" size="30" maxlength="30"></td>
          </tr>
          <tr bgcolor="#6B716F">
            <td height="3" colspan="4" valign="top" class="stylewhite"><div align="center">Operational Expences</div></td>
          </tr>
          <tr class="stylegreen">
            <td height="20" valign="top" bgcolor="#ADCE4C" class="stylegreen"><p align="left">&nbsp; Fuel</p>            </td>
            <td height="20" colspan="3" valign="top" bgcolor="#ADCE4C" class="style1">
              <div align="left">
                <input name="txtbottomdepth3" type="text" class="styleblack" id="txtbottomdepth3" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10">
              </div></td>
          </tr>
          <tr class="stylegreen">
            <td height="7" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Ice</div></td>
            <td height="7" colspan="3" valign="top" bgcolor="#ADCE4C" class="style1">
              <div align="left">
                <input name="txtbottomdepth4" type="text" class="styleblack" id="txtbottomdepth4" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10">
              </div></td>
          </tr>
          <tr class="stylegreen">
            <td height="7" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Food</div></td>
            <td height="7" colspan="3" valign="top" bgcolor="#ADCE4C" class="style1">
              <div align="left">
                <input name="txtbottomdepth5" type="text" class="styleblack" id="txtbottomdepth5" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10">
              </div></td>
          </tr>
          <tr class="stylegreen">
            <td height="3" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Repair</div></td>
            <td height="3" colspan="3" valign="top" bgcolor="#ADCE4C" class="style1">
              <div align="left">
                <input name="txtbottomdepth6" type="text" class="styleblack" id="txtbottomdepth6" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10">
              </div></td>
          </tr>
          <tr class="stylegreen">
            <td height="2" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="left">&nbsp; Maintenance</div></td>
            <td height="2" colspan="3" valign="top" bgcolor="#ADCE4C" class="style1"><input name="txtbottomdepth7" type="text" class="styleblack" id="txtbottomdepth7" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10"></td>
          </tr>
          <tr class="stylegreen">
            <td height="2" valign="top" bgcolor="#ADCE4C" class="stylegreen"> <div align="left">&nbsp; Miscellaneous </div></td>
            <td height="2" colspan="3" valign="top" bgcolor="#ADCE4C" class="style1"><input name="txtbottomdepth8" type="text" class="styleblack" id="txtbottomdepth8" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" size="10" maxlength="10"></td>
          </tr>
          <tr class="stylegreen">
            <td height="34" colspan="4" bgcolor="#ADCE4C"><div align="right">
                    <label> </label>
                    <div align="center">
                      <input name="submit" type="submit" class="styleblack" id="submit2" value="Insert" />
                    </div>
            </div></td>
          </tr>
          <tr>
            <td height="19" colspan="4" bgcolor="#6B716F"><div align="right"></div></td>
          </tr>
        </table>
      </form>
      <?
      }
	 if(isset($_GET["catchoptid"]))
	  {
	  ?>
      <form action="fishoperation.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 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"];
	  require_once("fishing_function.inc.php");
	  $totalbycatch = $dbtotalcatch-$totalprimary;
	  updatetotalcatch($decodeid, $totalprimary,$totalbycatch);
	  ?>
        <br><table width="70%" height="108" 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 class="stylewhite">Primary Sorting</span>)</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="5" colspan="2" bgcolor="#ADCE4C">&nbsp;<span class="styleblack">
              <input type="hidden" name="hdoptid2" id="hdoptid2" value="<? echo $decodeid; ?>">
            </span></td>
          </tr>
          <tr>
            <td height="10" 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="90%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
                    <tr bgcolor="#000000" class="styleblack">
                      <td width="18%" class="stylewhitesmall"><div align="center">No</div></td>
                      <td width="51%" class="stylewhitesmall"><div align="left">Species</div></td>
                      <td width="15%" class="stylewhitesmall"><div align="center">Weight(kg.)</div></td>
                      <td width="16%" class="stylewhitesmall"><div align="center">Price/kg.</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">&nbsp;</td>
                    </tr>
                    <?
			  }
			  ?>
              <tr class="styleblack">
                      <td colspan="4" bgcolor="#000000" class="stylewhitesmall"><div align="right"><a href="fishoperation.php?secondcatchoptid=<? echo $_GET["catchoptid"]; ?>">Add Secondary 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="1" 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="2" valign="top" bgcolor="#ADCE4C" class="styleblack"><div align="right">No. of tray </div></td>
            <td width="63%" height="0" bgcolor="#ADCE4C" class="styleblack"><span class="style36">
              <input name="txtcatchweight4" type="text" class="styleblack" id="txtcatchweight4" onKeyPress="if (event.keyCode&lt;46||event.keyCode&gt;57) event.returnValue=false" value="" size="7" maxlength="7" />
            </span></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="7" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right" class="styleblack">Price/kg.</div></td>
            <td width="63%" height="7" bgcolor="#ADCE4C"><span 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="" size="7" maxlength="7" />
            </span></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="fishoperation.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">Fishing Operation </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>
<!-- End ImageReady Slices -->
</body>
</html>