<?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                         # ||
|| #################################################################### ||
\*======================================================================*/
require_once '../inc/config.php';
include_once ('../lang/language.php');
include_once ('../lang/'.$lang_file.'');
include_once ('../inc/weapons_array.php');

$_GET = security::escape($_GET);
$_POST = security::escape($_POST);
 
 if(isset($_GET['weapon']) && !empty($_GET['weapon']) && $_GET['weapon'] != '') {
       $weapon = $_GET['weapon']; 
   }else{
     $weapon = "AEK971";
 }

if (array_key_exists($weapon , $aWeaponsName)){
  $weapon = $weapon;
}else{
	$weapon = "AEK971";
  }
   
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
				<head>
					<title><?php echo lang_details_ex; ?></title>
	         <link rel="stylesheet" type="text/css" href="../css/fancybox.css" media="screen">
	        <link rel="stylesheet" type="text/css" href="../css/style.css" /> 
	      </head>
	       <body>
	         <script type="text/javascript" src="../js/jquery.simpletip-1.3.1.js"></script>
	          <script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
	         <script type="text/javascript" src="../js/jquery.fancybox-1.3.1.js"></script>
	        <script type="text/javascript" src="../js/jquery.tablesorter.js"></script>
	       </body> 
		<div class="body_ministats">
<table class="default_m" id="weapons" cellspacing="0" cellpadding="2" style="margin-top:12px;">
     <thead>
       <td class="head" colspan="7" ><?php echo lang_details_ex; ?> <?php echo $aWeaponsName[$weapon]; ?></td>
        <tr>
        <td class="result" colspan="7">
        	<img src="<?php echo $installdir; ?>/img/weapons/<?php echo $weapon; ?>.png" width="500px" border="0" />
        </td>
        <tr>
         <td class="result" colspan="7"></td>
     <tr> 
			    <th><?php echo server_name; ?></th>
			     <th width="120px"><?php echo lang_details_stars; ?></th>
			     <th width="100px"><?php echo lang_details_progress; ?></th>
				    <th><?php echo lang_kills; ?></th>
				     <th width="100px"><?php echo lang_deaths; ?></th>
				    <th width="100px"><?php echo lang_stats_head; ?></th>
				   <th width="115px"><?php echo lang_stats_headpro; ?></th>
			</tr>
       </thead> 
        <tbody> 
        	<?php
         $queryI = 'a.`'.$weapon.'_kills`, a.`'.$weapon.'_hs`, a.`'.$weapon.'_deaths` , WeaponStatsID';
         $ORDER = 'a.`'.$weapon.'_kills`';
         $sSql = "SELECT 
                   SUM(b.`".$weapon."_kills`) AS `".$weapon."_kills` 
                  FROM 
                   tbl_weaponstats b LIMIT 50";
         $result = db_query($sSql); 
         $row = mysql_fetch_assoc($result);	
         $allkills = $row[$weapon.'_kills'];


        $sSql = "SELECT 
                  ".$queryI.", 
                  b.PlayerID,
                  b.SoldierName 
                 FROM 
                  tbl_weaponstats a 
                 Left JOIN 
                  tbl_playerdata b ON a.WeaponStatsID = b.PlayerID
                 ORDER BY 
                  ".$ORDER." DESC  LIMIT 50";
       
        
        $result = db_query($sSql); 
 while ($data = mysql_fetch_assoc($result)) {	

			if($data[$weapon.'_kills'] > 0){
    if ($data[$weapon.'_deaths'] == 0) {
 $kd = 0;
}else{
 $kd = ($data[$weapon.'_kills']/$data[$weapon.'_deaths']);
}

if($kd >= 1){
	  $kd = "<span class=positiv>".number_format($kd, 2, '.', '.')."</span>";
	}else{
    $kd = "<span class=negativ>".number_format($kd, 2, '.', '.')."</span>";	
}

	if ($data[$weapon.'_kills'] > 0){
			$hpro = number_format($data[$weapon.'_hs']*100/$data[$weapon.'_kills'], 2, '.', '.').'&#37;';
		}else{
			$hpro = '0.00&#37;';
		}


if ($allkills > 0){
      	$prozent = number_format($data[$weapon.'_kills']*100/$allkills, 2, '.', '.');
      	$progress = $data[$weapon.'_kills']*100/$allkills;
      }else{
      	$prozent = 0;
      	$progress = 0;
      }
      
	      $key = $weapon;
	      if(in_array($weapon,$aGadgets)){
	      	include ('../inc/stars_gadgets.php');
	      }else{
          include ('../inc/stars_weapon.php');
       }
       
       
   ?>
      <tr class="hov">	
      	<td class="result"><a href="<?php echo $installdir; ?>/ministats.php?name=<?php echo urlencode($data['SoldierName']); ?>"><?php echo htmlspecialchars($data['SoldierName']); ?></a></td>
      	 <td class="result"><?php echo $bron.$silv.$count.$gold.$plat; ?></td>
        	<td class="result">
        	<div class="progress_weapon">
      		<div class="progress_size_weapon" style="width:<?php echo $progress; ?>%;" title="<?php echo $prozent; ?>%">&nbsp;</div>
				</div>
			</td>
        	 <td class="result"><?php echo number_format($data[$weapon.'_kills'], 0, ',', ' '); ?></td>
        	  <td class="result"><?php echo number_format($data[$weapon.'_deaths'], 0, ',', ' '); ?></td>
        	   <td class="result"><?php echo number_format($data[$weapon.'_hs'], 0, ',', ' '); ?></td>
        	  <td class="result"><?php echo $hpro; ?></td>
        	 <tr>  
   <?php 	
             }      
     	}
   ?>
      </table>
     <?php include_once ("../inc/footerm.php"); ?>
	  <br /> 
 </tbody>
</div>
 <script type="text/javascript">
     $(document).ready(function() { 
    	jQuery.tablesorter.addParser({
  id: "commaDigit",
  is: function(s, table) {
    var c = table.config;
    return $.tablesorter.isDigit(s.replace(/[,. ]/g, ""), c);
  },
  format: function(s) {
    return $.tablesorter.formatFloat(s.replace(/[,. ]/g, ""));
  },
  type: "numeric"
});
    $("#weapons").tablesorter({ 
    	
        headers: { 
            0: {   
                sorter: false 
            },
            
        } 
     
    }); 
});
 </script>  	
	