#!/usr/bin/perl

use CGI;
$query = new CGI;
$the_score=$query->param('score');
$the_name=$query->param('name');

print "Content-type: text/html\n\n<html><head><title>Shariki Top 100".
"</title></head><body>\n<h1>Shariki Top 100 </h1>\n".
"<table border=\"1\", cellpadding=\"2\">\n".
"<tr><th> # </th><th> Score </th><th> Name </th><th> Date </th><th> Time </th>".
"<th> Host </th></tr>\n";
$place=$prscr=0;
$color="";
open(FILE, "sort -r -n ./top100 |") || die "File not found!";
while(<FILE>){
  $splace="-";
  ($score, $name, $date, $time, $hstn) = split('\t');
  if($score!=$prscr){
    $place++;
    $splace=$place;
  }
  $color="bgcolor=#e8e8e8" if $score==$the_score && $name eq $the_name;
  print "<tr ".$color."><td>$splace</td><td>$score</td><td>$name</td><td>$date</td>".
  "<td>$time</td><td>$hstn</td></tr>\n" if $score>0;
  $prscr=$score;
  $color="";
}
close(FILE);
print "</table>\n<h3>To start a new game press BACK button of your ".
"browser.</h3>\n</body></html>";
