<?
function InsertPort($pid,$portname,$province,$desc)
{
	include "connect.inc.php";
	$sqlchk = "select * from fishingport where portname='$portname' and province='$province'";
	//echo $sqlchk;
	$qrychk = mysql_query($sqlchk);
	$numchk = mysql_num_rows($qrychk);
	if($numchk < 1)
	{
	$sqlinsert = "insert fishingport(portid,portname,province,sitedescrip) values($pid,'$portname','$province','$desc')";
	mysql_query($sqlinsert);
	}
	else
	{
	require_once("usr_function.php");
	ErrMsg("Sampling port is duplicate!");
	}
}
function EditPort($pid,$portname,$province,$desc)
{
	include "connect.inc.php";
	$sqledit = "update fishingport set portname='$portname',province='$province',sitedescrip='$desc' where portid='$pid'";
	//echo $sqledit;
	mysql_query($sqledit) or die(mysql_error());
}
function DeletePort($pid)
{
	include "connect.inc.php";
	$sqldelfile = "select sitepic from fishingport where portid=$pid";
	$qrydelfile = mysql_query($sqldelfile);
	$resdelfile = mysql_fetch_array($qrydelfile);
	$fname = $resdelfile["sitepic"];
	if($fname != "")
	{
		$filepath = "port/".$fname;
		unlink($filepath);
	}
	$sqldelete = "delete from fishingport where portid=$pid";
	//echo $sqldelete;
	mysql_query($sqldelete) or die(mysql_error());
}
function InsertPortPic($portid,$picpart)
{
	include "connect.inc.php";
	$sqlinspic = "update fishingport set sitepic = '$picpart' where portid = '$portid'";
	//echo $sqlinspic;
	mysql_query($sqlinspic) or die(mysql_error());
}
function DeletePortFile($pid)
{
	include "connect.inc.php";
	$sqldelfile = "select sitepic from fishingport where portid=$pid";
	$qrydelfile = mysql_query($sqldelfile);
	$resdelfile = mysql_fetch_array($qrydelfile);
	$fname = $resdelfile["sitepic"];
	//echo $fname;
	if($fname != "")
	{
		$filepath = "port/".$fname;
		unlink($filepath);
	}
	$updatepicpath = "update fishingport set sitepic='' where portid=$pid";
	//echo "Unlink and ".$updatepicpath;
	mysql_query($updatepicpath);
}
?>