<?php
define('USERNAME_REQUIRED', TRUE);
define('ACCOUNT_REQUIRED', TRUE);
include('global.php');
define("THIS_SCRIPT", 'settings');
?>
<!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"> 
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<head>
<title><?php echo $sitename." - ".$lang['settings']; ?></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" src="Public/JS/jquery.history.js"></script>
	<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js"></script>
</head> 

<script type="text/javascript">

	function doCheckMail() {
		name = $("#email").val();
		$.get("./register/mailcheck.php", {ajaxAct: "check_habbo_name", mail: name}, function(data) {
			if( $.trim(data) == "0" ) {
				$("#habbo_name_message_box").html("<?php echo $lang['settings_mail_error']; ?>");
				$("#habbo_name_message_box").removeClass().addClass("errormsg");
				MailisFree = 0;
			} else {
				MailisFree = 1;
			}
		});
	}

$().ready(function() {
	$('#email').keypress(function(e){
		if(e.which == 13){
			doCheckMail();
		}
	});

	$('#email').blur(function(e){
		doCheckMail();
	});

	$("#UserEmail").validate({
		submitHandler: function(form) {
			doCheckMail();
			if (MailisFree === 1) {
				form.submit();
			}
		},
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			email: "<?php echo $lang['settings_mail_invalid']; ?>"
		}
	});	
});

MailisFree = 0;

</script>

<link type="text/css" rel="stylesheet" href="Public/Styles/<?php echo $currentstyle ?>/CSS/main.css" />

<?php
if(!isset($_GET['page']))
$_GET['page'] = 'general';
?>

<body id="news_body"> 
 
<div class="mainBox"> 
	<?php include("header.php"); ?>
	<?php include("system/homenav.php"); ?>
    
	<div class="mid" id="midcontent"> 


<div class="column" id="column1">
	<div class="contentBox">
		<div class="boxHeader"><?php echo $lang['account_settings']; ?></div>
		<div class="boxContent">
			<a href="?page=general" <?php if($_GET['page'] == 'general') echo 'class="selected"'; ?>><?php echo $lang['general_settings']; ?></a><br/>
			<a href="?page=email" <?php if($_GET['page'] == 'email') echo 'class="selected"'; ?>><?php echo $lang['mail_settings']; ?></a><br/>
			<a href="?page=password" <?php if($_GET['page'] == 'password') echo 'class="selected"'; ?>><?php echo $lang['password_settings']; ?></a>
		</div>
	</div>
</div>
		
<div class="column" id="column2">
	<div class="contentBox">
		<?php
		$userq = mysql_query("SELECT * FROM users WHERE username = '".$_SESSION['username']."' LIMIT 1");
		$user = mysql_fetch_array($userq);
        if($_GET['page'] == 'general')
		{
		?>
			<div class="boxHeader"><?php echo $lang['general_settings']; ?></div>
			<div class="boxContent">
				<?php
                if(isset($_GET['success']) && $_GET['success'] == 'false')
				{
				?>
					<div class="errormsg" id="habbo_name_message_box"> 
						<h3><?php echo $lang['settings_general_error']; ?></h3> 
					</div>
				<?php
				}
                elseif(isset($_GET['success']) && $_GET['success'] == 'true')
				{
				?>
					<div class="goodmsg" id="habbo_name_message_box"> 
						<h3><?php echo $lang['settings_general_updated']; ?></h3> 
					</div>
				<?php
				}
				?>
				<form name="UserSettings" action="functions/updateusersettings.php" method="post">
					<p><strong><?php echo $lang['settings_friend_request']; ?></strong><br/>
					<input type="checkbox" name="friendreqs" id="friendreqs" <?php if($user['block_newfriends'] == 0) echo 'checked=checked'; ?> />
					<label for="friendreqs"><?php echo $lang['settings_friend_request_text']; ?></label></p>
					<p><strong><?php echo $lang['settings_online_status']; ?></strong><br/>
					<input type="checkbox" name="online" id="online" <?php if($user['hide_online'] == 0) echo 'checked=checked'; ?>  />
					<label for="online"><?php echo $lang['settings_online_status_text']; ?></label></p>
					<p><strong><?php echo $lang['settings_follow_me']; ?></strong><br/>
					<input type="checkbox" name="stalking" id="stalking" <?php if($user['hide_inroom'] == 0) echo 'checked=checked'; ?>  />
					<label for="stalking"><?php echo $lang['settings_follow_me_text']; ?></label></p>
					<div class="Submitbtn right">
						<button type="submit" class="positive" name="submitcomment"><?php echo $lang['submit']; ?></button>
		   			</div>
	   			</form>
			</div>
		<?php
		}
		if($_GET['page'] == 'email')
		{
		?>
			<div class="boxHeader"><?php echo $lang['mail_settings']; ?></div>
			<div class="boxContent">
				<?php
                if(isset($_GET['success']) && $_GET['success'] == 'false')
				{
				?>
					<div class="errormsg" id="habbo_name_message_box"> 
						<h3><?php echo $lang['settings_general_error']; ?></h3> 
					</div>
				<?php
				}
                elseif(isset($_GET['success']) && $_GET['success'] == 'true')
				{
				?>
					<div class="goodmsg" id="habbo_name_message_box"> 
						<h3><?php echo $lang['settings_mail_updated']; ?></h3> 
					</div>
				<?php
				}
				if($user['mail_verified'] != 'true')
				{
				?>
					<div class="errormsg" id="habbo_name_message_box"> 
						<h3><?php echo $lang['settings_mail_not_verified']; ?></h3> 
					</div>
                <?php
				}
				if(isset($_GET['sent']) && $_GET['sent'] == 'true')
				{
				?>
					<div class="goodmsg" id="habbo_name_message_box"> 
						<?php echo $lang['settings_mail_verify_sent']; ?>
					</div>
				<?php
				}
				if(isset($_GET['validated']) && $_GET['validated'] == 'true')
				{
				?>
					<div class="goodmsg" id="habbo_name_message_box"> 
						<h3><?php echo $lang['settings_mail_verified']; ?></h3> 
					</div>
				<?php
				}
				?>
				<form id="UserEmail" name="UserEmail" action="functions/updatemail.php" method="post">
					<label for="email"><?php echo $lang['settings_mail_address']; ?></label><br/>
					<input type="text" name="email" id="email" value="<?php echo $user['mail']; ?>" /><br/>
					<div class="Submitbtn right">
						<?php if($user['mail_verified'] != 'true'){?><a href="functions/send_validateemail.php" class="regular"><?php echo $lang['settings_re-send_mail']; ?></a><?php } ?>
					    <button type="submit" class="positive" name="submitcomment"><?php echo $lang['submit']; ?></button>
		   			</div>
	   			</form>
			</div>
		<?php
		}
		if($_GET['page'] == 'password')
		{
		?>
			<div class="boxHeader"><?php echo $lang['password_settings']; ?></div>
			<div class="boxContent">
				<?php
                if(isset($_GET['success']) && $_GET['success'] == 'false')
				{
				?>
					<div class="errormsg" id="habbo_name_message_box"> 
						<h3><?php echo $lang['settings_general_error']; ?></h3> 
					</div>
								<?php
				}
                elseif(isset($_GET['success']) && $_GET['success'] == 'true')
				{
				?>
					<div class="goodmsg" id="habbo_name_message_box"> 
						<h3><?php echo $lang['settings_password_updated']; ?></h3> 
					</div>
				<?php
				}
				?>
				<form name="UserPassword" action="functions/updatepassword.php" method="post">
					<label for="curpassword"><?php echo $lang['settings_current_password']; ?></label><br/>
					<input type="password" name="curpassword" id="curpassword" /><br/>
					<label for="newpassword"><?php echo $lang['settings_new_password']; ?></label><br/>
					<input type="password" name="newpassword" id="newpassword" /><br/>
					<label for="conpassword"><?php echo $lang['settings_confirm_password']; ?></label><br/>
					<input type="password" name="conpassword" id="conpassword" /><br/>
					<div class="Submitbtn right">
						<button type="submit" class="positive" name="submitcomment"><?php echo $lang['submit']; ?></button>
		   			</div>
	   			</form>
			</div>
		<?php
		}
		?>
	</div>
</div>
		
<?php include("system/sideads.php"); ?>

	</div> 

	<?php include("system/footer.php"); ?>
</div> 

</body> 
</html>