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

$albumObj = new AlbumObj();

$template -> set_filenames(array(
		'page' => MODULE_PATH.'profiles/template/albumAdmin.htm'));

	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
		$albumObj->ProfileId = $_POST['ProfileId'];
		$albumObj->AlbumId = $_POST['AlbumId'];
		$albumObj->AlbumName = $_POST['AlbumName'];
		$albumObj->ReleaseDate = $_POST['ReleaseDate'];
		$albumObj->Producer = $_POST['Producer'];
		
		$albumMsg = $albumObj->UpdateAlbum();
		if(strpos($albumMsg, 'error'))
		{
			$template -> assign_block_vars('page_error', array());
			$template -> assign_block_vars('page_error.error_msg', array(
				'ERROR_MSG' => $albumMsg
			));
		} else {
			$template -> assign_block_vars('page_msg', array());
			$template -> assign_block_vars('page_msg.msg', array(
				'MSG' => $albumMsg
			));
		}
		
		foreach ($albumObj as $key => $value)
		{
			$albumObj->$key = stripslashes($value);
		}
	}
	else
	{
		if (isset($_GET['AlbumId']))
		{
			$albumObj->AlbumId = $_GET['AlbumId'];
			$albumObj->GetAlbum();
		}
		else
		{
			$albumObj->ProfileId = $_SESSION['UserProfileId'];
		}
	}


	$template -> assign_vars(array(
		'PROFILE_ID' => $albumObj->ProfileId,
		'ALBUM_ID' => $albumObj->AlbumId,
		'ALBUM_NAME' => $albumObj->AlbumName,
		'RELEASE_DATE' => $albumObj->ReleaseDate,
		'PRODUCER' => $albumObj->Producer
		));
		
	$trackList = $albumObj->Tracks;
	for($k=0; $k < count($trackList); $k++)
	{
	
		$template -> assign_block_vars('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
			));
	}

?>