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

class CommentsObj
{
    public function GetComments($profileId)
	{
		$query = <<<EOD
			SELECT
				*
			FROM
				Comments
			WHERE
				 ProfileId = {$profileId}
			ORDER BY 
				PostedDate desc
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$commentsArray = array();
		while($row = mysql_fetch_assoc($result)) {
			$tempObj = new CommentsObj;
			$tempObj -> ProfileId = $row['ProfileId'];
			$tempObj -> CommentId = $row['CommentId'];
			$tempObj -> PostedDate = $row['PostedDate'];
			$tempObj -> PostedUserId = $row['PostedUserId'];
			$tempObj -> Comment = $row['Comment'];
			$tempObj -> Likes = $row['Likes'];
			$tempObj -> DisLikes = $row['DisLikes'];
			$tempObj -> IsHidden = $row['IsHidden'];
			$tempObj -> IsApproved = $row['IsApproved'];
			
			$commentsArray[] = $tempObj;
		}
		
		return $commentsArray;
	}
	
	public function GetComment()
	{
		$query = <<<EOD
			SELECT
				*
			FROM
				Comments
			WHERE
				 CommentId = {$this->CommentId}
EOD;

		$result = mysql_query($query) or die(mysql_error() . "<br>$query");
		
		$row = mysql_fetch_assoc($result);
		
		$this -> ProfileId = $row['ProfileId'];
		$this -> CommentId = $row['CommentId'];
		$this -> PostedDate = $row['PostedDate'];
		$this -> PostedUserId = $row['PostedUserId'];
		$this -> Comment = $row['Comment'];
		$this -> Likes = $row['Likes'];
		$this -> DisLikes = $row['DisLikes'];
		$this -> IsHidden = $row['IsHidden'];
		$this -> IsApproved = $row['IsApproved'];
		
	}
	
	public function UpdateComment()
	{
		if($this -> CommentId != '') {
			$query = <<<EOD
				UPDATE
					Comments
				SET
					ProfileId = {$this->ProfileId},
					PostedDate = '{$this->PostedDate}',
					PostedUserId = {$this->PostedUserId},
					Comment = '{$this->Comment}',
					Likes = {$this->Likes},
					DisLikes = {$this->DisLikes},
					IsHidden = {$this->IsHidden},
					IsApproved = {$this->IsApproved}
				WHERE
					CommentId = {$this->CommentId}
EOD;
			$result = mysql_query($query);
			$userMsg = "Comment information has successfully updated.";
		} else {
			$query = <<<EOD
				INSERT INTO
					Comments
					(ProfileId, 
					PostedDate,
					PostedUserId,
					Comment,
					Likes,
					DisLikes,
					IsHidden,
					IsApproved)
				VALUES
					({$this->ProfileId},
					'{$this->PostedDate}',
					{$this->PostedUserId},
					'{$this->Comment}',
					{$this->Likes},
					{$this->DisLikes},
					{$this->IsHidden},
					{$this->IsApproved})
EOD;

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