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

class AlbumObj
{
    public function GetAlbums($profileId)
	{
		$query = <<<EOD
			SELECT
				*
			FROM
				Albums
			WHERE
				 ProfileId = {$profileId}
			ORDER BY 
				ReleaseDate desc
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$albumArray = array();
		$trackObj = new TrackObj();
		while($row = mysql_fetch_assoc($result)) {
			$tempObj = new AlbumObj;
			$tempObj -> ProfileId = $row['ProfileId'];
			$tempObj -> AlbumId = $row['AlbumId'];
			$tempObj -> AlbumName = $row['AlbumName'];
			$tempObj -> ReleaseDate = $row['ReleaseDate'];
			$tempObj -> Producer = $row['Producer'];
			
			
			$tempObj -> Tracks = $trackObj->GetTracks($tempObj -> AlbumId);
			
			$albumArray[] = $tempObj;
		}
		
		return $albumArray;
	}
	
	public function GetAlbum()
	{

		$query = <<<EOD
			SELECT
				*
			FROM
				Albums
			WHERE
				 AlbumId = {$this->AlbumId}
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$trackObj = new TrackObj();
		$row = mysql_fetch_assoc($result);
		
			$this -> ProfileId = $row['ProfileId'];
			$this -> AlbumId = $row['AlbumId'];
			$this -> AlbumName = $row['AlbumName'];
			$this -> ReleaseDate = $row['ReleaseDate'];
			$this -> Producer = $row['Producer'];
			
			$this -> Tracks = $trackObj->GetTracks($this -> AlbumId);
	}
	
	public function UpdateAlbum()
	{
		if($this -> AlbumId != '') {
			$query = <<<EOD
				UPDATE
					Albums
				SET
					ProfileId = {$this->ProfileId},
					AlbumName = '{$this->AlbumName}',
					ReleaseDate = '{$this->ReleaseDate}',
					Producer = '{$this->Producer}'
				WHERE
					AlbumId = {$this->AlbumId}
EOD;
			$result = mysql_query($query);
			$userMsg = "Album information has successfully updated.";
		} else {
			$query = <<<EOD
				INSERT INTO
					Albums
					(ProfileId, 
					AlbumName,
					ReleaseDate,
					Producer)
				VALUES
					({$this->ProfileId},
					'{$this->AlbumName}',
					'{$this->ReleaseDate}',
					'{$this->Producer}')
EOD;

			$result = mysql_query($query) or die(mysql_error()."<br>".$query);
			$this -> AlbumId = mysql_insert_id();
			$userMsg = "Album has been added successfully.";
		}
		if(mysql_error() != '') {
			$userMsg = "An error has occurred while attempting your request.  Please try again.  If you continue to experience problems, please contact the site administrator<br>";
			$userMsg .= mysql_error() . "<br>$query";
			die($userMsg);
		}
		return $userMsg;
	}
}
?>