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

class MemberObj
{
    public function GetCurrentMembers($profileId, $isCurrent)
	{
		$isCur = $isCurrent ? 1 : 0;
		
		$query = <<<EOD
			SELECT
				*
			FROM
				Members
			WHERE
				 MainProfileId = $profileId
				 AND IsCurrentMember = $isCur
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$memberArray = array();
		while($row = mysql_fetch_assoc($result)) {
			$tempObj = new MemberObj;
			$tempObj -> MainProfileId = $row['MainProfileId'];
			$tempObj -> MemberProfileId = $row['MemberProfileId'];
			$tempObj -> MemberId = $row['MemberId'];
			$tempObj -> MemberName = $row['MemberName'];
			$tempObj -> Role = $row['Role'];
			$tempObj -> IsCurrentMember = $row['IsCurrentMember']; 
			
			$memberArray[] = $tempObj;
		}
		
		return $memberArray;
	}
	
	public function GetMember()
	{
		$query = <<<EOD
			SELECT
				*
			FROM
				Members
			WHERE
				 MemberId = $this->MemberId
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$row = mysql_fetch_assoc($result);
			
			$this -> MainProfileId = $row['MainProfileId'];
			$this -> MemberProfileId = $row['MemberProfileId'];
			$this -> MemberId = $row['MemberId'];
			$this -> MemberName = $row['MemberName'];
			$this -> Role = $row['Role'];
			$this -> IsCurrentMember = $row['IsCurrentMember']; 
	}
	
	public function UpdateMember()
	{
		if($this -> MemberId != '') {
			$query = <<<EOD
				UPDATE
					Members
				SET
					MainProfileId = {$this->MainProfileId},
					MemberProfileId = {$this->MemberProfileId},
					MemberName = '{$this->MemberName}',
					Role = '{$this->Role}',
					IsCurrentMember = {$this->IsCurrentMember}
				WHERE
					MemberId = {$this->MemberId}
EOD;
			$result = mysql_query($query);
			$userMsg = "Member information has successfully updated.";
		} else {
			$query = <<<EOD
				INSERT INTO
					Members
					(MainProfileId, 
					MemberProfileId,
					MemberName,
					Role,
					IsCurrentMember)
				VALUES
					({$this->MainProfileId},
					{$this->MemberProfileId},
					'{$this->MemberName}',
					'{$this->Role}',
					{$this->IsCurrentMember})
EOD;

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