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

function onUpdate() 
{ 
		if(form2.txtdistrict2.value =="")
		{
			alert("You not fill Sampling port!");
			form2.txtdistrict2.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;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (Untitled-1) -->
<table width="1024" height="679" 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="431" height="585" valign="top" bgcolor="#CCCCCC">
	    <?
if($_POST[submit])
{
	$insdid = trim($_POST["hddid"]);
	$insdistrict = trim($_POST["txtdistrict"]);
	require_once("district_function.inc.php");
	InsertDistrict($insdid,$insdistrict);
	$tlog = "Add district ".$insdistrict;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
if($_POST[submit2])
{
	$edtdid = trim($_POST["hddid2"]);
	$edtdistrict = trim($_POST["txtdistrict2"]);
	
	require_once("district_function.inc.php");
	EditDistrict($edtdid,$edtdistrict);
	$tlog = "Edit district ".$edtdistrict;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}
if($_POST[submit3])
{
	$dedid = $_POST["hddid3"];
	require_once("district_function.inc.php");
	DeleteDistrict($dedid);
	$tlog = "Delete District ".$dedid;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
}

?>
	 <br>      
	    <table width="78%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
          <tr>
            <td width="64%" bgcolor="#000000"><div align="center" class="stylewhitesmall">State/Province</div></td>
            <td width="18%" bgcolor="#000000" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Edit</span></div></td>
            <td width="18%" bgcolor="#000000" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Delete</span></div></td>
          </tr>
          <div align="center"> <span class="stylegreen">
            <?
	  include "connect.inc.php";
	  $sqlgetdistrict = "select disid,disname from district order by disname";
	  $qrygetdistrict = mysql_query($sqlgetdistrict);
	  $numgetdistrict = mysql_num_rows($qrygetdistrict);
	   for($i=1;$i<=$numgetdistrict;$i++)
		{
			$resgetdistrict = mysql_fetch_array($qrygetdistrict);
			$dbdistrictid = $resgetdistrict["disid"];
			$dbdistrictname = $resgetdistrict["disname"];
			$encodedistrict = base64_encode($dbdistrictid);
			?>
            </span>
              <tr class="styleblack">
                <td bgcolor="#006666"><span class="stylegreen"><a href="district.php?edtdistrict=<? echo $encodedistrict; ?>">
				<? echo $dbdistrictname; ?>
                </a></span></td>
                <td align="center" bgcolor="#006666"><a href="district.php?edtdistrict=<? echo $encodedistrict; ?>"><img src="images/document_edit.png" width="20" height="20" border="0"></a></td>
                <td align="center" bgcolor="#006666"><a href="district.php?deldistrict=<? echo $encodedistrict; ?>"><img src="images/close.png" width="20" height="20" border="0"></a></td>
              </tr>
              <span class="stylegreen">
                <?
        }
      ?>
            </span></div>
	      <tr>
            <td colspan="3" bgcolor="#000000"><div align="right"><span class="stylewhitesmall"><a href="district.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="587" height="585" valign="top" bgcolor="#CCCCCC"><?
	  if(!isset($_GET["edtdistrict"]) && !isset($_GET["deldistrict"]))
	  {
	  ?>
<form action="district.php" method="post" name="form1" id="form1" onSubmit="return onInsert();"><br>
<table width="80%" height="98" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="19" colspan="2" background="images/index_01.gif"><div align="center" class="stylewhite">Insert State/Province</div>
                  <div align="right"></div></td>
            </tr>
            <tr>
              <td height="14" colspan="2" bgcolor="#ADCE4C" class="style1"><label><span class="styleblack"><? 
			  	$sqlgetid = "select max(disid) as dmax from district";
				$qrygetid = mysql_query($sqlgetid);
				$resultgetid = mysql_fetch_array($qrygetid);
				$maxId = $resultgetid["dmax"];
				$distid = $maxId+1;
			  ?>
                      <input type="hidden" name="hddid" id="hddid" value="<? echo $distid; ?>">
              </span></label></td>
            </tr>

            <tr>
              <td width="29%" height="12" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylewhitesmall">State/Province</span>&nbsp; </div></td>
              <td width="71%" height="12" bgcolor="#ADCE4C"><label>
                <input name="txtdistrict" type="text" class="styleblack" id="txtdistrict" size="30" maxlength="30" />
              </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["edtdistrict"]))
		//if(isset($edtport))
		{
		//echo "set edit";
		$edtdistrictid = base64_decode($_GET["edtdistrict"]);
		$sqlgetdesc = "select disid,disname from district where disid = $edtdistrictid";
		//echo $sqlgetdesc;
		$qrygetdesc = mysql_query($sqlgetdesc);
		$resgetdesc = mysql_fetch_array($qrygetdesc);
		$editdistrict = $resgetdesc["disname"];
		
        ?>
<form action="district.php" method="post" name="form2" id="form2" onSubmit="return onUpdate()"><br>
<table width="80%" height="98" 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 State/Province</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="27%" height="12" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen"><span class="styleblack">
                <input type="hidden" name="hddid2" id="hddid2" value="<? echo $edtdistrictid; ?>">
              </span><span class="stylewhitesmall">State/Province</span></span>&nbsp; </div></td>
              <td width="73%" height="12" bgcolor="#ADCE4C"><label>
                <input name="txtdistrict2" type="text" class="styleblack" id="txtdistrict2" size="30" maxlength="30" value="<? echo $editdistrict; ?>" />
              </label></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='district.php';">
                  </div>
                </label></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <?
		}
		if(isset($_GET["deldistrict"]))
		{
		$deldistrictid = base64_decode($_GET["deldistrict"]);
		$sqlgetdesc2 = "select disid,disname from district where disid ='$deldistrictid'";
		//echo $sqlgetdesc2;
		$qrygetdesc2 = mysql_query($sqlgetdesc2);
		$resgetdesc2 = mysql_fetch_array($qrygetdesc2);
		$editdistrict2 = $resgetdesc2["disname"];
		?>
       <br>
        <form action="district.php" method="post" name="form3" id="form3"><br>
          <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 State/Province</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="hddid3" id="hddid3" value="<? echo $deldistrictid; ?>">
                </span>&nbsp; Are you sure to delete <br>
                 district '<span class="styleblacklargered"><? echo $editdistrict2; ?></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='district.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>
<p><!-- End ImageReady Slices -->
</p>
</body>
</html>