Sync from --pgweb.
authorSteinar H. Gunderson <sesse@samfundet.no>
Mon, 4 Apr 2005 16:00:29 +0000 (16:00 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Mon, 4 Apr 2005 16:00:29 +0000 (16:00 +0000)
Patches applied:

 * sgunderson@bigfoot.com--2005-private/ccbs--pgweb--1.0--patch-21
   Add a listing of all songs.

html/songs.pl [new file with mode: 0755]
html/templates/index.tmpl
html/templates/songs.tmpl [new file with mode: 0644]

diff --git a/html/songs.pl b/html/songs.pl
new file mode 100755 (executable)
index 0000000..6ae2469
--- /dev/null
@@ -0,0 +1,18 @@
+#! /usr/bin/perl
+
+use ccbs;
+use strict;
+use warnings;
+
+my $cgi = new CGI;
+my $id = $cgi->param('id');
+
+my $dbh = ccbs::db_connect();
+
+my $songs = ccbs::db_fetch_all($dbh, 'SELECT machinename,song,title,artist,avg_score,stddev_score,high_score,high_score_player,high_score_nick FROM machinesongs NATURAL JOIN songs NATURAL JOIN machines NATURAL LEFT JOIN ( SELECT song,AVG(score)::integer AS avg_score,STDDEV(score)::integer AS stddev_score,MAX(score) AS high_score FROM scores GROUP BY song ) t1 NATURAL LEFT JOIN ( SELECT DISTINCT ON (song) song,player AS high_score_player,nick AS high_score_nick,score AS high_score FROM scores NATURAL JOIN players ORDER BY song,score DESC ) t2 ORDER BY machine,LOWER(title)');
+
+ccbs::print_header();
+ccbs::process_template('songs.tmpl', 'Songs', {
+       songs => $songs,
+});
+$dbh->disconnect;
index 466c76e..289249f 100644 (file)
@@ -10,6 +10,7 @@
   <ul>
     <li><a href="tournaments.pl">Turneringer</a></li>
     <li><a href="players.pl">Spillere</a></li>
+    <li><a href="songs.pl">Sanger</a></li>
 [% IF !public %]
     <li><a href="add-tournament.pl">Legg til turnering</a></li>
     <li><a href="randomsongs.pl">Sangvelger</a></li>
diff --git a/html/templates/songs.tmpl b/html/templates/songs.tmpl
new file mode 100644 (file)
index 0000000..2d3c0b2
--- /dev/null
@@ -0,0 +1,39 @@
+[%# vim:set filetype=html: %]
+
+[% SET last_machine = '' %]
+
+[% FOR s = songs %]
+[% IF s.machinename != last_machine %]
+[% IF last_machine != '' %]
+    </table>
+  </div>
+[% END %]
+
+[% SET last_machine = s.machinename %]
+  <h2>[% s.machinename %]</h2>
+
+  <div>
+    <table class="scores">
+      <tr>
+        <th>Song name</th>
+        <th>Artist</th>
+        <th>Average</th>
+        <th>Std. dev</th>
+        <th>High score</th>
+      </tr>
+[% END %]
+
+      <tr>
+        <td><a href="song.pl?id=[% s.song %]">[% s.title %]</a></td>
+        <td>[% s.artist %]</td>
+        <td>[% s.avg_score %]</td>
+        <td>[% s.stddev_score %]</td>
+[% IF s.high_score == '' %]
+        <td></td>
+[% ELSE %]
+        <td>[% s.high_score %] by <a href="song.pl?id=[% s.high_score_player %]">[% s.high_score_nick %]</a></td>
+[% END %]
+      </tr>
+[% END %]
+    </table>
+  </div>