<?php
include 'rb-include.php';
rb_header();

echo '<p>Here is a summary of all of the information you have entered:</p>', "\n";

$artists_res = pg_exec($db, "select id, created, name, website from artists where owner='$uid'");
if (pg_numrows($artists_res) == 0) {
	// no artists
}
for ($artist_row = 0; $artist_row < pg_numrows($artists_res); $artist_row++) {
	$artist = pg_result($artists_res, $artist_row, 0);
	
	$artist_name = pg_result($artists_res, $artist_row, 2);
	if ($artist_name == '') {
		$artist_name = '<font color="#d00000">Unnamed Artist</font>';
	}
	$artist_site = pg_result($artists_res, $artist_row, 3);
	if ($artist_site == '') {
		$artist_site = '<i>None</i>';
	} else {
		$artist_site = '<a href="' . $artist_site . '">' . $artist_site . '</a>';
	}
	
	echo '<table border="1">', "\n";
	echo '<tr>', "\n";
	echo '<td valign="top">', "\n";
	echo '<font size="+1">', $artist_name, '</font><br/>', "\n";
	echo '<font size="-2">Created: ', pg_result($artists_res, $artist_row, 1), '</font><br/>', "\n";
	echo '<font size="-1">Website: ', $artist_site, '</font><br/>', "\n";
	echo '<a href="rb-artist.php?id=', $artist, '"><font size="-1" color="#800000">(Edit Artist)</font></a>', "\n";
	echo '</td>',"\n";
	echo '</tr>', "\n";
	echo '<tr>', "\n";
	echo '<td valign="top">', "\n";
	
	$songs_res = pg_exec($db, "select id, created, title, lyrics, license, length from songs where owner='$uid' and artist='$artist'");
	if (pg_numrows($songs_res) == 0) {
		// no songs for artist
	}
	for ($song_row = 0; $song_row < pg_numrows($songs_res); $song_row++) {
		$song = pg_result($songs_res, $song_row, 0);
		
		echo '<table border="1">', "\n";
		echo '<tr>', "\n";
		echo '<td valign="top" colspan="2">', pg_result($songs_res, $song_row, 2), '</td>', "\n";
		echo '</tr>', "\n";
		echo '<tr>', "\n";
		echo '<td valign="top">', "\n";
		echo '<font size="-2">Created: ', pg_result($songs_res, $song_row, 1), '</font><br/>', "\n";
		$license = pg_result($songs_res, $song_row, 4);
		echo 'License: ', license_summary($license), '<br/>', "\n";
		// fixme: show lyrics, and maybe artist, length
		echo '<a href="rb-choose-license.php?id=', $song, '"><font size="-1" color="#800000">(Choose License)</font></a><br/>', "\n";
		echo '<a href="rb-song.php?id=', $song, '"><font size="-1" color="#800000">(Edit Song)</font></a>', "\n";
		echo '</td>', "\n";
		
		echo '<td valign="top">', "\n";
		
		$afs_res = pg_exec($db, "select id, filesize, format from audiofiles where owner='$uid' and song='$song'");
		if (pg_numrows($afs_res) == 0) {
			// no audiofiles for song
		}
		for ($af_row = 0; $af_row < pg_numrows($afs_res); $af_row++) {
			echo '<table border="1">', "\n";
			echo '<tr>', "\n";
			echo '<td>', "\n";
			echo pg_result($afs_res, $af_row, 2), ', ', pg_result($afs_res, $af_row, 1), ' bytes', "\n";
			echo '</td>', "\n";
			echo '</tr>', "\n";
			echo '<tr>', "\n";
			echo '<td>', "\n";
			
			$af = pg_result($afs_res, $af_row, 0);
			$available_res = pg_exec($db, "select url from available where owner='$uid' and audiofile='$af'");
			if (pg_numrows($available_res) == 0) {
				// no mirror for audiofile
			} else if (pg_numrows($available_res) > 1) {
				echo '<b>Mirrors:</b><br/>', "\n";
			}
			for ($available_row = 0; $available_row < pg_numrows($available_res); $available_row++) {
				$available_url = pg_result($available_res, $available_row, 0);
				echo '<a href="', $available_url, '"><font size="-2">', $available_url, '</font></a><br/>', "\n";
			}
			pg_freeresult($available_res);
			
			echo '</td>', "\n";
			echo '</tr>', "\n";
			echo '</table>', "\n";
		}
		pg_freeresult($afs_res);
		
		echo '</td>', "\n";
		echo '</tr>', "\n";
		echo '</table>', "\n";
	}
	pg_freeresult($songs_res);
	
	echo '</td>', "\n";
	echo '</tr>', "\n";
	echo '</table>', "\n";
}
if (pg_numrows($artists_res) != 0) {
	echo '<p><a href="rdf-finalize.php">Click here to finalize your music for distribution on Gnomoradio by creating an RDF file.</a></p>', "\n";
}
pg_freeresult($artists_res);

/*
"select url from available where owner='$uid' and (use='2' or audiofile='0')"

"select blah from albums where owner='$uid';"
for
	select blah from albumsongs where album='' some sort of union with songs
	for
*/

echo '<p><a href="rb-enter-locations.php">Click here to add more music files.</a></p>', "\n";

rb_footer();
?>
