]> git.sesse.net Git - ccbs/blob - html/player.pl
Restore inadvertedly removed rm -f.
[ccbs] / html / player.pl
1 #! /usr/bin/perl
2
3 use ccbs;
4 use strict;
5 use warnings;
6
7 my $cgi = new CGI;
8 my $id = $cgi->param('id');
9
10 my $dbh = ccbs::db_connect();
11
12 my $player = $dbh->selectrow_hashref('SELECT * FROM players NATURAL JOIN countries NATURAL LEFT JOIN clubs WHERE player=?', undef, $id);
13 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);
14
15 my ($countries, $clubs);
16 unless ($ccbs::ccbs_noadmin) {
17         $countries = ccbs::db_fetch_all($dbh, 'SELECT * FROM countries ORDER BY countrycode');
18         $clubs = ccbs::db_fetch_all($dbh, 'SELECT * FROM clubs ORDER BY clubcode');
19 }
20
21 # Fetch all scores and count a bit
22 my $columns = 0;
23 my @allsongs = ();
24 my $last_song = undef;
25
26 my $scores = ccbs::db_fetch_all($dbh, 'SELECT song,title,score FROM scores NATURAL JOIN songs WHERE player=? ORDER BY title,score DESC', $id);
27 for my $score (@$scores) {
28         my $song = $score->{'song'};
29
30         if (!defined($last_song) || $song != $last_song) {
31                 push @allsongs, { song => $song, title => $score->{'title'}, scores => [] };
32         }
33
34         push @{$allsongs[$#allsongs]->{'scores'}}, $score->{'score'};
35
36         my $this_columns = scalar @{$allsongs[$#allsongs]->{'scores'}};
37         $columns = $this_columns if ($this_columns > $columns);
38
39         $last_song = $song;
40 }
41
42 ccbs::print_header();
43 ccbs::process_template('player.tmpl', $player->{'nick'}, {
44         player => $player,
45         bestsongs => $bestsongs,
46         allsongs => \@allsongs,
47         columns => $columns,
48         countries => $countries,
49         clubs => $clubs
50 });
51 $dbh->disconnect;