<?
include "config.php";
include "function.php";

$connection=connectdb();

if ($Submit){
	$initquery="update files set";
	if ($artist){$qupdate[] = "artist='$artist'";}
	if ($album) {$qupdate[] = "album='$album'";}
	if ($genre) {$qupdate[] = "genreid='$genre'";}
	if ($title) {$qupdate[] = "title='$title'";}
	
	$merged = join (", ", $qupdate);
	if ($merged){
		$query="$initquery $merged where id='$id'";
	}
	$result=mysql_query($query, $connection);
	if (!$result){
		// Altered output to $errormes which is echo-ed in the start_maintable(); function.
		// It is not correct to echo this before the <html> tag.
		// Since I added the header() function below there might be no output.
		$errormes.="update failed";
	} 
	// ADDED by skippybal (on 28-04-2002@13:10)
	else {
		header ("Location: playlist.php?artist=$artist&song=$title&genre=$genre&Submit=1");
	}
}

$query="select * from files where id='$id'";
$result=mysql_query($query, $connection);
$row=mysql_fetch_array($result);

html_header();
start_maintable();
?>
              <form method="post" action="">
                <table class="searchtable" cellspacing="0">
                  <tr> 
                    <th width="25%" class="searchtable"><img src="<? echo $skindir.$skin; ?>/header-artist.jpg"></th>
                    <th width="25%" class="searchtable"><img src="<? echo $skindir.$skin; ?>/header-album.jpg"></th>
                    <th width="25%" class="searchtable"><img src="<? echo $skindir.$skin; ?>/header-searchgenre.jpg"></th>
                    <th width="25%" class="searchtable"><img src="<? echo $skindir.$skin; ?>/header-song.jpg"></th>
                  </tr>
                  <tr> 
                    <td width="25%" class="searchtable"><input type="text" name="artist" <? echo "value=\"$row[artist]\"";?>></td>
                    <td width="25%" class="searchtable"><input type="text" name="album" <? echo "value=\"$row[album]\"";?>></td>
                    <td width="25%" class="searchtable"><select name="genre">
<?
$genreid=$row[genreid];
$query="select * from genres";
$result=mysql_query($query, $connection);
while ($rowgenre=mysql_fetch_array($result)){
	if ($genreid == $rowgenre[id]){ 
		$selected="selected"; 
	}
	else 
		$selected='';
		echo"<option value=\"$rowgenre[id]\"$selected>$rowgenre[description]</option>\n";
}
?>
                      </select>
					</td>
                    <td width="25%" class="searchtable"><input type="text" name="title" <? echo "value=\"$row[title]\"";?>></td>
                  </tr>
                </table>
                <br><input type="submit" name="Submit" value="update song information">
              </form>
<?
end_maintable();
html_footer();
?>
