]> git.sesse.net Git - ccbs/blobdiff - html/player.pl
Pull in player editing code from --baby.
[ccbs] / html / player.pl
index 0fbde00f445ba54436b7951367fe931c746bc722..93d93282d5a57a77b73f5fd33793854b38cb221d 100755 (executable)
@@ -12,16 +12,23 @@ my $dbh = ccbs::db_connect();
 my $player = $dbh->selectrow_hashref('SELECT * FROM players NATURAL JOIN countries NATURAL LEFT JOIN clubs WHERE player=?', undef, $id);
 my $bestsongs = ccbs::db_fetch_all($dbh, 'SELECT song,title,score,tournament,tournamentname FROM ( SELECT DISTINCT ON (song) song,score,tournament FROM scores WHERE player=? AND score IS NOT NULL ORDER BY song,score DESC ) t1 NATURAL JOIN songs NATURAL JOIN tournaments ORDER BY score DESC LIMIT 10', $id);
 
+my ($countries, $clubs);
+unless ($ccbs::ccbs_noadmin) {
+       $countries = ccbs::db_fetch_all($dbh, 'SELECT * FROM countries ORDER BY countrycode');
+       $clubs = ccbs::db_fetch_all($dbh, 'SELECT * FROM clubs ORDER BY clubcode');
+}
+
 # Fetch all scores and count a bit
 my $columns = 0;
 my @allsongs = ();
-my $last_title = undef;
+my $last_song = undef;
 
-my $scores = ccbs::db_fetch_all($dbh, 'SELECT title,score FROM scores NATURAL JOIN songs WHERE player=? ORDER BY title,score DESC', $id);
+my $scores = ccbs::db_fetch_all($dbh, 'SELECT song,title,score FROM scores NATURAL JOIN songs WHERE player=? ORDER BY title,score DESC', $id);
 for my $score (@$scores) {
-       my $title = $score->{'title'};
-       if (!defined($last_title) || $title ne $last_title) {
-               push @allsongs, { title => $title, scores => [] };
+       my $song = $score->{'song'};
+
+       if (!defined($last_song) || $song != $last_song) {
+               push @allsongs, { song => $song, title => $score->{'title'}, scores => [] };
        }
 
        push @{$allsongs[$#allsongs]->{'scores'}}, $score->{'score'};
@@ -29,14 +36,16 @@ for my $score (@$scores) {
        my $this_columns = scalar @{$allsongs[$#allsongs]->{'scores'}};
        $columns = $this_columns if ($this_columns > $columns);
 
-       $last_title = $title;
+       $last_song = $song;
 }
 
 ccbs::print_header();
-ccbs::process_template('player.tmpl', $player->{'title'}, {
+ccbs::process_template('player.tmpl', $player->{'nick'}, {
        player => $player,
        bestsongs => $bestsongs,
        allsongs => \@allsongs,
-       columns => $columns
+       columns => $columns,
+       countries => $countries,
+       clubs => $clubs
 });
 $dbh->disconnect;