<?
function getSectorName($s)
{

	include "connect.inc.php";
	$sqlgetSector = "select shptid,manpower,sector from shiptype  INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid where shptid=$s";
	//echo $sqlgetSector; 
	$qrygetSector = mysql_query($sqlgetSector);
	$resgetSector = mysql_fetch_array($qrygetSector);
	$retsector =  $resgetSector["sector"];
	return $retsector;
}
function getGearName($g)
{
	include "connect.inc.php";
	$sqlgetgear = "select fgid,fishinggear from gearandmethod where fgid=$g order by fgid";
	//echo $sqlgetgear;
	$qrygetgear = mysql_query($sqlgetgear);
	$resgetgear = mysql_fetch_array($qrygetgear);
	$retgear = $resgetgear["fishinggear"];
	return $retgear;
}

function getCatchData($y,$s,$g,$z,$v,$sp,$m)
{
	include "connect.inc.php";
	$sqlgetsp = "SELECT sum(catch.weight) as sw FROM catch";
	$sqlgetsp = $sqlgetsp." INNER JOIN fishspecies ON catch.spid = fishspecies.spid";
	$sqlgetsp = $sqlgetsp." INNER JOIN fishoperation ON fishoperation.Optid = catch.Optid";
	$sqlgetsp = $sqlgetsp." INNER JOIN ship ON fishoperation.VesselId = ship.ShipName";
	$sqlgetsp = $sqlgetsp." INNER JOIN shiptype ON ship.fishsector = shiptype.shptid";
	$sqlgetsp = $sqlgetsp." INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
	$sqlgetsp = $sqlgetsp." INNER JOIN gearandmethod ON ship.GearType = gearandmethod.fgid";
	$sqlgetsp = $sqlgetsp." WHERE year(DepartureDate) = '$y' and shiptype.shptid = $s and ship.GearType=$g and fishoperation.zoneid='$z' and fishoperation.VesselId ='$v'";
	$sqlgetsp = $sqlgetsp." and catch.spid = $sp and Month(DepartureDate) = '$m'";
	//echo $sqlgetsp;
	$qrygetsp = mysql_query($sqlgetsp);
	$resgetsp = mysql_fetch_array($qrygetsp);
	$retsp = $resgetsp["sw"];
	if($resgetsp["sw"] == NULL)
	{
	return 0;
	}
	else
	{
	return $retsp;
	}
}
function getNoFishingDay($y,$s,$g,$z,$v,$m)
{
	include "connect.inc.php";
	$sqlgetdu = "SELECT sum(Duration) as du FROM fishoperation";
	$sqlgetdu = $sqlgetdu." INNER JOIN ship ON fishoperation.VesselId = ship.ShipName";
	$sqlgetdu = $sqlgetdu." INNER JOIN shiptype ON ship.fishsector = shiptype.shptid";
	$sqlgetdu = $sqlgetdu." INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
	$sqlgetdu = $sqlgetdu." INNER JOIN gearandmethod ON ship.GearType = gearandmethod.fgid";
	$sqlgetdu = $sqlgetdu." WHERE year(DepartureDate) = '$y' and shiptype.shptid = $s and ship.GearType=$g and fishoperation.zoneid='$z' and fishoperation.VesselId ='$v'";
	$sqlgetdu = $sqlgetdu." and Month(DepartureDate) = '$m'";
	//echo $sqlgetdu."<br>";
	$qrygetdu = mysql_query($sqlgetdu);
	$resgetdu = mysql_fetch_array($qrygetdu);
	$retdu = $resgetdu["du"];
	if($resgetdu["du"] == NULL)
	{
	return 0;
	}
	else
	{
	return $retdu;
	}
}
function getCatchDataSp($y,$g,$z,$sp,$m)
{
	include "connect.inc.php";
	$sqlgetsp = "SELECT sum(catch.Weight) as sw FROM catch";
	$sqlgetsp = $sqlgetsp." INNER JOIN fishspecies ON catch.spid = fishspecies.spid";
	$sqlgetsp = $sqlgetsp." INNER JOIN fishoperation ON fishoperation.Optid = catch.Optid";
	$sqlgetsp = $sqlgetsp." INNER JOIN ship ON fishoperation.VesselId = ship.ShipName";
	$sqlgetsp = $sqlgetsp." INNER JOIN shiptype ON ship.fishsector = shiptype.shptid";
	$sqlgetsp = $sqlgetsp." INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
	$sqlgetsp = $sqlgetsp." INNER JOIN gearandmethod ON ship.GearType = gearandmethod.fgid";
	$sqlgetsp = $sqlgetsp." WHERE year(ArrivalDate) = '$y' and ship.GearType=$g and fishoperation.zoneid='$z'";
	$sqlgetsp = $sqlgetsp." and catch.spid = $sp and Month(ArrivalDate) = '$m'";
	//echo $sqlgetsp;
	$qrygetsp = mysql_query($sqlgetsp);
	$resgetsp = mysql_fetch_array($qrygetsp);
	$retsp = $resgetsp["sw"];
	if($resgetsp["sw"] == NULL)
	{
	return 0;
	}
	else
	{
	return $retsp;
	}
}
function getCatchValueData($y,$s,$g,$z,$v,$sp,$m)
{
	include "connect.inc.php";
	$sqlgetsp = "SELECT sum(catch.Weight*catch.Price) as sw FROM catch";
	$sqlgetsp = $sqlgetsp." INNER JOIN fishspecies ON catch.spid = fishspecies.spid";
	$sqlgetsp = $sqlgetsp." INNER JOIN fishoperation ON fishoperation.Optid = catch.Optid";
	$sqlgetsp = $sqlgetsp." INNER JOIN ship ON fishoperation.VesselId = ship.ShipName";
	$sqlgetsp = $sqlgetsp." INNER JOIN shiptype ON ship.fishsector = shiptype.shptid";
	$sqlgetsp = $sqlgetsp." INNER JOIN fishingsector ON shiptype.sid = fishingsector.sid";
	$sqlgetsp = $sqlgetsp." INNER JOIN gearandmethod ON ship.GearType = gearandmethod.fgid";
	$sqlgetsp = $sqlgetsp." WHERE year(ArrivalDate) = '$y' and shiptype.shptid = $s and ship.GearType=$g and fishoperation.zoneid='$z' and fishoperation.VesselId ='$v'";
	$sqlgetsp = $sqlgetsp." and catch.spid = $sp and Month(DepartureDate) = '$m' and catch.Price != 0.00";
	//echo $sqlgetsp;
	$qrygetsp = mysql_query($sqlgetsp);
	$resgetsp = mysql_fetch_array($qrygetsp);
	$retsp = $resgetsp["sw"];
	if($resgetsp["sw"] == NULL)
	{
	return 0;
	}
	else
	{
	return $retsp;
	}
}
?>
