<?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 ('../gameserver/BC2Conn.php');

$iS = count($aServerips);
	
   if(isset($_GET['serverID']) && !empty($_GET['serverID']) && $_GET['serverID'] != '' && $_GET['serverID'] <= $iS) {
      $sID = $_GET['serverID']; 
  }else{
      $sID = 1;
}
	
    $sIP = $aServerips[$sID-1]['ip'];
    $sQPORT = $aServerips[$sID-1]['qport'];
    $rconPW = $aServerips[$sID-1]['rconPW'];

$BC2Conn = new BC2Conn($sIP,$sQPORT);
$BC2Conn->loginSecure($rconPW);


if (!$BC2Conn->isLoggedIn() or !$BC2Conn->isConnected()) {
	include ('../error/banlist.html');
}else{
if ($BC2Conn->adminVarGetCrosshair() == 1){$Crosshair = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$Crosshair = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGetPunkbuster() == 1){$Punkbuster = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$Punkbuster = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGetAdminPassword() == 1){$Password = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$Password = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGetHardcore() == 1){$Hardcore = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$Hardcore = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGetRanked() == 1){$Ranked = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$Ranked = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGetRankLimit() == '-1'){$RankLimit = '<span class="negativ">'.server_gerneral_off.'</span>';}else{$RankLimit = '<span class="positiv">'.$BC2Conn->adminVarGetRankLimit().'</span>';}
if ($BC2Conn->adminVarGetTeambalance() == 1){$Teambalance = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$Teambalance = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGetFriendlyFire() == 1){$FriendlyFire = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$FriendlyFire = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGetKillCam() == 1){$KillCam = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$KillCam = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGetMiniMap() == 1){$MiniMap = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$MiniMap = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGet3dSpotting() == 1){$dSpotting = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$dSpotting = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGetMiniMapSpotting() == 1){$MiniMapSpotting = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$MiniMapSpotting = '<span class="negativ">'.server_gerneral_off.'</span>';}
if ($BC2Conn->adminVarGet3rdPersonVehiCam() == 1){$PersonVehiCam = '<span class="positiv">'.server_gerneral_on.'</span>';}else{$PersonVehiCam = '<span class="negativ">'.server_gerneral_off.'</span>';}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
      <head>
		    <title><?php echo server_gerneral_title.htmlspecialchars($BC2Conn->getServerName()); ?></title>
	        <link rel="stylesheet" type="text/css" href="../css/fancybox.css" media="screen">
	      <link rel="stylesheet" type="text/css" href="../css/style.css" /> 
	      <meta http-equiv="content-type" content="text/html; charset=utf-8">
	    </head>
	     <html>
	      <div class="body_ministats"> 
	     	 <table class="default_m" style="float: left; width: 160px; height: 210px; margin-left: 8px;margin-top:5px;" cellspacing="0" cellpadding="0">
	       <td class="head" colspan="1"><?php echo server_gerneral_server_maprotation; ?></td>
          <tr>
          	<?php
          	$maplist = $BC2Conn->adminMaplistList();
             $ii = 0;
	            for ($i = 1; $i < count($maplist); $i+=1){
	            	$Map = $maplist[$i];
	            	 include ("../inc/map_array.php");
	            	  $tooltip = '<a class="tooltip" href="#">'.$Mapname.'<span><img src="'.$installdir.'/img/mapsbig/'.$Map.'.jpg" border="0" width="560px"></span></a>';
	            	?>
		           <td class="result" style="text-align:center;">&nbsp;<?php echo $tooltip; ?></td><tr>
		       	<?php ++$ii; } ?>       
          </tr>  	 
        </table>
	    
    
	     <table class="default_m" style="float:left;width:622px;height: 210px;margin-left:8px;margin-top:5px;" cellspacing="0" cellpadding="0" >
         <td class="head" colspan="5"><?php echo server_gerneral_serverb_des; ?></td>
          <tr> 
          	<td class="result" colspan="5" style="text-align:center;"><img src="<?php echo $BC2Conn->adminVarGetBannerURL() ?>" border="0" /></td><tr>
          		<?php
          		if(strlen($BC2Conn->adminVarGetServerDescription()) <= 400) {
           $Beschreibung = $BC2Conn->adminVarGetServerDescription();
        } else {
          $Beschreibung = substr($BC2Conn->adminVarGetServerDescription(),0,400) . '...'; 
      }
      ?>
	      <td class="result" colspan="5" style="text-align:center;"><b><img src="<?php echo $installdir; ?>/img/crosshair.png" border="0" />&nbsp;<?php echo str_replace( '|', '<br />&nbsp;', htmlspecialchars($Beschreibung)); ?></b></td>
         </tr>
            <td class="result" style="text-align:left;"><?php echo server_gerneral_Crosshair.$Crosshair; ?></td>
             <td class="result" style="text-align:left;"><?php echo server_gerneral_Punkbuster.$Punkbuster; ?></td>
              <td class="result" style="text-align:left;"><?php echo server_gerneral_Password.$Password; ?></td>
             <td class="result" style="text-align:left;"><?php echo server_gerneral_Hardcore.$Hardcore; ?></td>
            <td class="result" style="text-align:left;"><?php echo server_gerneral_Ranked.$Ranked; ?></td>
          <tr>
          	<td class="result" style="text-align:left;"><?php echo server_gerneral_RankLimit.$RankLimit; ?></td>
             <td class="result" style="text-align:left;"><?php echo server_gerneral_Teambalance.$Teambalance; ?></td>
              <td class="result" style="text-align:left;"><?php echo server_gerneral_FriendlyFire.$FriendlyFire; ?></td>
             <td class="result" style="text-align:left;"><?php echo server_gerneral_KillCam.$KillCam; ?></td>
            <td class="result" style="text-align:left;"><?php echo server_gerneral_3dSpotting.$dSpotting; ?></td>
          <tr> 
          	<td class="result" style="text-align:left;"><?php echo server_gerneral_MiniMapSpotting.$MiniMapSpotting; ?></td>
            <td class="result" colspan="4" style="text-align:left;"><?php echo server_gerneral_PersonVehiCam.$PersonVehiCam; ?></td>
       </tr>
    </table>
<?php


$Bannlist = $BC2Conn->adminBanlistList();
$bans = '';
$ii = 0;
	for ($i = 2; $i < count($Bannlist); $i+=5){
		$bans[$ii]['typ'] = $Bannlist[$i];
		$bans[$ii]['name'] = $Bannlist[$i+1];
		$bans[$ii]['art'] = $Bannlist[$i+2];
		$bans[$ii]['seconds'] = $Bannlist[$i+3];
		$bans[$ii]['grund'] = $Bannlist[$i+4];
		++$ii;
	}
  
 $Sites = ceil($ii/10);
	
	if(isset($_GET['page']) && !empty($_GET['page']) && $_GET['page'] != '' && $_GET['page'] > 0) {
     $page = $_GET['page'];
     $g_page = $_GET['page'];
   }else{
   	 $page = 1;
   	 $g_page = 1;
 }
 
     if ($page > $Sites ){
     	$page = $Sites;
     }elseif ($page == 2){
	    $page = ($page-1)*11;
	   }elseif ($page >= 3){
	    $page = (($page-1)*11)-($page-2);
    }
 
 if ($bans != '')$bans = array_slice($bans,$page-1, 10);
 if ($Banlist_only == 1){
?>
        
	<table class="default_m" cellspacing="0" cellpadding="0">
     <td class="head" colspan="5" cellspacing="0"><?php echo server_gerneral_banlist; ?></td>
			  <tr> 
			     <th width="200px"><?php echo server_gerneral_name; ?></th>
			      <th width="90px"><?php echo server_gerneral_art; ?></th>
				   <th width="120px"><?php echo server_gerneral_seconds; ?></th> 
				  <th style="text-align:left;"><?php echo server_gerneral_grund; ?></th>
			 </tr>
<?php
if (!$bans)echo '<td class="result" colspan="5" style="text-align:center;" height="20px"><span class="sonstige"><b>'.lang_server_ban_error.'</b></span></td><tr>';
if(is_array($bans))foreach ($bans as $banlist){
	
	if (strlen($banlist['name']) >= 20) { 
      $name = substr($banlist['name'],0, 20) . "..."; 
	   }else{
	    $name = $banlist['name'];
   }
	
	if(preg_match("/EA_/",$name)){
	    $playerN = htmlspecialchars($name);
	   }else{
		  $playerN = '<a href=http://bfbcs.com/stats_pc/'.urlencode($banlist['name']).'>'.htmlspecialchars($name).'</a>';
	}
	
	if ($banlist['art'] =='perm'){
		  $ban = server_gerneral_perm;
	  }else{
	  	$ban = server_gerneral_secondsb;
	}
	
  if ($banlist['seconds'] == 0){
	    $banTime = '<img src="'.$installdir.'/img/permban.png" title="'.server_gerneral_permban.'" />';
	  }else{
		  $banTime = sprintf("%02dh %02dm",$banlist['seconds']/60/60,$banlist['seconds']/60%60);;
	}
	
	?>
	<tr class="hov">
	   <td class="result" style="text-align:center;" height="20px"><?php echo $playerN; ?></td>
	    <td class="result" style="text-align:center;"  height="20px"><?php echo $ban; ?></td>
	   <td class="result" style="text-align:center;" height="20px"><?php echo $banTime; ?></td>
	  <td class="result" height="20px" style="text-align:left;"><?php echo htmlspecialchars($banlist['grund']); ?></td>
   </tr>
	<?php
}


function blaetterfunktion_array($g_page,$maxseite,$anzahl=1,$get_name="page") {   
   global $g_page;
   global $sID;
   global $installdir;
 
   if($anzahl%2 != 0) $anzahl++;
      $a = $g_page-($anzahl/2);
      $b = 0;
      $blaetter = array();
   while($b <= $anzahl) {
       if($a > 0 AND $a <= $maxseite) {
          $blaetter[] = $a;
          $b++;
   }else if($a > $maxseite AND ($a-$anzahl-2)>=0) {
         $blaetter = array();
         $a -= ($anzahl+2);
         $b = 0;
   }elseif($a > $maxseite AND ($a-$anzahl-2)<0) {
        break;
     }
      $a++;
  }
   $return = "";
   
   
   if(!in_array(1,$blaetter) AND count($blaetter) > 1) {
      if(!in_array(2,$blaetter)) $return .= "&nbsp;<a id=serverstats_{$sID} href=\"{$installdir}/stats/general_server.php?{$get_name}=1&serverID={$sID}\">1</a>&nbsp;...";
        else $return .= "&nbsp;<a id={$sID} href=\"{$installdir}/stats/general_server.php?{$get_name}=1&serverID={$sID}\">1</a>&nbsp;";
   }

   foreach($blaetter AS $blatt) {
       if($blatt == $g_page) $return .= "&nbsp;<b><span class='sonstige'>$blatt</span></b>&nbsp;";
        else $return .= "&nbsp;<a id=serverstats_{$sID} href=\"{$installdir}/stats/general_server.php?{$get_name}=$blatt&serverID={$sID}\">$blatt</a>&nbsp;";
    }

   if(!in_array($maxseite,$blaetter) AND count($blaetter) > 1) {
       if(!in_array(($maxseite-1),$blaetter)) $return .= "...&nbsp;<a id=serverstats_{$sID} href=\"{$installdir}/stats/general_server.php?{$get_name}=$maxseite&serverID={$sID}\">".server_gerneral_server_last."($maxseite)</a>&nbsp;";
        else $return .= "&nbsp;<a id=serverstats_{$sID} href=\"{$installdir}/stats/general_server.php?{$get_name}=$maxseite&serverID={$sID}\">$maxseite</a>&nbsp;";
    }

   if(empty($return))
      return  "&nbsp;<b><span class='sonstige'>1</span></b>&nbsp;";
   else
      return $return;
   }  
   
     echo "<td class=result colspan=5>
            <center><b>".server_gerneral_serverb_page.":</b>"; 
             echo blaetterfunktion_array($g_page, $Sites)."
      </td>
    </font>";

	?>
		   <script type="text/javascript">  	
		     $(document).ready(function() {
				 $("a#serverstats_<?php echo $sID ?>").fancybox({
			    'autoDimensions'	: true,
			    'transitionIn'		: 'none',
			    'transitionOut'		: 'none',
			    'padding' : 0
			  });
      });
	   </script> 
	    </td>	
	   </table>	  
    <?php } include_once ("../inc/footerm.php"); }?>
   <br /> 
  </html>
 </div>