<?php
/*======================================================================*\
|| #################################################################### ||
|| # EoT-Clan BF3 Leaderboard                                         # ||
|| # ---------------------------------------------------------------- # ||
|| # Dieses Copyright darf nicht entfernet werden                     # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # -----------------BF3 Leaderboard is a free Software--------------# ||
|| #                   http://eot-clan.net                            # ||
|| #################################################################### ||
\*======================================================================*/
require_once ('inc/config.php');
require_once ('language/'.$row['language'].'.php');

$_GET = security::escape($_GET);
$_POST = security::escape($_POST);
$EoT = new eGamersofTomorrow;
  
     if(isset($_GET['name']) && !empty($_GET['name']) && $_GET['name'] != '') {
	 $iPlayer = $_GET['name']; 
 }else{
	include ('error/errorPlayers.html');
   exit;
}
	
	   $sWhere = "a.soldiername = '{$iPlayer}'";	
    
	$sSql = "
		SELECT 
			a.soldiername,
			a.dogtagsStats,
			a.pid
		FROM 
			  ".DBPrefix."generalStats a
	  WHERE 
			{$sWhere}";
	
		$rResult = mysql_query($sSql) or $sError = 'Error in Query: ' . mysql_error() . ' in SQL: ' . print_r($sSql, true);


			    $data= mysql_fetch_assoc($rResult);
			    $entrys = mysql_num_rows($rResult);
			    if ($entrys == 0){
		include ('error/errorPlayers.html');
		exit;
	}		 
 



  $gesamt = 0;
 $aData = json_decode($data['dogtagsStats'],true);
     if ($aData['taken'] != "" && $aData != ""){
    $Dogtags = array_keys($aData['taken']);
		  $array = array();
      $i = 0;
     foreach ($Dogtags as $Name){
     	$time = array_keys($aData['taken'][$Name]);
      $array[$i]['name'] = $Name;
     	$array[$i]['time'] = $time[0];   
     	$array[$i]['i'] = $aData['taken'][$Name][$time[0]]['i'];
     	$array[$i]['tag'] = $aData['taken'][$Name][$time[0]]['tag'];
     	$array[$i]['adv'] = $aData['taken'][$Name][$time[0]]['adv'];
     	$array[$i]['dogtag'] = $aData['taken'][$Name][$time[0]]['name'];
     	$array[$i]['desc'] = $aData['taken'][$Name][$time[0]]['desc'];
     	$array[$i]['image'] = $aData['taken'][$Name][$time[0]]['image'];
     	$array[$i]['count'] = count($aData['taken'][$Name]);
     ++$i;
    }
    usort($array, "sortDogtags");
    foreach ($array as $all){
    	$gesamt += $all['count'];
   }
  }
   
      

   ?>
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
   <head>
    <title>Dogtags--<?php echo htmlspecialchars($data['soldiername']) ?></title>
    <?php echo $styleSettings; ?>
     </head>
			<body> 
				<script type="text/javascript" src="js/wz_tooltip.js"></script>
				 <script type="text/javascript" src="js/jquery-1.4.3.min.js"></script>
	          <script type="text/javascript" src="js/jquery.mousewheel-3.0.4.pack.js"></script>
	           <script type="text/javascript" src="js/jquery.fancybox-1.3.4.pack.js"></script>
	            <script type="text/javascript">var url="<?php echo $domain ?>"</script>
	          <script type="text/javascript" src="js/ajaxtabs.js"></script>
	        <link rel="stylesheet" type="text/css" href="css/jquery.fancybox-1.3.4.css" media="screen" />		
			</body>
   <div class="body_bfLB">
   	<?php echo $Banner; ?>
    <ul id="dogtagstabs" 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($data['soldiername']); ?>" >Details</a></li>
        <li><a href="Alldogtags.php?name=<?php echo rawurlencode($data['soldiername']); ?>" class="selected">Dogtags</a></li>
          <?php if($row['History'] == 1){ ?>
        <li><a id="bf3stats" href="history.php?pid=<?php echo $data['pid']; ?>">History</a></li>
        <?php }
          if($row['platform'] == "pc"){ ?>
        <li><a href="serverHistory.php?name=<?php echo rawurlencode($data['soldiername']); ?>">ServerHistory</a></li>
        <?php }
          if($row['battlereports'] == 1){ ?>
        <li><a href="battlereport.php?name=<?php echo rawurlencode($data['soldiername']); ?>">Battlereports</a></li>
        <?php } ?>
      </ul>
      
     <div style="float:left;">
      <table class="default" style="float:left;width:400px;margin-left:10px;" cellspacing="0" cellpadding="5">
      	<td class="head" colspan="4" cellspacing="0" ><?php echo LANG_DOGTAGS_TITLE3.'('.$gesamt.')'; ?></td>
	    <tr>
	  	  <td class="object"><?php echo LANG_DOGTAGS_NAME; ?></td>
	  	  <td class="object">Tag</td>
	  	  <td class="object"><?php echo LANG_DOGTAGS_COUNT; ?></td>
	  	  <td class="object"><?php echo LANG_DOGTAGS_LAST; ?></td>
	  	  <?php 
	  	   if (isset($array)){ 
	  	   $i = 0;	
          foreach ($array as $key => $data){
          	$back = "";
          	if (in_array($data['tag'],$clantag)){
          		$back = 'style="background-image:url('.$domain.'/img/members.png)"';
          	}
         ?>
         <tr <?php echo $back; ?>>
          <td class="result"><a class="tooltip" href="http://bf3stats.com/stats_<?php echo $row['platform']; ?>/<?php echo rawurlencode($data['name']);?>" target="_blank" ><?php echo htmlspecialchars($data['name']); ?>
          	<span style='margin-top:-35px;margin-left:-215px;width:250px;z-index:1000;'>	
          	 <?php
          	   $time = array_keys($aData['taken'][$data['name']]);
          	   $array = $aData['taken'][$data['name']]; 
          	   $i = 0;
          	     foreach ($array as $key => $moreD){
          	  	   if ($i >= 1) echo '<hr>';
                    ?><b><?php echo htmlspecialchars($moreD['name']); ?></b><br>
                         <img src="<?php echo $domain; ?>/img/dogtags_s/<?php echo $moreD['image']; ?>.png" border="0" /><br />
          	         <?php echo $EoT->unix_to_time($time[$i]); ?>
          	       <br />
          	    <?php 
               ++$i;
          	  }
          	  ?>
          	</span>
           </a>
          </td> 	
           <td class="result"><?php echo tag($data['tag']); ?></td>
           <td class="result"><?php echo $data['count']; ?></td>
           <td class="result"><?php echo $EoT->unix_to_time($data['time']); ?></td>
         <tr>
       	<?php       
          }
         }else{
    	     echo '<tr><td class="result" colspan="4">'.LANG_DOGTAGS_NO_TAKEN.'</td>';
        }
       ?>
 	  </table>
   </div>

      
      <?php
      $gesamt = 0;
      if ($aData['lost'] != "" && $aData != ""){
           $Dogtags = array_keys($aData['lost']);
		  $array = array();
      $i = 0;
    foreach ($Dogtags as $Name){
    	$time = array_keys($aData['lost'][$Name]);
      $array[$i]['name'] = $Name;
     	$array[$i]['time'] = $time[0];   
     	$array[$i]['i'] = $aData['lost'][$Name][$time[0]]['i'];
     	$array[$i]['adv'] = $aData['lost'][$Name][$time[0]]['adv'];
     	$array[$i]['dogtag'] = $aData['lost'][$Name][$time[0]]['name'];
     	$array[$i]['desc'] = $aData['lost'][$Name][$time[0]]['desc'];
     	$array[$i]['image'] = $aData['lost'][$Name][$time[0]]['image'];
     	$array[$i]['count'] = count($aData['lost'][$Name]);
      ++$i;
    }
    usort($array, "sortDogtags");
     foreach ($array as $all){
    	$gesamt += $all['count'];
   }
  }
  
  
   ?>
      <div style="float:left;">
       <table class="default" style="float:left;width:400px;margin-left:10px;" cellspacing="0" cellpadding="5">
        <td class="head" colspan="3" cellspacing="0"> <?php echo LANG_DOGTAGS_TITLE4.'('.$gesamt.')'; ?></td>
	      <tr>
	  	   <td class="object"><?php echo LANG_DOGTAGS_NAME; ?></td>
	  	   <td class="object"><?php echo LANG_DOGTAGS_COUNT; ?></td>
	  	   <td class="object"><?php echo LANG_DOGTAGS_LAST; ?></td>
	      
	  	    <?php  
	  	     if (isset($array)){ 
	  	      $i = 0;	
           foreach ($array as $key => $data){ 
         ?>
           <tr>
             <td class="result"><a class="tooltip" href="http://bf3stats.com/stats_<?php echo $row['platform']; ?>/<?php echo rawurlencode($data['name']);?>" target="_blank" ><?php echo htmlspecialchars($data['name']); ?>
             	<span style='margin-top:-35px;margin-left:-215px;width:250px;z-index:1000;'>
          	   <?php
          	  $time = array_keys($aData['lost'][$data['name']]);
          	  $array = $aData['lost'][$data['name']]; 
          	  $i = 0;
          	  foreach ($array as $key => $moreD){
          	  	if ($i >= 1) echo '<hr>';
                ?><b><?php echo htmlspecialchars($moreD['name']); ?></b> <br>
                     <img src="<?php echo $domain; ?>/img/dogtags_s/<?php echo $moreD['image']; ?>.png" border="0" /><br />
          	         <?php echo $EoT->unix_to_time($time[$i]); ?><br />
          	    <?php 
               ++$i;
          	  }
          	  ?>
          	</span>
           </a>
          </td>
             <td class="result"><?php echo $data['count']; ?></td>
             <td class="result"><?php echo $EoT->unix_to_time($data['time']); ?></td>
            <tr>
       	   <?php        
           }
        }else{
    	    echo '<tr><td class="result" colspan="3">'.LANG_DOGTAGS_NO_LOST.'</td>';
        }
	  	?>
	  </table>
   </div> 
   
 <?php function sortDogtags($a, $b) { return $a["count"]<$b["count"]; }
       
       function tag($tag){
       	if ($tag == ""){
       		$tag = "---";
       	}else{
       		$tag = htmlspecialchars($tag);
       	}
      return $tag;      
    }
    
     include_once 'inc/footer.php';
    ?> 
    </div>
    
   <script type="text/javascript">
		$(document).ready(function() {
	
			$("a#bf3stats").fancybox({
			'autoDimensions'	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'padding' : 0,
      'overlayColor'		: '#000',
			'overlayOpacity'	: 0.6
	   });
   });
	</script> 