<?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['medal']) && !empty($_GET['medal']) && $_GET['medal'] != '') {
       $medal = $_GET['medal']; 
   }else{
     $medal = "m1";
 }
 
            $sSql = "SELECT a.soldiername,a.pid,b.".$medal."_count,b.".$medal."_date,b.".$medal."_curr,b.".$medal."_needed,b.stats_pid FROM ".DBPrefix."generalStats a
                      Left JOIN 
                      ".DBPrefix."medals b  ON a.pid = b.stats_pid WHERE b.".$medal."_count > 0
                      ORDER BY ".$medal."_count DESC";       
             $result= mysql_query($sSql)or die(mysql_error()) ;
         
         $Medalsconstante = 'LANG_MEDALS_TEXT_'.$medal.'';
             
?>      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
         <title>BF3 LB / <?php echo LANG_CLANSTATS_MEDALS_TITLE; ?></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" class="selected">Medals</a></li>
        <li><a href="events.php"> Events</a></li>
        <li><a href="serverHistory.php">S.History</a></li>
      </ul>
				<table class="default" style="width:<?php echo $style['IndexTableWidth']; ?>px;" cellspacing="0" cellpadding="0">
					<tr>
           <td class="head" colspan="8" height="20px"><?php echo LANG_CLANSTATS_MEDALS_TITLE; ?></td>
           <tr>
        	<td colspan="8">
      		<img src="<?php echo $domain; ?>/img/medals/<?php echo $medal; ?>.png" /><br /><?php echo constant($Medalsconstante); ?>
      		</td>
      	<tr>
      		<td class="object" width="20px"><?php echo LANG_INDEX_PLACE; ?></td> 
      <td class="object"><?php echo LANG_INDEX_NAME; ?></td> 
       <td class="object" width="120px"><?php echo LANG_MEDALS_COUNT; ?></td> 
        <td class="object" width="80px"><?php echo LANG_MEDALS_CURR; ?></td>
       <td class="object" width="87px"><?php echo LANG_MEDALS_NEEDALL; ?></td>
       <td class="object" width="87px"><?php echo LANG_MEDALS_NEED; ?></td>
      <td class="object" width="46px"><?php echo LANG_INDEX_ALL_PROGRESS; ?></td>  
      <td class="object" width="140px"><?php echo LANG_MEDALS_LAST; ?></td>
	  <tr height=20px >
     
   <?php
       $num = mysql_num_rows($result);
        $place = 1;
        if ($num == 0){
        	echo '<td class="result" colspan="8">'.LANG_MEDALS_NO_MEDALS.'</td><tr>';
        	echo '<td class="result" colspan="8">'.LANG_MEDALS_NO_MEDALS_NEXT.'</td><tr>';
        	         $sSql = "SELECT a.soldiername,b.".$medal."_needed - b.".$medal."_curr AS need ,b.stats_pid,b.".$medal."_curr,b.".$medal."_needed FROM ".DBPrefix."generalStats a
                      Left JOIN 
                      ".DBPrefix."medals b  ON a.pid = b.stats_pid
                      ORDER BY need ASC LIMIT 5";       
                 $result= mysql_query($sSql)or die(mysql_error()) ;
                while ($data = mysql_fetch_assoc($result)) {
                	$progress = round($data[''.$medal.'_curr']) * 100 / $data[''.$medal.'_needed'];
                	if ($medal == "m50" OR $medal == "m49" OR $medal == "m48" OR $medal == "m47" OR $medal == "m46" OR $medal == "m45" OR $medal == "m44" OR $medal == "m43" OR $medal == "m42" OR $medal == "m41" OR $medal == "m40" ){
                      $needed = $EoT->time_h($data[''.$medal.'_needed']);
                      $curr = $EoT->time_H_M($data[''.$medal.'_curr']);
                      $need = $EoT->time_H_M($data[''.$medal.'_needed']-$data[''.$medal.'_curr']);
                    }else{
  	                  $needed = $data[''.$medal.'_needed'];
                    	$curr = $data[''.$medal.'_curr'];
                    	$need = $data[$medal.'_needed']-$data[$medal.'_curr'];
                    }
                  echo '<td class="result" colspan="1">'.$place++.'</td>';
                	echo '<td class="result" colspan="1"><a href="../stats.php?name='.rawurlencode($data['soldiername']).'" target="_self">'.htmlspecialchars($data['soldiername']).'</a></td>';
                	echo '<td class="result" colspan="1">---</td>';
                	echo '<td class="result" colspan="1">'.$curr.'</td>';
                	echo '<td class="result" colspan="1">'.$needed.'</td>';
                	echo '<td class="result" colspan="1">'.$need.'</td>';
                	echo '<td class="result"><div class="progress_small" style="width:100px;">
	 		                   <div class="progress_size_small" style="width:'.$progress.'%;max-width:99px;">&nbsp;</div>
	 		                   </div>
	 		                  </td>';
	 		            echo '<td class="result" colspan="1">---</td><tr>';
                }
        }else{       
      while ($data = mysql_fetch_assoc($result)) {	
        
          
     if ($medal == "m50" OR $medal == "m49" OR $medal == "m48" OR $medal == "m47" OR $medal == "m46" OR $medal == "m45" OR $medal == "m44" OR $medal == "m43" OR $medal == "m42" OR $medal == "m41" OR $medal == "m40" ){
    $needed = $EoT->time_h($data[''.$medal.'_needed']);
    $curr = $EoT->time_H_M($data[''.$medal.'_curr']);
    $need = $EoT->time_H_M($data[''.$medal.'_needed']-$data[''.$medal.'_curr']);
  }else{
  	$needed = $data[''.$medal.'_needed'];
  	$curr = $data[''.$medal.'_curr'];
  	$need = $data[$medal.'_needed']-$data[$medal.'_curr'];
  }
     
     
     if ($data[$medal.'_count'] >= 1){
		$progress = (round($data[''.$medal.'_curr'])-($data[''.$medal.'_needed']/($data[$medal.'_count']+1))*$data[$medal.'_count'])*100/($data[''.$medal.'_needed']/($data[$medal.'_count']+1));
	}else{
	 	$progress = round($data[''.$medal.'_curr']) * 100 / $data[''.$medal.'_needed'];
	}
	
      $tooltip = '<img src="'.$domain.'/img/medals/'.$medal.'.png" /><br />'.constant($Medalsconstante);
      ?>
      <td class="result"><?php echo $place++; ?></td>
      <td class="result"><a href="../stats.php?name=<?php echo rawurlencode($data['soldiername']); ?>" target="_self"><?php echo $EoT->nameTrimchars($data['soldiername']); ?></a></td>
      <td class="result"><?php echo $data[$medal.'_count']; ?></td>
      <td class="result"><?php echo $curr; ?></td>
      <td class="result"><?php echo $needed; ?></td>
      <td class="result"><?php echo $need; ?></td>
      <td class="result"><div class="progress_small" style="width:100px;">
	 		  <div class="progress_size_small" style="width:<?php echo $progress; ?>%;max-width:99px;">&nbsp;</div>
	 		 </div>
	 		</td>
	 		 <td class="result"><?php echo $EoT->unix_to_time($data[''.$medal.'_date']); ?></td>
     <tr>
      <?php
  }
}

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