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

class MediaGroupObj
{
    public function GetMediaGroups($profileId)
	{
		$query = <<<EOD
			SELECT
				*
			FROM
				MeidaGroups
			WHERE
				 ProfileId = {$profileId}
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$mediaGroupArray = array();
		$mediaObj = new MediaObj();
		while($row = mysql_fetch_assoc($result)) {
			$tempObj = new MediaGroupObj;
			$tempObj -> ProfileId = $row['ProfileId'];
			$tempObj -> MediaGroupId = $row['MediaGroupId'];
			$tempObj -> MediaGroupName = $row['MeidaGroupName'];			
			
			$tempObj -> Media = $mediaObj->GetMediaList($tempObj -> MediaGroupId);
			
			$mediaGroupArray[] = $tempObj;
		}
		
		return $mediaGroupArray;
	}
	
	public function GetMediaGroup()
	{

		$query = <<<EOD
			SELECT
				*
			FROM
				MediaGroups
			WHERE
				 MediaGroupId = {$this->MediaGroupId}
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$mediaObj = new MediaObj();
		$row = mysql_fetch_assoc($result);
		
			$this -> ProfileId = $row['ProfileId'];
			$this -> MediaGroupId = $row['MediaGroupId'];
			$this -> MediaGroupName = $row['MediaGroupName'];			
			
			$this -> Media = $mediaObj->GetMediaList($this -> MediaGroupId);
	}
	
	public function UpdateMediaGroup()
	{
		if($this -> MediaGroupId != '') {
			$query = <<<EOD
				UPDATE
					MediaGroups
				SET
					ProfileId = {$this->ProfileId},
					MediaGroupName = '{$this->MediaGroupName}'
				WHERE
					MediaGroupId = {$this->MediaGroupId}
EOD;
			$result = mysql_query($query);
			$userMsg = "Media Group information has successfully updated.";
		} else {
			$query = <<<EOD
				INSERT INTO
					MediaGroups
					(ProfileId, 
					MediaGroupName)
				VALUES
					({$this->ProfileId},
					'{$this->MediaGroupName}')
EOD;

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