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

	if(ADMIN_FULL == "admin" || ADMIN_ARTIST == "artist") 
	{
		$nav .= '&nbsp;&gt;&nbsp;<a href="index.php?action=artist&function=artistlist">Artist List</a>';
		/******************************************************/
		/*  Artist List Page
		/******************************************************/
		if($_GET['function'] == 'artistlist' || $_GET['function'] == '') 
		{
			$artistObj = new ArtistObj();
			$artistList = $artistObj -> list_artists();
			$template -> assign_block_vars("artist_list",array());
			if(count($artistList) > 0)
			{
				foreach($artistList as $key => $value)
				{
					$template -> assign_block_vars("artist_list.artist", array(
						"ARTIST_ID" => $value->get_artist_id(),
						"ARTIST_NAME" => $value->get_artist_name(),
						"ARTIST_BAND" => $value->get_artist_band(),
						"ARTIST_PROFILE_PIC" => $value->get_artist_profile_pic(),
						"ARTIST_EMAIL" => $value->get_artist_email(),
						"ARTIST_PHONE" => $value->get_artist_phone(),
						"ARTIST_URL" => $value->get_artist_url(),
						"ARTIST_CITY" => $value->get_artist_city(),
						"ARTIST_STATE" => $value->get_artist_state()));
				}
			}
			$template -> assign_var_from_handle('ARTIST_ADMIN_PAGE', 'artistadminpage');
		}
		/******************************************************/
		/*  Artist View/Edit Page
		/******************************************************/
		elseif($_GET['function'] == 'artistview' || $_GET['function'] == 'artistedit' || $_GET['function'] == 'artistadd')
		{
			if($_POST['post_form'] == 'true' && ($_POST['artistadd'] == 'true' || $_POST['artist_id'] != ''))
			{
				$artistObj = new ArtistObj();
				$artistObj->set_artist_id($_POST['artist_id']);
				$artistObj->set_artist_name($_POST['artist_name']);
				$artistObj->set_artist_band($_POST['artist_band']);
				$artistObj->set_artist_bio($_POST['artist_bio']);
				$artistObj->set_artist_sample_mp3($_POST['artist_sample_mp3']);
				$artistObj->set_artist_profile_pic($_POST['artist_profile_pic']);
				$artistObj->set_artist_banner($_POST['artist_banner']);
				$artistObj->set_artist_email($_POST['artist_email']);
				$artistObj->set_artist_phone($_POST['artist_phone']);
				$artistObj->set_artist_url($_POST['artist_url']);
				$artistObj->set_artist_myspace($_POST['artist_myspace']);
				$artistObj->set_artist_address($_POST['artist_address']);
				$artistObj->set_artist_city($_POST['artist_city']);
				$artistObj->set_artist_state($_POST['artist_state']);
				$artistObj->set_artist_zip($_POST['artist_zip']);
				$artistMsg = $artistObj->updateArtist();
				
				$template -> assign_block_vars("artist_msg", array(
					"ARTIST_MSG" => $artistMsg));
			}
			else
			{
				if($_GET['function'] == 'artistadd')
				{
					$template -> assign_block_vars("artist_view", array(
						"DISABLED" => " DISABLED"));
					$template -> assign_block_vars("artist_view.edit", array());
					$template -> assign_block_vars("artist_view.add", array());
				}
				elseif($_GET['artist_id'] == '' && $_POST['artist_id'] == '')
				{
					header("Location: index.php?action=artist&function=artistlist");
				}
				else
				{	
					$artistObj = new ArtistObj();
					$artistObj->set_artist_id($_GET['artist_id']);
					$artistObj->getArtist();
					if($artistObj->get_artist_name() == '')
					{
						$template -> assign_block_vars("page_error",array());
						$template -> assign_block_vars("page_error.error_msg", array(
							"ERROR_MSG" => "No artist found with the provided id.  Please try again."));
					}
					else
					{
						if($artistObj->get_artist_band() == 1)
						{
							$bandChecked = " CHECKED";
							$bandText = "Artist is a band or has a band.";
						}
						else
						{
							$bandChecked = "";
							$bandText = "Artist performs as a solo act.";
						}
						$template -> assign_block_vars("artist_view", array(
							"ARTIST_ID" => $artistObj->get_artist_id(),
							"ARTIST_NAME" => $artistObj->get_artist_name(),
							"ARTIST_BAND_CHECK" => $bandChecked,
							"ARTIST_BAND_TEXT" => $bandText,
							"ARTIST_BIO" => $artistObj->get_artist_bio(),
							"ARTIST_SAMPLE_MP3" => $artistObj->get_artist_sample_mp3(),
							"ARTIST_PROFILE_PIC" => $artistObj->get_artist_profile_pic(),
							"ARTIST_BANNER" => $artistObj->get_artist_banner(),
							"ARTIST_EMAIL" => $artistObj->get_artist_email(),
							"ARTIST_PHONE" => $artistObj->get_artist_phone(),
							"ARTIST_URL" => $artistObj->get_artist_url(),
							"ARTIST_MYSPACE" => $artistObj->get_artist_myspace(),
							"ARTIST_ADDRESS" => $artistObj->get_artist_address(),
							"ARTIST_CITY" => $artistObj->get_artist_city(),
							"ARTIST_STATE" => $artistObj->get_artist_state(),
							"ARTIST_ZIP" => $artistObj->get_artist_zip()));
							
						if($_GET['function'] == 'artistedit') 
						{
							$template -> assign_block_vars("artist_view.edit", array());
							$nav .= '&nbsp;&gt;&nbsp;<a href="index.php?action=artist&function=artistview&artist_id='.$_GET['artist_id'].'">Artist View</a>';
						}
						else
						{
							$template -> assign_block_vars("artist_view.view", array());
						}
					}
				}
			}
			$template -> assign_var_from_handle('ARTIST_ADMIN_PAGE', 'artistadminpage');
		}
		/******************************************************/
		/*  User Del(Deactivate)
		/******************************************************/
		elseif($_GET['function'] == 'artistdel')
		{
			if($_GET['artist_id'] == '')
			{
				$template -> assign_block_vars("page_error",array());
				$template -> assign_block_vars("page_error.error_msg", array(
					"ERROR_MSG" => "No artist provided.  Please try again."));
			}
			else
			{
				$artistObj = new ArtistObj();
				$artistObj->set_artist_id($_GET['artist_id']);
				$artistMsg = $artistObj->delArtist();
				$template -> assign_block_vars("artist_msg", array(
					"ARTIST_MSG" => $artistMsg));
			}
			$template -> assign_var_from_handle('ARTIST_ADMIN_PAGE', 'artistadminpage');
		}
	} 
	else
	{
		$template -> assign_block_vars("page_error",array());
		$template -> assign_block_vars("page_error.permission", array());
	}
?>