Add a (hidden) script for showing song ratings.
[ccbs] / html / songratings.pl
1 #! /usr/bin/perl
2
3 use ccbs;
4 use strict;
5 use warnings;
6
7 my $cgi = new CGI;
8 my $machine = $cgi->param('machine');
9
10 my $dbh = ccbs::db_connect();
11
12 my $songs_raw = ccbs::db_fetch_all($dbh, 'SELECT song,title,playmode,difficulty,feetrating FROM songratings NATURAL JOIN songs WHERE machine=? ORDER BY machine,song', $machine);
13
14 my @songs = ();
15
16 my $last_song = -1;
17 my $show_challenge = 0;
18 for my $song (@$songs_raw) {
19         if ($song->{'song'} != $last_song) {
20                 push @songs, { song => $song->{'song'}, title => $song->{'title'} };
21         }
22
23         my $key = $song->{'playmode'} . '_' . $song->{'difficulty'};
24         $songs[$#songs]->{$key} = $song->{'feetrating'};
25         $last_song = $song->{'song'};
26
27         $show_challenge = 1 if ($song->{'difficulty'} eq 'challenge');
28 }
29
30 ccbs::print_header();
31 ccbs::process_template('songratings.tmpl', 'Sanger', {
32         songs => \@songs,
33 });
34 $dbh->disconnect;