<?php

session_start();

include "../header.php";
include "../config.php";
include "../style.php";

$mip = $_GET['showmip'];

if( isset($_SESSION["alogin"]) ) {

    	?><table>
      	<tr>
        <td width="15%" valign=top><br>
        <? include("adminnavigation.php"); ?>
        </td>
        <td  valign="top" align="center"><br><br> <?
		
    	echo "<font size=2 face='$fonttype' color='$fontcolour'><p><center>";?>
			Enter the IP Adress in the text box below to ban the IP Address
	        <center>
	        <form method="POST" action="leaves_banipdo.php">
            <font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">
	        <input type="text" name="ipaddress" maxLength="50" size="40" value=""><br>
	        <input type="submit" value="Ban IP">
	        </form>
            </font>
	        </center><br><br><br><br>
			
			Enter the IP Adress in the text box below to show members by IP Address
			<center>
	        <form method="POST" action="leaves_do.php">
            <font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">
	        <input type="text" name="ipaddress" maxLength="50" size="40" value=""><br>
	        <input type="submit" value="Show members with the same IP Adress">
	        </form>
            </font>
	        </center>
			<br><br>
			
			Click the button below to show the list of banned IP's<br>
			(You can also unban IP's in this list)
			<center>
	        <form method="POST" action="leaves_banip.php?showmip=1">
	        <input type="submit" value="Show members with the banned IP list">
	        </form>
            </font>
	        </center>
			<br><br>
	    <?
	
	if( ($mip != 0) and ($mip != 1) ) 
	{
		$query = "SELECT * FROM `members` WHERE ip='$mip' ORDER BY `members`.`joindate` ASC";
		$result = mysql_query ($query)
			 or die ("Query failed");
		   $num_rows = mysql_num_rows($result);
			?><table>
			<tr>
			<td width="15%" valign=top><br>
			</td>
			<td valign="top" align="center"><br><br> <?
		echo "<font size=2 face='$fonttype' color='$fontcolour'><p><center>";
		echo "<center><p><b>";
		echo "$num_rows Results found<br><br>";
		
		echo "</center></p></b>";
		?>
		<center>
		<table width=70% border=0 cellpadding=2 cellspacing=2>


			<tr>
			  <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"> Name </font></center></td>
			  <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"> Userid </font></center></td>
			  <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"> Membership </font></center></td>
			  <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"> Contact Email </font></center></td>
			  <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"> IP </font></center></td>
			  <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"> Join Date</font></center></td>
			  <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"> Delete Member </font></center></td>
			</tr>
		<?

		while ($line = mysql_fetch_array($result))
		{
			$name = $line["name"];
			$userid = $line["userid"];
			$contactemail = $line["contact_email"];
			$ip = $line["ip"];
			$memtype = $line["memtype"];
			$joindate = $line["joindate"];
			
			
			?>
			<tr>
			  <td bgcolor="<? echo $basecolour; ?>"><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center><? echo $name; ?></font></center></td>
			  <td bgcolor="<? echo $basecolour; ?>"><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center><? echo $userid; ?></font></center></td>
			  <td bgcolor="<? echo $basecolour; ?>"><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center><? echo $memtype; ?></font></center></td>
			  <td bgcolor="<? echo $basecolour; ?>"><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center><? echo $contactemail; ?></font></center></td>
			  <td bgcolor="<? echo $basecolour; ?>"><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center><? echo $ip; ?></font></center></td>
			  <td width="10" bgcolor="<? echo $basecolour; ?>"><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center><? echo $joindate; ?></font></center></td>
			  <td valign="middle" bgcolor="<? echo $basecolour; ?>"><center><br>
			  <form method=POST action=deletethismember.php>
			  <input type="hidden" name="userid" value="<? echo $userid; ?>">
			  <input type="submit" value="Delete Member">
			  </form> </center>
			  </td>
				
		</center>
		</td>
      	</tr>
    	</table>
			<? 
		}
		 echo "</table></td></tr></table>";
	}
	
	if( $mip == 1 ) 
	{
		$query = "SELECT * FROM `leaves_bannedips` ORDER BY `leaves_bannedips`.`ip` ASC";
		$result = mysql_query ($query)
			 or die ("Query failed");
		   $num_rows = mysql_num_rows($result);
			?><table>
			<tr>
			<td width="15%" valign=top><br>
			</td>
			<td valign="top" align="center"><br><br> <?
		echo "<font size=2 face='$fonttype' color='$fontcolour'><p><center>";
		echo "<center><p><b>";
		echo "$num_rows Results found<br><br>";
		
		echo "</center></p></b>";
		?>
		<center>
		<table width=70% border=0 cellpadding=2 cellspacing=2>


			<tr>
			  <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"> IP Address </font></center></td>
			  <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"> Unban IP </font></center></td>
			</tr>
		<?

		while ($line = mysql_fetch_array($result))
		{
			$ip = $line["ip"];
			
			
			?>
			<tr>
			  <td bgcolor="<? echo $basecolour; ?>"><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center><? echo $ip; ?></font></center></td>
			  <td valign="middle" bgcolor="<? echo $basecolour; ?>"><center><br>
			  <form method="POST" action="leaves_unbanip.php">
			  <input type="hidden" name="ip" value="<? echo $ip ?>">
			  <input type="submit" value="Unban IP">
			  </form> </center>
			  </td>
			<? 
		}
		?>
		</center>
		</td>
      	</tr>
    	</table>
		<?
		 echo "</table></td></tr></table>";
	}
}

else 
{
 	echo "Unauthorised Access!";
 	
}
echo "</td></tr></table>";
include "../footer.php";
mysql_close($dblink);
?>