<?
session_start();
ob_start();
?>
<html>
<head>
<script type="text/javascript">

function onInsert()
{ 
		if(form1.pwd1.value =="")
		{
			alert("You not fill first password!");
			form1.pwd1.focus();
			return false;
		}
		else if(form1.pwd2.value =="")
		{
			alert("You not fill second password!");
			form1.pwd2.focus();
			return false;
		}
		else if(form1.pwd1.value != form1.pwd2.value)
		{
			alert("Password doesn't match!");
			form1.pwd2.value = "";
			form1.pwd2.focus();
			return false;
		}
		else
		{
			return true; 
		}	 
}
function onInsertUser()
{ 
		if(form2.txtuname.value =="")
		{
			alert("You not fill user name!");
			form2.txtuname.focus();
			return false;
		}
		else if(form2.txtpwd.value =="")
		{
			alert("You not fill first password!");
			form2.txtpwd.focus();
			return false;
		}
		else if(form2.txtpwd2.value =="")
		{
			alert("You not fill second password!");
			form2.txtpwd2.focus();
			return false;
		}
		else if(form2.txtpwd.value != form2.txtpwd2.value)
		{
			alert("Password doesn't match!");
			form2.txtpwd2.value = "";
			form2.txtpwd2.focus();
			return false;
		}
		else if(form2.txtnameuser.value =="")
		{
			alert("You not fill name of user");
			form2.txtnameuser.focus();
			return false;
		}
		else
		{
			return true; 
		}	 
} 
function onUpdateUser()
{ 
		if(form3.txtuname2.value =="")
		{
			alert("You not fill user name!");
			form3.txtuname2.focus();
			return false;
		}
		else if(form3.txtpwd3.value != form3.txtpwd4.value)
		{
			alert("Password doesn't match!");
			form3.txtpwd4.value = "";
			form3.txtpwd4.focus();
			return false;
		}
		else if(form3.txtnameuser2.value =="")
		{
			alert("You not fill name of user");
			form3.txtnameuser2.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) -->

  <?
  if($_POST[submit])
	{
	$edtpwd = trim($_POST["pwd1"]);
	$uid = $_SESSION['myusername'];
	require_once("usr_function.php");
	ChangePassword($uid,$edtpwd);
	$tlog = "Change Password";
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	}	
	if($_POST[submit2])
	{
	$insuname = trim($_POST["txtuname"]);
	$inspwd = trim($_POST["txtpwd"]);
	$insnameuser = trim($_POST["txtnameuser"]);
	$insstatus = $_POST["lststatus"];
	require_once("usr_function.php");
	AddUser($insuname,$inspwd,$insnameuser,$insstatus);
	$tlog = "Insert User ".$insuname;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	}
	if($_POST[submit3])
	{
	$edtuname = trim($_POST["hduname"]);
	$edtnewuname = trim($_POST["txtuname2"]);
	$edtpwd = trim($_POST["txtpwd3"]);
	$edtnameuser = trim($_POST["txtnameuser2"]);
	$edtstatus = $_POST["lststatus2"];
	if($edtpwd != "")
	{
	require_once("usr_function.php");
	UpdateUser($edtuname,$edtnewuname,$edtpwd,$edtnameuser,$edtstatus);
	}
	else
	{
	require_once("usr_function.php");
	UpdateUserNoPass($edtuname,$edtnewuname,$edtnameuser,$edtstatus);
	}
	$tlog = "Update user ".$edtuname." to ".$edtnewuname;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	}
	if($_POST[submit4])
	{
	$deluname = trim($_POST["hduname2"]);
	require_once("usr_function.php");
	DeleteUser($deluname);
	$tlog = "Delete user ".$deluname;
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	}	
?>

    <table width="1024" height="804" 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="10" colspan="2" bgcolor="#006666"><span class="styleblack">&nbsp;</span><a href="main.php">Home</a><span class="style1">&nbsp;</span> | User<a href="usr.php"></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></td>
      </tr>
      <tr>
        <td width="408" height="707" valign="top" bgcolor="#CCCCCC"><br><table width="95%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
          <tr class="stylewhitesmall">
          <?
		   if($_SESSION['status'] == 0)
	  		{
			?>
            <td width="47%" bgcolor="#000000" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">User</span></div></td>
            <td width="8%" bgcolor="#000000" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Edit</span></div></td>
            <td width="12%" bgcolor="#000000" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">Delete</span></div></td>
            <?
			}
			else
			{
			?>
            <td width="33%" bgcolor="#000000" class="stylewhitesmall"><div align="center"><span class="stylewhitesmall">User</span></div></td>
            <?
			}
			?>
          </tr>
          <div align="center"><span class="stylegreen">
            <?
	  include "connect.inc.php";
	  if($_SESSION['status'] == 0)
	  {
	   $sqlgetusr = "select uname,nameofuser,status,IF(status = 1,'Administrator','General User') as status from sysuser where nameofuser != 'Administrator' order by status,nameofuser ASC";
	  }
	  else
	  {
	  	$un = $_SESSION['myusername'];
	   $sqlgetusr = "select uname,nameofuser,status from sysuser where uname = '$un'";
	  }
	 
	  $qrygetusr = mysql_query($sqlgetusr);
	  $numgetusr = mysql_num_rows($qrygetusr);
	  if($numgetusr != 0)
	  {
	   for($i=1;$i<=$numgetusr;$i++)
		{
			$resgetusr = mysql_fetch_array($qrygetusr);
			$dbuser = $resgetusr["uname"];
			$dbname = $resgetusr["nameofuser"];
			$dbstatus = $resgetusr["status"];
			$encodeusr = base64_encode($dbuser);
			?>
		</span>
            <tr class="stylewhitesmall">
			<?
            if($_SESSION['status'] == 0)
			{
			?>
			<td bgcolor="#006666"><div align="center"><span class="stylegreen">
			  <div align="left" class="stylewhitesmall"><? echo $dbname." (".$dbstatus.")"; ?></div>
			</span></div></td>
            	<td width="8%" bgcolor="#006666"><div align="center"><span class="stylegreen"><a href="usr.php?edtusr=<? echo $encodeusr; ?>"><img src="images/document_edit.png" width="20" height="20" border="0"></a></span></div></td>
           	<td width="12%" bgcolor="#006666"><div align="center"><span class="stylegreen"><a href="usr.php?delusr=<? echo $encodeusr; ?>"><img src="images/close.png" width="20" height="20" border="0"></a></span></div></td>
            <?
			}
			else
			{
			?>
			<td width="33%" bgcolor='#006666'><div align="center"><span class="stylewhitesmall"><? echo $dbname; ?></span></div></td>
            <?
			}
			?>
		    </tr>
            <span class="stylegreen"></span><span class="stylegreen">
            <?
		}
	}
	else
	{
		echo "<td bgcolor='#006666'>"."<span class='stylewhitesmall'>"."No General User"."</span>"."</td>";
	}
      ?>
            </span></div>
          <tr>
            <td colspan="3" bgcolor="#000000"><div align="right"><span class="stylewhitesmall">
            <? 
			if($_SESSION['status'] == 0)
			{
			?>
            <a href="usr.php?adduser=<? echo base64_encode(1); ?>"><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>        </p>        </td>
        <td width="610" valign="top" bgcolor="#CCCCCC"><p>&nbsp;</p>
        <?
		$getnum = base64_decode($_GET[adduser]);
		if(isset($_GET[adduser]))
		{
		?>
        <form action="usr.php" method="post" name="form2" id="form2" onSubmit="return onInsertUser();">
          <table width="70%" height="128" 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">Insert User </span> </div>
                  <div align="right"></div></td>
            </tr>
            <tr>
              <td width="40%" height="12" bgcolor="#ADCE4C" class="style1"><div align="right"></div></td>
              <td width="60%" height="12" bgcolor="#ADCE4C">&nbsp;</td>
            </tr>
            <tr>
              <td height="3" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Full Name&nbsp;</span>&nbsp; </div></td>
              <td width="60%" height="3" bgcolor="#ADCE4C"><input name="txtnameuser" type="text" class="styleblack" id="txtnameuser" size="30" maxlength="30" /></td>
            </tr>
            <tr>
              <td height="3" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">User Name</span>&nbsp;</div></td>
              <td height="3" bgcolor="#ADCE4C"><input name="txtuname" type="text" class="styleblack" id="txtuname" size="10" maxlength="10" /></td>
            </tr>
            <tr>
              <td height="7" bgcolor="#ADCE4C" class="style1"><div align="right" class="stylegreen">User Type&nbsp;&nbsp; </div></td>
              <td width="60%" height="7" bgcolor="#ADCE4C"><select name="lststatus" class="styleblack" id="lststatus">
                <option value="1">Administrator</option>
                <option value="0">General User</option>
              </select>              </td>
            </tr>
            <tr>
              <td height="12" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Password </span>&nbsp; </div></td>
              <td height="0" bgcolor="#ADCE4C"><label>
                <input name="txtpwd" type="password" class="styleblack" id="txtpwd" size="10" maxlength="10" />
              </label></td>
            </tr>
            <tr>
              <td height="13" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Re-Password&nbsp;&nbsp; </span> </div></td>
              <td height="0" bgcolor="#ADCE4C"><input name="txtpwd2" type="password" class="styleblack" id="txtpwd2" size="10" maxlength="10" /></td>
            </tr>
            <tr>
              <td height="34" colspan="2" bgcolor="#ADCE4C"><label>
                  <div align="center">
                    <input name="submit2" type="submit" class="styleblack" id="submit2" value="Insert" />
                    <label>
                    <input name="Button" type="button" class="styleblack" id="button" value="Cancel" onClick="window.location='usr.php';">
                    </label>
                  </div>
                </label></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <?
		}
		else if(isset($_GET[edtusr]))
		{
			$euser = base64_decode($_GET[edtusr]);
			include "connect.inc.php";
			$sqlgetuser = "select uname,nameofuser,pwd,status from sysuser where uname='$euser'";
			$qrygetuser = mysql_query($sqlgetuser);
			$resgetuser = mysql_fetch_array($qrygetuser);
			$dbusername = $resgetuser["uname"];
			$dbnameofuser = $resgetuser["nameofuser"];
			$dbpwd = $resgetuser["pwd"];
			$dbst = $resgetuser["status"];
		  ?>
        <form action="usr.php" method="post" name="form3" id="form3" onSubmit="return onUpdateUser();">
          <table width="70%" height="113" 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 User </span> </div>
                  <div align="right"></div></td>
            </tr>
            <tr>
              <td width="40%" height="1" bgcolor="#ADCE4C" class="style1">&nbsp;</td>
              <td width="60%" height="1" bgcolor="#ADCE4C">&nbsp;</td>
            </tr>
            <tr>
              <td height="2" bgcolor="#ADCE4C" class="style1"><div align="right" class="stylegreen">Full Name &nbsp;</div></td>
              <td width="60%" height="2" bgcolor="#ADCE4C"><input name="txtnameuser2" type="text" class="styleblack" id="txtnameuser2" value="<? echo $dbnameofuser; ?>" size="30" maxlength="30"  /></td>
            </tr>
            <tr>
              <td height="3" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">User Name</span>&nbsp; </div></td>
              <td height="3" bgcolor="#ADCE4C"><input name="txtuname2" type="text" class="styleblack" id="txtuname2" value="<? echo $dbusername; ?>" size="10" maxlength="10" />
                <input name="hduname" type="hidden" id="hduname" value="<? echo $dbusername; ?>"></td>
            </tr>
            <tr>
              <td height="7" bgcolor="#ADCE4C" class="style1"><div align="right" class="stylegreen">User Type&nbsp;&nbsp; </div></td>
              <td height="7" bgcolor="#ADCE4C"><select name="lststatus2" class="styleblack" id="lststatus2">
              <?
			  if($dbst == 1)
			  {
			  ?>
                  <option value="1">Administrator</option>
                  <option value="0">General User</option>
               <?
			   }
			   else
			   {
			   ?>
              
                  <option value="0">General User</option>
                   <option value="1">Administrator</option>
               <?
			   }
			   ?>
                </select>              </td>
            </tr>
            <tr>
              <td height="12" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Password </span>&nbsp; </div></td>
              <td height="0" bgcolor="#ADCE4C"><label>
                <input name="txtpwd3" type="password" class="styleblack" id="txtpwd3" size="10" maxlength="10" />
              </label></td>
            </tr>
            <tr>
              <td height="13" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Re-Password&nbsp;&nbsp; </span> </div></td>
              <td height="0" bgcolor="#ADCE4C"><input name="txtpwd4" type="password" class="styleblack" id="txtpwd4" size="10" maxlength="10" /></td>
            </tr>

            <tr>
              <td height="34" colspan="2" bgcolor="#ADCE4C"><label>
                <div align="center">
                    <input name="submit3" type="submit" class="styleblack" id="submit3" value="Update" />
                    <label></label>
                    <input name="button2" type="button" class="styleblack" id="button2" value="Cancel" onClick="window.location='usr.php';">
                </div>
                </label></td>
            </tr>
            <tr>
              <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <? 		
		}
		else if(isset($_GET[delusr]))
		{
		$deluname = base64_decode($_GET[delusr]);
		?>
        <form action="usr.php" method="post" name="form4" id="form4">
          <table width="70%" 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 User</span> </div>
                  <div align="right"></div></td>
            </tr>
            <tr>
              <td height="25" bgcolor="#ADCE4C" class="style1"><label>
                  <br>
                <div align="center" class="stylewhite">
                  <input name="hduname2" type="hidden" id="hduname2" value="<? echo $deluname; ?>">
                  &nbsp; Are you sure to delete user '<span class="styleblacklargered"><? echo $deluname; ?></span>'?</div></td>
            </tr>
            <tr>
              <td height="34" bgcolor="#ADCE4C"><label>
                  <div align="center">
                    <input name="submit4" type="submit" class="styleblack" id="submit4" value="Confirm" />
                    <input name="button3" type="button" class="styleblack" id="button3" value="Cancel" onClick="window.location='usr.php';">
                  </div>
                </label></td>
            </tr>
            <tr>
              <td height="19" bgcolor="#6B716F"><div align="right"></div></td>
            </tr>
          </table>
        </form>
        <?
		}
		else
		{
		?>
          <form action="usr.php" method="post" name="form1" id="form1" onSubmit="return onInsert()">
            <table width="70%" height="161" 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">Change Your Password</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="51%" height="12" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">User Name </span>&nbsp; </div></td>
                <td width="49%" height="12" bgcolor="#ADCE4C" class="styleblack"><? echo $_SESSION['myusername']; ?></td>
              </tr>
              <tr>
                <td height="13" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">New Password&nbsp;&nbsp; </span></div></td>
                <td width="49%" height="13" bgcolor="#ADCE4C"><input name="pwd1" type="password" id="pwd1" size="10" maxlength="10"></td>
              </tr>
              <tr>
                <td height="25" valign="top" bgcolor="#ADCE4C" class="style1"><div align="right"><span class="stylegreen">Re- New Password </span>&nbsp; </div></td>
                <td height="25" bgcolor="#ADCE4C"><label>
                  <input name="pwd2" type="password" id="pwd2" size="10" maxlength="10">
                </label></td>
              </tr>
              <tr>
                <td height="34" colspan="2" bgcolor="#ADCE4C"><label> </label>
                    <div align="center">
                      <input name="submit" type="submit" class="styleblack" id="submit" value="Change Password" />
                  </div></td>
              </tr>
              <tr>
                <td height="19" colspan="2" bgcolor="#6B716F"><div align="right"></div></td>
              </tr>
            </table>
          </form>
          <?
		  }
		  ?>
        <p></p></td>
      </tr>
      <tr>
        <td height="25" colspan="2" bgcolor="#006666"><div align="right"><span class="styleblack">@SEAFDEC 2012</span></div></td>
      </tr>
    </table>
  

<!-- End ImageReady Slices -->
</body>
</html>