]> git.sesse.net Git - ccbs/blobdiff - html/songratings-text.pl
Pull from --pgweb.
[ccbs] / html / songratings-text.pl
diff --git a/html/songratings-text.pl b/html/songratings-text.pl
new file mode 100755 (executable)
index 0000000..44b1d0f
--- /dev/null
@@ -0,0 +1,42 @@
+#! /usr/bin/perl
+
+use ccbs;
+use strict;
+use warnings;
+
+my $cgi = new CGI;
+my $machine = $cgi->param('machine');
+
+my $dbh = ccbs::db_connect();
+
+my $songs_raw = ccbs::db_fetch_all($dbh, 'SELECT song,title,artist,playmode,difficulty,feetrating FROM songratings NATURAL JOIN songs WHERE machine=? ORDER BY LOWER(title)', $machine);
+
+my @songs = ();
+
+my $last_song = -1;
+for my $song (@$songs_raw) {
+       if ($song->{'song'} != $last_song) {
+               push @songs, { song => $song->{'song'}, title => $song->{'title'}, artist => $song->{'artist'} };
+       }
+
+       my $key = $song->{'playmode'} . '_' . $song->{'difficulty'};
+       $songs[$#songs]->{$key} = $song->{'feetrating'};
+       $last_song = $song->{'song'};
+}
+
+print CGI::header(-type=>'text/plain; charset=utf-8');
+my $config = {
+       INCLUDE_PATH => 'templates/',
+       INTERPOLATE  => 1,
+       POST_CHOMP   => 1,
+       EVAL_PERL    => 1,
+};
+my $template = Template->new($config);
+
+my $output = '';
+$template->process('songratings-text.tmpl', { songs => \@songs }, \$output)
+or die $template->error();
+
+print $output;
+
+$dbh->disconnect;