<?php
/*======================================================================*\
|| #################################################################### ||
|| # EoT-Clan BC2 Server Stats                                        # ||
|| # ---------------------------------------------------------------- # ||
|| # Dieses Copyright darf nicht entfernt werden                      # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # -----------------BC2 Server Stats is a free Software-------------# ||
|| #                      http://eot-clan.net                         # ||
|| #################################################################### ||
\*======================================================================*/
require_once '../inc/config.php';
include_once ('../lang/language.php');
include_once ('../lang/'.$lang_file.'');
	
	$_GET = security::escape($_GET);
  $_POST = security::escape($_POST); 
  
	?>
	      <head>
					<title><?php echo mapstats_title; ?></title>
	         <link rel="stylesheet" type="text/css" href="../css/fancybox.css" media="screen">
	        <link rel="stylesheet" type="text/css" href="../css/style.css" /> 
	      </head>
		<div class="body_ministats">
	<table class="default_m" cellspacing="0" cellpadding="0" style="margin-top:12px;">
     <td class="head" colspan="11" cellspacing="0"><a href="<?php echo $installdir; ?>/index.php" target="_self"><span style="float:left;margin-left:5px;"><?php echo lang_index_startseite; ?></a></span><?php echo mapstats_title; ?></td>      
   <?php
   	
		 $query = "SELECT 
		            a.* 
		           FROM 
		            tbl_mapstats a 
		           WHERE 
		            MinPlayers > 0 ORDER by TimeMapLoad DESC ";
	$result = db_query($query);
$array = array();
while($row = mysql_fetch_assoc($result)){
  $array[] = $row;
}

 $Days = array("0","1","2");
 

  foreach ($Days as $day){	
  	$date = date("Y-m-d",mktime(0, 0, 0, date("m"), date("d")-$day, date("Y"))); 
?>  	
      <tr>
			  <td colspan="10" style="text-align:center;"><hr width="775px"><?php echo mapstats_last_maps.$date; ?><hr width="775px"></td>
      <tr> 
      <th width="60px"><?php echo mapstats_load; ?></th>
			    <th width="60px"><?php echo  mapstats_mapname; ?></th>
			     <th width="60px"><?php echo mapstats_gamemode; ?></th> 
				     <th width="60px"><?php echo mapstats_round; ?></th>
				      <th width="60px"><?php echo mapstats_numbderofrounds; ?></th>
				       <th width="60px"><?php echo mapstats_minp; ?></th>
				      <th width="60px"><?php echo mapstats_avp; ?></th>
				     <th width="60px"><?php echo mapstats_maxp; ?></th>
				    <th width="80px"><?php echo mapstats_join; ?></th>
				   <th width="40px"><?php echo mapstats_left; ?></th>
			   <tr>
<?php


$max = 0;
$min = 0;
$left = 0;
$join = 0;
$av = 0;


$i = 0;
foreach ($array as $data){
	$datetime = $data['TimeMapLoad'];
    $datetime = explode(" ", $datetime);
    if ($datetime[0] ==  $date){
    	$Map = $data['MapName'];
    	include ('../inc/map_array.php');
    	
    	$tooltip = '<a class="tooltip" href="#">'.$Mapname.'<span><img src="'.$installdir.'/img/mapsbig/'.$Map.'.jpg" border="0" width="580px"></span></a>';

    	?>
    	 <td class="result" style="text-align:center;" height="20px">&nbsp;<?php echo $datetime[1]; ?></td>
    	  <td class="result" style="text-align:center;" height="20px"><?php echo $tooltip; ?></td>
    	   <td class="result" style="text-align:center;" height="20px"><?php echo $data['Gamemode']; ?></td>
    	   <td class="result" style="text-align:center;" height="20px"><?php echo $data['Roundcount']; ?></td>
    	    <td class="result" style="text-align:center;" height="20px"><?php echo $data['NumberofRounds']; ?></td>
    	     <td class="result" style="text-align:center;" height="20px"><?php echo $data['MinPlayers']; ?></td>
    	    <td class="result" style="text-align:center;" height="20px"><?php echo $data['AvgPlayers']; ?></td>
    	    <td class="result" style="text-align:center;" height="20px"><?php echo $data['MaxPlayers']; ?></td>
    	   <td class="result" style="text-align:center;" height="20px"><?php echo $data['PlayersJoinedServer']; ?></td>
    	 <td class="result" style="text-align:center;" height="20px"><?php echo $data['PlayersLeftServer']; ?></td>
    <tr>   		
    <?php
   if (++$i == $mapstats_count)break;
    }
}

$id1 = 0;
foreach ($array as $data){
	$datetime = $data['TimeMapLoad'];
  $datetime = explode(" ", $datetime);
    if ($datetime[0] ==  $date){
    	$max += 	$data['MaxPlayers'];
    	$min += 	$data['MinPlayers'];
   ++$id1;
    }
}

if ($id1 == 0){
$min = 0;
$max = 0;
$av = 0;
}else{
$min = $min/$id1;
$max = $max/$id1;
$av = ($min+$max)/2;
}

?>
    <td class="result" style="text-align:center;" colspan="2" height="20px"><?php echo mapstats_date; ?><b>:<span class="stats_players"><?php echo $date; ?></span></b></td>
     <td class="result" style="text-align:center;" colspan="1" height="20px"><?php echo mapstats_numbderofrounds; ?>:<b><span class="stats_players"><?php echo $id1; ?></span></b></td>
      <td class="result" style="text-align:center;" colspan="2"><?php echo mapstats_minp2; ?>:<b><span class="stats_players"><?php echo number_format($min, 2, ',', '.'); ?></span></b></td>
     <td class="result" style="text-align:center;" colspan="2"><?php echo mapstats_maxp2; ?>:<b><span class="stats_players"><?php echo number_format($max, 2, ',', '.'); ?></span></b></td>
    <td class="result" style="text-align:center;" colspan="3"><?php echo mapstats_avp2; ?>:<b><span class="stats_players"><?php echo number_format($av, 2, ',', '.'); ?></span></b></td>



<?php } ?>
  
	 </td>	
	</table>
	<?php include_once ("../inc/footerm.php"); ?>
	  <br /> 
</div>	
