<?

require_once("include/bittorrent.php");
hit_start();

dbconn(false);

hit_count();

loggedinorreturn();


stdhead("Flash scores - page 2");

if (get_user_class() < UC_USER)
{
stdmsg("Sorry...", "you do not have access.");
stdfoot();
exit;
}

?>
<table class=tableoutborder width=60% border=0 cellspacing=1 cellpadding=5><tr><td class=tabletitle>
<div align=center><B>Gesamtranking</B></td></tr>
<tr><td class=tablea><center><A HREF=arcade.php><b>Zurück zur Arcade</b></a></center><P></td></tr>
<tr><td class=tablea><center><A HREF=flashscores.php><b>Zurück zur ersten Seite</b></a></center><P></td></tr>
</table><br><br>
<?
$ID=0;
$result = MySQL_QUERY("SELECT * FROM flashscores GROUP BY user;");
while($populate = MySQL_FETCH_ARRAY($result))
{
$ID++;
if(!isset($gamesplayed[$ID]))
{
$gamesplayed[$ID]=0;
}
if(!isset($totalscore[$ID]))
{
$totalscore[$ID]=0;
}
if(!isset($megascore[$ID]))
{
$megascore[$ID]=0;
}
if(!isset($losspoints[$ID]))
{
$losspoints[$ID]=0;
}
if(!isset($averagerank[$ID]))
{
$averagerank[$ID]=0;
}
if(!isset($user[$populate["user"]]))
{
$user[$populate["user"]]=$ID;
}
if(!isset($IDofuser[$ID]))
{
$IDofuser[$ID]=$populate["user"];
}
}
$result = MySQL_QUERY("SELECT * FROM flashscores ORDER BY score DESC;");
while($scores = MySQL_FETCH_ARRAY($result))
{
$ranking = MySQL_QUERY("SELECT COUNT(*) FROM flashscores WHERE game = ".$scores["game"]." AND score > ".$scores["score"].";") OR DIE(MySQL_ERROR());
if($rankrow = mysql_fetch_row($ranking))
{
$rank = $rankrow[0]+1;
}else{
$rank = 1;
}
$losspoints[$user[$scores["user"]]]+=$rank;
if($rank<6)
{
$totalscore[$user[$scores["user"]]]+=(10-(($rank-1)*2));
}
$megascore[$user[$scores["user"]]]+=$scores["score"];
}
$result = MySQL_QUERY("SELECT * FROM flashscores GROUP BY user;");
while($scores = MySQL_FETCH_ARRAY($result))
{
$result2 = MySQL_QUERY("SELECT COUNT(*) FROM flashscores WHERE user = ".$scores["user"].";");
if($gamesamount = MYSQL_FETCH_ROW($result2))
{
$amountofgames = $gamesamount[0];
}
$gamesplayed[$user[$scores["user"]]]=$amountofgames;
}
arsort ($totalscore);
reset ($totalscore);
print("<TABLE class=tableoutborder border=0 cellspacing=1 cellpadding=5 align=center width=60%><TR><TD class=tabletitle COLSPAN=3><B><CENTER>Ergebnis Rang</CENTER></B></TD></TR>");
print("<TD align=left class=tablea WIDTH=50%><b>Name</b></TD><TD align=center class=tableb><b>Ergebnis</b></TD></TR>");
while (list ($userID, $score) = each ($totalscore)) {
$result = MySQL_QUERY("SELECT * FROM users WHERE id = ".$IDofuser[$userID].";");
if($userX = MySQL_FETCH_ARRAY($result))
{
$username = $userX["username"];
}else{
$username = "Unknown?!";
}
if($score>0)
{
if($IDofuser[$userID]==$CURUSER["id"])
{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tableb WIDTH=50%>$username</TD><TD align=center class=tableb>$score</TD></TR>";
}else{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tableb WIDTH=50%>$username</TD><TD align=center class=tableb>$score</TD></TR>";
}
}
}
print("</TABLE><P>");
arsort ($gamesplayed);
reset ($gamesplayed);
print("<TABLE class=tableoutborder border=0 cellspacing=1 cellpadding=5 align=center width=60%><TR><TD class=tabletitle COLSPAN=3><B><CENTER>Anzahl der gespielten Spiele</CENTER></B></TD></TR>");
print("<TD align=left class=tablea WIDTH=50%><b>Name</b></TD><TD align=center class=tableb><b>Spiele</b></TD></TR>");
while (list ($userID, $games) = each ($gamesplayed)) {
$result = MySQL_QUERY("SELECT * FROM users WHERE id = ".$IDofuser[$userID].";");
if($userX = MySQL_FETCH_ARRAY($result))
{
$username = $userX["username"];
}else{
$username = "Unknown?!";
}
if($games>0)
{
if($IDofuser[$userID]==$CURUSER["id"])
{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tablea WIDTH=50%>$username</TD><TD align=center class=tableb>$games</TD></TR>";
}else{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tablea WIDTH=50%>$username</TD><TD align=center class=tableb>$games</TD></TR>";
}
}
}
print("</TABLE><P>");
arsort ($megascore);
reset ($megascore);
print("<TABLE class=tableoutborder border=0 cellspacing=1 cellpadding=5 align=center width=60%><TR><TD class=tabletitle COLSPAN=3><B><CENTER>Gesamte Ergebnis</CENTER></B></TD></TR>");
print("<TD align=left class=tablea WIDTH=50%><b>Name</b></TD><TD align=center class=tableb><b>Ergebnis</b></TD></TR>");
while (list ($userID, $score) = each ($megascore)) {
$result = MySQL_QUERY("SELECT * FROM users WHERE id = ".$IDofuser[$userID].";");
if($userX = MySQL_FETCH_ARRAY($result))
{
$username = $userX["username"];
}else{
$username = "Unknown?!";
}
if($score>0)
{
if($IDofuser[$userID]==$CURUSER["id"])
{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tablea WIDTH=50%>$username</TD><TD align=center class=tableb>$score</TD></TR>";
}else{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tablea WIDTH=50%>$username</TD><TD align=center class=tableb>$score</TD></TR>";
}
}
}
print("</TABLE><P>");
asort ($losspoints);
reset ($losspoints);
print("<TABLE class=tableoutborder border=0 cellspacing=1 cellpadding=5 align=center width=60%><TR><TD class=tabletitle COLSPAN=3><B><CENTER>Verluste Punkte</CENTER></B></TD></TR>");
print("<TD align=left class=tablea WIDTH=50%><b>Name</b></TD><TD align=center class=tableb><b>Ergebnis</b></TD></TR>");
while (list ($userID, $score) = each ($losspoints)) {
$result = MySQL_QUERY("SELECT * FROM users WHERE id = ".$IDofuser[$userID].";");
if($userX = MySQL_FETCH_ARRAY($result))
{
$username = $userX["username"];
}else{
$username = "Unknown?!";
}
if($score>0)
{
if($IDofuser[$userID]==$CURUSER["id"])
{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tablea WIDTH=50%>$username</TD><TD align=center class=tableb>$score</TD></TR>";
}else{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tablea WIDTH=50%>$username</TD><TD align=center class=tableb>$score</TD></TR>";
}
}
}
print("</TABLE><P>");
$ID=0;
$result = MySQL_QUERY("SELECT * FROM flashscores GROUP BY user;");
while($populate = MySQL_FETCH_ARRAY($result))
{
$ID++;
$averagerank[$ID]=$losspoints[$ID]/$gamesplayed[$ID];
}
asort ($averagerank);
reset ($averagerank);
print("<TABLE class=tableoutborder border=0 cellspacing=1 cellpadding=5 align=center width=60%><TR><TD class=tabletitle COLSPAN=3><B><CENTER>Durchschnittsrang</CENTER></B></TD></TR>");
print("<TD align=left class=tablea WIDTH=50%><b>Name</b></TD><TD align=center class=tableb><b>Rang</b></TD></TR>");
while (list ($userID, $score) = each ($averagerank)) {
$result = MySQL_QUERY("SELECT * FROM users WHERE id = ".$IDofuser[$userID].";");
if($userX = MySQL_FETCH_ARRAY($result))
{
$username = $userX["username"];
}else{
$username = "Unknown?!";
}
if($score>0)
{
if($IDofuser[$userID]==$CURUSER["id"])
{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tablea WIDTH=50%>$username</TD><TD align=center class=tableb>$score</TD></TR>";
}else{
echo "<TR style=\"background-color: #BBBBBB\"><TD align=left class=tablea WIDTH=50%>$username</TD><TD align=center class=tableb>$score</TD></TR>";
}
}
}
print("</TABLE><P>");
?>
</td></tr>
</table>
</form>
<?

stdfoot();
hit_end();

?>