<?
session_start();
ob_start();
?>
<html>
<head>
<script language="JavaScript"> 
function onInsert()
{ 
		if(form1.txtport.value =="")
		{
			alert("You not fill Landing Site!");
			form1.txtport.focus();
			return false;
		}
		else
		{
			return true; 
		}	 
} 

function onUpdate() 
{ 
		if(form2.txtport2.value =="")
		{
			alert("You not fill Sampling port!");
			form2.txtport2.focus();
			return false;
		}
		else
		{
			return true;
		} 
} 
</script> 

<title>Fish landing data management system</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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}
.styleblacklargered {	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	font-weight: bold;
	color:#FF0000;
}
.styletextbox {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color:#000000; }
-->
</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><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>
	    <div align="right"></div></td></tr>
	<tr>
	  <td width="564" height="705" valign="top" bgcolor="#CCCCCC">
	    <?
if($_POST[submit])
{
	$inspid = trim($_POST["hdpid"]);
	$insport = trim($_POST["txtport"]);
	$insprovince = trim($_POST["lstdis"]);
	$insdesc = trim($_POST["txtdesc"]);
	require_once("port_function.inc.php");
	InsertPort($inspid,$insport,$insprovince,$insdesc);
	//InsertVessel($insshipid,$insshipname,$insowner,$insshiplength,$insenginetype,$inshoursepower);
	/*
					if($_FILES["fileField2"]["name"] != "")
						{
						  	if(($_FILES["fileField2"]["type"] == "image/gif")|| ($_FILES["fileField2"]["type"] == "image/pjpeg") && ($_FILES["fileField2"]["size"] < 20000))
							{
						  		//require("usr_function.php");
								ErrMsg("File type: JPG or GIF only");
						  	}
						  	else
						  	{			
								if($_FILES["fileField2"]["type"] == "image/gif")
								{
								$dnow = date("YmdHis");
								$newname = $dnow.".gif";
								}
								elseif($_FILES["fileField2"]["type"] == "image/pjpeg")
								{
								$dnow = date("YmdHis");
								$newname = $dnow.".jpg";
								}
								//echo $newname;
								//$fname = rename($_FILES["file"]["name"],$newname);
								//Create Folder--------------------------
								if (!file_exists("port/"))
								{
									mkdir("port/");
								} 
								//---------------------------------------

								$save_file = "port/".$newname;
								require_once("port_function.inc.php");
								InsertPortPic($inspid,$newname);
								require_once("usr_function.php");
								$tlog = "Add port File ".$newname."(".$insport.")";
								//require_once("usr_function.php");
								addLog($_SESSION['myusername'],$tlog);
						
								if(!copy($_FILES["fileField2"]["tmp_name"],$save_file))
								{
								echo "Upload: " . $_FILES["fileField2"]["name"] . "<br>";
    							echo "Type: " . $_FILES["fileField2"]["type"] . "<br>";
    							echo "Size: " . ($_FILES["fileField2"]["size"] / 1024) . " Kb<br>";
    							echo "Temp file: " . $_FILES["fileField2"]["tmp_name"] . "<br>";
				  				}
							}
						}
						*/
	$tlog = "Add Landing Port ".$insport;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
if($_POST[submit2])
{
	$edtpid = trim($_POST["hdpid2"]);
	$edtport = trim($_POST["txtport2"]);
	$edtprovince = trim($_POST["lstdis2"]);
	$edtdesc = trim($_POST["txtdesc2"]);
	require_once("port_function.inc.php");
	EditPort($edtpid,$edtport,$edtprovince,$edtdesc);
					/*
					
					if($_FILES["fileField"]["name"] != "")
						{
						require_once("port_function.inc.php");
						DeletePortFile($edtpid);
						if(($_FILES["fileField"]["type"] != "image/gif") && ($_FILES["fileField"]["type"] != "image/pjpeg"))
							{
						  		//require("usr_function.php");
								$msg = $_FILES["fileField"]["type"]."File type: JPG or GIF only";
								ErrMsg($msg);
						  	}
						  	else
						  	{			
								if($_FILES["fileField"]["type"] == "image/gif")
								{
								$dnow = date("YmdHis");
								$newname = $dnow.".gif";
								}
								elseif($_FILES["fileField"]["type"] == "image/pjpeg")
								{
								$dnow = date("YmdHis");
								$newname = $dnow.".jpg";
								}
								//echo $newname;
								//$fname = rename($_FILES["file"]["name"],$newname);
								//Create Folder--------------------------
								if (!file_exists("port/"))
								{
									mkdir("port/");
								} 
								//---------------------------------------

								$save_file = "port/".$newname;
								require_once("port_function.inc.php");
								InsertPortPic($edtpid,$newname);
								$tlog = "Edit Landing Port File ".$newname;
								//require_once("usr_function.php");
								require_once("usr_function.php");
								addLog($_SESSION['myusername'],$tlog);
								
								if(!copy($_FILES["fileField"]["tmp_name"],$save_file))
																
								{
								echo "Upload: " . $_FILES["fileField"]["name"] . "<br>";
    							echo "Type: " . $_FILES["fileField"]["type"] . "<br>";
    							echo "Size: " . ($_FILES["fileField"]["size"] / 1024) . " Kb<br>";
    							echo "Temp file: " . $_FILES["fileField"]["tmp_name"] . "<br>";
				  				}
							}
						}
							
		
	
	*/
	
	
	$tlog = "Edit Landing port ".$edtport." Province ".$edtprovince."(".$edtpid.")";
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
if($_POST[submit3])
{
	$delid = $_POST["hdpid3"];
	require_once("port_function.inc.php");
	DeletePort($delid);
	$tlog = "Delete Sampling port ".$delid;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
if($_POST[delimg])
{

	$delportid = trim($_POST["hdpid2"]);
	require_once("port_function.inc.php");
	DeletePortFile($delportid);
	//$encodeship = base64_encode($edtshipname);
	//header("vessel.php?edtship=$encodeship");
}	
?>
	 <br>      
	    <table width="95%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
          <tr>
            <td colspan="5" bgcolor="#000000"><div align="center"><span class="stylewhite">Landing Site</span></div></td>
          </tr>
          <tr>
            <td width="30%" bgcolor="#000000"><div align="center"><span class="stylewhitesmall">Landing Site</span></div></td>
            <td width="19%" bgcolor="#000000" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">State/province</span></div></td>
            <td width="30%" bgcolor="#000000" class="stylewhitesmall"><div align="center">Description</div></td>
            <td width="10%" bgcolor="#000000" class="stylewhitesmall"><div align="center">Edit</div></td>
            <td width="11%" bgcolor="#000000" class="stylewhitesmall"><div align="center">Delete</div></td>
          </tr>
          <div align="center"> <span class="stylegreen">
            <?
	  include "connect.inc.php";
	  $sqlgetport = "select portid,portname,disid,disname,sitedescrip 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"];
			$dbdesc = $resgetport["sitedescrip"];
			$encodeport = base64_encode($dbportid);
			?>
            </span>
              <tr class="stylewhitesmall">
                <td bgcolor="#006666"><div align="center" class="stylewhitesmall">
                <? echo $dbportname;?>
                </div></td>
                <td bgcolor="#006666"><div align="center" class="stylewhitesmall">
                  <div align="center" class="stylewhitesmall"><? echo $dbprovince; ?></div>
                </div></td>
                <td bgcolor="#006666"><div align="center" class="stylewhitesmall"><? echo $dbdesc; ?> </div></td>
                <td bgcolor="#006666"><div align="center"><a href="samplingport.php?edtport=<? echo $encodeport; ?>"><img src="images/document_edit.png" width="20" height="20" border="0"></a></div></td>
                <td bgcolor="#006666"><div align="center"><a href="samplingport.php?delport=<? echo $encodeport; ?>"><img src="images/close.png" width="20" height="20" border="0"></a></div></td>
            </tr>
              <span class="stylegreen">
                <?
        }
      ?>
            </span></div>
	      <tr>
            <td colspan="5" bgcolor="#000000"><div align="right"><span class="stylewhitesmall"><a href="samplingport.php"><img src="images/add.png" width="24" height="24" border="0"></a></span><span class="styleblack">&nbsp;&nbsp;&nbsp; </span></div></td>
          </tr>
        </table>	    
      <p>&nbsp;</p></td>
      <td width="454" height="705" valign="top" bgcolor="#CCCCCC"><?
	  if(!isset($_GET["edtport"]) && !isset($_GET["delport"]))
	  {
	  ?>
        <br>
        <form action="samplingport.php" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return onInsert();">
          <table width="80%" height="107" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="19" colspan="2" background="images/index_01.gif"><div align="center"><span class="stylewhite">Landing Site</span></div>
              <div align="right"></div></td>
            </tr>
            <tr>
              <td height="14" colspan="2" bgcolor="#ADCE4C" class="style1"><label>
                <div align="left"><span class="styleblack"><? 
					include "connect.inc.php";
			  	$sqlgetid = "select max(portid) as pmax from fishingport";
				$qrygetid = mysql_query($sqlgetid);
				$resultgetid = mysql_fetch_array($qrygetid);
				$maxId = $resultgetid["pmax"];
				$pid = $maxId+1;
			  ?>
                      <input type="hidden" name="hdpid" id="hdpid" value="<? echo $pid; ?>">
                  </span></div>
              </label></td>
            </tr>

            <tr>
              <td width="32%" height="12" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Landing Site </span>&nbsp; </div></td>
              <td width="68%" height="12" bgcolor="#ADCE4C"><label>
                <input name="txtport" type="text" class="styleblack" id="txtport" size="30" maxlength="30" />
              </label></td>
            </tr>
            <tr>
              <td height="6" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">State/province </span>&nbsp; </div></td>
              <td height="6" bgcolor="#ADCE4C"><span class="styletextbox">
                <select name="lstdis" class="styleblack" id="lstdis">
                  <?php
				  include "connect.inc.php";
				  echo "<option value=''></option>";
		 $sqlgetdis = "select disid,disname from district order by disname";
	  	$qrygetdis = mysql_query($sqlgetdis);
	  	$numgetdis = mysql_num_rows($qrygetdis);
	   for($i=1;$i<=$numgetdis;$i++)
		{
			$resgetdis = mysql_fetch_array($qrygetdis);
			$dbdisid = $resgetdis["disid"];
			$dbdisname = $resgetdis["disname"];
			echo "<option value='$dbdisid'>$dbdisname</option>";
		}
			  ?>
                </select>
              </span></td>
            </tr>
            <tr>
              <td height="3" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right" class="stylegreen">Description &nbsp; </div></td>
              <td height="3" bgcolor="#ADCE4C"><label>
                <textarea name="txtdesc" cols="25" rows="4" class="styleblack" id="txtdesc"></textarea>
              </label></td>
            </tr>
            <tr>
              <td height="34" colspan="2" bgcolor="#ADCE4C"><label>
                  <div align="center">
                    <input name="submit" type="submit" class="styleblack" id="submit" value="Insert" />
                    <input name="Reset" type="reset" class="styleblack" id="button" value="Cancel">
                  </div>
                </label></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <?
		}
		elseif(isset($_GET["edtport"]))
		//if(isset($edtport))
		{
		//echo "set edit";
		$edtportid = base64_decode($_GET["edtport"]);
		$sqlgetdesc = "select portid,portname,disid,disname,sitedescrip from fishingport left join district on district.disid = fishingport.province where portid = $edtportid";
		//echo $sqlgetdesc;
		$qrygetdesc = mysql_query($sqlgetdesc);
		$resgetdesc = mysql_fetch_array($qrygetdesc);
		$editport = $resgetdesc["portname"];
		$editdisid = $resgetdesc["disid"];
		$editdisname = $resgetdesc["disname"];
		$editdesc = $resgetdesc["sitedescrip"];
		//$editportImage = $resgetdesc["sitepic"];
        ?>
       <br>
        <form action="samplingport.php" method="post" enctype="multipart/form-data" name="form2" id="form2" onSubmit="return onUpdate()">
          <table width="95%" height="107" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="19" colspan="2" background="images/index_01.gif"><div align="center"><span class="stylewhite">Edit Landing Site</span></div>
              <div align="right"></div></td>
            </tr>
            <tr>
              <td height="14" colspan="2" bgcolor="#ADCE4C" class="style1"><label> &nbsp;</label>
                <div align="center">                </div></td>
            </tr>

            <tr>
              <td width="32%" height="12" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen"><span class="styleblack">
                <input type="hidden" name="hdpid2" id="hdpid2" value="<? echo $edtportid; ?>"></span>Sampling Port &nbsp;</span>&nbsp; </div></td>
            <td width="68%" height="12" bgcolor="#ADCE4C"><label>
                <input name="txtport2" type="text" class="styleblack" id="txtport2" size="30" maxlength="30" value="<? echo $editport; ?>" />
              </label></td>
            </tr>
            <tr>
              <td height="6" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">State/province&nbsp; </span></div></td>
              <td height="6" bgcolor="#ADCE4C"><span class="styletextbox">
                <select name="lstdis2" class="styleblack" id="lstdis2">
                  <?php
				  include "connect.inc.php";
				  echo "<option value='$editdisid'>$editdisname</option>";
				    echo "<option value=''></option>";
		 $sqlgetdis = "select disid,disname from district order by disname";
	  	$qrygetdis = mysql_query($sqlgetdis);
	  	$numgetdis = mysql_num_rows($qrygetdis);
	   for($i=1;$i<=$numgetdis;$i++)
		{
			$resgetdis = mysql_fetch_array($qrygetdis);
			$dbdisid = $resgetdis["disid"];
			$dbdisname = $resgetdis["disname"];
			echo "<option value='$dbdisid'>$dbdisname</option>";
		}
			  ?>
                </select>
              </span></td>
            </tr>
            <tr>
              <td height="3" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Description</span>&nbsp; </div></td>
              <td height="3" bgcolor="#ADCE4C"><textarea name="txtdesc2" cols="25" rows="4" class="styleblack" id="txtdesc2"><? echo $editdesc; ?></textarea></td>
            </tr>
            <tr>
              <td height="34" colspan="2" bgcolor="#ADCE4C"><label>
                  <div align="center">
                    <input name="submit2" type="submit" class="styleblack" id="submit2" value="Update" />
                    <input name="button2" type="button" class="styleblack" id="button2" value="Cancel" onClick="window.location='samplingport.php';">
                  </div>
                </label></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <?
		}
		if(isset($_GET["delport"]))
		{
		$delportid = base64_decode($_GET["delport"]);
		$sqlgetdesc2 = "select portid,portname from fishingport where portid = '$delportid'";
		//echo $sqlgetdesc2;
		$qrygetdesc2 = mysql_query($sqlgetdesc2);
		$resgetdesc2 = mysql_fetch_array($qrygetdesc2);
		$editport2 = $resgetdesc2["portname"];
		$editprovince2 = $resgetdesc2["province"];
		
		?>
       <br>
        <form action="samplingport.php" method="post" name="form3" id="form3">
          <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 Landing Site</span></div>
              <div align="right"></div></td>
            </tr>
            <tr>
              <td height="25" bgcolor="#ADCE4C" class="style1"><label>
                  <br>
                <div align="center" class="stylewhite"><span class="styleblack">
                  <input type="hidden" name="hdpid3" id="hdpid3" value="<? echo $delportid; ?>">
                </span>&nbsp; Are you sure to delete <br>
                 Landing Site '<span class="styleblacklargered"><? echo $editport2; ?></span>'?</div></td>
            </tr>
            <tr>
              <td height="34" bgcolor="#ADCE4C"><label>
                  <div align="center">
                    <input name="submit3" type="submit" class="styleblack" id="submit3" value="Confirm" />
                    <input name="button3" type="button" class="styleblack" id="button3" value="Cancel" onClick="window.location='samplingport.php';">
                  </div>
                </label></td>
            </tr>
            <tr>
              <td height="19" 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>