<?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["action"]) OR empty($_GET['action'])){
    $action = "";
   }else{
   	$action = htmlentities($_GET["action"]);
  }



  if(!isset($_GET['page']) OR empty($_GET['page'])){
    $page = 1;
   }else{
   	$page = $_GET['page'];
  }
  
  
   $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'];
	 	         }
   $iPlayer = "";
  if(isset($_GET['name']) && !empty($_GET['name']) && $_GET['name'] != '' && in_array($_GET['name'],$aPlayer)) {
	 $iPlayer = $_GET['name'];
	 $sWhere = "a.soldiername = '{$iPlayer}'";
 }else{
	 $sWhere = "1";		 
}
  
  $maxEntrys = 12; 
  $start = $page * $maxEntrys - $maxEntrys;      
 
	    
	$sSql = "
		SELECT 
			a.soldiername,
			a.pid,
			b.*
		FROM 
			  ".DBPrefix."generalStats a
	  Left JOIN 
         ".DBPrefix."battlereports b ON a.pid = b.stats_pid
	  WHERE 
			{$sWhere} ORDER BY CreatetAt DESC LIMIT $start, $maxEntrys";
   
   $result = mysql_query($sSql) or $sError = 'Error in Query: ' . mysql_error() . ' in SQL: ' . print_r($sSql, true);
     $aData = array();
	 while ($data = mysql_fetch_assoc($result)) {
	 	$aData[] = $data;
	}
	
	    $result = mysql_query("SELECT COUNT(ReportID) FROM ".DBPrefix."battlereports WHERE stats_pid = {$aData[0]['pid']}");
      $menge = mysql_fetch_row($result);
      $menge = $menge[0];
		
      $wieviele_seiten = ceil($menge / $maxEntrys);
	

  if ($iPlayer == "") $iPlayer = $aData[0]['soldiername'];
     ?>
           <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                    "http://www.w3.org/TR/html4/loose.dtd">
           <title><?php echo LANG_BATTLEREPORT_TITLE.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" />
             <script type="text/javascript">
               function update(soldier) {
                 window.location = "update/battlereports.php?update=" +soldier
               }
             </script>
           </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 $aData[0]['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); ?>" class="selected">Reports</a></li>
                      <?php } ?>
                      
                       <li><a href="mapstats.php?name=<?php echo rawurlencode($iPlayer); ?>">Mapstats</a></li>
             </ul>
             
				   <table class="default">
             <td class="head" colspan="3" cellspacing="0">
             	<span style="float:left;margin-left:10px;"><a href="javascript:update('<?php echo rawurlencode($iPlayer) ?>')"><img src="img/general/anim.gif" /></a></span>
             	<span style="margin-left:-26px;"><?php echo LANG_BATTLEREPORT_TITLE.htmlspecialchars($iPlayer).' ('.$menge.')'; ?></span>
             </td>
             	<tr> 
               <?php
  if ($menge == 0){
       echo '<td class="DIVtext" style="font-size:15px;height:30px;">'.LANG_BATTLEREPORT_DETAILS_ERROR.'</td>';
  }else{
                 $i=0; 
                 foreach($aData as $data){
           	      ++$i;
           	       if ($data['winStatus'] == 1){
           		         $div = "reportDIV_win";
           		         $status = LANG_BATTLEREPORT_WIN;
           	       }else{
           		         $div = "reportDIV_lost";
           		         $status = LANG_BATTLEREPORT_LOST;
           	       }
           	
           	      if ($page > 1){
			  	            $Lpage = '&page='.$page;
			            }else{
			  	            $Lpage= "";
			            }
			            
			            if (isset($_GET['reportID']) && $_GET['reportID'] == $data['ReportID']){
			            	$back = "background:#222222;";
			            }else{
			            	$back = "";
			            }
			            
			            if ($data['ServerMap'] == "XP1_001" OR $data['ServerMap'] == "XP1_002" OR $data['ServerMap'] == "XP1_003" OR $data['ServerMap'] == "XP1_004"){
			                $icon = "<img src='img/b2k.png' />";
			              }elseif ($data['ServerMap'] == "XP2_Palace" OR $data['ServerMap'] == "XP2_Skybar" OR $data['ServerMap'] == "XP2_Office" OR $data['ServerMap'] == "XP2_Factory"){
			            	  $icon = "<img src='img/cq.png' />";
			            	}else{
			            		$icon = "";
			            	}
        			?>
        			
         <td>
         	<div class="<?php echo $div; ?>" style="width:260px;height:110px;float:left;margin-left:5px;margin-top:5px;margin-bottom:5px;<?php echo $back; ?>"><span style="width:30px;float:right;margin-top:6px;"><?php echo $icon; ?></span><span style="margin-top:5px;float:left;margin-left:10px;"><?php echo $data['ServerName']; ?></span><br />
         	 <p style="border-bottom:1px solid <?php echo $style['table_border_color']; ?>;">
         		<div style="width:100px;height:60px;float:left;margin-left:5px;"><img class="maps" src="<?php echo $domain; ?>/img/gameserver/maps/<?php echo $data['ServerMap']; ?>.jpg" /></div>
         		<div style="width:145px;height:75px;float:left;margin-left:5px;">
         			<span style="float:left;margin-left:5px;"><?php echo $EoT->unix_to_time($data['CreatetAt']); ?></span>
         			<br />
         			<span style="float:left;margin-left:5px;"><?php echo LANG_BATTLEREPORT_MAP.$EoT->mapName($data['ServerMap']); ?></span>
         			<br />
         			<span style="float:left;margin-left:5px;"><?php echo LANG_BATTLEREPORT_MODUS.$EoT->GameMode($data['gameMode']); ?></span>
         			<br /><a href="battlereport.php?name=<?php echo $iPlayer; ?>&action=viewReport&reportID=<?php echo  $data['ReportID'].$Lpage;; ?>"><img class="detailbutton" style="margin-top:2px;float:left;margin-left:5px;" src="<?php echo $domain; ?>/img/blank.png" /></a>
         		</div>
         </td>
        <?php 
          if ($i % 3 == 0) echo'<tr />';     
        } ?>
       </div>

   <?php     
      echo '<tr>
	        <td class=result colspan=3>
           <b>'.LANG_GAMESERVER_PAGE.'</b><span class=DIVtext>';
    echo $EoT->blaetterfunktion($page,  $wieviele_seiten, 'battlereport.php?name='.$iPlayer.'&').'</td></span>';
 }     
 echo '</table>';
      
      if($action == "viewReport") {
      include 'stats/reportDetail.php';
    }
    
      
     include_once 'inc/footer.php'; 
   echo '</div>';	
     
   
   ?>
        <script type="text/javascript">
		$(document).ready(function() {
	
			$("a#bf3stats").fancybox({
			'autoDimensions'	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'padding' : 0,
      'overlayColor'		: '#000',
			'overlayOpacity'	: 0.8
	   });
   });
	</script>	