<?
function InsertVessel($shipid,$shipname,$owner,$shiplength,$enginetype,$enginehp,$shipwidth,$shipdepth,$grosston,$typeofhull,$datebuild,$placebuilt,$nationality,$numberofcrew,$owneraddress,$ownercontactnumber,$email,$district,$geartype,$netlength,$netwidth,$meshsize,$nohook,$fishsector,$gearlicence,$expiredate,$hooksize,$nounit)
//function InsertVessel($shipid,$shipname,$owner,$shiplength,$enginetype,$enginehp)
{
	include "connect.inc.php";
	$sqlchk = "select * from ship where ShipName='$shipname'";
	//echo $sqlchk;
	$qrychk = mysql_query($sqlchk);
	$numchk = mysql_num_rows($qrychk);
	if($numchk < 1)
	{
	$sqlinsert = "insert into ship(ShipId,ShipName,Owner,ShipLength,EngineType,EngineHP, ShipWidth,ShipDepth,GrossTon,TypeofHull,DateBuild,PlaceBuilt,Nationality,NumberofCrew,OwnerAddress,OwnerContactNumber,email,District,GearType,NetLength, NetWidth,MeshSize,NoHook,fishsector,gearlicence,expiredate,hooksize,nounit) values('$shipid','$shipname','$owner',$shiplength,'$enginetype',$enginehp,$shipwidth,$shipdepth,$grosston,'$typeofhull','$datebuild','$placebuilt','$nationality',$numberofcrew,'$owneraddress','$ownercontactnumber','$email','$district','$geartype',$netlength,$netwidth,$meshsize,$nohook,$fishsector,'$gearlicence','$expiredate',$hooksize,$nounit)";
	//$sqlinsert = "insert into ship(ShipId,ShipName,Owner,ShipLength,EngineType,EngineHP) values('$shipid','$shipname','$owner',$shiplength,'$enginetype',$enginehp)";
	//echo $sqlinsert;
	
	mysql_query($sqlinsert);
	}
	else
	{
	require_once("usr_function.php");
	ErrMsg("vessel is duplicate!");
	}
}
function InsertVesselPic($shipname,$picpart)
{
	include "connect.inc.php";
	$sqlinspic = "update ship set PicShip = '$picpart' where ShipName = '$shipname'";
	//echo $sqlinspic;
	mysql_query($sqlinspic) or die(mysql_error());
}
function EditVessel($shipid,$shipname,$newshipname,$owner,$shiplength,$enginetype,$enginehp,$shipwidth,$shipdepth,$grosston,$typeofhull,$datebuild,$placebuilt,$nationality,$numberofcrew,$owneraddress,$ownercontactnumber,$email,$district,$geartype,$netlength,$netwidth,$meshsize,$nohook,$fishsector,$gearlicence,$expiredate,$hooksize,$nounit)
{
	include "connect.inc.php";
	$sqlchk = "select * from ship where ShipName='$newshipname' and ShipName != '$shipname'";
	//echo $sqlchk;
	$qrychk = mysql_query($sqlchk);
	$numchk = mysql_num_rows($qrychk);
	if($numchk < 1)
	{
	$sqledit = "update ship set ShipId='$shipid',ShipName='$newshipname',Owner='$owner',ShipLength=$shiplength,EngineType='$enginetype',EngineHP=$enginehp, ShipWidth=$shipwidth,ShipDepth=$shipdepth,GrossTon='$grosston',TypeofHull='$typeofhull',DateBuild='$datebuild',PlaceBuilt='$placebuilt',Nationality='$nationality',NumberofCrew=$numberofcrew,OwnerAddress='$owneraddress',OwnerContactNumber='$ownercontactnumber',email='$email',District='$district',GearType=$geartype,NetLength=$netlength, NetWidth=$netwidth,MeshSize=$meshsize,NoHook=$nohook,fishsector=$fishsector,gearlicence='$gearlicence',expiredate='$expiredate',hooksize=$hooksize,nounit=nounit where ShipName='$shipname'";
	//echo $sqledit;
	mysql_query($sqledit) or die(mysql_error());
	}
	else
	{
	require_once("usr_function.php");
	ErrMsg("vessel is duplicate!");
	}
}
function DeleteVessel($shipname)
{
	include "connect.inc.php";
	$sqldelfile = "select PicShip from ship where ShipName = '$shipname'";
	$qrydelfile = mysql_query($sqldelfile);
	$resdelfile = mysql_fetch_array($qrydelfile);
	$fname = $resdelfile["PicShip"];
	if($fname != "")
	{
		$filepath = "ship/".$fname;
		unlink($filepath);
	}
	$sqldelete = "delete from ship where ShipName='$shipname'";
	//echo $sqldelete;
	mysql_query($sqldelete) or die(mysql_error());
}
function DeleteVesselFile($shipname)
{
	include "connect.inc.php";
	$sqldelfile = "select PicShip from ship where ShipName = '$shipname'";
	$qrydelfile = mysql_query($sqldelfile);
	$resdelfile = mysql_fetch_array($qrydelfile);
	$fname = $resdelfile["PicShip"];
	//echo $fname;
	if($fname != "")
	{
		$filepath = "ship/".$fname;
		unlink($filepath);
	}
	$updatepicpath = "update ship set PicShip='' where ShipName = '$shipname'";
	//echo "Unlink and ".$updatepicpath;
	mysql_query($updatepicpath);
}
function ShowImage($sname)
{
	include "connect.inc.php";
	$sqlGetImage = "select  PicShip  from ship where Shipname = '$sname'";
	$qryGetImage = mysql_query($sqlGetImage);
	$numGetImage = mysql_num_rows($qryGetImage);
	if($numGetImage ==1)
	{
		$resGetImage =  mysql_fetch_array($qryGetImage);
		$pic = $resGetImage["PicShip"];
		return $pic;
	}
}
?>