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

$mediaGroupObj = new MediaGroupObj();

$template -> set_filenames(array(
		'page' => MODULE_PATH.'profiles/template/mediaGroupAdmin.htm'));

	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
		$mediaGroupObj->ProfileId = $_POST['ProfileId'];
		$mediaGroupObj->MediaGroupId = $_POST['MediaGroupId'];
		$mediaGroupObj->MediaGroupName = $_POST['MediaGroupName'];
		
		$mediaGroupMsg = $mediaGroupObj->UpdateMediaGroup();
		if(strpos($mediaGroupMsg, 'error'))
		{
			$template -> assign_block_vars('page_error', array());
			$template -> assign_block_vars('page_error.error_msg', array(
				'ERROR_MSG' => $mediaGroupMsg
			));
		} else {
			$template -> assign_block_vars('page_msg', array());
			$template -> assign_block_vars('page_msg.msg', array(
				'MSG' => $mediaGroupMsg
			));
		}
		
		foreach ($mediaGroupObj as $key => $value)
		{
			$mediaGroupObj->$key = stripslashes($value);
		}
	}
	else
	{
		if (isset($_GET['MediaGroupId']))
		{
			$mediaGroupObj->MediaGroupId = $_GET['MediaGroupId'];
			$mediaGroupObj->GetMediaGroup();
		}
		else
		{
			$mediaGroupObj->ProfileId = $_SESSION['UserProfileId'];
		}
	}
	
		
	$template -> assign_vars(array(
		'PROFILE_ID' => $mediaGroupObj->ProfileId,
		'MEDIA_GROUP_ID' => $mediaGroupObj->MediaGroupId,
		'MEDIA_GROUP_NAME' => $mediaGroupObj->MediaGroupName
		));

	$mediaList = $mediaGroupObj->Media;
	for($k=0; $k < count($mediaList); $k++)
	{
	
		$template -> assign_block_vars('media', array(
			'MEDIA_ID' => $mediaList[$k]->Media,
			'MEDIA_NAME' => $mediaList[$k]->MediaName,
			'MEDIA_LOCATION' => $mediaList[$k]->MediaLocation
			));
	}

?>