<?php
/*======================================================================*\
|| #################################################################### ||
|| # eGamers of Tomorrow Battlefield 3 Leaderboard                    # ||
|| # ---------------------------------------------------------------- # ||
|| # Dieses Copyright darf nicht entfernt werden                      # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------Teil des Bf3 Leaderboards von EoT-----------------# ||
|| #                      http://eot-clan.net                         # ||
|| #################################################################### ||
\*======================================================================*/
  require_once ('inc/config.php');
	require_once ('language/'.$row['language'].'.php');
  require_once ('inc/BattlelogApi/battlelog.api.php');


   $_GET = security::escape($_GET);
   $_POST = security::escape($_POST);
   $battlelog = new BattlelogApiCurl;
   $EoT = new eGamersofTomorrow;
   
   
  $sSql = "SELECT soldiername FROM ".DBPrefix."generalStats";
     $result = mysql_query($sSql) or $sError = 'Error in Query: ' . mysql_error() . ' in SQL: ' . print_r($sSql, true);
		       $aPlayer = array();
		         while ($data = mysql_fetch_assoc($result)) {
		           	$aPlayer[] = $data['soldiername'];
	 	         }
  
  if(isset($_GET['name']) && !empty($_GET['name']) && $_GET['name'] != '' && in_array($_GET['name'],$aPlayer)) {
	 $iPlayer = $_GET['name']; 
 }else{
	include ('error/errorPlayers.html');
   exit;
}

$sSql = "SELECT soldiername,lastServerID,is_online FROM ".DBPrefix."generalStats WHERE soldiername = '{$iPlayer}'";
     $result = mysql_query($sSql) or $sError = 'Error in Query: ' . mysql_error() . ' in SQL: ' . print_r($sSql, true);
		         $data = mysql_fetch_assoc($result);


?>
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
   <title>Last Server <?php echo $iPlayer; ?></title>
   <?php echo $styleSettings; ?>
     		<table class="defaultUpdate" colspan="10">
      <?php
      if ($data['lastServerID'] == ""){
      	echo '<td class="result" colspan="6"><b>'.LANG_GAMESERVER_NO_SERVERS_FOUND.'</b></td>';
      }else{
     	 $server = $battlelog->ServerData($data['lastServerID']);
			   if ($server['message'] == "error"){
			   	echo '<td class="result" colspan="6"><b>'.LANG_GAMESERVER_ERROR.'</b></td>';
			  }else{
			  		 $Queued = '';
			  if ($server['numQueued'] > 0){
			  	$Queued = ' ['.$server['numQueued'].']';
			  }
			  
			  if ($data['is_online'] == 2 ){
			  	  $played = LANG_GAMESERVER_ONLINE_PLAY;
			  	}else{
			  		$played = LANG_GAMESERVER_LAST_PLAY;
			  	}
			  	$HCSETTING = $EoT->settings($server['preset']);
			  	?><td class="head" colspan="6" cellspacing="0"><?php echo htmlspecialchars($iPlayer); ?> --- <?php echo $played; ?><font class="DIVtext"><?php echo $server['name']; ?></font></td>
			  	  <tr>
			  	  	<td class="result" style="font-size:20px;" colspan="2"><span style="font-size:11px;"><?php echo  LANG_GAMESERVER_PLAYER; ?></span><br/><br/><?php echo '<font class="DIVtext">'.$server['numPlayers'].'/'.$server['maxPlayers'].'</font>'.$Queued;?></td>
			  	  	<td class="result" style="font-size:20px;"><span style="font-size:11px;"><?php echo  LANG_GAMESERVER_RANKED; ?></span><br/><br/><img src="<?php echo $domain; ?>/img/gameserver/icons/big/<?php echo Settings($server['ranked'],"rank") ; ?>.png" width="20px"/> <?php echo SettingsName($server['ranked']); ?></td>
			  	  	<td class="result" style="font-size:20px;"><span style="font-size:11px;"><?php echo  LANG_GAMESERVER_PB; ?></span><br/><br/><img src="<?php echo $domain; ?>/img/gameserver/icons/big/<?php echo Settings($server['punkbuster'],"pb") ; ?>.png" width="20px"/> <?php echo SettingsName($server['punkbuster']); ?></td>
			  	  	<td class="result" style="font-size:20px;"><span style="font-size:11px;"><?php echo  LANG_GAMESERVER_SETTINGS; ?></span><br/><br/><img src="<?php echo $domain; ?>/img/gameserver/icons/big/<?php echo Settings($HCSETTING,"hc") ; ?>.png" width="20px"/> <?php echo $EoT->settings($server['preset']); ?></td>
			  	  	<td class="result" style="font-size:20px;"><span style="font-size:11px;"><?php echo  LANG_GAMESERVER_PW; ?></span><br/><br/><img src="<?php echo $domain; ?>/img/gameserver/icons/big/<?php echo Settings($server['passworded'],"pw") ; ?>.png" width="20px"/> <?php echo SettingsName($server['passworded']); ?></td>  
			  	  <tr>
			  	  	<td class="result" colspan="6"><span style="font-size:12px;margin-left:10px;font-weight:bold;float:left;"><?php echo LANG_GAMESERVER_AKTIV_MAP; ?>: <font class="DIVtext"><?php echo $EoT->mapName($server['map']); ?></font></span>
			  	      <img src="<?php echo $domain; ?>/img/gameserver/maps/big/<?php echo $server['map']; ?>.jpg" style="border:3px solid #000"/>
			  	    <td>
			  	  <tr>
			  	  	<td class="result" colspan="2">
			  	  		 <span style="float:left"><?php echo LANG_GAMESERVER_SETTINGS1; ?></span><span style="float:right"><?php echo $EoT->region($server['region']); ?></span><br />
			  	  	   <span style="float:left"><?php echo LANG_GAMESERVER_SETTINGS2; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['autobalance']); ?></span><br />
			  	  	   <span style="float:left"><?php echo LANG_GAMESERVER_SETTINGS3; ?></span><span style="float:right"><?php echo  $server['settings']['respawnTime']; ?></span><br />
			  	  	   <span style="float:left"><?php echo LANG_GAMESERVER_SETTINGS4; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['killCam']); ?></span><br />
			  	  	   <span style="float:left"><?php echo LANG_GAMESERVER_SETTINGS5; ?></span><span style="float:right"><?php echo  $server['settings']['downTime']; ?></span><br />
			  	  	   <span style="float:left"><?php echo LANG_GAMESERVER_SETTINGS6; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['squadLeaderSpawnOnly']); ?></span><br />
			  	  	   <span style="float:left"><?php echo LANG_GAMESERVER_SETTINGS7; ?></span><span style="float:right"><?php echo  $server['settings']['tksBeforeKick']; ?></span>
			  	  	</td>
			  	  	<td class="result" colspan="2">
			  	  		 <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS8; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['showHud']); ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS9; ?></span><span style="float:right"><?php echo  $server['settings']['bulletDamage']; ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS10; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['vehicles']); ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS11; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['minimapSpotting']); ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS12; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['friendlyFire']); ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS13; ?></span><span style="float:right"><?php echo  $server['settings']['idleKickSeconds']; ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS14; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['thirdPersonVehicleCam']); ?></span><br />
			  	  	</td>
			  	  	<td class="result" colspan="2">
			  	  		 <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS15; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['showEnemyNameTags']); ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS16; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['showMinimap']); ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS17; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['healthRegen']); ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS18; ?></span><span style="float:right"><?php echo  $server['settings']['playerHealth']; ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS19; ?></span><span style="float:right"><?php echo  SettingsServer($server['settings']['3dSpotting']); ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS20; ?></span><span style="float:right"><?php echo  $server['settings']['kicksToBan']; ?></span><br />
			  	  	   <span style="float:left;margin-left:5px;"><?php echo LANG_GAMESERVER_SETTINGS21; ?></span><span style="float:right"><?php echo  $server['ip']; ?></span>
			  	  	</td>
			  	  <tr>
				  <td class="result" colspan="6"><span style="font-size:12px;margin-left:10px;font-weight:bold;float:left;"><?php echo LANG_GAMESERVER_PLAYERS; ?></span>
				  <tr>
				   <?php 
				   if ($server['numPlayers'] == 0) echo '<td colspan="6"><b>'.LANG_GAMESERVER_NNO_PLAYERS_FOUND.'</b></td>';
				     if (is_array($server["players"])){
				      $i = 0; 
				       foreach ($server["players"] as $players){  
				       	++$i;
				       	if (in_array($players["name"],$aPlayer)){
				       		$cPlayer = '<font class="DIVtext">'.TRIMUSERS($players["name"]).'</font>';
				       	}else{
				       		$cPlayer = TRIMUSERS($players["name"]);
				       	}
				       	?>
				       		<td colspan="1" style="font-size:12px;height:25px;font-style:bold;text-align:left">
				       		  <div>
				       		 	  <img style="border: 1px solid #008FC4;-moz-border-radius:5px 5px 5px 5px;-webkit-border-radius:5px 5px 5px 5px;border-radius:5px 5px 5px 5px;float:left;" src="http://www.gravatar.com/avatar/<?php echo $players['gravatar']; ?>?s=22&d=http%3A%2F%2Fbattlelog-cdn.battlefield.com%2Fpublic%2Fbase%2Fshared%2Fdefault-avatar-22.png%3Fv%3D7909" />
 	            	 	  </div>
 	            	 	  <div style="margin-top:3px;"> &nbsp;
				       		   <a href="http://battlelog.battlefield.com/bf3/de/user/<?php echo rawurlencode($players["name"]); ?>" target="_blank"><?php echo $cPlayer; ?></a>
				       		  </div>
				       		</td>
				       		
			  	  	<?php	
			  	  		if ($i % 6 == 0) echo'<tr />';
			  	      
			  	 }		  	
			  echo '</td>';
			 }
			 echo '</table>';
    }  
  }
  
   function mapID($name)
	{
		switch ($name)
		{
			case 'Grand Bazar':
				return 'MP_001';
			case 'Tehran Highway':
				return 'MP_003';
			case 'Caspian Border':
				return 'MP_007';
			case 'Canals':
				return 'MP_017';
			case 'Damavand Peak':
				return 'MP_013';
			case 'Operation Firestorm':
				return 'MP_012';
			case 'Seine Crossing':
				return 'MP_011';
			case 'Kharg Island':
				return 'MP_018';
			case 'Operation Metro':
				return 'MP_Subway';
			case 'Gulf of Oman':
				return 'XP1_002';
			case 'Sharqi Peninsula':
				return 'XP1_003';
			case 'Wake Island':
				return 'XP1_004';
		  case 'Strike at Karkand':
				return 'XP1_001';
			default:
				return 'Unknown';
		}
	}
    
 function Settings($data,$icon){
  if ($data == "1" OR $data == "true" OR $data == "Hardcore"){
  	 $return = $icon;
  	}else{
  		$return = $icon.'_no';
  	}
  return $return;
  }
  
  function SettingsName($data){
  if ($data == "1" OR $data == "true" OR $data == "Hardcore"){
  	 $return = LANG_GAMESERVER_YES;
  	}else{
  		$return = LANG_GAMESERVER_NO1;
  	}
  return $return;
  }
  
  function SettingsServer($data){
  if ($data == "1" OR $data == "true"){
  	 $return = LANG_GAMESERVER_YES1;
  	}else{
  		$return = LANG_GAMESERVER_NO2;
  	}
  return $return;
  }
  
  
  
  
  function TRIMNAME ($name) {
      if(strlen($name) <= 50) {
          $result = htmlspecialchars($name);
        }else{
          $result = htmlspecialchars(substr($name,0,48) . '.....'); 
        } 
     return $result;
  }  
  
  function TRIMUSERS ($name) {
      if(strlen($name) <= 11) {
          $result = htmlspecialchars($name);
        }else{
          $result = htmlspecialchars(substr($name,0,9) . '..'); 
        } 
     return $result;
  }  
  