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

$EoT = new eGamersofTomorrow;


$aWeapons = array("arAK74","wahUGL","arM416","wahUSG","arAEK","arM16","arAN94","arF2","arG3","arKH","srM40","srM98","srMK11","srSKS","srSV98","srSVD","mgM240","mgM249","mgM27","mgM60","mgPech","mgRPK","mgT88","caA91","caAKS","caG36","caM4","caSCAR","caSG553","srM39","wLAAFIM","wLAAIGL","wLATJAV","wLATRPG","wLATSMAW","pG17S","pG17","pg18S","pg18","pM1911L","pM1911","pM1911S","pM1911T","pM412","pM9F","pM9S","pM9","pM93R","pMP443L","pMP443S","pMP443","pTaurS","pTaur","sg870","sgDAO","sgM1014","sgSaiga","sgUSAS","smMP7","smP90","smPDR","smPP2000","smUMP","smVAL","wasK","arFAMAS","arL85A2","caHK53","caQBZ95B","mgQBB95","mgMG36","srL96","smPP19","sgJackH","srQBU88","arAUG","arSCARL","mgL86A1","mgLSAT","caACR","caMTAR21","srHK417","srJNG90","sgSPAS12","smM5K");

$event = array();
$ii = 0;
foreach ($aWeapons as $weapons){
$sSql = "SELECT a.soldiername,a.pid,b.".$weapons."_needed - b.".$weapons."_curr AS nextevent, b.".$weapons."_date, b.".$weapons."_count	FROM ".DBPrefix."generalStats a Left JOIN  ".DBPrefix."stars b ON a.pid = b.stats_pid WHERE 1";        
$rResult = mysql_query($sSql) or $sError = 'Error in Query: ' . mysql_error() . ' in SQL: ' . print_r($sSql, true);
while(($data= mysql_fetch_assoc($rResult)) !== FALSE ) {
$event[$ii]['name'] = $data['soldiername'];
$event[$ii]['weapon'] = $weapons;
$event[$ii]['nextevent'] = $data['nextevent'];
$event[$ii]['count'] = $data[$weapons.'_count'];
$event[$ii]['date'] = $data[$weapons.'_date'];
++$ii;
}
}
 ?>
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
 <title>BF3 LB / Next Events</title>
 <?php echo $styleSettings; ?>
  <div class="body_bfLB" style="width:<?php echo $style['IndexDivWidth']; ?>px;">   
	           <?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="class.php"><?php echo LANG_CLANSTATS_TAB_KITS; ?></a></li>
        <li><a href="skill.php"><?php echo LANG_CLANSTATS_TAB_SKILL; ?></a></li>
        <li><a href="teamplay.php" >Teamplay</a></li>
        <li><a href="vehicles.php"><?php echo LANG_CLANSTATS_TAB_VEHICLES; ?></a></li>
        <li><a href="weaponstats.php"><?php echo LANG_CLANSTATS_TAB_WEAPONS; ?></a></li>
        <li><a href="ribbonsstats.php">Ribbons</a></li>
        <li><a href="medalsstats.php">Medals</a></li>
        <li><a href="events.php" class="selected"> Events</a></li>
        <li><a href="serverHistory.php">S.History</a></li>
      </ul>
   <table class="default" cellspacing="0" cellpadding="5" style="width:<?php echo $style['IndexTableWidth']; ?>px;">
     <td class="head" colspan="8" cellspacing="0"><?php echo LANG_NEXT_TITLE; ?></td>
    <tr>
 <?php
      usort($event, "nextevent");  
      $i = 0;
    foreach ($event as $events){
    	$i++;
    	$WeaponNameC = 'LANG_WEAPONS_'.$events['weapon'];
		 	$WeaponTEXT = 'LANG_WEAPONS_TEXT_'.$events['weapon'];
		 	$WeaponName = constant($WeaponNameC);
		 	
		 	if(strlen($WeaponName) <= 8) {
        $WeaponName = $WeaponName;
      } else {
        $WeaponName = substr($WeaponName,0,8) . ''; 
      }   
      
      if(strlen($events['name']) <= 12) {
        $Name = $events['name'];
      } else {
        $Name = substr($events['name'],0,10) . '..'; 
      }   
      
      
    	?>
    	<td class="result" width="100px">
    	 <a class="tooltip"><?php echo $WeaponName; ?>
    		  <span style="margin-top:20px;margin-left:-10px;width:250px;">
	  			  <div style="text-align:center;width:120px;"><b><?php echo constant($WeaponNameC); ?></b></div><br />
	  			    <div style="float:left;"><img src="<?php echo $domain; ?>/img/weapons/<?php echo $events['weapon']; ?>.png" width="120px"/></div><div style="text-align:left;"><?php echo constant($WeaponTEXT); ?></div>
	  		   </span>
	  	 </a>
	  	  <br />
		 		  <div>
	  			   <img src="<?php echo $domain; ?>/img/stars/stars_back_big.png" />	
	  			    <div style="margin-left:<?php echo marginNextevent($events['count']+1); ?>px;position:absolute;font-size:11px;font-weight:bold;margin-top:-19px;"><?php echo $events['count']+1; ?>
	  			  </div>
	  		 </div>
		 		  <div class="DIVtext"><?php echo $events['nextevent']; ?> Kills </div>
		 		  <a href="<?php echo $domain; ?>/stats.php?name=<?php echo rawurlencode($events['name']); ?>" target="_self"><?php echo $Name; ?></a>
		 		</td>
	    <?php
	    if ($i % 8 == 0) echo'<tr />';
	    if ($i == 72) break;	     
   }

echo '</table>';



$aMedals = array("m1","m2","m3","m4","m5","m6","m7","m8","m9","m10","m11","m12","m13","m14",
"m15","m16","m17","m18","m19","m20","m21","m22","m23","m24","m25","m26","m27","m28","m29","m30",
"m31","m32","m33","m34","m35","m36","m37","m38","m39","m40","m41","m42","m43","m44","m45","m46","m47","m48","m49","m50");

$event = array();
$ii = 0;
foreach ($aMedals as $medals){
$sSql = "SELECT a.soldiername,a.pid,b.".$medals."_needed - b.".$medals."_curr AS nextevent, b.".$medals."_count	FROM ".DBPrefix."generalStats a Left JOIN  ".DBPrefix."medals b ON a.pid = b.stats_pid WHERE 1";        
$rResult = mysql_query($sSql) or $sError = 'Error in Query: ' . mysql_error() . ' in SQL: ' . print_r($sSql, true);
while(($data= mysql_fetch_assoc($rResult)) !== FALSE ) {
$event[$ii]['name'] = $data['soldiername'];
$event[$ii]['medals'] = $medals;
if ($medals == "m50" OR $medals == "m49" OR $medals == "m48" OR $medals == "m47" OR $medals == "m46" OR $medals == "m45" OR $medals == "m44" OR $medals == "m43" OR $medals == "m42" OR $medals == "m41"){
$event[$ii]['nextevent'] = $data['nextevent']/60;
}else{
$event[$ii]['nextevent'] = $data['nextevent'];
}
$event[$ii]['count'] = $data[$medals.'_count'];

++$ii;
}
}
 ?>
   <table class="default" cellspacing="0" cellpadding="5" style="width:<?php echo $style['IndexTableWidth']; ?>px;">
     <td class="head" colspan="8" cellspacing="0">Medals</td>
    <tr>
 <?php
      usort($event, "nextevent");  
      $i = 0;
    foreach ($event as $events){
    	
    	if ($events['nextevent'] > 0 ){
    	$i++;
       $Medalsconstante = 'LANG_MEDALS_TEXT_'.$events['medals'].'';
       $tooltip = '<img src="'.$domain.'/img/medals/'.$events['medals'].'.png" /><br />'.constant($Medalsconstante);
       
       if ($events['medals'] == "m50" OR $events['medals'] == "m49" OR $events['medals'] == "m48" OR $events['medals'] == "m47" OR $events['medals'] == "m46" OR $events['medals'] == "m45" OR $events['medals'] == "m44" OR $events['medals'] == "m43" OR $events['medals'] == "m42" OR $events['medals'] == "m41"){
          $needed = '~ '.round($events['nextevent']).LANG_GENERAL_NEXTEVENTS_MINUTES;
        }else{
        	 if ($events['nextevent'] > 1){
        	 $needed = $events['nextevent'].' Ribbons';
        	}else{
        	$needed = $events['nextevent'].' Ribbon';
         }
       }
       
       
       
       if(strlen($events['name']) <= 12) {
        $Name = $events['name'];
      } else {
        $Name = substr($events['name'],0,10) . '..'; 
      }
    	?>
    	<td class="result" width="100px">
    	  <a class="tooltip"><img src="<?php echo $domain; ?>/img/medals/<?php echo $events['medals']; ?>.png" width="80px"/>
	  			 <span style="margin-top:25px;margin-left:-85px;"><?php echo $tooltip; ?></span>
	  		 </a>
	  			   <div style="position:absolute;margin-left:45px;margin-top:-17px;background-color:#000;width:35px;opacity:0.70;filter: alpha(opacity=70);-moz-opacity: 0.7;"><?php echo $events['count']+1; ?>x</div>
		 		   <div class="DIVtext"><?php echo $needed; ?></div>
		 		  <a href="<?php echo $domain; ?>/stats.php?name=<?php echo rawurlencode($events['name']); ?>" target="_self"><?php echo $Name; ?></a>
		 		</td>
	    <?php
	    if ($i % 8 == 0) echo'<tr />';
	    if ($i == 56) break;	     
      }
   }

echo '</table>';


function nextevent($a, $b) { return $a["nextevent"]>$b["nextevent"]; }

 function marginNextevent($count){
	if ($count >= 10 && $count <=99){
		$return = 45;
	}else if ($count >= 100){
		$return = 42;
	}else{
		$return = 48;
	}
	
	return $return;
}

include_once '../inc/footer.php';
echo '</div>';


