<?
// This ensures all code knows it's being called by the bandTopia app
// If this variable is missing when another page is loaded.  It will redirect to bandTopia home.
define('IN_BANDTOPIA', "You're here!!!");

ini_set("display_errors","1");
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);

include("../include/config.php");

$templateStyle = 'cr';

include(INCLUDE_PATH."pageStart.php");

// Confirms the two security session variables are set
if(isset($_SESSION['HTTP_USER_AGENT']) && isset($_SESSION['lskejd'])) {
	
	// Creates concat string to verify against
	$string = $_SERVER['HTTP_USER_AGENT'];
	$string .= 'h8er89pkd3!';
	
	// if security session variables do not match what's expected, then redirect to login
	if($_SESSION['HTTP_USER_AGENT'] != md5($_SERVER['HTTP_USER_AGENT']) || $_SESSION['lskejd'] != md5($string)) {
		header("Location: ../index.php?action=login&cause=invalid&prev_action={$action}");
	} 
}

// Set main html page to use for page
$template -> set_filenames(array(
	"body" => SERVER_PATH."cr/template/main.htm"));
	
// Start Navigation
$nav = '<a href="index.php">Control Room Home</a>';

if(defined('LOGGEDIN')) {
	$template -> assign_block_vars("logged_in", array());
	$staffArray = array(2,4);

	if(in_array($_SESSION['UserTypeId'],$staffArray)) 
	{
		$template -> assign_block_vars("logged_in.staff_user", array());
	}
}
else {
	$template -> assign_block_vars("logged_out", array());
}

/******************************************************/
/*  Main Page                                         */
/******************************************************/
if (isset($_REQUEST['oauth_verifier']))
{
	$action = 'twitterAccess';
}
if($action == 'main')
{
	$template -> assign_block_vars("page_main",array());
	
	$template -> assign_block_vars("page_main.profileMain", array());
	
	$template -> assign_block_vars("page_main.promoteMain", array());
	
	$template -> assign_block_vars("page_main.performMain", array());
	
	$template -> assign_block_vars("page_main.professionMain", array());
}

/******************************************************/
/*  Profile Page
/******************************************************/
elseif($action == 'profileHome' || $action == 'profileAdmin')
{
	include(MODULE_PATH.'profiles/profile.php');
}
elseif($action == 'albumAdmin')
{
	include(MODULE_PATH.'profiles/album.php');
}
elseif($action == 'linkAdmin')
{
	include(MODULE_PATH.'profiles/link.php');
}
elseif($action == 'twitterStart')
{
	include(MODULE_PATH.'profiles/link.php');
}
elseif($action == 'twitterAccess')
{
	include(MODULE_PATH.'profiles/link.php');
}
elseif($action == 'memberAdmin')
{
	include(MODULE_PATH.'profiles/member.php');
}
elseif($action == 'trackAdmin')
{
	include(MODULE_PATH.'profiles/track.php');
}
elseif($action == 'commentAdmin')
{
	include(MODULE_PATH.'profiles/comment.php');
}
elseif($action == 'mediaAdmin')
{
	include(MODULE_PATH.'profiles/media.php');
}
elseif($action == 'mediaGroupAdmin')
{
	include(MODULE_PATH.'profiles/mediagroup.php');
}
/******************************************************/
/*  Error Page                                        */
/******************************************************/
else
{
	$template -> assign_block_vars("page_error",array());
	$template -> assign_block_vars("page_error.action", array());
}
if($action != 'login')
{
	$template -> assign_block_vars("logout", array());
}

$template->assign_var('NAV',$nav);

include(INCLUDE_PATH."pageend.php");
