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

$profileObj = new ProfileObj();

$template -> set_filenames(array(
		'page' => MODULE_PATH.'profiles/template/profile.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->Instrements = $_POST['Instrements'];
		$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' => $accountMsg
			));
		} 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
	{
		$profileObj->ProfileId = _GET['ProfileId'];
		$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,
		'INSTREMENTS' => $profileObj->Instrements,
		'MUSIC_LABEL' => $profileObj->MusicLabel,
		'DATE_FOUNDED' => $profileObj->DateFounded
		));
		
	
	$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
			));
	}
	
	$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(
				'LINK_ID' => $albumList[$i]->AlbumId,
				'LINK_NAME' => $albumList[$i]->AlbumName,
				'LINK_URL' => $albumList[$i]->ReleaseDate,
				'LINK_ICON' => $albumList[$i]->Producer
				));
				
			$trackList = $albumList[$i]->Tracks;
			for($k=0; $k < count($trackList); $k++)
			{
				$template -> assign_block_vars('albums.tracks', array(
					'LINK_ID' => $trackList[$k]->TrackId,
					'LINK_NAME' => $trackList[$k]->TrackName,
					'LINK_URL' => $trackList[$k]->TrackLength,
					'LINK_ICON' => $trackList[$k]->Producer
					));
					
				
			}
		}
	}
?>