<?php include('inc/header.php'); ?>
<h1>Management - Ban Logs</h1>
<div class="container">
<?php
	odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['web'] . ']');
	echo '<div id="pageinc">';
	if(!isset($_GET['page'])) { $_GET['page'] = 1; }
	$page = $_GET['page'];
	$perpage = 20;
	$select = odbc_exec($odbc_connect, 'SELECT * FROM [LOG_BANS] ORDER BY datetime DESC');
	$resultset = array();
	$counter = 0;
	while($row = odbc_fetch_array($select)) {
		$resultset[$counter++] = $row;
	}
	$all = odbc_exec($odbc_connect, 'SELECT * FROM [LOG_BANS]');
	$count = odbc_num_rows($all);
	$countpages = $count / $perpage;
	echo '
<table cellspacing="0">
	<thead>
		<tr>
			<td></td>
			<td>Account</td>
			<td>Bis</td>
			<td>Vorher</td>
			<td>Von</td>
			<td>Grund</td>
			<td class="center"><img src="../images/date.png" /> Änderungsdatum</td>
		</tr>
	</thead>
	<tbody>';
	for($i = $perpage * ($page-1);$i < $perpage*$page;$i++) {
		if(isset($resultset[$i])) {
			odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['acc'] . ']');
			$resbanned = odbc_exec($odbc_connect, 'SELECT * FROM [ACCOUNT_TBL_DETAIL] WHERE account=\''.mssql_escape_string($resultset[$i]['account']).'\'');
			$resultbanned = odbc_fetch_array($resbanned);
			echo '
		<tr>
			<td>';
				if(strtotime($resultbanned['BlockTime']) > strtotime(date('Ymd'))) {
					echo '<a href="account_users.php?inputField='.$resultset[$i]['account'].'&acc" title="Account \''.$resultset[$i]['account'].'\' is still banned." rel="tooltip"><img src="../images/banned.png" width="16" /></a>';
				} else {
					echo '<a href="account_users.php?inputField='.$resultset[$i]['account'].'&acc" title="Account \''.$resultset[$i]['account'].'\' is not banned anymore." rel="tooltip"><img src="../images/unbanned.png" width="16" /></a>';
				}
			if($resultset[$i]['now'] < time()) {
				$icon = '<a href="account_users.php?inputField='.$resultset[$i]['account'].'&acc" title="Der Bann wurde aufgehoben" rel="tooltip"><img src="../../images/icons/misc/1.png" width="8" alt="" title=""></a>';
			}
			elseif($resultset[$i]['now'] == $resultset[$i]['before']) {
				$icon = '<a href="account_users.php?inputField='.$resultset[$i]['account'].'&acc" title="Bannzeit hat sich nicht verändert" rel="tooltip"><img src="../../images/icons/misc/0.png" width="8" alt="" title=""></a>';
			}
			elseif($resultset[$i]['now'] > $resultset[$i]['before']) {
				$icon = '<a href="account_users.php?inputField='.$resultset[$i]['account'].'&acc" title="Der Bann wurde verlängert" rel="tooltip"><img src="../../images/icons/misc/3.png" width="8" alt="" title=""></a>';
			}
			elseif($resultset[$i]['now'] < $resultset[$i]['before']) {
				$icon = '<a href="account_users.php?inputField='.$resultset[$i]['account'].'&acc" title="Der Bann wurde verkürzt" rel="tooltip"><img src="../../images/icons/misc/2.png" width="8" alt="" title=""></a>';
			}
			echo '</td>
			<td>'.$resultset[$i]['account'].'</td>
			<td>'.date('d.m.Y', $resultset[$i]['now']).' '.$icon.'</td>
			<td>'.date('d.m.Y', $resultset[$i]['before']).'</td>
			<td>'.$resultset[$i]['byadmin'].'</td>
			<td>'.$resultset[$i]['reason'].'</td>
			<td class="center">'.date('d.m.Y, H:i', strtotime($resultset[$i]['datetime'])).' Uhr</td>
		</tr>';
		}
	}
	echo '
	</tbody>
</table>
<br />';
	for($i=0; $i < $countpages; $i++) {
		$k = $i + 1;
		if($page == $k) {
			 echo '<p class="page"><b>'.$k.'</b></p>';
		} else {
			echo '<p class="page"><a href="list_banlogs.php?page='.$k.'">'.$k.'</a></p>';
		}
	}
	echo '</div>';
?>
</div>
<?php include('inc/footer.php'); ?>