<?php
/*======================================================================*\
|| #################################################################### ||
|| # EoT-Clan BC2 Server Stats                                        # ||
|| # ---------------------------------------------------------------- # ||
|| # Dieses Copyright darf nicht entfernt werden                      # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # -----------------BC2 Server Stats is a free Software-------------# ||
|| #                      http://eot-clan.net                         # ||
|| #################################################################### ||
\*======================================================================*/
if (!defined('INCLUDE_ME')){ 
die('access not allowed'); 
}
$sSql = "SELECT 
          SUM(a.playerScore) AS Score, 
          SUM(a.playerKills) AS Kills, 
          SUM(a.playerDeaths) AS  Deaths,
          SUM(a.playerHeadshots) AS Headshots, 
          SUM(a.playerSuicide) AS Suicide, 
          SUM(a.playerTKs) AS Teamkills,
          SUM(a.playerPlaytime) AS Time,
          SUM(a.playerRounds) AS Rounds,
          SUM(b.BonusPoints) AS BonusPoints,
          COUNT(a.StatsID) AS PLAYERCOUNT
         FROM 
          tbl_playerstats a
         Left JOIN 
          tbl_playerdata b ON a.StatsID = b.PlayerID";              
    $sResult = mysql_query($sSql);
    $sStats = mysql_fetch_assoc($sResult);
     
     
    $Dquery = "SELECT 
             SUM(a.Count) as Count
            FROM 
             tbl_dogtags a";              
    $Dresult = mysql_query($Dquery);
    $Dstats = mysql_fetch_assoc($Dresult);
    
    
   $newquery = "SELECT
             Count(a.FirstSeenOnServer)
            FROM 
             tbl_playerstats a
            WHERE 
             TO_DAYS(a.FirstSeenOnServer) = TO_DAYS(NOW())";              
    $newresult = mysql_query($newquery);
    $newstats = mysql_fetch_assoc($newresult);
    
    $kstreakquery = "SELECT
             a.StatsID,
             a.Killstreak,
             b.SoldierName
            FROM 
             tbl_playerstats a
            Left JOIN 
             tbl_playerdata b ON a.StatsID = b.PlayerID
            ORDER by
             a.Killstreak DESC LIMIT 1";              
    $kstreakresult = mysql_query($kstreakquery);
    $kstreakstats = mysql_fetch_assoc($kstreakresult);
    
     $dstreakquery = "SELECT
             a.StatsID,
             a.Deathstreak,
             b.SoldierName
            FROM 
             tbl_playerstats a
            Left JOIN 
             tbl_playerdata b ON a.StatsID = b.PlayerID
            ORDER by
             a.Deathstreak DESC LIMIT 1";              
    $dstreakresult = mysql_query($dstreakquery);
    $dstreakstats = mysql_fetch_assoc($dstreakresult);
    
$time_a	= $sStats['Time'];
$s = $time_a;
$time = sprintf(" %02dT. %02dStd. %02dmin.",$s/24/60/60,$s/60/60%24,$s/60%60);
 
 if ($sStats['Deaths'] == 0){
		        $s_KD = '0';
	       }else{ 
	       	$s_KD = ($sStats['Kills']/$sStats['Deaths']); 
   	
	     }
             if($s_KD  >= 1 ){
	             $KD_p = "<span class='positiv'>" . number_format($s_KD, 2, '.', '.') . "</span>";
	           }else{
             	 $KD_p = "<span class='negativ'>" . number_format($s_KD, 2, '.', '.') . "</span>";
	               }

if ($sStats['Rounds'] == 0){
	$ppr = 0;
}else{
	$ppr = ($sStats['Score']/$sStats['Rounds']);
}

if ($sStats['Time'] == 0){
  $ppm = 0;
}else{
	$Time = ($sStats['Time']/60);
	$ppm = ($sStats['Score']/$Time);
}
?>
<table class="default_h" id="index"  cellspacing="0" cellpadding="0">
			<td class="head" colspan="4">Serverstats</td>
				<tr>
				    <td class="result" style="width:190px;text-align:left;height:18px;">&nbsp;<?php echo lang_serverstats_allpoints; ?>: <?php echo number_format($sStats['Score'], 0, ',', ' '); ?></td>
				    <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_points; ?>: <?php echo number_format($sStats['Score']-$sStats['BonusPoints'], 0, ',', ' '); ?></td>
				    <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_bonus; ?>: <?php echo number_format($sStats['BonusPoints'], 0, ',', ' '); ?></td>
            <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_time; ?>: <?php echo $time; ?></td>
          </tr>
           <tr>
            <td class="result" style="width:190px;text-align:left;height:18px;">&nbsp;<?php echo lang_serverstats_kills; ?>: <?php echo number_format($sStats['Kills'], 0, ',', ' '); ?></td>
				    <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_deaths; ?>: <?php echo number_format($sStats['Deaths'], 0, ',', ' '); ?></td>
				    <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_tk; ?>: <?php echo number_format($sStats['Teamkills'], 0, ',', ' '); ?></td>
				    <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_kd; ?>: <?php echo $KD_p; ?></td>   	
         </tr>
           <tr>
            <td class="result" style="width:190px;text-align:left;height:18px;">&nbsp;<?php echo lang_serverstats_head; ?>: <?php echo number_format($sStats['Headshots'], 0, ',', ' '); ?></td>
				    <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_suicide; ?>: <?php echo number_format($sStats['Suicide'], 0, ',', ' '); ?></td>
				    <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_round; ?>: <?php echo number_format($sStats['Rounds'], 0, ',', ' '); ?></td>
				    <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_Dogtags; ?>: <?php echo number_format($Dstats['Count'], 0, ',', ' '); ?></td>
				  </tr>
           <tr>
				    <td class="result" style="width:190px;text-align:left;height:18px;">&nbsp;<?php echo lang_serverstats_ppr; ?>: <?php echo number_format($ppr, 0, ',', ' '); ?></td>
				    <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_ppm; ?>: <?php echo number_format($ppm, 2, ',', ' '); ?></td>   	
            <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_newp; ?>: <?php echo $newstats['Count(a.FirstSeenOnServer)']; ?></td>   	
            <td class="result" style="width:190px;text-align:left;height:18px;"><?php echo lang_serverstats_kstreak; ?>: <?php echo $kstreakstats['Killstreak']; ?> (<a href="ministats.php?name=<?php echo urlencode($kstreakstats['SoldierName']); ?>"><?php echo htmlspecialchars($kstreakstats['SoldierName']); ?></a>)</td>   	
         </tr>
           <tr>
				    <td class="result" colspan="2" style="width:380px;text-align:left;height:18px;">&nbsp;<?php echo lang_serverstats_dstreak; ?>: <?php echo $dstreakstats['Deathstreak']; ?> (<a href="ministats.php?name=<?php echo urlencode($dstreakstats['SoldierName']); ?>"><?php echo htmlspecialchars($dstreakstats['SoldierName']); ?></a>)</td>
				    <td class="result" colspan="2" style="width:380px;text-align:left;height:18px;"><?php echo lang_serverstats_allplayers; ?>: <span class="sonstige"><?php echo $sStats['PLAYERCOUNT']; ?></span></td>
         </tr>
			</table>

