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

function onUpdate() 
{ 
		if(form2.txtgear2.value =="")
		{
			alert("You not fill fishing gear!");
			form2.txtgear2.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><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="537" height="705" valign="top" bgcolor="#CCCCCC">
	    <?
if($_POST[submit])
{
	//include "usr_function.php";
	$insfgid = trim($_POST["hdgid"]);
	$insgear = trim($_POST["txtgear"]);
	$inslocal = trim($_POST["txtlocal"]);
	$insdesc = trim($_POST["txtdesc"]);
	$insclass = trim($_POST["lstclass"]);
	require_once("fgmethod_function.inc.php");
	//InsertGearAndMethod($fgid,$fg,$lo,$gt,$desc)
	InsertGearAndMethod($insfgid,$insgear,$inslocal,$insclass,$insdesc);
	$tlog = "Add Fishing gear ".$insgear."and class ".$insclass;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
if($_POST[submit2])
{
	//include "usr_function.php";
	$edtfgid = trim($_POST["hdgid2"]);
	$edtgear = trim($_POST["txtgear2"]);
	$edtlocal = trim($_POST["txtlocal2"]);
	$edtdesc = trim($_POST["txtdesc2"]);
	$edtlass = $_POST["lstclass2"];
	require_once("fgmethod_function.inc.php");
	//function EditGearAndMethod($fgid,$fg,$lo,$gt,$desc)
	EditGearAndMethod($edtfgid,$edtgear,$edtlocal,$edtlass,$edtdesc);
	$tlog = "Edit Fishing gear ".$edtgear." and class ".$edtlass;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
if($_POST[submit3])
{
	$delid = $_POST["hdgid3"];
	require_once("fgmethod_function.inc.php");
	DeleteGearAndMethod($delid);
	$tlog = "Delete Fishing gear ".$delid;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}

?>
	 <br>      
	    <table width="90%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
          <tr>
            <td colspan="5" bgcolor="#000000"><div align="center"><span class="stylewhite">Fishing Gear and Method</span></div></td>
          </tr>
          <tr class="stylewhitesmall">
            <td width="26%" bgcolor="#000000"><div align="center">English Name</div></td>
            <td width="23%" bgcolor="#000000"><div align="center">Local Name</div></td>
            <td width="28%" bgcolor="#000000"><div align="center">Fishing Gear Classification</div></td>
            <td width="12%" bgcolor="#000000"><div align="center">Edit</div></td>
            <td width="11%" bgcolor="#000000"><div align="center">Delete</div></td>
          </tr>
          <div align="center"> <span class="stylegreen">
            <?
	  include "connect.inc.php";
	  $sqlgetgear = "select fgid,fishinggear,localname,gearandmethod.gtid,gdesc,fgtype from gearandmethod left join geartype on gearandmethod.gtid = geartype.gtid  order by fgtype,fishinggear";
	 // echo $sqlgetgear;
	  $qrygetgear = mysql_query($sqlgetgear);
	  $numgetgear = mysql_num_rows($qrygetgear);
	   for($i=1;$i<=$numgetgear;$i++)
		{
			$resgetgear = mysql_fetch_array($qrygetgear);
			$dbfgid = $resgetgear["fgid"];
			$dbgear = $resgetgear["fishinggear"];
			$dblocalname = $resgetgear["localname"];
			$dbdesc = $resgetgear["gdesc"];
			$dbgeartype = $resgetgear["fgtype"];
			$encodegear = base64_encode($dbfgid);
			?>
            </span>
              <tr class="styleblack">
                <td bgcolor="#006666" class="stylewhitesmall"><span class="stylewhitesmall"><? echo $dbgear; ?></span></td>
                <td bgcolor="#006666" class="stylewhitesmall"><? echo $dblocalname; ?></td>
                <td align="center" bgcolor="#006666" class="stylewhitesmall"><? echo $dbgeartype; ?></td>
                <td bgcolor="#006666"><div align="center"><a href="fgmethod.php?edtgear=<? echo $encodegear; ?>"><img src="images/document_edit.png" width="20" height="20" border="0"></a></div></td>
                <td bgcolor="#006666"><div align="center"><a href="fgmethod.php?delgear=<? echo $encodegear; ?>"><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="fgmethod.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="481" height="705" valign="top" bgcolor="#CCCCCC"><?
	  if(!isset($_GET["edtgear"]) && !isset($_GET["delgear"]))
	  {
	  ?>
        <br>
        <form action="fgmethod.php" method="post" name="form1" id="form1" onSubmit="return onInsert();">
          <table width="80%" height="204" 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">Add Fishing Gear and Method</span></div>
                  <div align="right"></div></td>
            </tr>
            <tr>
              <td height="38" colspan="2" bgcolor="#ADCE4C" class="style1"><label>
                  <div align="left"><span class="styleblack"><? 
			  	$sqlgetid = "select max(fgid) as gmax from gearandmethod";
				$qrygetid = mysql_query($sqlgetid);
				$resultgetid = mysql_fetch_array($qrygetid);
				$maxId = $resultgetid["gmax"];
				$gid = $maxId+1;
			  ?>
                  <input type="hidden" name="hdgid" id="hdgid" value="<? echo $gid; ?>">
                  </span></div>
              </label></td>
            </tr>

            <tr>
              <td width="38%" height="6" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">English Name</span>&nbsp; </div></td>
              <td width="62%" height="0" bgcolor="#ADCE4C"><label>
                <input name="txtgear" type="text" class="styleblack" id="txtgear" size="30" maxlength="30" />
              </label></td>
            </tr>
            <tr>
              <td height="6" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Local Name&nbsp; </span></div></td>
              <td width="62%" height="0" bgcolor="#ADCE4C"><input name="txtlocal" type="text" class="styleblack" id="txtlocal" size="30" maxlength="30" /></td>
            </tr>
            <tr>
              <td height="3" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Classification&nbsp; </div></td>
              <td width="62%" height="3" bgcolor="#ADCE4C" class="styleblack"><span class="styletextbox">
              <select name="lstclass" class="styleblack" id="lstclass">
              <option value=""></option>
                  <?php
				  include "connect.inc.php";
		 			$sqlgetclass = "SELECT gtid,fgtype FROM geartype";
	  				$qrygetclass = mysql_query($sqlgetclass);
	  				$numgetclass = mysql_num_rows($qrygetclass);
	   				for($i=1;$i<=$numgetclass;$i++)
					{
						$resgetclass = mysql_fetch_array($qrygetclass);
						$dbclassid = $resgetclass["gtid"];
						$dbclassname = $resgetclass["fgtype"];
						echo "<option value='$dbclassid'>$dbclassname</option>";
					}
			  ?>
              </select>
              </span></td>
            </tr>
            <tr>
              <td height="13" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Description</span>&nbsp;&nbsp;  </div></td>
              <td height="13" bgcolor="#ADCE4C"><textarea name="txtdesc" cols="25" rows="4" class="styleblack" id="txtdesc"></textarea></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["edtgear"]))
		{
		$edtgearid = base64_decode($_GET["edtgear"]);
		$sqlgetdesc = "select fgid,fishinggear,localname,gearandmethod.gtid,gdesc,fgtype from gearandmethod left join geartype on gearandmethod.gtid = geartype.gtid where fgid = '$edtgearid'";
		$qrygetdesc = mysql_query($sqlgetdesc);
		$resgetdesc = mysql_fetch_array($qrygetdesc);
		$editgear = $resgetdesc["fishinggear"];
		$editlocal = $resgetdesc["localname"];
		$editdesc = $resgetdesc["gdesc"];
		$editgtid = $resgetdesc["gtid"];
		$editcalss = $resgetdesc["fgtype"];
        ?>
       <br>
        <form action="fgmethod.php" method="post" name="form2" id="form2" onSubmit="return onUpdate()">
          <table width="80%" height="137" 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 Fishing Gear and Method</span></div>
                  <div align="right"></div></td>
            </tr>
            <tr>
              <td height="14" colspan="2" bgcolor="#ADCE4C" class="style1"><label> &nbsp;</label></td>
            </tr>

            <tr>
              <td width="39%" height="12" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen"><span class="styleblack">
                <input type="hidden" name="hdgid2" id="hdgid2" value="<? echo $edtgearid; ?>">
              </span>English Name</span>&nbsp; </div></td>
              <td width="61%" height="12" bgcolor="#ADCE4C">
                <input name="txtgear2" type="text" class="styleblack" id="txtgear2" size="30" maxlength="30" value="<? echo $editgear; ?>" />                </td>
            </tr>
            <tr>
              <td height="6" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Local Name &nbsp; </span></div></td>
              <td height="0" bgcolor="#ADCE4C"><input name="txtlocal2" type="text" class="styleblack" id="txtlocal2" value="<? echo $editlocal; ?>" size="30" maxlength="30" /></td>
            </tr>
            <tr>
              <td height="7" valign="top" bgcolor="#ADCE4C" class="stylegreen"><div align="right">Classification&nbsp; </div></td>
              <td height="0" bgcolor="#ADCE4C"><span class="styletextbox">
                <select name="lstclass2" class="styleblack" id="lstclass2">
               
                  <?php
				  echo "<option value='$editgtid'>$editcalss</option>";
				   echo "<option value=''></option>";
				  include "connect.inc.php";
		 			$sqlgetclass = "SELECT gtid,fgtype FROM geartype";
	  				$qrygetclass = mysql_query($sqlgetclass);
	  				$numgetclass = mysql_num_rows($qrygetclass);
	   				for($j=1;$j<=$numgetclass;$j++)
					{
						$resgetclass = mysql_fetch_array($qrygetclass);
						$dbclassid = $resgetclass["gtid"];
						$dbclassname = $resgetclass["fgtype"];
						echo "<option value='$dbclassid'>$dbclassname</option>";
					}
			  ?>
                </select>
              </span></td>
            </tr>
            <tr>
              <td height="13" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Description</span>&nbsp; </div></td>
              <td height="13" 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='fgmethod.php';">
                  </div>
                </label></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <?
		}
		if(isset($delgear))
		{
		$delgearid = base64_decode($_GET["delgear"]);
		$sqlgetdesc2 = "select fishinggear from gearandmethod where fgid = '$delgearid'";
		//echo $sqlgetdesc2;
		$qrygetdesc2 = mysql_query($sqlgetdesc2);
		$resgetdesc2 = mysql_fetch_array($qrygetdesc2);
		$editgear2 = $resgetdesc2["fishinggear"];
		$editmethod2 = $resgetdesc2["fishmethod"];
		
		
	
		?>
       <br>
        <form action="fgmethod.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 Fishing Gear and Method</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="hdgid3" id="hdgid3" value="<? echo $delgearid; ?>">
                </span>&nbsp; Are you sure to delete <br>fishing gear and method <br> '<span class="styleblacklargered"><? echo  $editgear2; ?></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="button22" type="button" class="styleblack" id="button22" value="Cancel" onClick="window.location='fgmethod.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>