<?php include('inc/header.php'); ?>
<h1>Listen - Bannliste</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>
		<tr>
			<th></th>
			<th style="text-align:left;">Account</th>
			<th style="text-align:left;">Bis</th>
			<th style="text-align:left;">Vorher bis</th>
			<th style="text-align:left;">Von</th>
			<th style="text-align:left;">Grund</th>
			<th style="text-align: center;"><img src="img/date.png" /> Änderungsdatum</th>
		</tr>';
	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 id="banid_'.$resultset[$i]['banid'].'" class="row">
				<td style="min-width:30px; max-width:30px;">';
				if(strtotime($resultbanned['BlockTime']) > strtotime(date('Ymd'))) {
					echo '<a title="'.$resultset[$i]['account'].' ist gebannt." rel="tooltip" href="search.php?search='.$resultset[$i]['account'].'&account=Accountsuche"><img src="../images/banned.png" width="16" /></a>';
				} else {
					echo '<a title="'.$resultset[$i]['account'].' ist nicht mehr gebannt." rel="tooltip" href="search.php?search='.$resultset[$i]['account'].'&account=Accountsuche"><img src="../images/unbanned.png" width="16" /></a>';
				}
			if($resultset[$i]['now'] < time()) {
				$icon = '<a 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 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 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 title="Der Bann wurde verkürzt" rel="tooltip"><img src="../../images/icons/misc/2.png" width="8" alt="" title=""></a>';
			}
			echo '</td>
				<td style="width:150px;"><a href="search.php?search='.$resultset[$i]['account'].'&account=Accountsuche">'.$resultset[$i]['account'].'</a></td>
				<td style="width:110px;">'.date('d.m.Y', $resultset[$i]['now']).' '.$icon.'</td>
				<td style="width:110px;">'.date('d.m.Y', $resultset[$i]['before']).'</td>
				<td style="width:130px;">'.$resultset[$i]['byadmin'].'</td>
				<td style="min-width:150px; max-width:500px;">'.$resultset[$i]['reason'].'</td>
				<td style="width:150px; text-align: center;">'.date('d.m.Y, H:i', strtotime($resultset[$i]['datetime'])).'</td>
			</tr>';
		}
	}
	echo '</table><br/>';
	for($i=0; $i < $countpages; $i++) {
		$k = $i + 1;
		if($page == $k) {
			 echo '<span id="page"><b>'.$k.'</b></span>';
		} else {
			echo '<span id="page"><a href="list_bans.php?page='.$k.'">'.$k.'</a></span>';
		}
	}
	echo '</div><br/>';
?>
</div>
<?php include('inc/footer.php'); ?>