<?

require "include/bittorrent.php";
dbconn(false);
loggedinorreturn();
ob_start("ob_gzhandler");
if (get_user_class() >= UC_ADMINISTRATOR)
$edit = 1;

$res2 = mysql_query("select count(*) from casino") or die(mysql_error());
$row2 = mysql_fetch_array($res2);
$count = $row2[0];


$perpage = 50;

list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["PHP_SELF"] ."?" );

$res = mysql_query("select users.id as userid,users.username, users.downloaded,users.uploaded,casino.win,casino.lost,casino.deposit from casino inner join users on casino.userid = users.id  ORDER BY (casino.win - casino.lost) DESC $limit") or sqlerr();

stdhead("Players");



if (mysql_num_rows($res) == 0)
print("<p align=center><b>No players</b></p>\n");
else
{
print("<p align=center><b><h1>Results</h1></b></p>\n");
print("<p align=center><a href=casino.php>Back</a></p>\n");
echo $pagertop;
print("<table border=1 cellspacing=0 cellpadding=5>\n");


if($edit==0)
print("<tr><td class=colhead>Username</td><td class=colhead align=left>Uploaded</td><td class=colhead align=left>Downloaded</td><td class=colhead align=left>Ratio</td><td class=colhead align=left>Deposit on P2P</td><td class=colhead align=left>Won</td><td class=colhead align=left>Lost</td><td class=colhead align=left>Tries</td><td class=colhead align=left>Total</td>\n");
else
print("<tr><td class=colhead>Username</td><td class=colhead align=left>Uploaded</td><td class=colhead align=left>Downloaded</td><td class=colhead align=left>Ratio</td><td class=colhead align=left>Deposit on P2P</td><td class=colhead align=left>Won</td><td class=colhead align=left>Lost</td><td class=colhead align=left>Tries</td><td class=colhead align=left>Total</td><td class=colhead align=left>edit user</td>\n");


while ($arr = mysql_fetch_assoc($res))
{
$rez = mysql_query("select * from casino where userid=$arr[userid]");
$arz = mysql_fetch_array($rez);
if ($arr["downloaded"] > 0)
{
     $ratio = number_format($arr["uploaded"] / $arr["downloaded"], 3);
     $ratio = "<font color=" . get_ratio_color($ratio) . ">$ratio</font>";
  }
  else
     if ($arr["uploaded"] > 0)
       $ratio = "Inf.";
else
$ratio = "---";
$uploaded =mksize($arr["uploaded"]);
$downloaded = mksize($arr["downloaded"]);
if ($CURUSER[id] == $arr[userid])
$bg = "bgcolor=#c0c0c0";
else
$bg = "";

$all = $arz[win]-$arz[lost];
if($all < 0)
{
$all = $all * -1;
$minus = "-";
}

if($edit==0)
print("<tr><td $bg><a href=userdetails.php?id=$arr[userid]><b>$arr[username]</b></a></td><td align=left $bg>$uploaded</td><td align=left $bg>$downloaded</td><td align=left $bg>$ratio</td><td align=center $bg>".mksize($arz[deposit])."</td><td align=left $bg>".mksize($arz[win])."</td><td align=left $bg>".mksize($arz[lost])."</td><td align=left $bg>$arz[trys]</td><td align=left $bg> $minus".mksize($all)."</td></tr>\n");
else
print("<tr><td $bg><a href=userdetails.php?id=$arr[userid]><b>$arr[username]</b></a></td><td align=left $bg>$uploaded</td><td align=left $bg>$downloaded</td><td align=left $bg>$ratio</td><td align=center $bg>".mksize($arz[deposit])."</td><td align=left $bg>".mksize($arz[win])."</td><td align=left $bg>".mksize($arz[lost])."</td><td align=left $bg>$arz[trys]</td><td align=left $bg> $minus".mksize($all)."</td><td align=left $bg><form name=edit-player method=post action=casino_player_edit.php><input type=hidden name=userid value=$arr[userid]> <input class=btn type=submit value=edit ></form></td></tr>\n");

}
print("</table>\n");
}


stdfoot();

?>