#!/usr/local/bin/perl 
my $INCLUDE_HEADER=($ENV{'DOCUMENT_ROOT'}||"/home/httpd/html");
require "/home/sites/site3/lokad/header1.inc";
print "International Axis and Allies Players Association Database Players Rank</i></H1>";
print "</center>";

print "<h2 align=center><a href=\"/public/faqs/part19.html\">IAAPA Ratings and 
Rankings Formulae</a></h2>";

use CGI;
$q=new  CGI;
$parent=$q->param('parent');

print "<H3>Current RANK = $parent</H3><br>";	
$parent =~ s/ALL/%/g;
print "<p> <br><br> <Table><td>";

print "<FORM METHOD=POST ACTION='http:/cgi-local/axis/AxisAndAllies.cgi'> 
        Name: <td><INPUT NAME=parent size= 30 maxlength=30 value=''>
               <input type=hidden name=SEARCH value='1'>
              <td><INPUT TYPE=submit value='View player'></FORM><tr>"; 

print "<td><FORM METHOD=POST ACTION='http:/cgi-local/axis/Rank.cgi'>
       <input type=hidden name=TOP value='1'> Top 30 players: 
       <td><INPUT TYPE=submit value='Top rating 30'></FORM><td>"; 

print "<FORM METHOD=POST ACTION='http:/cgi-local/axis/Rank.cgi'>
       <input type=hidden name=TOP value='2'>
       <INPUT TYPE=submit value='Top rank 30'></FORM><tr>"; 

print "<td><FORM METHOD=POST ACTION='http:/cgi-local/axis/Games.cgi'> Game #:
       <td> <INPUT NAME=gameno size= 6 maxlength=6 value=''>
       <td><INPUT TYPE=submit value='View game'></FORM><br> </table>";

print "<H3> <blockquote>";

print "Ranks ";
@ranks=('GEN****','GEN***','GEN**','GEN*','COL','MAJ','CPT','LT','MSGT','SGT','CPL','PVT','ROOKIE','ALL');
for ($i=0; $i < 15; $i++){
   printf(" <A href=\"/cgi-local/axis/Rank.cgi?parent=%s\"> %s </a> \n",$ranks[$i],$ranks[$i]);
}

print "<br><br><br>";

$toppl=$q->param('TOP');

$query = "select alias, rank, gamespl, rankpoints, Resetrec, points, gameswon, gamelost from players where inactive = 'N'";

$query .= " and  rank like '$parent' order by playerid " if ($toppl ne '1' && $toppl ne '2' ); 

#$query .= " order by rankpoints DESC LIMIT 30"  if ($toppl eq '2'); 
$query = "  select  alias, rank, gamespl, rankpoints, Resetrec, points, gameswon, gamelost, ( CASE 1 WHEN rank='GEN****' THEN 15 WHEN rank='GEN***' THEN 14 WHEN rank='GEN**' THEN 13 WHEN rank='GEN*' THEN 12 WHEN rank='COL' THEN 11 WHEN rank='MAJ' THEN 10 WHEN rank='CPT' THEN 9 WHEN rank='LT' THEN 8 WHEN rank='MSGT' THEN 7 WHEN rank='SGT' THEN 6 WHEN rank='CPL' THEN 5 WHEN rank='PVT' THEN 4 WHEN rank='ROOKIE' THEN 3 ELSE 0 END ) as RANKVALUE from players where inactive = 'N' order by RANKVALUE DESC, rankpoints DESC LIMIT 30" if ($toppl eq '2'); 


$query .= "  order by points DESC LIMIT 30" if ($toppl eq "1");


die "prepare\n" unless ($cursor = $dbh->prepare($query)); 
$cursor->execute;
print "<table>
       <td>Rank
       <td>Player
       <td>Games played
       <td>Record
       <td>Ranking points<tr>";

while(@row=$cursor->fetchrow) {
      $record = $row[6]." - ".$row[7];  
printf("<td>%s<td><A href=\"/cgi-local/axis/AxisAndAllies.cgi?parent=%s\">%s </a> (%d)<td><b><right>%s</right></b><td>%s<td>%s<tr>", $row[1],$row[0], $row[0], $row[5],$row[2], $record,$row[3]);

}

print "</table></H3>";
exit (0);
