<?php

session_start();

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

if( isset($_SESSION["alogin"]) ) {
	?>
	<!-- Setting up the page -->
	<table>
	<tr>
		<td width="15%" valign=top><br>
			<? include("adminnavigation.php"); ?>
		</td>
	<td  valign="top" align="center"><br><br>
	<center>
	<!-- Setting up the page -->
	
	<?
		// Load the settings
		$query = "select * from jse_bdomainsettings";
			$result = mysql_query( $query )
				or die( "Connection error. Check database settings!" );
	
		$array = mysql_fetch_array($result);
		$jse_mode = $array["type"];
		
		// Get all the information of the domains listed in jse_allow
		if( $jse_mode == 'allow' )
		{
			$query2 = "select * from jse_allow";
			$result2 = mysql_query( $query2 )
				or die( "Connection error. Check database settings!(2)" );
	
			$array2 = mysql_fetch_array($result2);
		}
		// Get all the information of the domains listed in jse_allow
		else if( $jse_mode == 'reject' )
		{
			$query2 = "select * from jse_reject";
			$result2 = mysql_query( $query2 )
				or die( "Connection error. Check database settings!(2)" );
				
			$array2 = mysql_fetch_array($result2);
		}
		$jse_rows = mysql_num_rows( $result2 );
		$jse_domain = $array2['domain'];
	?>
	
	<H3>E-mail Registration Management</H3><br><br><br>
	
	<?
		if( $jse_mode == 'allow' )
		{
			echo( "You're currently running in &quot;<b>Allow Mode</b>&quot;.<br>In this mode people can only register on your site if they use one of the below e-mail addresses.<br>" );
			?>
			<br><form method="POST" action="jse_changemode.php">
			<input type="submit" value="Change to Reject Mode">
			</form><br>
			<?
		}
		else if( $jse_mode == 'reject' )
		{
			echo( "You're currently running in &quot;<b>Reject Mode</b>&quot;.<br>In this mode people can only register on your site if they use an e-mail address that is not listed below.<br>" );
			?>
			<br><form method="POST" action="jse_changemode.php">
			<input type="submit" value="Change to Allow Mode">
			</form><br>
			<?
		}
	?>
	
	<br><br><br>Add a domain to this list:
	<form method="POST" action="jse_adddomain.php">
	<input type="text" name="domainname" value=""><br>
	<input type="submit" value="Add Domain">
	</form><br>
	
	<b>Note:</b><br>When adding a domain, please leave out the '@' sign.<br>So if you only want people with a "<font color='blue'>@gmail.com</font>" address to be allowed or rejected,<br>simply input "<font color='green'>gmail.com</font>" (without the quotes) in the list and click on "Add Domain".<br><br>
	<br>
	
	<?
	if( $jse_rows != 0 )
	{
	?>
		<?
			if( $jse_mode == 'allow' )
			{
				echo( "<b>Currently people can only join if they use one of the following domains:</b><br><br>" );
			}
			else if( $jse_mode == 'reject' )
			{
				echo( "<b>Currently people can only join if they use a domain not listed below:</b><br><br>" );
			}
		?>
		
		<table cellpadding='2px' cellspacing='2px' border='0' align='center' valign='middle'>
			
			
			<tr>
				<td valign="middle" bgcolor="<? echo $contrastcolour; ?>">
					<center>
						<font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Domain Name</font>
					</center>
				</td>
						
				<td valign="middle" bgcolor="<? echo $contrastcolour; ?>">
					<center>
						<font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Delete</font>
					</center>
				</td>
			</tr>
			
			<!-- Show the first row -->
			<tr>
				<td valign="middle" bgcolor="<? echo $basecolour; ?>">
					<center>
						<? echo( $jse_domain ); ?>
					</center>
				</td>
				
				<td valign="middle" bgcolor="<? echo $basecolour; ?>">
					<center>
						<form method="POST" action="jse_deletedomain.php">
						<input type="hidden" name="domainname" value="<? echo( $jse_domain ); ?>">
						<input type="submit" value="Delete Entry">
						</form>
					</center>
				</td>
			</tr>
			
		<?
			while( $line = mysql_fetch_array( $result2 ) )
			{
				$jse_domain = $line['domain'];
				?>
				<tr>
					<td valign="middle" bgcolor="<? echo $basecolour; ?>">
						<center>
							<? echo( $jse_domain ); ?>
						</center>
					</td>
						
					<td valign="middle" bgcolor="<? echo $basecolour; ?>">
						<center>
							<form method="POST" action="jse_deletedomain.php">
							<input type="hidden" name="domainname" value="<? echo( $jse_domain ); ?>">
							<input type="submit" value="Delete Entry">
							</form>
						</center>
					</td>
				</tr>
				<?
			}
		?>
		</table> <!-- End the table of e-mails -->
		
	<?
	}
	else
	{
	?>
		<H4><font color='red'><b>[ You don't have any domains added. Please use the form above to add a domain.] </b></font></H4>
	<?
	}
	?>
	
	<!-- Ending of the page -->
	</center></td></tr></table>
	<!-- Ending of the page -->
<?
}
else
{
	echo "Unauthorised Access!";
}

include "../footer.php";
mysql_close($dblink);
?>