<?php
include("include/session.php");
$bConfigFail = True;
$errorString = "";
if(UNIVERSE_ID == "universeid" || UNIVERSE_PASS == "universepass")
{
	$errorString = $errorString . "You have not changed the <b><i>\"UNIVERSE_ID\"</b></i> or <b><i>\"UNIVERSE_PASS\"</b></i> settings from the default values. Please open the <b><i>/include/constants.php</b></i> file and modify these values for your installation.<br><br>\n";
}
else if(UNIVERSE_ADMIN_NAME == "someone" || UNIVERSE_ADMIN_EMAIL == "someone@somewhere.com")
{
	$errorString = $errorString . "You have not changed the <b><i>\"UNIVERSE_ADMIN_NAME\"</b></i> or <b><i>\"UNIVERSE_ADMIN_EMAIL\"</b></i> settings from the default values. Please open the <b><i>/include/constants.php</b></i> file and modify these values for your installation.<br><br>\n";
}
else if(EMAIL_FROM_NAME == "My Universe" || EMAIL_FROM_ADDR == "myuniverse@mywebsite.com")
{
	$errorString = $errorString . "You have not changed the <b><i>\"EMAIL_FROM_NAME\"</b></i> or <b><i>\"EMAIL_FROM_ADDR\"</b></i> settings from the default values. Please open the <b><i>/include/constants.php</b></i> file and modify these values for your installation.<br><br>\n";
}
else if(UNIVERSE_URL == "http://www.mywebsite.com/universalunreal/")
{
	$errorString = $errorString . "You have not changed the <b><i>\"UNIVERSE_URL\"</b></i> setting from the default value. Please open the <b><i>/include/constants.php</b></i> file and modify this values for your installation.<br><br>\n";
}
else
{
	$bConfigFail = False;
}

if($bConfigFail)
{
	die("<html><head><title>Configuration Error!</title></head><body>".$errorString."</body></html>");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="universal, unreal, tournament, ut99, server, communication, buddy, messaging, " />
<meta name="description" content="<?php echo UNIVERSE_ID; ?> Universe - Powered by Universal Unreal, The Dynamic UT Server Information, Messaging, and Buddy System" />
<title><?php echo UNIVERSE_ID; ?> Universe - Powered by Universal Unreal</title>

<!-- <link rel="stylesheet" href="templates/css/system.css" type="text/css" /> -->
<link rel="stylesheet" href="templates/css/general.css" type="text/css" />
<link rel="stylesheet" href="templates/css/template.css" type="text/css" />
<link rel="stylesheet" href="templates/css/red.css" type="text/css" />
<link rel="stylesheet" href="templates/css/red_bg.css" type="text/css" />
<link rel="shortcut icon" href="favicon.ico" />

<script type="text/javascript">
var i = <?php echo time(); ?>;
var page = "./include/get_message_history.php";

function confirmSubmit(text)
{
	var agree=confirm(text);
	if (agree)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function ajax(url,target)
 {
    // native XMLHttpRequest object
   //document.getElementById(target).innerHTML = 'Loading...';
   if (window.XMLHttpRequest) {
       req = new XMLHttpRequest();
       req.onreadystatechange = function() {ajaxDone(target);};
       req.open("GET", url+"?c="+i, true);
       req.send(null);
   // IE/Windows ActiveX version
   } else if (window.ActiveXObject) {
       req = new ActiveXObject("Microsoft.XMLHTTP");
       if (req) {
           req.onreadystatechange = function() {ajaxDone(target);};
           req.open("GET", url+"?c="+i, true);
           req.send();
       }
   }
		   i++;
		   setTimeout("ajax(page,'scriptoutput')", 5000);
}

function getAjax(url,target)
 {
    // native XMLHttpRequest object
   //document.getElementById(target).innerHTML = 'Loading...';
   if (window.XMLHttpRequest) {
       req = new XMLHttpRequest();
       req.onreadystatechange = function() {ajaxDone(target);};
       req.open("GET", url+"&c="+i, true);
       req.send(null);
   // IE/Windows ActiveX version
   } else if (window.ActiveXObject) {
       req = new ActiveXObject("Microsoft.XMLHTTP");
       if (req) {
           req.onreadystatechange = function() {ajaxDone(target);};
           req.open("GET", url+"&c="+i, true);
           req.send();
       }
   }
		   i++;
}

function ajaxDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200 || req.status == 304) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="AJAX Error: " + req.statusText;
}
}
}
</script>

</head>
<body id="page_bg" class="color_red bg_red width_fmax">
<a name="up" id="up"></a>
<div class="center" align="center">
	<div id="wrapper">
		<div id="wrapper_r">
			<div id="header">
				<div id="header_l">
					<div id="header_r">
						<div id="logo"></div>
						
					</div>
				</div>
			</div>

			<div id="tabarea">
				<div id="tabarea_l">
					<div id="tabarea_r">
						<!-- WHITESPACE -->
					</div>
				</div>
			</div>

			<div class="clr"></div>

			<div id="whitebox">
				<div id="whitebox_t">
					<div id="whitebox_tl">
						<div id="whitebox_tr"></div>
					</div>
				</div>

				<div id="whitebox_m">
					<div id="area">
									

<div id="leftcolumn">
	<div class="module_menu">
		<div>
			<div>
				<div>
					<h3>Main Menu</h3>
						<ul class="menu">
							<li class="item1"><a href="index.php?p=home"><span>Home</span></a></li>
<?php
if($session->logged_in)
{

							echo "<li class=\"item2\"><a href=\"index.php?p=buddies\"><span>Buddy List</span></a></li>\n";
							echo "<li class=\"item3\"><a href=\"index.php?p=account\"><span>Account</span></a></li>\n";
							echo "<li class=\"item4\"><a href=\"index.php?p=messages\"><span>Private Messages</span></a></li>\n";
							echo "<li class=\"item5\"><a href=\"index.php?p=members\"><span>Member List</span></a></li>\n";
							if($session->isQueryAdmin())
							{
								echo "<li class=\"item6\"><a href=\"index.php?p=queryadmin\"><span>Query Admin</span></a></li>\n";
							}
							if($session->isAdmin())
							{
								echo "<li class=\"item6\"><a href=\"index.php?p=admin\"><span>Administration</span></a></li>\n";
							}
}
else
{
							echo "<li class=\"item2\"><a href=\"index.php?p=register\"><span>Create Account</span></a></li>\n";
}
?>
						</ul><hr>
						<ul class="menu">
							<li class="item1"><a href="index.php?p=help"><span>Help &amp; How To Use</span></a></li>
							<li class="item2"><a href="index.php?p=about"><span>About</span></a></li>
							<li class="item3"><a href="index.php?p=credits"><span>Credits</span></a></li>
						</ul>
				</div>
			</div>
		</div>
	</div>
	<div class="module_menu">
		<div>
			<div>
				<div>
					<h3>About This Universe</h3>
						<span>Registered Players: <?php $database->printUserCount(); ?></span><br>
						<span>Member Servers: <?php $database->printServerCount(); ?>
						<?php $database->printServerData(); ?></span>
				</div>
			</div>
		</div>
	</div>

</div>

<div id="maincolumn">
	<table class="nopad">
		<tr valign="top">
			<td>
<?php
if(isset($_GET['p']))
{
	//$requestPage = preg_match('/[^A-Za-z0-9]/', $_GET['p']) ? '' : $_GET['p'];
	$requestPage = $_GET['p'];
		
	switch($requestPage)
	{
		case "":
			include('pages/home.php');
			break;
		case "home":
			include('pages/home.php');
			break;
		case "help":
			include('pages/help.php');
			break;
		case "about":
			include('pages/about.php');
			break;
		case "credits":
			include('pages/credits.php');
			break;
		case "players":
			include('pages/players.php');
			break;
		case "buddies":
			if($session->logged_in) include('pages/buddies.php'); else echo '<meta http-equiv="refresh" content="0;url=index.php">';
			break;
		case "members":
			if($session->logged_in) include('pages/members.php'); else echo '<meta http-equiv="refresh" content="0;url=index.php">';
			break;
		case "account":
			if($session->logged_in) include('pages/account.php'); else echo '<meta http-equiv="refresh" content="0;url=index.php">';
			break;
		case "messages":
			if($session->logged_in) include('pages/messages.php'); else echo '<meta http-equiv="refresh" content="0;url=index.php">';
			break;
		case "admin":
			if($session->logged_in && $session->isAdmin()) include('pages/admin.php'); else echo '<meta http-equiv="refresh" content="0;url=index.php">';
			break;
		case "queryadmin":
			if($session->logged_in && $session->isqueryadmin()) include('pages/queryadmin.php'); else echo '<meta http-equiv="refresh" content="0;url=index.php">';
			break;
		case "register":
			if($session->logged_in) echo '<meta http-equiv="refresh" content="0;url=index.php">'; else include('pages/register.php');
			break;
		case "forgotpass":
			if($session->logged_in) echo '<meta http-equiv="refresh" content="0;url=index.php">'; else include('pages/forgotpass.php');
			break;
		default:
			include('pages/home.php');
			break;
	}
}
else
{
	include('pages/home.php');
}
?>
<br><br>

									</td>
																			<td class="greyline">&nbsp;</td>
										<td width="170">
													<div class="moduletable">
		<div class="module_menu">
			<div>
				<div>
					<div>
													<h3>Login Status</h3>
<?php
if($session->logged_in){
											echo "<span>You are logged in as:<br><b>".$session->username."</b><br><br><a href=\"process.php\">Logout</a></span>\n";
}
else
{
											echo "<span>You are not logged in.</span><br><br>\n";
	if($form->num_errors > 0){
  	 echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
	}

echo "<form action=\"process.php\" method=\"POST\">\n";
echo "Username: <input type=\"text\" name=\"user\" maxlength=\"30\" size=\"18\" value=\"". $form->value("user") ."\"> ". $form->error("user") ."<br>\n";
echo "Password: <input type=\"password\" name=\"pass\" maxlength=\"30\" size=\"18\" value=\"". $form->value("pass") ."\"> ". $form->error("pass") ."<br>\n";
echo "<input type=\"checkbox\" name=\"remember\" ";
if($form->value("remember") != ""){ echo "checked"; }
echo"> Remember me<br>\n";
echo "<input type=\"hidden\" name=\"sublogin\" value=\"1\">\n";
echo "<input type=\"submit\" value=\"Login\">\n";
echo "</form><br>\n";
echo "<span><a href=\"index.php?p=forgotpass\">Forget Your Password?</a></span><br>\n";
echo "<span><a href=\"index.php?p=register\">Create An Account</a></span>\n";

}
?>
					</div>
				</div>
			</div>
		</div>

			<div class="moduletable">
					<h3>Who's Online</h3>
					 We have <?php echo $database->num_active_guests; ?> guests and <?php echo $database->num_active_users; ?> members online
					 <?php echo $database->printActiveUsers(); ?>
			</div>
<?php
if($session->logged_in){

			echo "<div class=\"moduletable\">\n";
			echo "<h3>Who's Gaming</h3>\n";
			$database->printActiveBuddies($session->userDBid);
			echo "</div>";
}
?>
		</div>
	
										</td>
																	</tr>
							</table>

						</div>
						<div class="clr"></div>
					</div>
					<div class="clr"></div>
				</div>

				<div id="whitebox_b">
					<div id="whitebox_bl">
						<div id="whitebox_br"></div>
					</div>
				</div>
			</div><br>
			<span><a href="index.php?p=credits">Credits Page &amp; Donation Information</a></span>
			<div id="footerspacer"></div>
		</div>

		<div id="footer">
			<div id="footer_l">
				<div id="footer_r">
					<p id="moduletable">
						<span>Universal Unreal &#169; 2009 MSuLL</span><br>
					</p>
				</div>
			</div>
		</div>
	</div>
</div>

</body>
</html>
