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

if(isset($_GET['page']) && !empty($_GET['page']) && $_GET['page'] != ''){
   $seite = $_GET['page'];
   }else{
   	$seite = 1;
  }

if (isset($_GET['player']) && !empty($_GET['player']) && $_GET['player'] != ''){
	$WHERE = "logSoldierName = '{$_GET['player']}'";
	$get = 	"&player=".urlencode($_GET['player'])."";
}elseif (isset($_GET['server']) && !empty($_GET['server']) && $_GET['server'] != ''){
	$WHERE = "logServer = '{$_GET['server']}'";	
	$get = 	"&server=".urlencode($_GET['server'])."";
}else{
	$WHERE = '1';
	$get = 	"";
}

	?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
	      <head>
					<title><?php echo lang_stats_chat_entrys; ?></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="5" 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 lang_stats_chat_entrys; ?></td>
			<tr> 
			    <th width="130px" style="text-align:left;"><?php echo lang_chat_date; ?></th>
			     <th width="200px" style="text-align:left;"><?php echo lang_chat_server; ?></th>
			      <th width="80px" style="text-align:center;"><?php echo lang_chat_subset; ?></th>
				   <th width="120px" style="text-align:left;"><?php echo lang_chat_soldier; ?></th> 
				  <th style="text-align:left;"><?php echo lang_chat_message; ?></th>
			</tr>
			<?php
			
 $entrys = 20; 
 $start = $seite * $entrys - $entrys; 
 
 $query = "
		SELECT 
			a.*
		FROM 
			tbl_chatlog a 
		WHERE {$WHERE}
		ORDER by 
		 a.logDate DESC";
 $result = db_query($query); 
 $num_rows = mysql_num_rows($result);
 $Sites = ceil($num_rows / $entrys);
 
 
	$query = "
		SELECT 
			a.*
		FROM 
			tbl_chatlog a 
		WHERE {$WHERE}
		ORDER by 
		 a.logDate DESC
		 LIMIT {$start}, {$entrys}";

	$result = db_query($query);
	$num_rows = mysql_num_rows($result);
	
	
$error = '';
if ($num_rows === 0) {
$error = '<td class="result" colspan="5"><span class="sonstige"><b>'.server_chatlog_error.'</b></span></td>';
}
echo $error;

	while ($row = mysql_fetch_assoc($result)){
		if(strlen($row['logServer']) <= 40) {
           $Server = $row['logServer'];
        } else {
          $Server= substr($row['logServer'],0,40) . '..'; 
      }
      
      if(strlen($row['logMessage']) <= 40) {
           $message = $row['logMessage'];
        } else {
          $message = substr($row['logMessage'],0,40) . '..'; 
      }
     
     
    if ($row['logSubset'] == 'Team'){
    	$style = '<tr class="chat_team" style="height:25px;">';
    }elseif ($row['logSubset'] == 'Squad'){
    	$style = '<tr class="chat_squad" style="height:25px;">';
    }else{
    	$style = '<tr class="chat_global" style="height:25px;">';
    }
    if ($row['logMessage'] != 'Scoring disabled due to too few players'){
		?>
	<?php echo $style; ?>
		<td class="result" style="text-align:left;"><?php echo $row['logDate']; ?></td>
		<td class="result" style="text-align:left;"><?php echo htmlspecialchars ($Server); ?></td>
		<td class="result" style="text-align:center;"><?php echo $row['logSubset']; ?></td>
		<td class="result" style="text-align:left;"><a href="<?php echo $installdir; ?>/ministats.php?name=<?php echo rawurlencode($row['logSoldierName']); ?>"><?php echo htmlspecialchars ($row['logSoldierName']); ?></a></td>
		<td class="result" style="text-align:left;"><?php echo htmlspecialchars ($message); ?></td>
	</tr>	
		<?php
		}
	}
	
function blaetterfunktion_chat($seite,$maxseite,$url="",$anzahl=6,$get_name="page") {
   global $get;
   global $installdir;
   $anhang = "?";
   if($anzahl%2 != 0) $anzahl++;

   $a = $seite-($anzahl/2);
   $b = 0;
   $blaetter = array();
   while($b <= $anzahl) {
      if($a > 0 AND $a <= $maxseite) {
         $blaetter[] = $a;
         $b++;
         }
      else if($a > $maxseite AND ($a-$anzahl-2)>=0) {
         $blaetter = array();
         $a -= ($anzahl+2);
         $b = 0;
       }
      else if($a > $maxseite AND ($a-$anzahl-2)<0) {
         break;
         }

      $a++;
      }
   $return = "";
   if(!in_array(1,$blaetter) AND count($blaetter) > 1) {
      if(!in_array(2,$blaetter)) $return .= "&nbsp;<a id=chatentrys href=\"{$installdir}/stats/chatentrys.php{$anhang}{$get_name}=1{$get}\">1</a>&nbsp;...";
      else $return .= "&nbsp;<a id=chatentrys href=\"{$installdir}/stats/chatentrys.php{$anhang}{$get_name}=1{$get}\">1</a>&nbsp;";
      }

   foreach($blaetter AS $blatt) {
      if($blatt == $seite) $return .= "&nbsp;<b>$blatt</b>&nbsp;";
      else $return .= "&nbsp;<a id=chatentrys href=\"{$installdir}/stats/chatentrys.php{$anhang}{$get_name}=$blatt{$get}\">$blatt</a>&nbsp;";
      }

   if(!in_array($maxseite,$blaetter) AND count($blaetter) > 1) {
      if(!in_array(($maxseite-1),$blaetter)) $return .= "...&nbsp;<a id=chatentrys href=\"{$installdir}/stats/chatentrys.php{$anhang}{$get_name}=$maxseite{$get}\">".server_gerneral_server_last."($maxseite)</a>&nbsp;";
      else $return .= "&nbsp;<a id=chatentrys href=\"{$installdir}/stats/chatentrys.php{$anhang}{$get_name}=$maxseite{$get}\">$maxseite</a>&nbsp;";
      }

   if(empty($return))
      return  "&nbsp;<b>1</b>&nbsp;";
   else
      return $return;
   }  
   
	echo "</tbody><tr>
        <td class=result colspan=14>
      <b>".server_gerneral_serverb_page.":<font color=orange></b>";

echo blaetterfunktion_chat($seite,  $Sites)."</td></font>";

echo "</table>";
	 include_once ("../inc/footerm.php"); ?>
	 <script type="text/javascript">  	
		     $(document).ready(function() {
				 $("a#chatentrys").fancybox({
			    'autoDimensions'	: true,
			    'transitionIn'		: 'none',
			    'transitionOut'		: 'none',
			    'padding' : 0
			  });
      });
	   </script>
	  <br /> 
</div>	