<?php
/*
Fretsweb - A Frets on Fire chart server
Copyright (C) 2009 Daan Sprenkels
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Include the common file
require_once "admin/common.php";
// Send headers for content-type
header('Content-Type: text/html; charset=utf-8');
// Include the language
require_once "lang/$language.php";
// Write header
print_header($lang['scores']);
// Set $ContestPoints if it isn't set (will never occur)
if (! isset($ContestPoints) )
$ContestPoints = array ( 25, 20, 18, 16, 14, 12, 10, 8, 7, 6, 5, 4, 3, 2, 1 );
// Get data
$users = mysql_query( "SELECT * FROM contest_players" ) or die( "DB error (get players in DCC)" );
$dbbig = mysql_query( "SELECT `hash`,`difficulty`,`name`,`score` FROM `contest_scores`" ) or die( "DB Error (get bigdata in DCC)" );
while( $row = mysql_fetch_assoc( $dbbig ) ){
$data[ $row["difficulty"] ][ $row["hash"] ][ $row["name"] ] = $row["score"];
}
mysql_free_result($dbbig);
// Calculate the score for each difficulty
echo("<table class=\"small\"><tr>");
foreach( array( "Amazing", "Medium", "Easy", "Supaeasy" ) as $difficulty ) {
echo("<td>");
echo("<h3>{$lang[$difficulty]}</h3>");
// reset users' scores
unset($points);
for( $i = 0; $i < mysql_numrows( $users ); $i++ )
if( mysql_result($users, $i, $difficulty) ) // init only if the user is allowed to upload scores at this difficulty
$points[ mysql_result($users, $i, "name") ] = 0;
// calc
if(isset($data[$difficulty]))
{
foreach( $data[$difficulty] as $hash => $name_score )
{
arsort( $name_score );
$counter = -1;
$oldscore = -1;
foreach( $name_score as $name => $score )
{
if( $score != $oldscore )
{
$counter++;
}
$oldscore = $score;
if( $counter < count( $ContestPoints ) )
$points[ $name ] += $ContestPoints[ $counter ];
}
}
}
// show the score for a given difficulty
if( array_sum($points) > 0 )
{
echo "<table>\n";
ksort( $points ); // arsort is not stable, but at least this way we always guarantee the same order for players with the same score
arsort( $points );
$counter = 0;
$oldscore = -1;
foreach ($points as $user => $score)
{
if( $score != $oldscore )
{
$counter++;
}
$oldscore = $score;
if($score > 0)
{
echo "<tr>";
if($counter == 1)
echo "<td><img src=\"images/gold-small.png\" alt=\"G\"></td>\n";
elseif($counter == 2)
echo "<td><img src=\"images/silver-small.png\" alt=\"S\"></td>\n";
elseif($counter == 3)
echo "<td><img src=\"images/bronze-small.png\" alt=\"B\"></td>\n";
else
echo "<td>$counter</td>";
echo "<td><a href=\"player.php?name=$user\">$user</a></td><td>$score {$lang['points']}</td>";
echo "</tr>";
}
}
echo "</table>\n";
}
echo("</td>");
}
echo("</tr></table>");
// Write score explanation
echo "{$lang["scoring_system"]} <table class=\"small\"><tr><th>" . $lang["position:"] . "</th>";
for ( $i = 1; $i <= count( $ContestPoints ); $i++ )
{
echo "<td>$i</td>";
}
echo "<td>> " . count($ContestPoints) . "</td></tr><tr><th>" . $lang["points:"] . "</th>";
for ( $i = 0; $i < count( $ContestPoints ); $i++ )
{
echo "<td>" . $ContestPoints[$i] . "</td>";
}
echo "<td>0</td></tr></table>";
// Write footer
echo "</div>";
include "admin/pagefooter.php";
echo "
</div>
</body>
</html>";
// Close database link
mysql_close( $db_link );
?>