<?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                            # ||
|| #################################################################### ||
\*======================================================================*/
   if(!defined('DIRECTACCESS')){
echo 'You cannot access this file directly!';
die;
}


  $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'];
   }
  }
   
      

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