<?php
/*======================================================================*\
|| #################################################################### ||
|| # EoT-Clan BF3 Leaderboard                                         # ||
|| # ---------------------------------------------------------------- # ||
|| # Dieses Copyright darf nicht entfernt 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');


$EoT = new eGamersofTomorrow;
$xajax = new xajax();
$xajax->configure('javascript URI', 'js/xajax');

$xajax->register(XAJAX_FUNCTION, 'updateStats');


$xajax->processRequest();


$_GET = security::escape($_GET);
$_POST = security::escape($_POST);

 $order = "asc";
if (isset($_GET['sort'])){
 $sort = $EoT->sort($_GET['sort']);
 $order = $EoT->order($_GET['sort']);
}

  
?>
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
       <head>
        	<title><?php echo LANG_INDEX_TITLE; ?></title>
          <?php echo $styleSettings; ?> 
	     </head>
	  <?php $xajax->printJavascript(); ?>
	       <body>
	       	 <script type="text/javascript" src="js/wz_tooltip.js"></script>
             <script type="text/javascript" src="js/jquery-1.2.2.pack.js"></script>
	            <script type="text/javascript" src="js/ajaxupdate.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>
	          <link rel="stylesheet" type="text/css" href="css/jquery.fancybox-1.3.4.css" media="screen" />
           <div class="body_bfLB" style="width:<?php echo $style['IndexDivWidth']; ?>px;">   
	          <input type="hidden" id="updating" value="0" />
	           <?php echo $Banner; ?>                      	  
      <ul id="statstabs" class="shadetabs" style="margin-top:10px;margin-bottom:-10px;width:<?php echo $tabs; ?>px;">
        <li><a href="index.php" rel="#default" class="selected">Leaderboard</a></li>
        <li><a href="stats/class.php"><?php echo LANG_CLANSTATS_TAB_KITS; ?></a></li>
        <li><a href="stats/skill.php"><?php echo LANG_CLANSTATS_TAB_SKILL; ?></a></li>
        <li><a href="stats/teamplay.php">Teamplay</a></li>
        <li><a href="stats/vehicles.php"><?php echo LANG_CLANSTATS_TAB_VEHICLES; ?></a></li>
        <li><a href="stats/weaponstats.php"><?php echo LANG_CLANSTATS_TAB_WEAPONS; ?></a></li>
        <li><a href="stats/ribbonsstats.php">Ribbons</a></li>
        <li><a href="stats/medalsstats.php">Medals</a></li>
        <li><a href="stats/events.php">Events</a></li>
        <?php if($row['platform'] == "pc"){ ?>
        <li><a href="stats/serverHistory.php">S.History</a></li>
      <?php } ?>
      </ul>
           <table class="default" style="width:<?php echo $style['IndexTableWidth']; ?>px;" cellspacing="0" cellpadding="0">
            <tr>
    		     <td class="head" colspan="20" height="20px" ><div><a href="<?php echo $row['clanhompage']; ?>" target="_blank"><img src="<?php echo $domain; ?>/img/hp.png" style="float:left;" /></a><div><div style="margin-right:150px;"><?php echo LANG_INDEX_HEAD.htmlspecialchars($row['clanname']); ?>&nbsp;&nbsp;<img src="img/general/<?php echo $row['platform']; ?>.png" /></div></td>
    	      </tr>
           <tr>
     	       <td class="object" width="20px"><b><?php echo LANG_INDEX_PLACE; ?></b></a></td> 
     	       <?php if($row['rank'] == 1 ){ ?><td class="object" width="45px"><a href="index.php?sort=<?php echo $order ?>&tab=rank"><b><?php echo LANG_INDEX_RANK; ?></b></a></td> <?php } ?>
              <td class="object" width="150px"><a href="index.php?sort=<?php echo $order ?>&tab=soldiername"><b><?php echo LANG_INDEX_NAME; ?></b></a></td> 
         	     <?php if($row['progress'] == 1 ){ ?><td class="object" width="80px"><b><?php echo LANG_INDEX_ALL_PROGRESS; ?></b></a></td> <?php } ?>
         	     	<?php if($row['time'] == 1 ){ ?><td class="object" width="80px"><a href="index.php?sort=<?php echo $order ?>&tab=playtime"><b><?php echo LANG_INDEX_PLAYTIME; ?></b></a></td><?php } ?> 
                 <?php if($row['kills'] == 1 ){ ?><td class="object" width="80px"><a href="index.php?sort=<?php echo $order ?>&tab=kills"><b><?php echo LANG_INDEX_KILLS; ?></b></a></td><?php } ?>
                  <?php if($row['deaths'] == 1 ){ ?><td class="object" width="80px"><a href="index.php?sort=<?php echo $order ?>&tab=deaths"><b><?php echo LANG_INDEX_DEATHS; ?></b></a></td><?php } ?>
       		        <?php if($row['round'] == 1 ){ ?><td class="object" width="50px"><a href="index.php?sort=<?php echo $order ?>&tab=rounds"><b><?php echo LANG_INDEX_ROUNDS; ?></b></a></td><?php } ?> 
       	        <?php if($row['dogtags'] == 1 ){ ?><td class="object" width="50px"><a href="index.php?sort=<?php echo $order ?>&tab=dogtags"><b><?php echo LANG_INDEX_DOGTAGS; ?></b></a></td><?php } ?>
       	       <?php if($row['kd'] == 1 ){ ?><td class="object" width="40px"><a href="index.php?sort=<?php echo $order ?>&tab=KD"><b><?php echo LANG_INDEX_KD; ?></b></a></td><?php } ?> 
       	       <?php if($row['team'] == 1 ){ ?><td class="object" width="110px"><a href="index.php?sort=<?php echo $order ?>&tab=team"><b>Team</b></a></td><?php } ?> 
              <?php if($row['points'] == 1 ){ ?><td class="object" width="110px"><a href="index.php?sort=<?php echo $order ?>&tab=points"><b><?php echo LANG_INDEX_POINTS; ?></b></a></td><?php } ?>
             <?php if( $row['playerOnlineView'] == 1){ ?><td class="object" width="20px"></td><?php } ?>
             <td class="object" style="font-size:11px;"><?php echo LANG_INDEX_REFRESH; ?></td>
       <?php
    $place = 1;
    $gKills = 0;
    $gDeaths = 0;
    $gTime = 0;
    $gRounds = 0;
    $gDogtags = 0;
    $gPoints = 0;
    $gRank = 0;
    $gTeam = 0;
     $aData = stats::getStats();
 
      if (is_array($aData) && !empty($aData)){	
		     foreach ($aData as $data){	 
        
       $color = $row['vip_color']; 
       $vip = $data['vip_member'];
    
    

      if ($data['rank'] <= 144 && $data['nextrank'] > 0){
      	   $a = $data['nextrank'] - $data['rankscore'];
					 $b = $data['nextrank'] - $data['points'];
					 $points = $a-$b;
           $progress = number_format($points * 100 / $a, 2, '.', '');
        }else{
        	$b= 'unknown';
        	$progress = '100';  
      }
      
   if ($data['rank'] <= 144 ){
 	                		$tooltip  = '<img src=img/rank/big/P0'.$data['rank'].'.png width=100px /><br /><b>'.$EoT->rankname($data['rank']).'</b><br /><b>Level('.$data['rank'].')</b><br /><br />'.htmlspecialchars($data['soldiername']).LANG_INDEX_NEXT_POINTS.'<font color=#008FC4>'.$b.'</font>'.LANG_INDEX_NEXT_POINTS2.'<font color=#008FC4>'.$progress.'</font>'.LANG_INDEX_NEXT_POINTS3.'<p class=DIVtext>'.LANG_INDEX_ALL_LAST_UPDATE.'<br />'.$EoT->unix_to_time($data['playerupdate']).'</p>';
 	                		}else{
 	                		$tooltip =  '<img src=img/rank/big/P0'.$data['rank'].'.png width=100px /><br /><b>'.$EoT->rankname($data["rank"]).'</b><br /><b>Level('.$data['rank'].')</b><br /><br />'.htmlspecialchars($data['soldiername']).LANG_INDEX_NEXT_FINISH.'<p class=DIVtext>'.LANG_INDEX_ALL_LAST_UPDATE.'<br />'.$EoT->unix_to_time($data['playerupdate']).'</p>';
 	                	}
      
      if ($style['IndexRankIcon'] <= 20){
      	 $rankIMG = '<img src="img/rank/P0'.$data['rank'].'.png"/>';
      	}else{
      	$rankIMG = '<img src="img/rank/big/P0'.$data['rank'].'.png" width="'.$style['IndexRankIcon'].'"/>';
      }
      
      if ($data['is_online'] == 2){
      	$online = '<img src="img/online.png" title="Playing" />';
      }else{
      	$online = '<img src="img/offline.png" title="Offline" />';
      }
      
        if ($data['is_online'] == 2){
        	   $border = '#008FC4';
          }else if ($data['is_online'] == 1){
          	 $border = '#00FF00';
          }else{
          	 $border = '#999999';
          }
          
          
          	$premium = explode(',',$data['expansion']);
            $prem = "";
              if (is_array($premium)){
                if (in_array('1024',$premium)){
	               $prem = '<img src="img/prem_s.gif" style="float:right;margin-right:1px;border:0;" />';
                }
              }
    ?>
         <tr class="hov">
 	         <td class="result" style="height:<?php echo $style['IndexLineHeight']; ?>px">
 	   	      <input type="hidden" id="<?php echo $data['pid']; ?>" value="false" /><?php echo $place++; ?></td>
 	           <?php if($row['rank'] == 1 ){ ?>
 	              <td id="rank_<?php echo $data['pid']; ?>" class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px">
 	              	<a onmouseover="Tip('<?php echo $tooltip; ?>',WIDTH, 200, TEXTALIGN, 'center', OFFSETY, -110, OFFSETX, 125)" onmouseout="UnTip()"><?php echo $rankIMG; ?></a></td>
 	           <?php } ?>
 	            <td class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px"><img src="img/fav/<?php echo $EoT->favclass($data['assault'],$data['recon'],$data['support'],$data['engineer']); ?>.png" title="<?php echo $EoT->favclass($data['assault'],$data['recon'],$data['support'],$data['engineer']); ?>" style="float:left;" />
 	            	 <a class="tooltip" href="stats.php?name=<?php echo rawurlencode($data['soldiername']); ?>" target="_self"><?php echo $EoT->nameTrimchars($data['soldiername']).$prem; ?>
 	            	 	<span style="margin-top:-55px;margin-left:-95px;width:105px;z-index:1000;">
 	            	 		<img style="border: 3px solid <?php echo $border; ?>;-moz-border-radius:5px 5px 5px 5px;-webkit-border-radius:5px 5px 5px 5px;border-radius:5px 5px 5px 5px;" src="http://www.gravatar.com/avatar/<?php echo $data['gravatarMD5']; ?>?s=150&d=http%3A%2F%2Fbattlelog-cdn.battlefield.com%2Fpublic%2Fbase%2Fshared%2Fdefault-avatar-304.png%3Fv%3D7909" width="100px"/>
 	            	 	</span>
 	            	 	</a></td>
 	           <?php if ($row['progress'] == 1){
 	           	?>
 	           	<td class="result" style="border-left:<?php echo $style['result_border']; ?>">
								         <div class="progress">
									        <div class="progress_size" style="width:<?php echo $progress; ?>%">&nbsp;</div>
								         </div>
							       </td>
							 <?php } 
							       if($row['time'] == 1 ){ ?><td id="time_<?php echo $data['pid']; ?>" class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px"><?php echo $EoT->timeIndex($data['playtime']); ?></td><?php } ?>
						   <?php if($row['kills'] == 1 ){ ?><td id="kills_<?php echo $data['pid']; ?>" class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px"><?php echo $EoT->points($data['kills']); ?></td><?php } ?>
 	              <?php if($row['deaths'] == 1 ){ ?><td id="deaths_<?php echo $data['pid']; ?>" class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px"><?php echo $EoT->points($data['deaths']); ?></td><?php } ?>
 	                <?php if($row['round'] == 1 ){ ?><td id="round_<?php echo $data['pid']; ?>" class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px"><?php echo $EoT->points($data['rounds']); ?></td><?php } ?>
 	                <?php if($row['dogtags'] == 1 ){ ?><td id="dogtags_<?php echo $data['pid']; ?>" class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px"><?php echo $EoT->points($data['dogtags']); ?></td><?php } ?>
 	                 <?php if($row['kd'] == 1 ){ ?><td id="kd_<?php echo $data['pid']; ?>" class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px"><?php echo $EoT->kd($data['kills'],$data['deaths']); ?></td><?php } ?>
 	                 	<?php if($row['team'] == 1 ){ ?><td id="team_<?php echo $data['pid']; ?>" class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px"><?php echo $EoT->points($data['team']); ?></td><?php } ?>
 	                  <?php if($row['points'] == 1 ){ ?><td id="score_<?php echo $data['pid']; ?>" class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px">
 	                  	<?php if($row['History'] == 1 && $style['IndexTableWidth'] >= "814" ){ ?><a id="bf3stats_<?php echo $data['pid']; ?>" href="history.php?pid=<?php echo $data['pid']; ?>"><?php } ?>
 	                  		<?php echo $EoT->points($data['points']); ?></td><?php if($row['History'] == 1 ){ ?></a><?php }} ?>                  		
 	                 <?php if($row['playerOnlineView'] == 1){ ?><td class="result" style="border-left:<?php echo $style['result_border']; ?>">
 	                 	   <?php if($row['platform'] == "pc"){ ?> <a id="bf3server_<?php echo $data['soldiername']; ?>" href="DetailServer.php?name=<?php echo rawurlencode($data['soldiername']); ?>"><?php } echo $online; ?></a></td><?php } ?>
 	                 <td class="result"  onclick="refreshStats(<?php echo $data['pid']; ?>);">
								     <img id="anim_<?php echo $data['pid']; ?>" src="img/general/anim.gif" style='border: 0; cursor: pointer;' width="16px" />
								     <img id="anim_<?php echo $data['pid']; ?>_loading" src="img/general/anim1.gif" style='border: 0; cursor: pointer; display: none;' width="16px" />
							     </td>
							     
							      <script type="text/javascript">  	
		                $(document).ready(function() {
			                $("a#bf3stats_<?php echo $data['pid']; ?>").fancybox({
			                  'autoDimensions'	: true,
			                  'transitionIn'		: 'none',
			                  'transitionOut'		: 'none',
			                  'padding' : 0,
			                  'overlayColor'		: '#000',
				                'overlayOpacity'	: 0.8
			               });
                   });
	               </script>
	               
	                <script type="text/javascript">  	
		                $(document).ready(function() {
			                $("a#bf3server_<?php echo $data['soldiername']; ?>").fancybox({
			                  'autoDimensions'	: true,
			                  'transitionIn'		: 'none',
			                  'transitionOut'		: 'none',
			                  'padding' : 0,
			                  'overlayColor'		: '#000',
				                'overlayOpacity'	: 0.9
			               });
                   });
	               </script>
							     
 	              
 	                 
	          <?php
 	             $gKills += $data['kills'];
 	             $gDeaths += $data['deaths'];
 	             $gTime += $data['playtime'];
 	             $gRounds += $data['rounds'];
 	             $gDogtags += $data['dogtags'];
 	             $gPoints += $data['points'];
 	             $gRank += $data['rank'];
 	             $gTeam += $data['team'];
 	          
         } 
      }
      ?>
       <tr>
      <td class="result" height="20px">&Oslash;</td>
   <?php
      if ($place == 1){
      	$dRank = 0;
      }else{
      $dRank = round($gRank/($place-1));
    }
        $tooltip  = '<img src=img/rank/big/P0'.$dRank.'.png width=100px /><br /><b>'.$EoT->rankname($dRank).'<br />Level('.$dRank.')</b>';
      	if($row['rank'] == 1 ){ ?>
      	<td class="result" style="border-left:<?php echo $style['result_border']; ?>" height="20px"><a onmouseover="Tip('<?php echo $tooltip; ?>', TEXTALIGN, 'center', OFFSETY, -110, OFFSETX, 125)" onmouseout="UnTip()"><img src="img/rank/P0<?php echo $dRank; ?>.png" />     
      	</a></td>
      <?php }
      echo '<td class="result" style="border-left:'.$style['result_border'].'"  height="20px">'.LANG_INDEX_ALL_STATS.'</td>';
      if ($row['progress'] == 1){ echo '<td class="result" style="border-left:'.$style['result_border'].'">--</td>'; }
      if($row['time'] == 1 ){ echo '<td class="result" style="border-left:'.$style['result_border'].'" height="20px">'.$EoT->timeIndex($gTime).'</td>';}
      if($row['kills'] == 1 ){ echo '<td class="result" style="border-left:'.$style['result_border'].'" height="20px">'.$EoT->points($gKills).'</td>'; }
      if($row['deaths'] == 1 ){echo '<td class="result" style="border-left:'.$style['result_border'].'" height="20px">'.$EoT->points($gDeaths).'</td>'; } 
      if($row['round'] == 1 ){ echo '<td class="result" style="border-left:'.$style['result_border'].'" height="20px">'.$EoT->points($gRounds).'</td>';}
      if($row['dogtags'] == 1 ){echo '<td class="result" style="border-left:'.$style['result_border'].'" height="20px">'.$EoT->points($gDogtags).'</td>'; }
      if($row['kd'] == 1 ){echo '<td class="result" style="border-left:'.$style['result_border'].'" height="20px">'.$EoT->kd($gKills,$gDeaths).'</td>'; }
      if($row['team'] == 1 ){echo '<td class="result" style="border-left:'.$style['result_border'].'" height="20px">'.$EoT->points($gTeam).'</td>'; }
      if($row['points'] == 1 ){echo '<td class="result" style="border-left:'.$style['result_border'].'" height="20px">'.$EoT->points($gPoints).'</td>'; }
      if($row['platform'] == "pc"  &&  $row['playerOnlineView'] == 1 ){echo '<td class="result" height="20px"></td>'; }
      echo '<td class="result"  height="20px"></td>';
 ?>  
   </tr>
  <tr>
  	<td class="result" height="20px" colspan="20">Legende: <font color="<?php echo $row['vip_color']; ?>"><?php echo $row['vip']; ?></font> | <a href="#">Member</a></td></tr>
    </table> 
   <?php 
     if ($row['autoupdateEnabled'] == 1 ){
    include_once 'inc/nextact.php';
  }
    include_once 'inc/footer.php'; 
    ?>
   </div>
  </div> 
	</body>
</html>


