<?
// 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);

// Load the configuration for this instance of bandTopia
require ("include/config.php");

// Starts the processing for the page.
require (INCLUDE_PATH."pageStart.php");

// Set main html page to use for page
$template -> set_filenames(array(
	"body" => "main.htm"));
	
// Start Navigation
$nav = '<a href="index.php">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());
}

/******************************************************/
/*  Login Page                                        */
/******************************************************/
if($action == 'login') 
{
	// Jason needs to do in the future.
}
elseif($action == 'userpage') {
	include('modules/core/userpage.php');
}
/******************************************************/
/*  Main Page                                         */
/******************************************************/
elseif($action == 'main')
{
	$template -> assign_block_vars("page_main",array());
	$profileOn = false;
	
	if(!is_null(ARTIST_ID)) {
		$template -> assign_block_vars("page_main.artist_cp",array());
	}
}
/******************************************************/
/*  Profile Page
/******************************************************/
elseif($action == 'artistdisplay')
{ 
	include('modules/core/artistdisplay.php');
}
elseif($action == 'addFav')
{
	//form processing for adding a favorite band
	if($_SERVER['REQUEST_METHOD'] == 'POST') {
		$r = mysql_query("INSERT INTO FavArtists(UserId,ArtistId,StreetTeam) VALUES('{SESSION_USERID}','{$_GET['aID']}', 0)") or die(mysql_error()); 
		$template -> assign_block_vars('dynamic_page', array(
			"CONTENT" => "Artist has been added to your favorites."));
	}
}
elseif($action == 'artist_profile') {
 header("Location: /promotion/artist_profile.php");//?UserId=".$userObj->get_UserId());
}
/******************************************************/
/*  Profile Page
/******************************************************/
elseif($action == 'bandfinder')
{
	include("modules/core/bandfinder.php");
}



/******************************************************/
/*  Signup Page                                        */
/******************************************************/
elseif($action == 'signup') 
{
	$template -> assign_block_vars("page_signup",array());
	$userTypeObj = new UserTypeObj;
	$userTypeList = $userTypeObj -> UserTypeList();
	foreach ($userTypeList as $key)
	{
		$template -> assign_block_vars("page_signup.user_type", array(
			"USER_TYPE_ID" => $key->get_user_type_id(),
			"USER_TYPE" => $key->get_user_type_title()));
	}
}
elseif($action == 'signupsubmit')
{
	$userObj = new UserObj();
	$userObj -> set_UserName($_POST['username']);
	$userObj -> set_Password($_POST['password']);
	$userObj -> set_FirstName($_POST['firstname']);
	$userObj -> set_LastName($_POST['lastname']);
	$userObj -> set_UserTypeId($_POST['usertypeid']);
	$userMsg = $userObj -> updateUser();
	
	if($userMsg == "User has been added successfully.")
	{
		switch($userObj -> get_UserTypeId())
		{
			case 1:
			case 3:
				header("Location: index.php?action=artistAdd&prev_action=signupsubmit&UserId=".$userObj->get_UserId());
				break;
			default:
				header("Location: index.php?action=main");
				break;
		}				
	}
}
/******************************************************/
/*  Artist Add Page                                        */
/******************************************************/
elseif($action == 'artistAdd') 
{
	$template -> assign_block_vars("page_artistAdd",array());
	$template -> assign_var("USERID", $_GET['UserId']);
}
elseif($action == 'artistAddsubmit')
{
	$artistObj = new ArtistObj();
	$artistObj -> set_Name($_POST['name']);
	$artistObj -> set_Address($_POST['address']);
	$artistObj -> set_City($_POST['city']);
	$artistObj -> set_State($_POST['state']);
	$artistObj -> set_Phone($_POST['phone']);
	$artistObj -> set_Email($_POST['email']);
	$artistObj -> set_URL($_POST['url']);
	$artistObj -> set_Bio($_POST['bio']);
	$artistObj -> set_UserId($_POST['userid']);
	$artistMsg = $artistObj -> updateArtist();
	
	if($artistMsg == "Artist has been added successfully.")
	{
		header("Location: index.php?action=main");
	}
}
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");
?>