#!/usr/bin/perl # ================================================================================ # $Rev: 359 $ $URL: file:///C:/daten/archiv/PlayChess/trunk/cgi/rank.cgi $ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Author: $Author: epts $ # Modified: $Date: 2008-04-25 21:25:50 +0200 (Fr, 25 Apr 2008) $ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Copyright at playchess.de - all rights reserved # ================================================================================ use lib "../cgi-bin"; use CGI qw( :standard ); use CGI::Carp qw(fatalsToBrowser); use PC; use PCLeagueUtil; use PCSession; use Member; use Template; use Util; use ChessConfig; use MyDbi; ##-------------------------------------------------------------------------- ## LOCAL CONFIGURATION ##-------------------------------------------------------------------------- local $config = getConfig(); $URL = $ENV{DOCUMENT_URI}; # url of your domain $ROOT = $ENV{DOCUMENT_ROOT}; # path to document root $SERVER = $ENV{SERVER_NAME}; # server name $HOST = $ENV{HTTP_HOST}; $ppp = 25; # ppp = players per page $min = 0; $max = 0; local ($starttime,$endtime) = (time(),0); local $cgi = CGI->new(); local $sobj = PCSession->new( $cgi ); local $sname = $sobj->getValue( 'name' ); local $action = $cgi->param( 'action' ); local $sort = $cgi->param( 'sort' ); local $name = $cgi->param( 'name' ) || $cookie_name; local $league = $cgi->param('league'); local $class = $cgi->param('class'); local $cflag = $cgi->param('cflag'); local $ppp = $cgi->param('ppp') || 50; local $min = $cgi->param('min'); local $max = $cgi->param('max'); local $namepattern = $cgi->param('namepattern'); local $mailpattern = $cgi->param('mailpattern'); local $admin = $cgi->param('admin'); # local $mingames = 0+$cgi->param('mingames'); local $mingames = 10; ($flag,$country) = split('-',$cflag) if $cflag; #-------------------- Result list --------------------------- { my ($stmt, $rows, $r, $order, $having, $limit, @PlayerList ); # Following actions require database access #------------------------------------------ $dbh = dbiConnect() or exit(1); # Selecting the players # (requiring _valid_ games needs _much_ more time!) #-------------------------------------------------- $min = 0 unless $min; $ppp = 50 if( $ppp<=10 || $ppp>500); my $membercols = ", m.type, m.until"; my $memberjoin = " left join tbl_member m on m.pid=p.pid"; my $membercond = " m.type>0 and m.until>unix_timestamp(now())"; # Select stmt #-------------- $stmt = " select p.pid, p.name, p.country, p.flag, r1.ratedgames, r1.class, r1.rating, r1.league, unix_timestamp(r1.ts) $membercols from (tbl_player p, tbl_rating r1) $memberjoin where 1 and unix_timestamp(r1.ts) > unix_timestamp(now())-3*30*86400 and (p.deleted is NULL or p.deleted <> 1) and p.pid=r1.pid and $membercond "; $stmt .= " and r1.ratedgames >= $mingames" if( $mingames ); $stmt .= " and r1.league='$league'" if( $league ); $stmt .= " and r1.class='$class'" if( $class ); $stmt .= " and p.country='$country'" if( $country ); $stmt .= " order by r1.rating desc, r1.ts desc"; # print "
$stmt"; # $stmt .= " order by r1.rating desc, p.name" if( $sort eq 'elo' ); # $stmt .= " order by r1.class desc, p.name" if( $sort eq 'class' ); # $stmt .= " order by p.gpp desc" if( $sort eq 'gpp' ); # $stmt .= " order by p.lastvisit desc" if( $sort eq 'visit' ); # $stmt .= " order by r1.ratedgames desc" if( $sort eq 'games' ); # $stmt .= " order by p.name asc" if( !$sort || $sort eq 'name' ); $stmt .= " limit $min,$ppp"; # Count statement # ~~~~~~~~~~~~~~~ $cstmt = " select count(*) from (tbl_player p, tbl_rating r1) $memberjoin where (p.deleted is NULL or p.deleted <> 1) and unix_timestamp(r1.ts) > unix_timestamp(now())-3*30*86400 and p.pid=r1.pid and $membercond "; $cstmt .= " and r1.ratedgames >= $mingames" if( $mingames ); $cstmt .= " and p.country='$country'" if( $country ); $cstmt .= " and r1.league='$league'" if( $league ); $cstmt .= " and r1.class='$class'" if( $class ); my $starttime = time; $tp = MyDbi::getValue( $cstmt ); $rows = MyDbi::getRows( $stmt ); #print "
$#{$rows} rows found
"; #AUS( __FILE__,__LINE__, $#{$rows}, "SELECT TIME:", time()-$starttime, $starttime, time ); for $r ( 0 .. $#{$rows} ) { my( $id, $name, $country, $flag, $ngames, $c1, $r1, $l1, $ts, $mtype, $muntil ) = @{ $rows->[$r] }; $since = Util::getDate($lv,"dd.mm. hh:mm"); $since = Util::getDate($ts,"dd.mm. hh:mm"); $even = ($r % 2); $linecolor = ($even) ? '#EEEEEE' : '#FFFFFF'; my $mstring = Member::evalMemberType( $mtype, $muntil ); # if ( $mtype == 3 && $muntil>time ) { $mstring = "P"; } # elsif( $mtype == 2 && $muntil>time && $muntil>time+6*30*86400 ) { $mstring = "SP"; } # elsif( $mtype == 2 && $muntil>time ) { $mstring = "S"; } # elsif( $mtype == 1 && $muntil>time ) { $mstring = "T"; } # else { $mstring = "G"; } $line = join("|", $min+$r+1, $even, $name, $country, $flag, 0+$ngames, $since, $r1, $c1, $l1, $linecolor, $mstring ); #AUS( __FILE__,__LINE__, $line ); push @PlayerList, $line; #print "$line"; } # End of DB access #----------------- $dbh->disconnect(); # Create output #-------------- my $tplstart = time; my $t; #for $loop (1 .. 200 ) { my $tpl = Template->new( "rank.tpl" ); my( $p, $ListTitle, $anz ); $ListTitle = "Player List"; $tpl->addMakro( "LISTTITLE", $ListTitle ); $tpl->addMakro( "LEAGUE", $league ); $tpl->addMakro( "CLASS", $class ); $tpl->addMakro( "SORT", $sort ); $tpl->addMakro( "MINGAMES", $mingames ); $tpl->addMakro( "COUNTRY", $country ); $tpl->addMakro( "CFLAG", $cflag ); $tpl->addMakro( "TP", $tp ); $tpl->addArray( "ARRAY", \@PlayerList ); $tpl->addBatch( $min, $ppp, scalar @PlayerList, $tp ); $tpl->addSelectMakro( "cflag", $cflag ); $tpl->addSelectMakro( "league", $league ); $tpl->addSelectMakro( "class", $class ); $tpl->addSelectMakro( "sort", $sort ); $t = $tpl->Expand($sobj); } print $t; #print "