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

if ($name) {
	pg_exec($db, "update artists set name='$name', last_manual_update=current_timestamp where id='$id' and owner='$uid'");
}
if ($website) {
	pg_exec($db, "update artists set website='$website', last_manual_update=current_timestamp where id='$id' and owner='$uid'");
}

if ($name || $website) {
	echo '<p>Your submission has been saved.  Please return to the <a href="rb-main.php">main menu</a>.</p>', "\n";
	rb_footer();
	exit(0);
}

$artists_res = pg_exec($db, "select name, website from artists where id='$id' and owner='$uid'");
if (pg_numrows($artists_res) == 0) {
	echo '<p>Error: artist does not exist</p>', "\n";
} else {
	echo '<p><b>Edit artist information:</b></p>', "\n";
	echo '<table>', "\n";
	echo '<form method="post" action="rb-artist.php">', "\n";
	echo '<input type="hidden" name="id" value="', $id, '"/>', "\n";
	echo '<tr valign="top"><td align="right"><b>Name: </b></td><td><input size="40" name="name" value="', pg_result($artists_res, 0, 0), '"/></td></tr>', "\n";
	echo '<tr valign="top"><td align="right"><b>Web site: </b></td><td><input size="50" name="website" value="', pg_result($artists_res, 0, 1), '"/></td></tr>', "\n";
	echo '<tr><td></td><td><input type="submit" value="Save"/></td></tr>', "\n";
	echo '</form>', "\n";
	echo '</table>', "\n";
}
pg_freeresult($artists_res);

rb_footer();
?>
