<?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;
        

if(isset($_GET['name']) && !empty($_GET['name']) && $_GET['name'] != '') {
	 $iPlayer = $_GET['name']; 
 }else{
	include ('error/errorPlayers.html');
   exit;
}
	
 $mArray = array(
                 'MP_001',
                 'MP_003',
                 'MP_007',
                 'MP_017',
                 'MP_013',
                 'MP_012',
                 'MP_011',
                 'MP_018',
                 'MP_Subway',
                 'XP1_002',
                 'XP1_003',
                 'XP1_004',
                 'XP1_001',
                 'XP2_Palace',
                 'XP2_Skybar',
                 'XP2_Office',
                 'XP2_Factory'
                );
    	
	 $aTime = array();
	 $mTime = "";
	foreach ($mArray as $Maps ){	  
	   $sWhere = "a.soldiername = '{$iPlayer}'";	
      $sSql = "
		    SELECT 
			   a.soldiername,
			   a.pid,
		     b.map,
		     b.intData
		   FROM 
			     ".DBPrefix."generalStats a
       Left JOIN 
            ".DBPrefix."battlereportsDetails b ON a.pid = b.stats_pid
	     WHERE 
			   {$sWhere} AND b.map = '{$Maps}'";
 
    		$rResult = mysql_query($sSql) or $sError = 'Error in Query: ' . mysql_error() . ' in SQL: ' . print_r($sSql, true);
			  while ($data= mysql_fetch_assoc($rResult)){
                  $pid = $data['pid'];
			  	        $int = json_decode($data['intData'],true);
			  	      if (is_array($int)){
			  	       $mTime += arrayKey('c___sa_g',$int); 
       	       }
			  }
			    
               $aTime[] = $mTime;
             
     }


        $i = 0;
        $aMaps = array();
			foreach ($aTime as $key => $MapTime){
				if ($i > 0){
				  $aMaps[$mArray[$i]] = ($MapTime-$aTime[$i-1]);
				}else{
					$aMaps[$mArray[$i]] = $MapTime;
				}
						$i++;
			}	
  
  arsort($aMaps);
  
  ?>
           <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                    "http://www.w3.org/TR/html4/loose.dtd">
           <title><?php echo 'Mapstats ---'.htmlspecialchars($iPlayer); ?></title>
           <?php echo $styleSettings; ?>
           <head>
             <script type="text/javascript" src="js/jquery-1.4.3.min.js"></script>
             <script type="text/javascript" src="js/jquery.fancybox-1.3.4.pack.js"></script>
             <link rel="stylesheet" type="text/css" href="css/jquery.fancybox-1.3.4.css" media="screen" />
           </head>	
           <div class="body_bfLB">   
	            <?php echo $Banner; ?>
              <ul id="statstabs" class="shadetabs" style="margin-top:10px;margin-bottom:-10px;">
               <li><a href="index.php">Leaderboard</a></li>
                      <li><a href="stats.php?name=<?php echo rawurlencode($iPlayer); ?>" >Details</a></li>
        
                      <li><a href="stats.php?name=<?php echo rawurlencode($iPlayer); ?>&action=weapons_vehicles" >Weapons/Vehicles</a></li>
        
                      <?php if ($row['ribbons_box'] == 1){ ?>
                      <li><a href="stats.php?name=<?php echo rawurlencode($iPlayer); ?>&action=awards" >Awards</a></li>
                       <?php } ?>
         
                      <?php if ($row['coop_box'] == 1){ ?>
                      <li><a href="stats.php?name=<?php echo rawurlencode($iPlayer); ?>&action=coop" >Coop</a></li>
                      <?php } ?>
         
                      <?php if ($row['assignments'] == 1){ ?> 
                      <li><a href="stats.php?name=<?php echo rawurlencode($iPlayer); ?>&action=assignments" ><?php echo LANG_GENERAL_ASSIGNMENTS; ?></a></li>
                      <?php } ?>
          
                      <li><a href="stats.php?name=<?php echo rawurlencode($iPlayer); ?>&action=dogtags" >Dogtags</a></li>
        
                      <?php if($row['History'] == 1){ ?>
                      <li><a id="bf3stats" href="history.php?pid=<?php echo $pid; ?>" >History</a></li>
                      <?php }
        
                        if($row['platform'] == "pc"){ ?>
                      <li><a href="ServerHistory.php?name=<?php echo rawurlencode($iPlayer); ?>" >S.History</a></li>
                      <?php }
        
                        if($row['battlereports'] == 1){ ?>
                      <li><a href="battlereport.php?name=<?php echo rawurlencode($iPlayer); ?>" >Reports</a></li>
                      <?php } ?>
                      
                      
                      <li><a href="mapstats.php?name=<?php echo rawurlencode($iPlayer); ?>" class="selected">Mapstats</a></li>
        
             </ul>
             <table class="default">
             <td class="head" colspan="4" cellspacing="0">
             	<span style="margin-left:-26px;"><?php echo LANG_MAPSTATS_TITLE; ?><?php echo  htmlspecialchars($iPlayer); ?></span>
             </td>
             	<tr> 
  
       <?php
            $place = 0;
            $iI = 0;
            
            foreach ($aMaps as $key => $maps){
            	$place++;
            	
                  $sSql = "
		                  SELECT 
			                 a.soldiername,
			                 a.pid,
		                   b.map,
		                   b.intData
		                 FROM 
			                ".DBPrefix."generalStats a
                     Left JOIN 
                      ".DBPrefix."battlereportsDetails b ON a.pid = b.stats_pid
	                  WHERE 
			                {$sWhere} AND b.map = '{$key}'";
 
    		$rResult = mysql_query($sSql) or $sError = 'Error in Query: ' . mysql_error() . ' in SQL: ' . print_r($sSql, true);
			      $entrys = mysql_num_rows($rResult);
			      $i = 0;
			      $kills = "";
			      $deaths = "";
			      $helps = "";
			      $shots = "";
			      $hits = "";
			      $award = "";
			      $squad = "";
			      $team = "";
			      $general = "";
			      $objec = "";
			      $assault = "";
			      $engineer = "";
			      $support = "";
			      $recon = "";
			      $score = "";
			      $bonus = "";
			  while ($data= mysql_fetch_assoc($rResult)){
			  	   $i++;
			  	   if ($i > $entrys){
			  	   	$i = 0;
			  	  }
			  	  
			  	       $int = json_decode($data['intData'],true);
			  	     if (is_array($int)){
			  	       $kills += arrayKey('c___k_g',$int);
			  	       $deaths += arrayKey('c___d_g',$int);  
			  	       $helps += arrayKey('c___ka_g',$int);
			  	       $shots += arrayKey('c___sfw_g',$int);
			  	       $hits += arrayKey('c___shw_g',$int);
			  	       $award += arrayKey('sc_award',$int);
			  	       $squad += arrayKey('sc_squad',$int);
			  	       $team += arrayKey('sc_team',$int);
			  	       $general += arrayKey('sc_general',$int);
			  	       $objec += arrayKey('sc_objective',$int);
			  	       $assault += arrayKey('sc_assault',$int);
			  	       $engineer += arrayKey('sc_engineer',$int);
			  	       $support += arrayKey('sc_support',$int);
			  	       $recon += arrayKey('sc_recon',$int);
			  	       $bonus += arrayKey('sc_bonus',$int);
			  	       $score += arrayKey('score',$int); 
			  	    }    
			  }
			  
                 	$KD = $EoT->kd($kills,$deaths);
               if ($shots > 0){
               	$ac = number_format($hits*100/$shots, 2, ',', ' ');
              }else{
              	$ac = '0,00';
              }
            	
            	if ($maps > 0){
            		$iI++;
			          $margin = "-24";
			          if ($place > 9){
			          	$margin = "-31";
			          }
              ?>
               <td class="result" style="width:40px;"><div><img src="img/place.png" /><span style="position:absolute;font-weight:bold;font-size:20px;margin-left:<?php echo $margin; ?>px;margin-top:8px;"><?php echo $place; ?></span></div></td>
            	 <td class="result" style="border-left:<?php echo $style['result_border']; ?>;width:265px">
            	 	  <span class="DIVtext" style="font-size:14px;float:left;margin-left:3px;"><?php echo $EoT->mapName($key); ?></span>
            	 	 <br />
            	 	  <img src="<?php echo $domain; ?>/img/gameserver/maps/<?php echo $key; ?>.jpg" style="float:left;margin-left:3px;margin-top:4px;" />
            	 </td>
            	 <td class="result">
            	 	<div class="rankDIV" style="width:220px;float:left;height:155px;margin-left:5px;margin-top:1px;">
            	 	  <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_PLAYTIME; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->time_map_stats($maps); ?></span><br />
            	    <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_KILLS; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($kills); ?></span><br />
            	    <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_DEATHS; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($deaths); ?></span><br />
            	    <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_KD; ?></span><span style="float:right;margin-right:3px;"><?php echo $KD; ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_KILL_ASSISTS; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($helps); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_SHOTS; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($shots); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_HITS; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($hits); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_ACCURACY; ?></span><span style="float:right;margin-right:3px;"><?php echo $ac; ?>%</span><br />
            	   <hr>
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_ASSIGNMENTS; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($award); ?></span><br />
            	  </div>
            	</td>
            	<td class="result">
            	 	<div class="rankDIV" style="width:220px;float:left;height:155px;margin-left:5px;margin-top:1px;"> 
            	 	 <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_SQUAD; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($squad); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_TEAM; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($team); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_MCON; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($objec); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_GLOBAL; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($general); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_ENGINEER; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($engineer); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_SUPPORT; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($support); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_RECON; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($recon); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_ASSAULT; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($assault); ?></span><br />
            	   <span class="DIVtext" style="float:left;margin-left:3px;"><?php echo LANG_MAPSTATS_BONUS; ?></span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($bonus); ?></span><br />
            	   <hr>
            	   <span class="DIVtext" style="float:left;margin-left:3px;">Gesamt:</span><span style="float:right;margin-right:3px;"><?php echo $EoT->points($score); ?></span><br />
            	  </div>
            	</td>
            	<tr> 	
              <?php	
            }
          }
          $no_entrys = "";
            if ($iI == 0){
			  	       $no_entrys =  '<td class="result" height="50px"><span class="DIVtext" style="font-size:16px"><?php echo LANG_MAPSTATS_ERROR; ?></td>';
			       }
            echo $no_entrys;
           echo '</table>';
          
           include_once 'inc/footer.php'; 
   echo '</div>';	
   
     function arrayKey($data,$int){
    	if(array_key_exists($data,$int)){
    		$data=$int[$data];
    	}else{
    		$data="";
    	}   	
    	return $data;
    }    
    
     
        ?>
        <script type="text/javascript">
		$(document).ready(function() {
	
			$("a#bf3stats").fancybox({
			'autoDimensions'	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'padding' : 0,
      'overlayColor'		: '#000',
			'overlayOpacity'	: 0.8
	   });
   });
	</script>	
       


      
      
    