<?php include('inc/header.php'); ?>
<h1>Management - Spendenlogs</h1>
<div class="container">
<?php
	odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['web'] . ']');
	
	echo '<div id="pageinc">
			<h2>Suche</h2>
			<table id="table" style="width:100%;">
				<tr><td colspan="6"><form method="post"><input type="text" name="searchTag" style="width:150px;" value="'.$_POST['searchTag'].'"/> <input type="submit" value="Suche starten" name="startSearch"/></form></td></tr>';
	if(isset($_POST['startSearch'])) {
		$_POST['searchTag'] = htmlspecialchars($_POST['searchTag']);
		$abf_q = odbc_exec($odbc_connect, 'SELECT * FROM [VALIDATE] WHERE [account] LIKE \'%'.$_POST['searchTag'].'%\' OR [email] LIKE \'%'.$_POST['searchTag'].'%\' ORDER BY [date] DESC');
		$searchNumber = 0;
		echo '	
				<tr>
					<td width="15%" id="key">Typ</td>
					<td width="20%" id="key">Account</td>
					<td width="20%" id="key">E-Mail</td>
					<td width="20%" id="key" style="text-align: center;"><table align="center"><tr><td><img src="../images/date.png" /></td><td>Datum / Uhrzeit</td></tr></table></td>
					<td width="5%" id="key" colspan="2">Aktionen</td>
					<td width="20%" id="key" colspan="2"></td>
				</tr>';
		if(odbc_num_rows($abf_q) > 0) {
			while($abf_a = @odbc_fetch_array($abf_q)) {
			echo '
				<tr id="regid_'.$searchNumber.'x" class="row">
					<td style="line-height:20px;" id="value">'.$abf_a['type'].'</td>
					<td id="value">'.str_ireplace($_POST['searchTag'], '<b>'.$_POST['searchTag'].'</b>', $abf_a['account']).'</td>
					<td id="value">'.str_ireplace($_POST['searchTag'], '<b>'.$_POST['searchTag'].'</b>', $abf_a['email']).'</td>
					<td id="value" align="center">'.date('Y/m/d H:i', $abf_a['date']).'</td>
					<td align="center"><a href="javascript:acceptValidation(\''.$searchNumber.'x\',\''.$abf_a['key'].'\');" title="Validieren" rel="tooltip"><img src="../images/add.png" alt="" /></a></td>
					<td align="center"><a href="javascript:denyValidation(\''.$searchNumber.'x\',\''.$abf_a['key'].'\');" title="Anfrage verwerfen" rel="tooltip"><img src="../images/delete.png" alt="" /></a></td>
				</tr>';
			$searchNumber++;}
		} else {echo '<tr class="row"><td colspan="6">Es wurden keine Einträge gefunden, die den Suchtag <b>'.$_POST['account'].'</b> beinhalten.</td></tr>';}
	} else {$_POST['account'] = '';}
	echo '</table><br /><br />';
	
	if(!isset($_GET['page'])) {$_GET['page'] = 1;}
	$page = $_GET['page'];
	$perpage = 50;
	$select = odbc_exec($odbc_connect, 'SELECT * FROM [VALIDATE] ORDER BY date DESC');
	$resultset = array();
	$counter = 0;
	while($row = odbc_fetch_array($select)) {$resultset[$counter++] = $row;}
	$all = odbc_exec($odbc_connect, 'SELECT COUNT(*) as count FROM [VALIDATE]');
	$count = odbc_result($all, 'count');
	$countpages = $count / $perpage;
	echo '<h2>Auf Validierung wartend</h2>';
	echo '<table id="table" style="width: 100%;">
			<tr>
				<td width="5%" id="key">Nr.</td>
				<td width="10%" id="key">Typ</td>
				<td width="20%" id="key">Account</td>
				<td width="20%" id="key">E-Mail</td>
				<td width="20%" id="key" style="text-align: center;"><table align="center"><tr><td><img src="../images/date.png" /></td><td>Datum / Uhrzeit</td></tr></table></td>
				<td width="5%" id="key" colspan="2">Aktionen</td>
				<td width="20%" id="key" colspan="2"></td>
			</tr>';
	for($i = $perpage * ($page-1);$i < $perpage*$page;$i++) {
		if(isset($resultset[$i])) {			
			echo '
			<tr id="regid_'.$i.'" class="row">
				<td style="line-height:20px;">#'.$i.'</td>
				<td>'.$resultset[$i]['type'].'</td>
				<td>'.$resultset[$i]['account'].'</td>
				<td>'.$resultset[$i]['email'].'</td>
				<td align="center">'.date('d.m.Y, H:i', $resultset[$i]['date']).' Uhr</td>
				<td align="center"><a href="javascript:acceptValidation(\''.$i.'\',\''.$resultset[$i]['key'].'\');" title="Validieren" rel="tooltip"><img src="../images/add.png" alt="" /></a></td>
				<td align="center"><a href="javascript:denyValidation(\''.$i.'\',\''.$resultset[$i]['key'].'\');" title="Anfrage verwerfen" rel="tooltip"><img src="../images/delete.png" alt="" /></a></td>
			</tr>';
		}
	}
	echo '</table><br/>';
	for($i=0; $i < $countpages; $i++) {
		$k = $i + 1;
		if(strlen($k) == 1) {$k = '0'.$k;} if($k == 51) {echo '<br /><br />';}
		if($page == $k) {echo '<span id="page"><b>'.$k.'</b></span>';} 
		else {echo '<span id="page"><a href="registration.php?page='.$k.'">'.$k.'</a></span>';}
	}
	echo '</div><br/>';
?>
</div>
<?php include('inc/footer.php'); ?>