<?php include('inc/header.php'); ?>
<h1>Management - Spendenlogs</h1>
<div id="box" style="display:none;"></div>
<div class="container">
<?php
	odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['web'] . ']');
	
	function getDonateType($integer) {
		if($integer == 0) {return 'PSC';}
		elseif ($integer == 1) {return 'Paypal';}
		elseif ($integer == 2) {return 'uKash';}
	}
	
	echo '
<div id="pageinc">
	<h2>Suche nach Account-ID / Spendenkey</h2>
	<form method="post">
		<input type="text" name="account" style="width:150px;" value="'.$_POST['account'].'"/>
		<input type="submit" value="Suche starten" name="searchForDonation"/>
	</form>';
	if(isset($_POST['searchForDonation'])) {
		$_POST['account'] = htmlspecialchars($_POST['account']);
		$abf_q = odbc_exec($odbc_connect, 'SELECT * FROM [LOG_DONATIONS] WHERE [account] LIKE \'%'.$_POST['account'].'%\' OR [key] = \''.$_POST['account'].'\' AND [state] < 3 ORDER BY [timestamp] DESC');
		if(odbc_num_rows($abf_q) > 0) {
		echo '
	<br />
	<table cellspacing="0">
		<thead>
			<tr>
				<td>&nbsp;</td>
				<td>Typ</td>
				<td>Account</td>
				<td><img src="../images/price.png"/> Worth</td>
				<td><img src="../images/price.png"/> DPs</td>
				<td><img src="../images/date.png" /> Date/Time</td>
				<td>Name</td>
				<td>E-Mail</td>
			</tr>
		</thead>
		<tbody>';
			while($abf_a = @odbc_fetch_array($abf_q)) {
				if($abf_a['state'] == 2) {
					echo '
			<tr style="text-decoration: line-through;">
				<td style="line-height:15px; font-weight: bold;">#'.$abf_a['id'].'</td>
				<td>'.getDonateType($abf_a['type']).'</td>
				<td>'.str_ireplace($_POST['account'], '<b>'.$_POST['account'].'</b>', $abf_a['account']).'</td>
				<td>'.$abf_a['worth'].' &euro;</td>
				<td>'.$abf_a['points'].'</td>
				<td>'.date('d.m.Y, H:i', $abf_a['timestamp']).'</td>
				<td>'.$abf_a['fieldAlfa'].'</td>
				<td>'.$abf_a['fieldBravo'].'</td>
			</tr>';
				}
				else {
					echo '
			<tr>
				<td style="line-height:15px; font-weight: bold;">#'.$abf_a['id'].'</td>
				<td>'.getDonateType($abf_a['type']).'</td>
				<td>'.str_ireplace($_POST['account'], '<b>'.$_POST['account'].'</b>', $abf_a['account']).'</td>
				<td>'.$abf_a['worth'].' &euro;</td>
				<td>'.$abf_a['points'].'</td>
				<td>'.date('d.m.Y, H:i', $abf_a['timestamp']).'</td>
				<td>'.$abf_a['fieldAlfa'].'</td>
				<td>'.$abf_a['fieldBravo'].'</td>
			</tr>';
				}
			}
			echo '
		</tbody>
	</table>';
		}
		else {
			echo '<p class="fail">Es wurden keine Einträge gefunden, die den Suchtag <b>'.$_POST['account'].'</b> beinhalten.</p>';
		}
	}
	else {
		$_POST['account'] = '';
	}
	
	if(!isset($_GET['page'])) {$_GET['page'] = 1;}
	$page = $_GET['page'];
	$perpage = 20;
	$select = odbc_exec($odbc_connect, 'SELECT * FROM [LOG_DONATIONS] WHERE [state] < 3 ORDER BY timestamp 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_DONATIONS] WHERE [state] < 2');
	$count = odbc_result($all, 'count');
	$countpages = $count / $perpage;
	echo '
<br /><br />
<h2>Spendensystem</h2>
<table cellspacing="0">
	<thead>
		<tr>
			<td>&nbsp;</td>
			<td>Typ</td>
			<td>Account</td>
			<td><img src="../images/price.png"/> Worth</td>
			<td><img src="../images/price.png"/> DPs</td>
			<td><img src="../images/date.png" /> Date/Time</td>
			<td>Name</td>
			<td>E-Mail</td>
			<td></td>
		</tr>
	</thead>
	<tbody>';
	for($i = $perpage * ($page-1);$i < $perpage*$page;$i++) {
		if(isset($resultset[$i])) {
			if($resultset[$i]['state'] == 2) {
				echo '
			<tr id="pscid_'.$resultset[$i]['id'].'" class="row" style="text-decoration: line-through;">
				<td style="line-height:15px; font-weight: bold; color:#000000;"><a href="#pscid_'.$resultset[$i]['id'].'" title="Key: '.$resultset[$i]['key'].'">#'.$resultset[$i]['id'].'</a></td>
				<td>'.getDonateType($resultset[$i]['type']).'</td>
				<td>'.$resultset[$i]['account'].'</td>
				<td>'.$resultset[$i]['worth'].' &euro;</td>
				<td>'.$resultset[$i]['points'].'</td>
				<td>'.date('d.m.Y, H:i', $resultset[$i]['timestamp']).'</td>
				<td>'.$resultset[$i]['fieldAlfa'].'</td>
				<td>'.$resultset[$i]['fieldBravo'].'</td>
				<td></td>
			</tr>';
			}
			else {
				echo '
			<tr id="pscid_'.$resultset[$i]['id'].'" class="row">
				<td style="line-height:15px; font-weight: bold; color:#000000;"><a href="#pscid_'.$resultset[$i]['id'].'" title="Key: '.$resultset[$i]['key'].'">#'.$resultset[$i]['id'].'</a></td>
				<td>'.getDonateType($resultset[$i]['type']).'</td>
				<td>'.$resultset[$i]['account'].'</td>
				<td>'.$resultset[$i]['worth'].' &euro;</td>
				<td>'.$resultset[$i]['points'].'</td>
				<td>'.date('d.m.Y, H:i', $resultset[$i]['timestamp']).'</td>
				<td>'.$resultset[$i]['fieldAlfa'].'</td>
				<td>'.$resultset[$i]['fieldBravo'].'</td>
				<td>';
			if($resultset[$i]['state'] == 1) {
				echo '<a href="javascript:pscUndone('.$resultset[$i]['id'].',\''.$resultset[$i]['account'].'\', '.$resultset[$i]['points'].');" id="pscid_'.$resultset[$i]['id'].'_done" title="Status: Done<br/> (Set to \'\'undone\'\')" rel="tooltip"><img src="../images/unbanned.png" /></a>';
			} else {
				echo '<a href="javascript:pscDone('.$resultset[$i]['id'].',\''.$resultset[$i]['account'].'\', '.$resultset[$i]['points'].');" id="pscid_'.$resultset[$i]['id'].'_undone" title="Status: Undone<br/> (Set to \'\'done\'\')" rel="tooltip"><img src="../images/banned.png" /></a>';
			}
			echo '<a href="javascript:psclogs_delete('.$resultset[$i]['id'].');" id="pscid_'.$resultset[$i]['id'].'_delete" title="Delete" rel="tooltip"><img src="../images/delete.png" /></a>
				</td>
			</tr>';
			}
		}
	}
	echo '
	</tbody>
</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 '<p class="page"><b>'.$k.'</b></p>';} 
		else {echo '<p class="page"><a href="' . basename($_SERVER['PHP_SELF']) . '?page='.$k.'">'.$k.'</a></p>';}
	}
	echo '</div>';
?>
</div>
<?php include('inc/footer.php'); ?>