<? 
session_start();
include("config.php");
include("header.php");
$menu_type = "normal";
include("menu.php");
if(isset($_SESSION['name'])){
	$query = mysql_query("SELECT * FROM users WHERE name='".$_SESSION['name']."'");
	$row = mysql_fetch_assoc($query);
	$hcDays = $row['clubDays'];
	$sex = $row['sex'];
	$figure = $row['figure'];
?>

	<?
	if($_SERVER['REMOTE_ADDR'] == "127.0.0.1"){
		$IP = "127.0.0.1";
	}else{
		$IP = "87.210.125.64";
	}
	?>
	
	<?php
	if(isset($_GET['newGender'])){
		mysql_query("UPDATE users SET sex='".$_GET['newGender']."', figure='".$_GET['figureData']."' WHERE name='". $_SESSION['name']."'") or die (mysql_error());

		//Socket Part
			$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); 
			$connection = socket_connect($socket,"127.0.0.1","90") or die("Can't find the host."); 
			$packet = "XXUPDATE".$_SESSION['name']."";
			$packet_len = strlen($packet);
			$packet_len = B64EncodeLenght($packet_len);
			socket_write($socket,"@".$packet_len."".$packet."");
		//Socket Part		

		echo "Your ID is updated..";
		
		$query = mysql_query("SELECT * FROM users WHERE name='".$_SESSION['name']."'");
		$row = mysql_fetch_assoc($query);
		$hcDays = $row['clubDays'];
		$sex = $row['sex'];
		$figure = $row['figure'];		
	}
	?>
		<style>
		#flashcontent{
			background: url("updateBG.gif") no-repeat;
			padding-top: 10px;
			padding-left: 10px;
			width: 426;
			height: 347;
		}
		</style>
		<div id="flashcontent">
			<script type="text/javascript" language="JavaScript">
				var swfobj = new SWFObject("http://<? echo IPfix(); ?>HabboRegistration.swf", "habboreg", "406", "327", "7");
				swfobj.addParam("base", "http://<? echo IPfix(); ?>");
				swfobj.addVariable("post_url", "http://<? echo IPfix(); ?>update.php?");
				<?
				if($hcDays > 0){
				?>
				swfobj.addVariable("figuredata_url", "http://<? echo IPfix(); ?>figure_data_xml_hc.xml");
				<?}else{?>
				swfobj.addVariable("figuredata_url", "http://<? echo IPfix(); ?>figure_data_xml.xml");
				<?}?>
				swfobj.addVariable("localization_url", "http://<? echo IPfix(); ?>profile_editor.xml");
				swfobj.addVariable("post_figure", "figureData");
				swfobj.addVariable("post_gender", "newGender");
				swfobj.addVariable("figure", "<? echo $figure; ?>");
				swfobj.addVariable("gender", "<? echo $sex; ?>");
				swfobj.write("flashcontent");
			</script>
		</div>
<?
}else{
	echo "Please log in to view this page.";
}
?>