<?
if (!defined('IN_BANDTOPIA'))
{
	exit;
}

$profileObj = new ProfileObj();

if ($action == 'profileHome')
{
$template -> set_filenames(array(
		'page' => MODULE_PATH.'profiles/template/profile.htm'));
}
else if ($action == 'profileAdmin')
{
	$template -> set_filenames(array(
		'page' => MODULE_PATH.'profiles/template/profileAdmin.htm'));
}

	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
		$profileObj->ProfileId = $_POST['ProfileId'];
		$profileObj->ProfileName = $_POST['ProfileName'];
		$profileObj->HasAlbums = $_POST['HasAlbums'];
		$profileObj->HasMembers = $_POST['HasMembers'];
		$profileObj->DisplayName = $_POST['DisplayName'];
		$profileObj->HomeTown = $_POST['HomeTown'];
		$profileObj->CurrentLocation = $_POST['CurrentLocation'];
		$profileObj->EmailAddress = $_POST['EmailAddress'];
		$profileObj->OfficalWebsite = $_POST['OfficalWebsite'];
		$profileObj->MissionStatement = $_POST['MissionStatement'];
		$profileObj->ShortBiography = $_POST['ShortBiography'];
		$profileObj->Biography = $_POST['Biography'];
		$profileObj->Genre = $_POST['Genre'];
		$profileObj->MusicalStyle = $_POST['MusicalStyle'];
		$profileObj->Instruments = $_POST['Instruments'];
		$profileObj->MusicLabel = $_POST['MusicLabel'];
		$profileObj->DateFounded = $_POST['DateFounded'];
		
		$profileMsg = $profileObj->UpdateProfile();
		if(strpos($profileMsg, 'error'))
		{
			$template -> assign_block_vars('page_error', array());
			$template -> assign_block_vars('page_error.error_msg', array(
				'ERROR_MSG' => $profileMsg
			));
		} else {
			$template -> assign_block_vars('page_msg', array());
			$template -> assign_block_vars('page_msg.msg', array(
				'MSG' => $profileMsg
			));
		}
		
		foreach ($profileObj as $key => $value)
		{
			$profileObj->$key = stripslashes($value);
		}
	}
	else
	{
		if (isset($_GET['ProfileId']))
		{
			$profileObj->ProfileId = $_GET['ProfileId'];
		}
		else if (isset($_SESSION['UserProfileId']))
		{
			$profileObj->ProfileId = $_SESSION['UserProfileId'];
		}
		else if (isset($_GET['ProfileName']))
		{
			$profileObj->ProfileName = $_GET['ProfileName'];
		}
		$profileObj->GetProfile();
	}
	
	$template -> assign_vars(array(
		'PROFILE_ID' => $profileObj->ProfileId,
		'PROFILE_NAME' => $profileObj->ProfileName,
		'HAS_ALBUMS' => $profileObj->HasAlbums,
		'HAS_MEMBERS' => $profileObj->HasMembers,
		'DISPLAY_NAME' => $profileObj->DisplayName,
		'HOME_TOWN' => $profileObj->HomeTown,
		'CURRENT_LOCATION' => $profileObj->CurrentLocation,
		'EMAIL_ADDRESS' => $profileObj->EmailAddress,
		'OFFICAL_WEBSITE' => $profileObj->OfficalWebsite,
		'MISSION_STATEMENT' => $profileObj->MissionStatement,
		'SHORT_BIOGRAPHY' => $profileObj->ShortBiography,
		'BIOGRAPHY' => $profileObj->Biography,
		'GENRE' => $profileObj->Genre,
		'MUSICAL_STYLE' => $profileObj->MusicalStyle,
		'INSTRUMENTS' => $profileObj->Instruments,
		'MUSIC_LABEL' => $profileObj->MusicLabel,
		'DATE_FOUNDED' => $profileObj->DateFounded,
		'PROFILE_IMAGE' => $profileObj->ProfileImage
		));
		
	
	$socialMediaList = $profileObj->SocialMediaLinks;
	for($i=0; $i < count($socialMediaList); $i++)
	{
		/*
		$template -> assign_block_vars('social_media', array(
			'LINK_ID' => $socialMediaList[$i]->LinkId,
			'LINK_NAME' => $socialMediaList[$i]->LinkName,
			'LINK_URL' => $socialMediaList[$i]->LinkUrl,
			'LINK_ICON' => $socialMediaList[$i]->LinkIcon,
			'SOCIAL_MEDIA_TYPE' => $socialMediaList[$i]->SocialMediaType,
			'SOCIAL_MEDIA_ACCOUNT_NAME' => $socialMediaList[$i]->SocialMediaAccountName
			));
			*/
		if ($socialMediaList[$i]->SocialMediaType == 1)
		{
			$template -> assign_block_vars('social_media', array(
				'FULL_LINK_DATA' => '<a href="http://twitter.com/' . $socialMediaList[$i]->SocialMediaAccountName . '"  target="_blank"><img src="/images/twitter_logo.png" border=0 /></a>'));
		}
		else if ($socialMediaList[$i]->SocialMediaType == 2)
		{
			$template -> assign_block_vars('social_media', array(
				'FULL_LINK_DATA' => '<a href="http://www.facebook.com/'.$socialMediaList[$i]->SocialMediaAccountName.'" target="_blank"><img src="/images/facebook_logo.png" border=0 /></a>'));
		}
		else
		{
			$template -> assign_block_vars('social_media', array(
				'FULL_LINK_DATA' => '<a href="' . $socialMediaList[$i]->LinkUrl . '">' . $socialMediaList[$i]->LinkName.'</a>'));
		}
	}
	
	$externalLinkList = $profileObj->ExternalLinks;
	for($i=0; $i < count($externalLinkList); $i++)
	{
		$template -> assign_block_vars('external_links', array(
			'LINK_ID' => $externalLinkList[$i]->LinkId,
			'LINK_NAME' => $externalLinkList[$i]->LinkName,
			'LINK_URL' => $externalLinkList[$i]->LinkUrl,
			'LINK_ICON' => $externalLinkList[$i]->LinkIcon
			));
			

	}
	
	if ($profileObj->HasAlbums)
	{
		$albumList = $profileObj->Albums;
		for($i=0; $i < count($albumList); $i++)
		{
			$template -> assign_block_vars('albums', array(
				'ALBUM_ID' => $albumList[$i]->AlbumId,
				'ALBUM_NAME' => $albumList[$i]->AlbumName,
				'RELEASE_DATE' => $albumList[$i]->ReleaseDate,
				'PRODUCER' => $albumList[$i]->Producer
				));
				

			$trackList = $albumList[$i]->Tracks;
			for($k=0; $k < count($trackList); $k++)
			{
			
				$template -> assign_block_vars('albums.tracks', array(
					'TRACK_ID' => $trackList[$k]->TrackId,
					'TRACK_NAME' => $trackList[$k]->TrackName,
					'TRACK_LENGTH' => $trackList[$k]->TrackLength,
					'RELEASE_DATE' => $trackList[$k]->ReleaseDate,
					'PRODUCER' => $trackList[$k]->Producer,
					'IS_FEATURED' => $trackList[$k]->IsFeatured,
					'IS_SINGLE' => $trackList[$k]->IsSingle,
					));
			}
		}
		
		$featuredTrackList = $profileObj->FeaturedTracks;
		for($k=0; $k < count($featuredTrackList); $k++)
		{
			$template -> assign_block_vars('featured_tracks', array(
				'TRACK_ID' => $featuredTrackList[$k]->TrackId,
				'TRACK_NAME' => $featuredTrackList[$k]->TrackName,
				'TRACK_LENGTH' => $featuredTrackList[$k]->TrackLength,
				'RELEASE_DATE' => $featuredTrackList[$k]->ReleaseDate,
				'PRODUCER' => $featuredTrackList[$k]->Producer,
				'IS_FEATURED' => $featuredTrackList[$k]->IsFeatured,
				'IS_SINGLE' => $featuredTrackList[$k]->IsSingle,
				));
		}
		
		$singleTrackList = $profileObj->Singles;
		for($k=0; $k < count($singleTrackList); $k++)
		{
			$template -> assign_block_vars('single_tracks', array(
				'TRACK_ID' => $singleTrackList[$k]->TrackId,
				'TRACK_NAME' => $singleTrackList[$k]->TrackName,
				'TRACK_LENGTH' => $singleTrackList[$k]->TrackLength,
				'RELEASE_DATE' => $singleTrackList[$k]->ReleaseDate,
				'PRODUCER' => $singleTrackList[$k]->Producer,
				'IS_FEATURED' => $singleTrackList[$k]->IsFeatured,
				'IS_SINGLE' => $singleTrackList[$k]->IsSingle,
				));
		}
	}
	
	if ($profileObj->HasMembers)
	{
		$currentMemberList = $profileObj->CurrentMembers;
		for($i=0; $i < count($currentMemberList); $i++)
		{
			$template -> assign_block_vars('current_members', array(
				'MEMBER_PROFILE_ID' => $currentMemberList[$i]->MemberProfileId,
				'MEMBER_ID' => $currentMemberList[$i]->MemberId,
				'MEMBER_NAME' => $currentMemberList[$i]->MemberName,
				'ROLE' => $currentMemberList[$i]->Role,
				'IS_CURRENT_MEMBER' => $currentMemberList[$i]->IsCurrentMember
				));
		}
		
		$previousMemberList = $profileObj->PreviousMembers;
		for($i=0; $i < count($previousMemberList); $i++)
		{
			$template -> assign_block_vars('previous_members', array(
				'MEMBER_PROFILE_ID' => $previousMemberList[$i]->MemberProfileId,
				'MEMBER_ID' => $previousMemberList[$i]->MemberId,
				'MEMBER_NAME' => $previousMemberList[$i]->MemberName,
				'ROLE' => $previousMemberList[$i]->Role,
				'IS_CURRENT_MEMBER' => $previousMemberList[$i]->IsCurrentMember
				));
		}
	}
	
	$currentComments = $profileObj->Comments;
	for($i=0; $i < count($currentComments); $i++)
	{
		$template -> assign_block_vars('current_comments', array(
			'COMMENT_ID' => $currentComments[$i]->CommentId,
			'POSTED_DATE' => $currentComments[$i]->PostedDate,
			'POSTED_USER_ID' => $currentComments[$i]->PostedUserId,
			'COMMENT' => $currentComments[$i]->Comment,
			'LIKES' => $currentComments[$i]->Likes,
			'DISLIKES' => $currentComments[$i]->DisLikes,
			'IS_HIDDEN' => $currentComments[$i]->IsHidden,
			'IS_APPROVED' => $currentComments[$i]->IsApproved
		));
	}
	
?>