#!/usr/bin/perl # ================================================================================ # $Rev: 184 $ $URL: svn://localhost/PlayChess/trunk/cgi/prv-list.cgi $ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Author: $Author: Thomas $ # Modified: $Date: 2006-05-20 10:29:26 +0000 (Sa, 20 Mai 2006) $ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Copyright at playchess.de - all rights reserved # ================================================================================ use lib "../cgi-bin"; use CGI qw( :standard ); use CGI::Carp qw(fatalsToBrowser); use PCLeagueUtil; use PCPlayer; use PC; use PCGame; use Object; use PCSession; use Template; use Util; use ChessConfig; use MyDbi; ##-------------------------------------------------------------------------- ## LOCAL CONFIGURATION ##-------------------------------------------------------------------------- local $config = getConfig(); local $URL = $ENV{DOCUMENT_URI}; # url of your domain local $ROOT = $ENV{DOCUMENT_ROOT}; # path to document root local $SERVER = $ENV{SERVER_NAME}; # server name local $HOST = $ENV{HTTP_HOST}; local $err = ''; # error message local $syserr = 0; local $| = 1; local $ppp = 50; # ppp = players per page local ($starttime,$endtime) = (time(),0); $cgi = CGI->new(); $sobj = PCSession->new( $cgi ); $sname = $sobj->getValue( 'name' ); $action = $cgi->param( 'action' ); $name = $cgi->param( 'name' ) || $sname; $ppp = $cgi->param('ppp') || 10; $min = $cgi->param('min'); $max = $cgi->param('max'); #$sort = $cgi->param('sort') || 'pcr'; # action: list of public private games # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { local $min = 0+$cgi->param( 'min' ); local $limit = 40; # Batch processing # ~~~~~~~~~~~~~~~~~~ my $pppMin = 10; my $pppMax = 100; $min = 0 unless $min; $ppp = $pppMin if( $ppp<=$pppMin || $ppp>$pppMax); my @table; my $stmt; my $cond_publish = ($sname eq $name) ? '' : "and (g.publish='all' or g.publish='privnotes')"; # Connect to database #-------------------- $dbh = dbiConnect() or die( "Cannot access database" ); # Select statement # ~~~~~~~~~~~~~~~~ $stmt = " select count(*) from tbl_player p1, tbl_player_game pg1, tbl_game g where p1.name = ? and p1.pid = pg1.pid and pg1.gid = g.gid $cond_publish and g.tid = 0 "; $tp = MyDbi::getValue( $stmt, $name ); $stmt = " select p2.name, pg1.color, g.result, g.lastmove, g.name, a.changed, p1.isengine from ( tbl_player p1, tbl_player_game pg1, tbl_game g, tbl_player_game pg2, tbl_player p2 ) left outer join tbl_annotation a on (a.gid=g.gid and a.apid=p1.pid) where p1.name = ? and p1.pid = pg1.pid and pg1.gid = pg2.gid and pg1.gid = g.gid and p2.pid = pg2.pid and pg1.pid <> pg2.pid $cond_publish and g.tid = 0 order by g.bd desc limit $min, $ppp "; $rows = MyDbi::getRows( $stmt, $name ); # print "
stmt = $stmt\n"; # print "
rows = $rows\n"; # fetch games # ~~~~~~~~~~~ my ( $r, $oppname, $mycolor, $result, $lastmove, $gamename, $annotated, $pts, $line, $changed, $isengine ); for $r ( 0 .. $#{$rows} ) { ( $oppname, $mycolor, $result, $lastmove, $gamename, $changed, $isengine ) = @{ $rows->[$r] }; # date of annotation (if exists) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $annotated = ($changed) ? Util::getDate($changed, "dd.mm.yy") : ""; $pts = ($result eq $mycolor) ? 1 : ($result eq 'd' ? 0.5 : 0); $pts = ' ? ' unless $result; # create output # ~~~~~~~~~~~~~ #$line = join( "|", $gamename, Util::getDate($lastmove,"dd.mm.yy"), $pts, $line = join( "|", $gamename, $lastmove, $pts, $mycolor, $oppname, $annotated, ($r+1), ($r%2), ($result ne '') ); push @table, $line; # print "$r: $line