<?
die('don\'t!');

require('includes/global.inc.php');

if ($_GET['a'] == 'rogier') {
	$sql = "SELECT `id234234sdfsdfwer234234rtt5ete4t6w435r445`, `username` FROM $table[players] ORDER BY id";
	$res = mysql_query($sql);
	while ($rec = mysql_fetch_array($res)) {
		$galaxy_id = getRandomGalaxyId();
		$galaxy_spot = getFreeGalaxySpot($galaxy_id);
		$sql_update = "UPDATE $table[players] SET `galaxy_id` = '$galaxy_id', `galaxy_spot` = '$galaxy_spot' WHERE `id` = '$rec[id]'";
		mysql_query($sql_update) or die(mysql_query());
		echo $sql_update.'<br>';
	}
} else {
	echo 'hah, no!';
}
?>
		}
	} else {
		$error = 101;
	}
}

if ($do == 'changegalaxy') { 
	$password = secureData($_POST['password']);
	$sql_checkgal = "SELECT `id`, `x`, `y` FROM $table[galaxy] WHERE `private` = '1' AND `password` = '$password'";
	$res_checkgal = mysql_query($sql_checkgal);
	$num_checkgal = mysql_num_rows($res_checkgal);
	$rec_checkgal = mysql_fetch_array($res_checkgal);
	
	if ($num_checkgal > 0) {
		if (getFreeGalaxySpot($rec_checkgal['id'])) {
			$galaxy_spot = getFreeGalaxySpot($rec_checkgal['id']);
			if ($playerdata['id'] == getGalaxyCommander($playerdata['galaxy_id'])) {
				$sql_updgalcom = "UPDATE $table[galaxy] SET `commander_id` = '0', `moc_id` = '0', `mow_id` = '0', `moe_id` = '0' WHERE `id` = '$playerdata[galaxy_id]'";
			}
			if ($field = isPlayerMinister($playerdata['id'])) {
				$sql_updgalcom = "UPDATE $table[galaxy] SET `$field` = '0' WHERE `id` = '$playerdata[galaxy_id]'";
			}
			$playerdata['galaxy_id'] = $rec_checkgal['id'];
			$playerdata['galaxy_spot'] = $galaxy_spot;
			$playerdata['res_steel'] -= ($playerdata['res_steel'] * 0.3);
			$playerdata['res_crystal'] -= ($playerdata['res_crystal'] * 0.3);
			$playerdata['res_erbium'] -= ($playerdata['res_erbium'] * 0.3);
			$playerdata['res_titanium'] -= ($playerdata['res_titanium'] * 0.3);
			
			$sql_remvotes = "DELETE FROM $table[politics] WHERE `player_id` = '$playerdata[id]' OR `voted_on` = '$playerdata[id]'";
			mysql_query($sql_remvotes) or die(mysql_error());
	$password = secureData($_POST['password']);
	$password2 = secureData($_POST['password2']);
	$email = secureData($_POST['email']);
	$email2 = secureData($_POST['email2']);

	if (getIdByUsername($username)) { $msg = '<font color=red>That username is already taken.</font>'; }
	elseif (getIdByRulername($rulername)) { $msg = '<font color=red>That rulername is already taken.</font>'; }
	elseif (getIdByPlanetname($planetname)) { $msg = '<font color=red>That planetname is already taken.</font>'; }
	elseif (getIdByEmail($email)) { $msg = '<font color=red>The email address you\'re trying to use, is already taken.</font>'; }
	elseif ($password != $password2) { $msg = '<font color=red>The passwords don\'t match!</font>'; }
	elseif ($email != $email2) { $msg = '<font color=red>The e-mails don\'t match!</font>'; }
	elseif (!$username || !$planetname || !$password || !$password2 || !$email) { $msg = '<font color=red>Empty fields are not allowed.</font>'; }
	else {
		$activation_code = md5($username.time().$email.$secretcode); /* Generate a unique md5 has by using the username, current time, email address and a private code. */
		$galaxy_id = getRandomGalaxyId();
		if (getFreeGalaxySpot($galaxy_id)) { $galaxy_spot = getFreeGalaxySpot($galaxy_id); }
		else { $msg = 'Registration failed. Your data was inserted correctly, but the galaxy spot is not right. Contact the crew'; }
		$password = md5($password);
		$sql_newplayer = "INSERT INTO `$table[players]` (`username` , `password` , `email` , `activated` , `activation_code` , `rulername`,`planetname` , `galaxy_id` , `galaxy_spot`)
							VALUES ('$username', '$password', '$email', '0', '$activation_code', '$rulername','$planetname', '$galaxy_id', '$galaxy_spot')";
		mysql_query($sql_newplayer) or die(mysql_error());

		$msg = '<font color=green>Thank you for registration. You will be redirected to the login page in 3 seconds.<br>You can not login yet, please check your email inbox for the activation e-mail.</font>';

		$mail_subject = 'Welcome to Imperial-Battle!';
		$mail_body = '<p><font face="Verdana">Hello '.$username.'!</font></p>
						<p><font face="Verdana">Thank you for signup on this new great game!</font></p>
						<p><font face="Verdana">Your username is: '.$username.'<br>
						Your password is: '.$password2.'<br>
						<br>
						To activate your account, follow this link: