<?php
/*===================================================+
|| # Woodpecker Housekeeping
|+====================================================+
|| # Copyright © 2008 SuperFun. All rights reserved.
|| # http://www.superfunn.nl/
|+===================================================+
|| # Notice: This is free software.
|+===================================================+
|| # Versions.
|| # Housekeeping version: V3.5
|| # Version of this file: V1.1 (index.php)
|+===================================================+
||
|| # Usage of this page:
|| # The loader.
||
|+===================================================*/
session_start();

include('./hk/inc/config.php');
include('./hk/inc/func.php');
include('./hk/inc/global.php');

if(isset($_GET['online'])){
	echo onlineusers().' '.$short.'\'s in the hotel';
	exit;
}
$loader_closed = configkey("2");

if($_SERVER['SERVER_NAME'] == 'virtual-hotel.tk'){
	header('location: http://www.virtual-hotel.tk/');
	exit;
}

if(strstr($_SERVER['REMOTE_ADDR'], '192.168.1')){
	$ipp = true;
}else{
	$ipp = false;
}
if($loader_closed == 0 && $ipp == false){
?>
<html>
<head>
<title><?php print $web_name; ?> Client</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/vnd.microsoft.icon" />
</head>

<body background="images/habbo_background.gif" alink="#ffff66" bgcolor="#2c708f" text="#333300" vlink="#ffff66" link="#ffff66">
<div style="position: absolute; width: 300px; height: 80px; z-index: 1; left: 50%; margin-left: -150px; top: 35px">
	<table border="0" id="table1" cellspacing="0" cellpadding="0" width="100%" height="100%">
		<tr>
			<td background="mainti/top_left.gif" width="20" height="20">&nbsp;</td>
			<td background="mainti/top.gif">&nbsp;</td>
			<td background="mainti/top_right.gif" width="20" height="20">&nbsp;</td>
		</tr>
		<tr align="center">
			<td background="mainti/left.gif" width="20">&nbsp;</td>
			<td background="mainti/mid.gif">
			<b><font face="Verdana" size="1" color="#FFFFFF">Offline</font></b>
			<br>
			<font face="Verdana" size="1">At the moment the hotel is offline,</font><br>
			<font face="Verdana" size="1">Please try again later</font><br><br>
			<font face="Verdana" size="1"><a href="javascript: void('0')" onclick="window.close();">Close</a></font>
			</td>
			<td background="mainti/right.gif" width="20">&nbsp;</td>
		</tr>
		<tr>
			<td background="mainti/bot_left.gif" width="20" height="20">&nbsp;</td>
			<td background="mainti/bot.gif">&nbsp;</td>
			<td background="mainti/bot_right.gif" width="20" height="20">&nbsp;</td>
		</tr>
	</table>
</div>

</body>

</html>
<?php
}else{
if(isset($_SESSION['loggedin'])){
if(settings("server.status") != "online"){
unset($_SESSION['loggedin']);
?>
<html>
<head>
<title><?php print $web_name; ?> Client</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/vnd.microsoft.icon" />
</head>

<body background="images/habbo_background.gif" alink="#ffff66" bgcolor="#2c708f" text="#333300" vlink="#ffff66" link="#ffff66">
<div style="position: absolute; width: 300px; height: 80px; z-index: 1; left: 50%; margin-left: -150px; top: 35px">
	<table border="0" id="table1" cellspacing="0" cellpadding="0" width="100%" height="100%">
		<tr>
			<td background="mainti/top_left.gif" width="20" height="20">&nbsp;</td>
			<td background="mainti/top.gif">&nbsp;</td>
			<td background="mainti/top_right.gif" width="20" height="20">&nbsp;</td>
		</tr>
		<tr align="center">
			<td background="mainti/left.gif" width="20">&nbsp;</td>
			<td background="mainti/mid.gif">
			<b><font face="Verdana" size="1" color="#FFFFFF">Offline</font></b>
			<br>
			<font face="Verdana" size="1">At the moment the hotel is offline,</font><br>
			<font face="Verdana" size="1">Please try again later</font><br><br>
			<font face="Verdana" size="1"><a href="javascript: void('0')" onclick="window.close();">Close</a></font>
			</td>
			<td background="mainti/right.gif" width="20">&nbsp;</td>
		</tr>
		<tr>
			<td background="mainti/bot_left.gif" width="20" height="20">&nbsp;</td>
			<td background="mainti/bot.gif">&nbsp;</td>
			<td background="mainti/bot_right.gif" width="20" height="20">&nbsp;</td>
		</tr>
	</table>
</div>

</body>

</html>
<?php
}else{
$ticket = GenerateTicket();
mysql_query("UPDATE users SET ticket = '".beveilig($ticket)."' WHERE id = '".beveilig($_SESSION['loggedin'])."'");
unset($_SESSION['loggedin']);
$scr = loader('scr');
$externalvars = loader('externalvars');
$externaltext = loader('externaltext');
$port = loader('port');
$musport = loader('musport');
$ip = loader('ip');
$musip = loader('musip');
$siteurl = loader('siteurl');
$clientreload = loader('clientreload');

$textrand = randomfortext();
$varrand = randomfortext();
?>
 <!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">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title><?php print $web_name; ?> Client</title>
<link href="css/habbo.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" language="javascript">
// <![CDATA[
var w = 740, h = 609;
function resizeWin() {
if (!document.all || screen.height > 600) {
if (document.all) {
document.all["client-topbar"].style.display = "block";
} else if (document.getElementById) {
document.getElementById("client-topbar").style.display = "block";
}}
if (document.all) { h += 20; }
if (window.opener != null) {
window.resizeTo(w,h);
if (window.innerHeight || document.body.offsetHeight) {
var winW = 0, winH = 0;
if (document.all) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
} else if (document.getElementById) {
winW = window.innerWidth;
winH = window.innerHeight;
}
doContentResize(winW, winH);
if (navigator.userAgent) {
ag = navigator.userAgent.toLowerCase();
if (ag.indexOf("safari") != -1 || (ag.indexOf("firefox") != -1 && ag.indexOf("windows") != -1)) window.setTimeout(function() { doContentResize(); }, 500);
}}}
GETRequest();
}
function doContentResize(winW, winH) { window.resizeBy(w-winW, h-winH); }
window.onload = resizeWin;
function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); }}
function GETRequest() { url = 'loader.php?online'; createXMLHttpRequest(); xmlHttp.open("GET", url, true); xmlHttp.onreadystatechange = GETHandle; xmlHttp.send(null); setTimeout("GETRequest()",15000); }
function GETHandle(){ if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { document.getElementById('update').innerHTML = xmlHttp.responseText; }}}
// ]]>
</script>
</head>
<body id="client"><div id="client-topbar" style="display:none">
<div class="logo"><img src="images/popup_topbar_habbologo.gif" alt="" align="middle"/></div>
<div class="habbocount"><div id="habboCountUpdateTarget"> <div id="update"><?php echo onlineusers(); ?> <?php echo $short; ?>'s in the hotel</div>


</div></div>
<div class="logout"><a href="#" onclick="window.close();">loguit</a></div></div><div>

<div id="loader" name="loader" style="z-index: 2">
<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0" id="habbo" width="720" height="540">
<param name="src" value="<?php echo $scr; ?>">
<param name="swRemote" value="swSaveEnabled='true' swVolume='true' swRestart='false' swPausePlay='false' swFastForward='false' swTitle='Habbo Hotel' swContextMenu='true' ">
<param name="swStretchStyle" value="none">

<param name="swText" value="">
<param name="sw6" value="external.variables.txt=<?php echo $externalvars; ?>">
<param name="sw7" value="use.sso.ticket=1;sso.ticket=<?php echo $ticket; ?>">
<param name="sw8" value="site.url=<?php echo $siteurl; ?>">
<param name="sw2" value="connection.info.port=<?php echo $port; ?>">
<param name="sw4" value="connection.mus.host=<?php echo $musip; ?>">
<param name="sw3" value="client.reload.url=<?php echo $clientreload; ?>">
<param name="sw1" value="connection.info.host=<?php echo $ip; ?>">
<param name="sw7" value="external.texts.txt=<?php echo $externaltext; ?>">
<param name="sw5" value="connection.mus.port=<?php echo $musport; ?>">

<param name="bgColor" value="#000000">
<embed src="<?php echo $scr; ?>"
	bgColor="#000000" width="720" height="540"
	swRemote="swSaveEnabled='true' swVolume='true' swRestart='false' swPausePlay='false' swFastForward='false' swTitle='Habbo Hotel' swContextMenu='true'"
	swStretchStyle="none" swText=""
	sw6="external.variables.txt=<?php echo $externalvars; ?>" 
sw8="site.url=<?php echo $siteurl; ?>" 
sw7="use.sso.ticket=1;sso.ticket=<?php echo $ticket; ?>"
sw2="connection.info.port=<?php echo $port; ?>"
sw4="connection.mus.host=<?php echo $musip; ?>" 
sw3="client.reload.url=<?php echo $clientreload; ?>" 
sw1="connection.info.host=<?php echo $ip; ?>" 
sw7="external.texts.txt=<?php echo $externaltext; ?>" 
sw5="connection.mus.port=<?php echo $musport; ?>"

	type="application/x-director"
	pluginspage="http://www.macromedia.com/shockwave/download/" >
</embed>
</object>
</div>

</div>
</body>

</html>

<?php
exit;
}
}else{
if(isset($_GET['do']) && $_GET['do'] == 'register'){
	if(isset($_POST['submit'])){
		if(!empty($_POST['user']) && !empty($_POST['pass']) && !empty($_POST['email'])){
			$a = mysql_query("SELECT username FROM users WHERE username = '".beveilig($_POST['user'])."'");
			if(mysql_num_rows($a) > 0){
				$_SESSION['error'] = 'The username is already taken';
			}elseif(strlen($_POST['pass']) <= 3){
				$_SESSION['error'] = 'Password too short. Your password must be at least 4 chars.';
			}elseif(!validemail($_POST['email'])){
				$_SESSION['error'] = 'The email address is invalid';
			}elseif(!IsValidName($_POST['user'])){
				$_SESSION['error'] = 'The username can only contain letters and numbers';
			}else{
				$pass = md5($_POST['pass'].settings("cryptography.md5.salt").strtolower($_POST['user']));
				mysql_query("INSERT INTO users (username, password, email, signedup, lastactivity, club_lastupdate) VALUES ('".beveilig($_POST['user'])."', '".beveilig($pass)."', '".beveilig($_POST['email'])."', NOW(), NOW(), NOW())");
				$_SESSION['error'] = 'Welcome '.$_SESSION['user'].', you have been registered';
				header('location: /loader.php');
				exit;
			}
		}else{
			$_SESSION['error'] = 'One or more fields are left blank.';
		}
	}
?>
<html>
<head>
<title><?php print $web_name; ?> Registration</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/vnd.microsoft.icon" />
</head>

<body background="images/habbo_background.gif" alink="#ffff66" bgcolor="#2c708f" text="#333300" vlink="#ffff66" link="#ffff66"<?php if(isset($_SESSION['error'])){ echo ' onload="alert(\''.$_SESSION['error'].'\');"'; unset($_SESSION['error']); } ?>>
<div style="position: absolute; width: 300px; height: 80px; z-index: 1; left: 50%; margin-left: -150px; top: 35px">
	<table border="0" id="table1" cellspacing="0" cellpadding="0" width="100%" height="100%">
		<tr>
			<td background="mainti/top_left.gif" width="20" height="20">&nbsp;</td>
			<td background="mainti/top.gif">&nbsp;</td>
			<td background="mainti/top_right.gif" width="20" height="20">&nbsp;</td>
		</tr>
		<tr align="center">
			<td background="mainti/left.gif" width="20">&nbsp;</td>
			<td background="mainti/mid.gif">
			<b><font face="Verdana" size="1" color="#FFFFFF">Registration</font></b>
			<br>
			<form method="post" action="/loader.php?do=register">
			&nbsp;<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td width="80">
					<img border="0" src="images/frank_16.gif" width="70" height="85"></td>
					<td><b><font face="Verdana" size="1">Username:</font></b><br><input type="text" name="user"<?php if(isset($_POST['user'])){ echo ' value="'.$_POST['user'].'"'; } ?>><br><br><b><font face="Verdana" size="1">Password</font></b><br><input type="password" name="pass"><br><br><b><font face="Verdana" size="1">Email</font></b><br><input type="text" name="email"<?php if(isset($_POST['email'])){ echo ' value="'.$_POST['email'].'"'; } ?>><br><br><input type="submit" name="submit" value="Register"></td>
				</tr>
			</table>
			</form>
			<p><font face="Verdana"><font size="2"><a href="/loader.php">Got an account? Log in here</a></font>
			<br>&nbsp;</font>
			</td>
			<td background="mainti/right.gif" width="20">&nbsp;</td>
		</tr>
		<tr>
			<td background="mainti/bot_left.gif" width="20" height="20">&nbsp;</td>
			<td background="mainti/bot.gif">&nbsp;</td>
			<td background="mainti/bot_right.gif" width="20" height="20">&nbsp;</td>
		</tr>
	</table>
</div>

</body>

</html>
<?php
}else{
	if(isset($_POST['submit'])){
		if(!empty($_POST['user']) && !empty($_POST['pass'])){
			$pass = md5($_POST['pass'].settings("cryptography.md5.salt").strtolower($_POST['user']));
			$a = mysql_query("SELECT id FROM users WHERE username = '".beveilig($_POST['user'])."' AND password = '".beveilig($pass)."'");
			if(mysql_num_rows($a) == 1){
				$b = mysqL_fetch_assoc($a);
				$_SESSION['loggedin'] = $b['id'];
				header('location: /loader.php');
				exit;
			}else{
				$_SESSION['error'] = 'Wrong username or password';
			}
		}else{
			$_SESSION['error'] = 'One or more fields are left blank';
		}
	}
?>
<html>
<head>
<title><?php print $web_name; ?> Login</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/vnd.microsoft.icon" />
</head>

<body background="images/habbo_background.gif" alink="#ffff66" bgcolor="#2c708f" text="#333300" vlink="#ffff66" link="#ffff66"<?php if(isset($_SESSION['error'])){ echo ' onload="alert(\''.$_SESSION['error'].'\');"'; unset($_SESSION['error']); } ?>>
<div style="position: absolute; width: 300px; height: 80px; z-index: 1; left: 50%; margin-left: -150px; top: 35px">
	<table border="0" id="table1" cellspacing="0" cellpadding="0" width="100%" height="100%">
		<tr>
			<td background="mainti/top_left.gif" width="20" height="20">&nbsp;</td>
			<td background="mainti/top.gif">&nbsp;</td>
			<td background="mainti/top_right.gif" width="20" height="20">&nbsp;</td>
		</tr>
		<tr align="center">
			<td background="mainti/left.gif" width="20">&nbsp;</td>
			<td background="mainti/mid.gif">
			<b><font face="Verdana" size="1" color="#FFFFFF">Login</font></b>
			<br>
			<form method="post" action="/loader.php">
			&nbsp;<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td width="72">
					<img border="0" src="images/frank_04.gif" width="54" height="86"></td>
					<td><b><font face="Verdana" size="1">Username:</font></b><br><input type="text" name="user"<?php if(isset($_POST['user'])){ echo ' value="'.$_POST['user'].'"'; } ?>><br><br><b><font face="Verdana" size="1">Password</font></b><br><input type="password" name="pass"><br><br><input type="submit" name="submit" value="Login"></td>
				</tr>
			</table>
			</form>
			<p><font face="Verdana"><font size="2"><a href="/loader.php?do=register">Not got an account? Register here.</a><br><a href="javascript:void('0');" onclick="alert('Please contact a member of staff.');"><i>Forgotten Password</i></a></font>
			<br>&nbsp;</font>
			</td>
			<td background="mainti/right.gif" width="20">&nbsp;</td>
		</tr>
		<tr>
			<td background="mainti/bot_left.gif" width="20" height="20">&nbsp;</td>
			<td background="mainti/bot.gif">&nbsp;</td>
			<td background="mainti/bot_right.gif" width="20" height="20">&nbsp;</td>
		</tr>
	</table>
</div>

</body>

</html>
<?php
}
}
}
?>
