<?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 (index.php)
|+===================================================+
||
|| # Usage of this page:
|| # The homepage
||
|+===================================================*/

include('./hk/inc/config.php');
include('./hk/inc/func.php');
include('./hk/inc/global.php');
$loader_closed = configkey("2");

if($_SERVER['SERVER_NAME'] == 'virtual-hotel.tk'){
	header('location: http://www.virtual-hotel.tk/');
	exit;
}

if(isset($_POST['submit'])){
	$a = mysql_query("SELECT * FROM users WHERE username = '".beveilig($_POST['user'])."' AND email = '".beveilig($_POST['email'])."' LIMIT 1");
	if(mysql_num_rows($a) == 1){
		$b = mysql_fetch_assoc($a);
		if(mysql_num_rows(mysql_query("SELECT * FROM password_reset WHERE userid = '".$b['id']."' LIMIT 1")) == 0){
			echo '<h1>SELECT * FROM password_reset WHERE userid = "'.$b['id'].'" LIMIT 1</h1>';
			$running = true;
			while($running){
				$code = randomfortext();
				if(mysql_num_rows(mysql_query("SELECT code FROM password_reset WHERE code = '".beveilig($code)."' LIMIT 1")) > 0){
					$running = true;
				}else{
					$running = false;
				}
			}
			mysql_query("INSERT INTO password_reset (userid, code, tijd, ip) VALUES ('".beveilig($b['id'])."', '".beveilig($code)."', '".beveilig(time())."', '".beveilig($_SERVER['REMOTE_ADDR'])."')");
			email($b['username'], $b['email'], 'Virtual-Hotel - Wachtwoord reset voor '.$b['username'], 'Hoi '.$b['username'].',<br>Bij deze ontvang je de bevestiging van je wachtwoord reset,<br><br>Klik op de volgende link je wachtwoord reset te bevestigen<br><a href="http://www.virtual-hotel.tk/passwd.php?code='.$code.'">http://www.virtual-hotel.tk/passwd.php?code='.$code.'</a><br><br>We hopen je snel weer te zien! :)<br><br>Groetjes,<br>Frank<br>Virtual-Hotel Hotelmanager');
			echo '<script>alert(\'Er is een bevestiging naar je emailadres verzonden, controleer je email.\');</script>';
		}else{
			echo '<script>alert(\'Je hebt al een nieuw wachtwoord aangevraagd, deze aanvraging verloopt over 24 uur of wanneer deze is bevestigt.\');</script>';
		}
	}else{
		echo '<script>alert(\'We hebben geen account gevonden met deze naam/email combinatie.\');</script>';
	}
}

if(isset($_GET['code']) && !empty($_GET['code'])){
	//check code
	//als die bestaat en binnen tijd
	//verzend nieuw wachtwoord
}
?>
<html>

<head>
<title>Virtual-Hotel - Wachtwoord Reset</title>

<style type="text/css">
<!--
body {
	background-image: url(images/habbo_background.gif);
}
-->
</style>
</head>

<body>

<table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0" height="100%">
	<tr>
		<td align="center">
		<table border="1" width="400" id="table2" cellspacing="0" cellpadding="0" height="200">
			<tr>
				<td align="center" bgcolor="#FF9933" bordercolor="#000000"><b>
				<font color="#FFFFFF" face="Arial" size="4">Virtual-Hotel 
				Wachtwoord Reset<br><br></font></b>
				<font face="Arial" size="1">Vul hier je Accountnaam en emailadres in, hiermee zal er een bevestiging emailtje in je inbox komen waarnaar je wachtwoord word gereset.</font><br><br>
				<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
				<table border="0" id="table1" cellspacing="0" cellpadding="0">
					<tr>
						<td><font face="Arial" size="1">Accountnaam:&nbsp;&nbsp;</font></td>
						<td><input type="text" name="user"></td>
					</tr>
					<tr>
						<td><font face="Arial" size="1">Email:&nbsp;&nbsp;</font></td>
						<td><input type="text" name="email"></td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td><input type="submit" name="submit" value="Vraag wachtwoord op"></td>
					</tr>
				</table>
				</form>
			</tr>
		</table>
		</td>
	</tr>
</table>

</body>

</html>
