<?php
require(\"config.php\");
include(\"includes/functions.php\");
include(\"languages/GER.php\");
include(\"includes/ColorParser.php\");
$cp = new ColorParser();
$server_count = count($server_name);
if ($server_count == 1) {
if ($page == \'home\') $page = \"info\";
$serv = 0;
}
if (!is_null($serv)) include(\"includes/db_connect.php\");
?>
<html>
<head>
<title>TDR Dirt Cup - Current Rankings</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
<?php include(\"includes/styles.php\"); ?>
<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\">
<link rel=\"shortcut icon\" href=\"favicon.ico\">
<link rel=\"icon\" type=\"image/ico\" href=\"favicon.ico\">
</head>
<?php
print \"<p class=\\\"tabletitle\\\"><h1>TDR Dirt Cup - Current Rankings ( Top50 )</h1></p>\";
if (!$pos) $pos = 0;
if (is_null($orderby)) $orderby = \"rank\";
if (is_null($sort)) $sort = \"ASC\";
$sorturl = \"?serv=$serv&lang=$lang&page=$page&orderby=%s&sort=\".(($sort == \"ASC\") ? \"DESC\" : \"ASC\");
echo \"<style type=\\\"text/css\\\">
.row.a { background-color: $bg1 }
.row.b { background-color: $bg2 }
.row:hover { background-color: $bg3 }
</style>
print \"<table width=\\\"500\\\" border=\\\"0\\\" bgcolor=\\\"#ffffff\\\" align=\\\"center\\\">\";
$sql = \"SELECT * FROM (
SELECT t1.*, @r:=@r+1 AS rank
FROM (
SELECT p.*, r.avg, r.avg IS NULL AS norank
FROM players p
LEFT JOIN rs_rank r ON p.Id = r.playerID
ORDER BY norank ASC, r.avg ASC
) t1, (SELECT @r:=0) t2
) t3
ORDER BY %s
LIMIT $pos, $count\";
if ($orderby == \"rank\") {
$sql = sprintf($sql, \"norank $sort, $orderby $sort\");
} else {
$sql = sprintf($sql, \"$orderby $sort\");
}
$result = mysql_query($sql) or die(mysql_error());
$totalrows = mysql_num_rows(mysql_query(\"SELECT * FROM players\"));
if ($totalrows < 1) {
print \"<tr><td class=\\\"celltext\\\" colspan=\\\"10\\\">No results</td></tr>\";
} else {
$new_pos_next = $pos + $count;
$new_pos_prev = $pos - $count;
$link_next = ($new_pos_next >= $totalrows) ? \"\" : \"?serv=$serv&lang=$lang&page=$page&pos=$new_pos_next&orderby=$orderby&sort=$sort\";
$link_prev = ($new_pos_prev < 0) ? \"\" : \"?serv=$serv&lang=$lang&page=$page&pos=$new_pos_prev&orderby=$orderby&sort=$sort\";
$bg = \'a\';
while($data = mysql_fetch_array($result))
{
$MwTime = $data[\'TimePlayed\'];
$hours = floor($MwTime/3600);
$minutes = floor(($MwTime/60-$hours*60));
$seconds = substr($MwTime-$minutes*60-$hours*3600,-2);
$time = sprintf(\"%02dh%02dm%02ds\", $hours, $minutes, $seconds);
if (!is_null($data[\'avg\'])) {
$avg = sprintf (\"%.1f\", $data[\'avg\']/10000);
$rank = $data[\'rank\'];
} else {
$avg = \"-\";
$rank = \"-\";
}
$bg = ($bg == \'b\') ? \'a\' : \'b\';
echo \"<tr class=\\\"row $bg\\\">\";
if($rank==\"1\") { echo \"<td class=\\\"celltext\\\"><img src=\\\"img/medals/gold.png\\\" alt=\\\"Gold\\\" title=\\\"Gold\\\"></td>\"; }
elseif($rank==\"2\") { echo \"<td class=\\\"celltext\\\"><img src=\\\"img/medals/silber.png\\\" alt=\\\"Silver\\\" title=\\\"Silver\\\"></td>\"; }
elseif($rank==\"3\") { echo \"<td class=\\\"celltext\\\"><img src=\\\"img/medals/bronze.png\\\" alt=\\\"Bronze\\\" title=\\\"Bronze\\\"></td>\"; }
else{ echo \"<td class=\\\"celltext\\\">\".$rank.\"</td>\"; }
if($data[\'Nation\']){
echo \"<td class=\\\"celltext\\\"><img src=\\\"img/flags/\".$data[\'Nation\'].\".png\\\" alt=\\\"\".$data[\'Nation\'].\"\\\" title=\\\"\".$data[\'Nation\'].\"\\\"></td>\";
} else {
echo \"<td class=\\\"celltext\\\"><img src=\\\"img/flags/UKN.png\\\" alt=\\\"Unknown\\\" title=\\\"Unknown\\\"></td>\";
}
if($rank==\"1\") { echo \"<td class=\\\"celltext\\\"><a href=\\\"http://de.tm-ladder.com/\".$data[\'Login\'].\"_rech.php\\\" class=\\\"celltext\\\"><font size=\\\"6\\\">\".$cp->toHTML($data[\'NickName\']).\"</a></td></td>\"; }
elseif($rank==\"2\") { echo \"<td class=\\\"celltext\\\"><a href=\\\"http://de.tm-ladder.com/\".$data[\'Login\'].\"_rech.php\\\" class=\\\"celltext\\\"><font size=\\\"5\\\">\".$cp->toHTML($data[\'NickName\']).\"</a></td></td>\"; }
elseif($rank==\"3\") { echo \"<td class=\\\"celltext\\\"><a href=\\\"http://de.tm-ladder.com/\".$data[\'Login\'].\"_rech.php\\\" class=\\\"celltext\\\"><font size=\\\"4\\\">\".$cp->toHTML($data[\'NickName\']).\"</a></td></td>\"; }
else{ echo \"<td class=\\\"celltext\\\"><a href=\\\"http://de.tm-ladder.com/\".$data[\'Login\'].\"_rech.php\\\" class=\\\"celltext\\\"><font size=\\\"1\\\">\".$cp->toHTML($data[\'NickName\']).\"</a></td></td>\"; }
echo \"<td class=\\\"celltext\\\">\".$avg.\"</td>\";
echo \"</tr>\";
}
}
?>
</table>