<?php
/*=======================================================================
| UberWeb - Lightweight site system for Uber
| #######################################################################
| Copyright (c) 2009, Roy 'Meth0d'
| http://www.meth0d.org
| #######################################################################
| 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;

if ($users->getUserVar(USER_ID, 'newbie_status') == "0")
{
	if (isset($_GET['createRoom']) && is_numeric($_GET['createRoom']))
	{

		switch (intval($_GET['createRoom']))
		{
			default:
			case 0:
				$roomId = RoomManager::CreateRoom(USER_NAME . "'s room", USER_NAME, 'model_a');
				RoomManager::PaintRoom($roomId, '607', '111');
				break;
				
			case 1:
				
				$roomId = RoomManager::CreateRoom(USER_NAME . "'s room", USER_NAME, 'model_a');
				RoomManager::PaintRoom($roomId, '607', '111');
				break;
				
			case 2:
				$roomId = RoomManager::CreateRoom(USER_NAME . "'s room", USER_NAME, 'model_a');
				RoomManager::PaintRoom($roomId, '1901', '301');
				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;
	}
}
if (isset($_GET['goto']) && is_numeric($_GET['goto']))
{
	dbquery("UPDATE users SET forward_active = '1' WHERE username = '".USER_NAME."' LIMIT 1");
	dbquery("UPDATE users SET forward_room = '".$_GET['goto']."' WHERE username = '".USER_NAME."' LIMIT 1");
}


$users->CheckSSO(USER_ID);

$tpl->Init();

$tpl->AddGeneric('head-init');
$tpl->AddIncludeSet('default');
$tpl->AddIncludeFile(new IncludeFile('text/css', '%www%/web-gallery/v2/styles/habboclient.css', 'stylesheet'));
$tpl->AddIncludeFile(new IncludeFile('text/css', '%www%/web-gallery/v2/styles/habboflashclient.css', 'stylesheet'));
$tpl->AddIncludeFile(new IncludeFile('text/javascript', '%www%/web-gallery/static/js/habboflashclient.js'));			
$tpl->WriteIncludeFiles();
$tpl->AddGeneric('head-bottom');

$client = new Template('page-client');
$client->SetParam('page_title', ' ~ Client');
$client->SetParam('hostaddr', $core->GetVar('gameip'));
$client->SetParam('hostport', $core->GetVar('gameport'));
$client->SetParam('sso_ticket', $users->GetUserVar(USER_ID, 'auth_ticket', false));
$client->SetParam('flash_base', $core->GetVar('swf_path'));
$client->SetParam('movie', $core->GetVar('habbo.swf'));
$client->SetParam('hoffurni', $core->GetVar('dynamic.download.url'));
$client->SetParam('variabls', $core->GetVar('variables'));
$client->SetParam('textes', $core->GetVar('texts'));
$client->SetParam('productdata', $core->GetVar('productdata'));
$client->SetParam('furnidata', $core->GetVar('furnidata'));
$client->SetParam('hotel_status', $core->GetUsersOnline() . ' users online now!');
$client->SetParam('forwardType', $forwardType);
$client->SetParam('forwardId', $forwardId);

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

$tpl->AddTemplate($client);

$tpl->Output();

?>