<?php
/*=======================================================================
| UberCMS - Advanced Website and Content Management System for uberEmu
| #######################################################################
| Copyright (c) 2010, Roy 'Meth0d' and updates by Matthew 'MDK'
| http://www.meth0d.org & http://www.sulake.biz
| #######################################################################
| This program is free software: you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation, either version 3 of the License, or
| (at your option) any later version.
| #######################################################################
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
\======================================================================*/

define('HIDE_FEEDBACK', true);

require_once "global.php";
require_once "inc/class.rooms.php";

if (!LOGGED_IN)
{
	header("Location: " . WWW. "/login_popup");
	exit;
}

$forwardType = 0;
$forwardId = 0;

$lang = '';
$habbo10 = '';

if (isset($_GET['lang']))
{
	$lang = $_GET['lang'];
}

switch ($lang)
{
        default:
	case "en":

		$lang = "";
        	dbquery("UPDATE users SET real_name = 'English' WHERE id = '" . USER_ID . "' LIMIT 1");
        	break;

	case "br":

        	$lang = "_br";
        	dbquery("UPDATE users SET real_name = 'Brazilian' WHERE id = '" . USER_ID . "' LIMIT 1");
        	break;

	case "de":

        	$lang = "_de";
        	dbquery("UPDATE users SET real_name = 'German' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;

	case "dk":

        	$lang = "_dk";
        	dbquery("UPDATE users SET real_name = 'Danish' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;

	case "es":

        	$lang = "_es";
        	dbquery("UPDATE users SET real_name = 'Spanish' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;

	case "fi":

		$lang = "_fi";
        	dbquery("UPDATE users SET real_name = 'Finnish' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;

	case "fr":

        	$lang = "_fr";
		dbquery("UPDATE users SET real_name = 'French' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;

	case "it":

        	$lang = "_it";
        	dbquery("UPDATE users SET real_name = 'Italian' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;

	case "jp":

        	$lang = "_jp";
        	$habbo10 = "_jp";
        	dbquery("UPDATE users SET real_name = 'Japanese' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;

	case "nl":

        	$lang = "_nl";
        	dbquery("UPDATE users SET real_name = 'Dutch' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;

	case "no":

        	$lang = "_no";
        	dbquery("UPDATE users SET real_name = 'Norwegian' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;

	case "se":

        	$lang = "_se";
        	dbquery("UPDATE users SET real_name = 'Swedish' WHERE id = '" . USER_ID . "' LIMIT 1");
		break;
}


if ($users->getUserVar(USER_ID, 'newbie_status') == "0")
{
	if (isset($_GET['createRoom']) && is_numeric($_GET['createRoom']))
	{
		$roomId = RoomManager::CreateRoom(USER_NAME . "'s kamer", USER_NAME, 'model_s');

		switch (intval($_GET['createRoom']))
		{
			default:
			case 0:
			
				RoomManager::PaintRoom($roomId, '1701', '601');
				break;
				
			case 1:
			
				RoomManager::PaintRoom($roomId, '607', '111');
				break;
				
			case 2:
			
				RoomManager::PaintRoom($roomId, '1901', '301');
				break;
				
			case 3:
			
				RoomManager::PaintRoom($roomId, '1801', '110');
				break;
				
			case 4:
			
				RoomManager::PaintRoom($roomId, '503', '104');
				break;
				
			case 5:
			
				RoomManager::PaintRoom($roomId, '804', '107');
				break;
		}

		//die('createRoom Result: ' . $roomId);
		dbquery("UPDATE users SET home_room = '" . $roomId . "', newbie_status = '1' WHERE id = '" . USER_ID . "' LIMIT 1");
		
		//$forwardType = 2;
		//$forwardId = $roomId;
	}
	else
	{
		header("Location: " . WWW . "/client?createRoom=" . rand(0, 5));
		exit;
	}
}
else if (isset($_GET['forwardType']) && isset($_GET['forwardId']) && is_numeric($_GET['forwardType']) && is_numeric($_GET['forwardId']))
{
	$forwardType = intval($_GET['forwardType']);
	$forwardId = intval($_GET['forwardId']);
	
	if ($forwardType >= 3 || $forwardType <= 0)
	{
		return;
	}
}

if ($users->GetUserVar(USER_ID, "newbie_status", false) == "1")
{
	dbquery("UPDATE users SET newbie_status = '2' WHERE id = '" . USER_ID . "' LIMIT 1");
}

$users->CheckSSO(USER_ID);

$tpl->Init();

$client = new Template('page-client-r63');

$client->SetParam('info_host', '127.0.0.1');
$client->SetParam('info_port', '30000');

$client->SetParam('flash_base', 'http://127.0.0.1/RELEASE57-27947-27946-201008260248_1079303621800c85173eddf186d0a4c8/');
$client->SetParam('flash_client_url', '%www%/client');
$client->SetParam('habbo10_swf', 'http://127.0.0.1/RELEASE57-27947-27946-201008260248_1079303621800c85173eddf186d0a4c8/Habbo10.swf');
$client->SetParam('external_flash_texts', 'http://127.0.0.1/RELEASE57-27947-27946-201008260248_1079303621800c85173eddf186d0a4c8/external_flash_texts.txt'.$lang);
$client->SetParam('external_variables', 'http://127.0.0.1/RELEASE57-27947-27946-201008260248_1079303621800c85173eddf186d0a4c8/external_variables.txt');

if (isset($_GET['forceTicket']) && $users->HasFuse(USER_ID, 'fuse_admin'))
{
	$client->SetParam('sso_ticket', $_GET['forceTicket']);
}
else
{
	$client->SetParam('sso_ticket', $users->GetUserVar(USER_ID, 'auth_ticket', false));
}

$tpl->AddTemplate($client);

$tpl->Output();
?>