<?php include('inc/header.php'); ?>
<h1>Management - Buying 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 = 30;
	$select = odbc_exec($odbc_connect, 'SELECT * FROM [LOG_PURCHASES] ORDER BY datetime DESC');
	$resultset = array();
	$counter = 0;
	while($row = odbc_fetch_array($select)) {
		$resultset[$counter++] = $row;
	}
	$all = odbc_exec($odbc_connect, 'SELECT COUNT(*) as count FROM [LOG_PURCHASES]');
	$count = odbc_result($all, 'count');
	$countpages = $count / $perpage;
	echo '
<table cellspacing="0">
	<thead>
		<tr>
			<td>Account</td>
			<td>Item</td>
			<td class="center"><img src="../images/count.png" /> Menge</td>
			<td class="center"><img src="../images/price.png" /> dPs</td>
			<td class="center"><img src="../images/date.png" /> Datum / Uhrzeit</td>
		</tr>
	</thead>
	<tbody>';
	for($i = $perpage * ($page-1);$i < $perpage*$page;$i++) {
		if(isset($resultset[$i])) {
			echo '
		<tr>
			<td>'.$resultset[$i]['account'].'</td>
			<td>'.$resultset[$i]['itemname'].'</td>
			<td class="center">'.$resultset[$i]['itemcount'].'</td>
			<td class="center">'.$resultset[$i]['itemworth'].'</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_buylogs.php?page='.$k.'">'.$k.'</a></p>';
		}
	}
	echo '</div>';
?>
</div>
<?php include('inc/footer.php'); ?>