<?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);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
				<head>
					<title><?php echo lang_stats_mini_weapons; ?></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_leaderboard_viewer">
			<?php if ($Banner == 1){ ?>
			<a href="../statistics.php" target="_blank"><img src="../img/banner/logo.jpg" style="margin-top:8px" border="0" /></a>
		<?php } ?>
<table class="default_h" id="weapons" cellspacing="0" cellpadding="2" style="margin-top:12px;">
     <thead>
       <td class="head" colspan="7" ><a href="../index.php" target="_self"><span style="float:left;margin-left:5px;"><?php echo lang_index_startseite; ?></a></span><?php echo lang_stats_mini_weapons; ?></td>
     <tr> 
     	   <th width="80px"><?php echo lang_details_pic; ?></th>
			    <th><?php echo server_name; ?></th>
			     <th><?php echo lang_details_progress; ?></th>
				    <th width="100px"><?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
        	
        	
$aWeapons = array("AEK971","XM8","F2000","AUG","AN94","M416","M16","M16K","9A91","SCAR","XM8C",
"AKS74U","UZI","PP2000","UMP","UMPK","PKM","M249","QJU88","M60","XM8LMG","MG36",
"MG3","MG3K","M24","QBU88","SV98","SVU","GOL","VSS","M95","M95K","M9","M1911","MP443",
"MP412","M9-3","870MCS","NS2000","SPAS12","S20K","USAS12","M1A1THOMPSON","MK14EBR","GARAND",
"MP7","M16A1V","AK47V","M79V","M14V","M2V","MAC10V","UZIV","M60V","RPKV","XM22V",
"M21V","SVDV","M40V","M14V","TT33V","FLAMETHROWER");


    foreach ($aWeapons as $weapons){
       $kquery = 'SUM(a.`'.$weapons.'_kills`) AS `'.$weapons.'_kills`';      
        $Kquery[] = $kquery;
       $hquery = 'SUM(a.`'.$weapons.'_hs`) AS `'.$weapons.'_hs`';
        $Hquery[] = $hquery;
       $dquery = 'SUM(a.`'.$weapons.'_deaths`) AS `'.$weapons.'_deaths`';
        $Dquery[] = $dquery;
   }

      $Kquery = implode(", " , $Kquery);
      $Hquery = implode(", " , $Hquery);
      $Dquery = implode(", " , $Dquery);

if(isset($_GET['clan']) && !empty($_GET['clan']) && $_GET['clan'] != '') {
    $clan = $_GET['clan'];
   	$clan = "b.ClanTag='{$clan}'";
   }else{
   	$clan = "1";
  }

        $sSql = "SELECT  
                  ".$Kquery." , 
                  ".$Hquery." , 
                  ".$Dquery." 
                 FROM 
                  tbl_playerdata b
                 LEFT JOIN tbl_weaponstats a ON b.PlayerID = a.WeaponStatsID
                 WHERE {$clan}
                 ";
        $result = db_query($sSql);
 while ($row = mysql_fetch_assoc($result)) {	

   foreach ($aWeapons as $weapons){
       $sWeapons = $weapons.'_kills';
       $aKills[$weapons] = $row[$sWeapons];
   }
   
  arsort($aKills);
   
$allkills = 0;
foreach ($aKills as $kills){
$allkills += $kills;
}

foreach ($aKills as $key => $kills){
				
			if($row[$key.'_kills'] > 0){
    if ($row[$key.'_deaths'] == 0) {
 $kd = 0;
}else{
 $kd = ($row[$key.'_kills']/$row[$key.'_deaths']);
}

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

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

$tooltip = '<a class="tooltip" href="#"><img src="'.$installdir.'/img/weapons/'.$key.'.png" width="70px" border="0" /><span><img src="'.$installdir.'/img/weapons/'.$key.'.png" border="0" width="300px"></span></a>';

if ($allkills > 0){
      	$prozent = number_format($row[$key.'_kills']*100/$allkills, 2, '.', '.');
      	$progress = $row[$key.'_kills']*100/$allkills;
      }else{
      	$prozent = 0;
      	$progress = 0;
      }
   ?>
      <tr class="hov">	
        <td class="result"><?php echo $tooltip; ?></td>
        	<td class="result"><a id="weapondetail" href="<?php echo $installdir; ?>/stats/weapons_detail.php?weapon=<?php echo $key; ?>"><?php echo $aWeaponsName[$key]; ?></a></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($row[$key.'_kills'], 0, '.', ' '); ?></td>
        	  <td class="result"><?php echo number_format($row[$key.'_deaths'], 0, '.', ' '); ?></td>
        	   <td class="result"><?php echo number_format($row[$key.'_hs'], 0, '.', ' '); ?></td>
        	  <td class="result"><?php echo $hpro; ?></td>
        	 <tr>
        	<script type="text/javascript">  	
		$(document).ready(function() {
	
			$("a#weapondetail").fancybox({
			'autoDimensions'	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'padding' : 0
			});
     });
	</script> 	     
   <?php
  	 }
             }      
     	}
   ?>
      </table>
    <?php include_once ("../inc/footer.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>  	
	