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

class ProfileObj
{
	public function GetProfile()
	{
		$query = <<<EOD
			SELECT
				*
			FROM
				Profiles
			WHERE
EOD;
		if($this -> ProfileId != '') {
			$query .= " ProfileId = {$this->ProfileId}";
		} 
		else
		{
			$query .= " ProfileName = '{$this->ProfileName}'";
		}

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$row = mysql_fetch_assoc($result);
		
		$this -> ProfileId = $row['ProfileId'];
		$this -> ProfileName = $row['ProfileName'];
		
		$this -> HasAlbums = $row['HasAlbums'];
		$this -> HasMembers = $row['HasMembers'];
		
		$this -> DisplayName = $row['DisplayName'];
		$this -> HomeTown = $row['HomeTown'];
		$this -> CurrentLocation = $row['CurrentLocation'];
		$this -> EmailAddress = $row['EmailAddress'];
		$this -> OfficalWebsite = $row['OfficalWebsite'];	
		$this -> MissionStatement = $row['MissionStatement'];
		$this -> ShortBiography = $row['ShortBiography'];
		$this -> Biography = $row['Biography'];
		$this -> Genre = $row['Genre'];
		$this -> MusicalStyle = $row['MusicalStyle'];
		$this -> Instruments = $row['Instruments'];
		$this -> MusicLabel = $row['MusicLabel'];
		$this -> DateFounded = $row['DateFounded'];
		
		$imageObj = new ImageObj();
		$this -> ProfileImage = $imageObj->GetProfileImage($this -> ProfileId);
		
		if($this -> ProfileId != null)
		{
			if ($this -> HasAlbums)
			{
				$albumObj = new AlbumObj();
				$trackObj = new TrackObj();
				$this -> Albums = $albumObj->GetAlbums($this -> ProfileId);
				$this -> FeaturedTracks = $trackObj->GetFeaturedTracks($this -> ProfileId);
				$this -> Singles = $trackObj->GetSingles($this -> ProfileId);
			}
			
			$linksObj = new LinksObj();
			$this -> SocialMediaLinks = $linksObj->GetSocialMediaLinks($this -> ProfileId);
			$this -> ExternalLinks = $linksObj->GetExternalLinks($this -> ProfileId);
			
			if ($this -> HasMembers)
			{
				$memberObj = new MemberObj();
				$this -> CurrentMembers = $memberObj->GetCurrentMembers($this -> ProfileId, true);
				$this -> PreviousMembers = $memberObj->GetCurrentMembers($this -> ProfileId, false);
			}
			
			$commentsObj = new CommentsObj();
			$this -> Comments = $commentsObj->GetComments($this->ProfileId);
		}
	}
	
	public function UpdateProfile() {
		if($this -> ProfileId != '') {
			$query = <<<EOD
				UPDATE
					Profiles
				SET
					DisplayName = '{$this->DisplayName}',
					HomeTown = '{$this->HomeTown}',
					CurrentLocation = '{$this->CurrentLocation}',
					EmailAddress = '{$this->EmailAddress}',
					OfficalWebsite = '{$this->OfficalWebsite}',
					MissionStatement = '{$this->MissionStatement}',
					ShortBiography = '{$this->ShortBiography}',
					Biography = '{$this->Biography}',
					Genre = '{$this->Genre}',
					MusicalStyle = '{$this->MusicalStyle}',
					Instruments = '{$this->Instruments}',
					MusicLabel = '{$this->MusicLabel}',
					DateFounded = '{$this->DateFounded}'
				WHERE
					ProfileId = {$this->ProfileId}
EOD;
			$result = mysql_query($query);
			$userMsg = "Profile information has successfully updated.";
		} else {
			$query = <<<EOD
				INSERT INTO
					Profiles
					(ProfileName, 
					DisplayName,
					HomeTown,
					CurrentLocation,
					EmailAddress,
					OfficalWebsite,
					MissionStatement,
					ShortBiography,
					Biography,
					Genre,
					MusicalStyle,
					Instruments,
					MusicLabel,
					DateFounded)
				VALUES
					('{$this->ProfileName}',
					'{$this->DisplayName}',
					'{$this->HomeTown}',
					'{$this->CurrentLocation}',
					'{$this->EmailAddress}',
					'{$this->OfficalWebsite}',
					'{$this->MissionStatement}',
					'{$this->ShortBiography}',
					'{$this->Biography}',
					'{$this->Genre}',
					'{$this->MusicalStyle}',
					'{$this->Instruments}',
					'{$this->MusicLabel}',
					'{$this->DateFounded}')
EOD;

			$result = mysql_query($query) or die(mysql_error()."<br>".$query);
			$this -> ProfileId = mysql_insert_id();
			$userMsg = "Profile 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;
	}
}
?>