<?php

	//Security
	if( ! defined( 'IS_INIT' ) )
	{
		die( 'Unauthorized Access');
	}
	
	global $Handler;
	
	$Handler->NewHandle( 'char' , new Characters( $Handler->user->UserOptions['nUserNo'] ) );
	
	if( LOGGED_IN == TRUE && ACC_LEVEL != GUEST )
	{
		$Handler->theme->SetValue( 'USER_NO' , $Handler->user->UserOptions['nUserNo'] );
		$Handler->theme->SetValue( 'SIDE_PANEL' ,
		"Hello, " . htmlentities( ucwords( strtolower( $_SESSION['UserID'] ) ) ) .
		"<br />Account Level : " . $Handler->user->UserOptions['nAuthID'].
		"<br />Risorial Coins : " . $Handler->user->UserOptions['cash'] .
		'<br /><a href="' . MAIN_URL . '?view=login&logout" style="position:absolute; display:block; margin-top:45px; margin-left:30px;">
		<button>Log Out!</button>
		</a>');
		
		($Handler->char->HasChars() == true ) ? $Handler->theme->SetValue( 'CHARS' ,  $Handler->char->FetchCharName() ) : $Handler->theme->SetValue( 'CHARS' , $Handler->theme->GetValue( 'NO_CHARS' ) ); 
		
		if( isset( $_GET['do'] ) )
		{
			switch( $_GET['do' ] )
			{
				default:
						include( PAGE_PATH . 'cp/main.php' );
				case "characters":
						include( PAGE_PATH . 'cp/characters.php' );
					break;
				case "mall":
						include( PAGE_PATH . '/cp/mall.php');
					break;
				case "settings":
						include( PAGE_PATH . '/cp/settings.php' );
					break;
			}
		}
		else
		{
			include( PAGE_PATH . 'cp/main.php' );
		}
		
		$Handler->theme->Parse( 'cp.html' );
	}
	else
	{
		$Handler->theme->SetValue( 'ERROR' , $Handler->theme->GetValue( 'ERROR_NOT_LOGGED_IN' ) );
		$Handler->theme->SetValue( 'GO_BACK' , $Handler->theme->GetValue( 'GO_LOGIN' ) );
		$Handler->theme->SetValue( 'RED_URL' , MAIN_URL . '?view=login' );
		$Handler->theme->Parse( 'error.html' );
	}
	
	?>