#! /usr/bin/perl

use ccbs;
use strict;
use warnings;

my $cgi = new CGI;
my $id = $cgi->param('id');

my $dbh = ccbs::db_connect();

my $song = $dbh->selectrow_hashref('SELECT * FROM songs WHERE song=?', undef, $id);
my $scores = ccbs::db_fetch_all($dbh, 'SELECT * FROM scores NATURAL JOIN players NATURAL JOIN tournaments WHERE song=? ORDER BY score DESC', $id);

ccbs::print_header();
ccbs::process_template('song.tmpl', $song->{'title'}, {
	song => $song,
	scores => $scores
});
$dbh->disconnect;
