<?PHP
// Include the configuration & database connection files.
require ( './Config.php' );
require ( './DBConnect.php' );
// Creating a class called powerGamers.
class powerGamers
{
// Creating a function called onRefresh.
function onRefresh ( )
{
// Include the configuration file.
require ( './Config.php' );
// Variables required by the onRefresh function.
$refreshTime = $config['GENERAL'][1];
$limitTop = $config['GENERAL'][2];
echo "<div class=\"info\"><h1>Top $limitTop PowerGamers</h1>The scoreboard will refresh each and every <strong>$refreshTime</strong> minutes.</div>";
}
// Creating a function called updateScores.
function updateScores ( )
{
// Include the configuration file.
require ( './Config.php' );
// Variables required by the updateScores function.
$onlineDays = $config['GENERAL'][0];
$DBPlayers = $config['DB'][4];
$DBPGs = $config['DB'][5];
$updated = fread ( fopen ( 'update.txt' , 'r' ) , filesize ( 'update.txt' ) );
$lastLogin = date ( "d-m-Y" , mktime ( 0 , 0 , 0 , date ( "m" ) , date ( "d" ) - $onlineDays , date ( "Y" ) ) );
$DBPlayersResult = mysql_query ( "SELECT * FROM `$DBPlayers`" );
// Loop the players.
while ( $row = mysql_fetch_array ( $DBPlayersResult ) )
{
// Required variables.
$playerLastLogin = date ( "d-m-Y" , $row[lastlogin] );
$DBPGsResult = mysql_query ( "SELECT * FROM `$DBPGs` WHERE `id` = $row[id]" );
$checkPGs = mysql_num_rows ( $DBPGsResult );
$fetchPGs = mysql_fetch_array ( $DBPGsResult );
// Check which player has been online the past X days.
if ( $playerLastLogin >= $lastLogin )
{
// Check if the players already exists in the PowerGamers table.
if ( $checkPGs == 0 )
{
// Add new powergamers.
mysql_query ( "
INSERT INTO $DBPGs ( id , oldexperience , newexperience , difference )
VALUES ( '$row[id]' , '$row[experience]' , '$row[experience]' , '0' )
" );
}
elseif ( $checkPGs >= 1 && $updated != date ( "H" ) )
{
$experience[old] = $fetchPGs[newexperience];
$experience[now] = $row[experience];
$experience[dif] = $experience[now] - $experience[old];
// Update the current powergamers.
mysql_query ( "
UPDATE $DBPGs
SET oldexperience = '$experience[old]',
newexperience = '$experience[now]',
difference = '$experience[dif]'
WHERE id = $row[id]
" );
// Change update.txt to contain 1 instead of 0.
$fileHandle = fopen ( 'update.txt' , 'w' );
fwrite ( $fileHandle, date ( "H" ) );
fclose ( $fileHandle );
}
}
}
}
// Creating a function called publicScoreboard.
function publicScoreboard ( )
{
// Include the configuration file.
require ( './Config.php' );
// Including the onRefresh & updateScores function.
$obj = new powerGamers;
$obj -> onRefresh();
$obj -> updateScores();
// Variables required by the publicScoreboard function.
$limitTop = $config['GENERAL'][2];
$DBPlayers = $config['DB'][4];
$DBPGs = $config['DB'][5];
$DBPGsResult = mysql_query ( "SELECT * FROM `$DBPGs` WHERE `difference` != '0' ORDER BY `difference` DESC LIMIT $limitTop" );
$DBPGsCheck = mysql_num_rows ( mysql_query ( "SELECT * FROM `$DBPGs` WHERE `difference` != '0'" ) );
$i = 0;
// Print scoretable titles.
echo "<div class=\"scoretitles\">";
echo "<div style=\"width: 5%; float: left;\">#</div>";
echo "<div style=\"width: 35%; float: left;\">Character</div> ";
echo "<div style=\"width: 35%; float: left;\">Old / New Experience</div> ";
echo "<div style=\"width: 23%; float: left;\">Difference</div>";
echo " </div>";
echo "<div class=\"score\">";
// Check if all the entries have difference 0.
if ( $DBPGsCheck == 0 )
{
echo "<div class=\"score1\"><div>There are currently no players with an experience increasement.</div></div>";
}
// Loop the players.
while ( $row = mysql_fetch_array ( $DBPGsResult ) )
{
// Required variables.
$i++;
$PGName = mysql_fetch_array ( mysql_query ( "SELECT * FROM `$DBPlayers` WHERE `id` = $row[id]" ) );
// Make every second background a different color.
switch ( $i % 2 )
{
case 1:
$bg = 1;
break;
default:
$bg = 2;
break;
}
// Print the result.
echo "<div class=\"score$bg\">";
echo "<div style=\"width: 5%; float: left;\">$i</div>";
echo "<div style=\"width: 35%; float: left;\"><a href=\"characters.php?char=$PGName[name]\">$PGName[name]</a></div> ";
echo "<div style=\"width: 35%; float: left;\"><strike style=\"color: #900808;\">$row[oldexperience]</strike> -> $row[newexperience]</div> ";
echo "<div style=\"width: 23%; float: left;\"><strong style=\"color: #539c33;\">+$row[difference]</strong></div>";
echo " </div>";
}
echo "</div>";
}
}
// Print the publicScoreboard function.
powerGamers::publicScoreboard();
?>