<?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                         # ||
|| #################################################################### ||
\*======================================================================*/

$iCounter = 0;
$ikills = 0;
$ideaths = 0;
$iscore = 0;
$pingAll = 0;

?><div style="float:left;">
   <table class="default_h" cellspacing="0" cellpadding="0" style="float:left;width:392px;margin-bottom:12px;margin-left:8px;">
     <thead>
      <td class="head" colspan="8"><?php echo $Team1; ?> (Tickets: <?php echo round($aServerSettings[9]) ?>)</td>
   <tr> 
	    <th width="45px"><?php echo server_tag; ?></th> 
	     <th width="20px"></th> 
	       <th><?php echo server_name; ?></th> 
           <th width="30px" align="right"><img src="img/viewer/kills.png" title="<?php echo lang_kills; ?>" /></th> 
            <th width="30px" align="right"><img src="img/viewer/deaths.png" title="<?php echo lang_deaths; ?>" /></th>  
          <th width="45px" align="right"><img src="img/viewer/kd.png" title="<?php echo lang_kd; ?>" /></th>  
        <th width="60px"><?php echo server_points; ?></th> 
       <th width="32px" align="right"><img src="img/viewer/ping.png" title="Ping" /></th> 
   </tr>
 </thead>
<tbody>

<?php

$i = 0;
if ($aServerSettings[2] >=1){
    if (is_array($Players_ar)) foreach ($Players_ar as $Players){
    	if ($Players['teamid'] == 1){
   
	       if ($Players['deaths'] == 0){
		        $s_KD = '0';
	       }else{ $s_KD = ($Players['kills']/$Players['deaths']); 
	       	
	     }
             if($s_KD  == 0 && ($Players['kills'] >= 1)){
	             $sKd = '<span class="positiv">'.$Players['kills'].'.00</span>';
	           }elseif ($s_KD  == 0 && ($Players['deaths'] >= 1)){
             	 $sKd = "<span class='negativ'>0.00</span>";	
	           }elseif ($s_KD  == 0 && ($Players['deaths'] == 0)){
	             $sKd = '0.00';
	           }elseif($s_KD  >= 1){
               $sKd = "<span class='positiv'>" . number_format($s_KD, 2, '.', '.') . "</span>";	
             }else{
               $sKd = "<span class='negativ'>" . number_format($s_KD, 2, '.', '.') . "</span>";	
            }
            
            
         if (in_array($Players['clantag'], $ClanTag)) {
		        $clantag = '<tr class="own_viewer" style="height:20px;"><td class="result"><span class="sonstige">' .htmlspecialchars($Players['clantag']) . '</span></td>';
           }elseif ($Players['clantag'] != "") {
           $clantag = '<tr style="height:20px;"><td class="result">'.htmlspecialchars($Players['clantag']).'</td>'; 
          }else{
	         $clantag = '<tr style="height:20px;"><td class="result">&nbsp;</td>';
	      }

      
       if(strlen($Players['name']) <= 16) {
           $PlayerN = $Players['name'];
        } else {
          $PlayerN = substr($Players['name'],0,14) . '..'; 
      }

   $abfrage = "SELECT a.PlayerID,SoldierName, b.bfbcsID,Rank FROM tbl_playerdata a
    Left JOIN tbl_bfbcs b ON a.PlayerID = b.bfbcsID
       WHERE a.SoldierName = '{$Players['name']}'"; 
      $ergebnis = mysql_query($abfrage);
     $row = mysql_fetch_assoc($ergebnis);
  if(isset($row['Rank'])){
   $Rank = $row['Rank'];
  }else{
  	$Rank = '0';
}

if ($Players['name'] == $row['SoldierName']){
	$link = '<td class="result"><a href="ministats.php?name='.urlencode($row['SoldierName']).'" target="_blank">'.htmlspecialchars($PlayerN).'</a></td>';
}else{
	$link = '<td class="result"><a href="http://bfbcs.com/stats_pc/'.urlencode($Players['name']).'" target="_blank">'.htmlspecialchars($PlayerN).'</a></td>';
}
  

         ?>
	       <?php echo $clantag ?>
	       <td class="result"><img src="img/rank/thumb/<?php echo $Rank; ?>.png" border="0" width="20px" title="<?php echo htmlspecialchars($PlayerN).lang_stats_haverank.$Rank.'('.$rankname[$Rank].')'; ?>" /></td>
	          <?php echo $link; ?>
	          <td class="result"><?php echo $Players['kills'] ?></td>
	            <td class="result"><?php echo $Players['deaths'] ?></td>
	           <td class="result"><?php echo $sKd ?></td>
	          <td class="result"><?php echo $Players['score'] ?></td>
	        <td class="result"><?php echo $Players['ping'] ?></td>
	       <?php
	       ++$iCounter;
	       $ikills += $Players['kills'];
	       $ideaths += $Players['deaths'];
	       $iscore += $Players['score'];
	       $pingAll += $Players['ping'];     
    }
  }
 }
 if ($ideaths == 0 ){
 	  $iPlayerKD = 0;
 	}else{
    $iPlayerKD = ($ikills/$ideaths);
  }
    if($iPlayerKD  == 0 && ($ikills >= 1)){
	             $iKd = '<span class="positiv">'.$ikills.'.00</span>';
	           }elseif ($iPlayerKD  == 0 && ($ideaths >= 1)){
             	 $iKd = '<span class="negativ">0.00</span>';	
	           }elseif ($iPlayerKD  == 0 && ($ideaths == 0)){
	             $iKd = '0.00';
	           }elseif($iPlayerKD  >= 1){
               $iKd = '<span class="positiv">' . number_format($iPlayerKD, 2, '.', '.') . '</span>';	
             }else{
               $iKd = '<span class="negativ">' . number_format($iPlayerKD, 2, '.', '.') . '</span>';	
            }
            
           if ($pingAll == 0){
 	           $ping = '0';
 	        }else{
            $ping = number_format($pingAll/$iCounter, 0, ',', '.');
        }
       	       
          
  ?>
</tbody>
     <td class="result" height="25px"><b>&oslash;</td>
     	<td class="result">&nbsp;</td> 
      <td class="result" ><b><?php echo server_players; ?> <span class="sonstige"><?php echo $iCounter ?></b></span></td>
  	    <td class="result"><b><?php echo $ikills ?></b></td>
  	     <td class="result"><b><?php echo $ideaths ?></b></td>
  	      <td class="result"><b><?php echo $iKd ?></b></td>
  	    <td class="result"><b><?php echo $iscore ?></b></td>
  	   <td class="result"><b><?php echo $ping ?></b></td>
  	   <td class="result"></td>
  </table>
</div>
  
  
  
   <?php
  $iiCounter = 0;
  $iikills = 0;
  $iideaths = 0;
  $iiscore = 0;
  $ipingAll = 0;
  ?>
  <div style="float:right;margin-right:8px;">
  <table class="default_h" cellspacing="0" cellpadding="0" style="float:left;width:392px;margin-bottom:12px;margin-left:8px;">
     <thead>
      <td class="head" colspan="8"><?php echo $Team2; ?> (Tickets: <?php echo round($aServerSettings[10]) ?>)</td>
   <tr> 
	    <th width="45px"><?php echo server_tag; ?></th> 
	     <th width="20px"></th> 
	       <th><?php echo server_name; ?></th> 
           <th width="30px" align="right"><img src="img/viewer/kills.png" title="<?php echo lang_kills; ?>" /></th> 
            <th width="30px" align="right"><img src="img/viewer/deaths.png" title="<?php echo lang_deaths; ?>" /></th>  
          <th width="45px" align="right"><img src="img/viewer/kd.png" title="<?php echo lang_kd; ?>" /></th>  
        <th width="60px"><?php echo server_points; ?></th> 
       <th width="32px" align="right"><img src="img/viewer/ping.png" title="Ping" /></th> 
   </tr>
 </thead>
<tbody>

<?php
if ($aServerSettings[2] >=1){
      if (is_array($Players_ar)) foreach ($Players_ar as $Players){
    	if ($Players['teamid'] == 2){
  
	       if ($Players['deaths'] == 0){
		        $s_KD = '0';
	       }else{ $s_KD = ($Players['kills']/$Players['deaths']); 
	       	
	     }
             if($s_KD  == 0 && ($Players['kills'] >= 1)){
	             $sKd = '<span class="positiv">'.$Players['kills'].'.00</span>';
	           }elseif ($s_KD  == 0 && ($Players['deaths'] >= 1)){
             	 $sKd = "<span class='negativ'>0.00</span>";	
	           }elseif ($s_KD  == 0 && ($Players['deaths'] == 0)){
	             $sKd = '0.00';
	           }elseif($s_KD  >= 1){
               $sKd = "<span class='positiv'>" . number_format($s_KD, 2, '.', '.') . "</span>";	
             }else{
               $sKd = "<span class='negativ'>" . number_format($s_KD, 2, '.', '.') . "</span>";	
            }
            
            
         if (in_array($Players['clantag'], $ClanTag)) {
		        $clantag = '<tr class="own_viewer" style="height:20px;"><td class="result"><span class="sonstige">' .htmlspecialchars($Players['clantag']) . '</span></td>';
           }elseif ($Players['clantag'] != "") {
           $clantag = '<tr style="height:20px;"><td class="result">' .htmlspecialchars($Players['clantag']) . '</td>'; 
          }else{
	         $clantag = '<tr style="height:20px;"><td class="result">&nbsp;</td>';
	      }
	      
	   if(strlen($Players['name']) <= 16) {
           $PlayerN = $Players['name'];
        } else {
          $PlayerN = substr($Players['name'],0,14) . '..'; 
      }
      
     


    $abfrage = "SELECT a.PlayerID,SoldierName, b.bfbcsID,Rank FROM tbl_playerdata a
    Left JOIN tbl_bfbcs b ON a.PlayerID = b.bfbcsID
       WHERE a.SoldierName = '{$Players['name']}'"; 
      $ergebnis = mysql_query($abfrage);
     $row = mysql_fetch_assoc($ergebnis);
  if(isset($row['Rank'])){
   $Rank = $row['Rank'];
  }else{
  	$Rank = '0';
}

if ($Players['name'] == $row['SoldierName']){
	$link = '<td class="result"><a href="ministats.php?name='.urlencode($row['SoldierName']).'" target="_blank">'.htmlspecialchars($PlayerN).'</a></td>';
}else{
	$link = '<td class="result"><a href="http://bfbcs.com/stats_pc/'.urlencode($Players['name']).'" target="_blank">'.htmlspecialchars($PlayerN).'</a></td>';
}
 
         ?>
	       <?php echo $clantag ?>
	       <td class="result"><img src="img/rank/thumb/<?php echo $Rank; ?>.png" border="0" width="20px" title="<?php echo htmlspecialchars($PlayerN).lang_stats_haverank.$Rank.'('.$rankname[$Rank].')'; ?>" /></td>
	          <?php echo $link; ?>
    <td class="result"><?php echo $Players['kills'] ?></td>
	            <td class="result"><?php echo $Players['deaths'] ?></td>
	           <td class="result"><?php echo $sKd ?></td>
	          <td class="result"><?php echo $Players['score'] ?></td>
	        <td class="result"><?php echo $Players['ping'] ?></td>
	       <?php
	       ++$iiCounter;
	       $iikills += $Players['kills'];
	       $iideaths += $Players['deaths'];
	       $iiscore += $Players['score'];
	       $ipingAll += $Players['ping'];
    }
  }
}
 if ($iideaths == 0 ){
 	  $iiPlayerKD = 0;
 	}else{
    $iiPlayerKD = ($iikills/$iideaths);
  }
    if($iiPlayerKD  == 0 && ($iikills >= 1)){
	             $iiKd = '<span class="positiv">'.$iikills.'.00</span>';
	           }elseif ($iiPlayerKD  == 0 && ($iideaths >= 1)){
             	 $iiKd = "<span class='negativ'>0.00</span>";	
	           }elseif ($iiPlayerKD  == 0 && ($iideaths == 0)){
	             $iiKd = '0.00';
	           }elseif($iiPlayerKD  >= 1){
               $iiKd = "<span class='positiv'>" . number_format($iiPlayerKD, 2, '.', '.') . "</span>";	
             }else{
               $iiKd = "<span class='negativ'>" . number_format($iiPlayerKD, 2, '.', '.') . "</span>";	
            }
            
           if ($ipingAll == 0){
 	           $iping = '0';
 	        }else{
            $iping = number_format($ipingAll/$iiCounter, 0, ',', '.');
        }
  ?>
</tbody>
     <td class="result" height="25px"><b>&oslash;</b></td>
     <td class="result">&nbsp;</td>
      <td class="result"><b><?php echo server_players; ?> <span class="sonstige"><?php echo $iiCounter ?></span></b></td>
  	    <td class="result"><b><?php echo $iikills ?></b></td>
  	     <td class="result"><b><?php echo $iideaths ?></b></td>
  	      <td class="result"><b><?php echo $iiKd ?></b></td>
  	    <td class="result"><b><?php echo $iiscore ?></b></td>
  	   <td class="result"><b><?php echo $iping ?></b></td>
  	   <td class="result"></td>
  </table>
 </div>
  
  