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

class MediaObj
{
    public function GetMediaList($mediaGroupId)
	{
		$query = <<<EOD
			SELECT
				*
			FROM
				Media
			WHERE
				 MediaGroupId = {$mediaGroupId}
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$mediaArray = array();

		while($row = mysql_fetch_assoc($result)) {
			$tempObj = new MediaObj;
			$tempObj -> ProfileId = $row['ProfileId'];
			$tempObj -> MediaGroupId = $row['MediaGroupId'];
			$tempObj -> MediaId = $row['MediaId'];
			$tempObj -> MediaName = $row['MeidaName'];
			$tempObj -> MediaLocation = $row['MediaLocation'];			
			
			$mediaArray[] = $tempObj;
		}
		
		return $mediaArray;
	}
	
	public function GetMedia()
	{

		$query = <<<EOD
			SELECT
				*
			FROM
				Media
			WHERE
				 MediaId = {$this->MediaId}
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$row = mysql_fetch_assoc($result);
		
			$this -> ProfileId = $row['ProfileId'];
			$this -> MediaGroupId = $row['MediaGroupId'];
			$this -> MediaId = $row['MediaId'];
			$this -> MediaName = $row['MeidaName'];			
			$this -> MediaLocation = $row['MediaLocation'];
			
	}
	
	public function UpdateMedia()
	{
		if($this -> MediaId != '') {
			$query = <<<EOD
				UPDATE
					Media
				SET
					ProfileId = {$this->ProfileId},
					MediaGroupId = {$this->MediaGroupId},
					MediaName = '{$this->MediaName}',
					MediaLocation = '{$this->MediaLocation}'
				WHERE
					MediaId = {$this->MediaId}
EOD;
			$result = mysql_query($query);
			$userMsg = "Media information has successfully updated.";
		} else {
			$query = <<<EOD
				INSERT INTO
					Media
					(ProfileId, 
					MediaGroupId,
					MediaName,
					MediaLocation)
				VALUES
					({$this->ProfileId},
					'{$this->MediaGroupId}',
					'{$this->MediaName}',
					'{$this->MediaLocation}')
EOD;

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