<?php include('inc/header.php'); ?>
<h1>Member - Users</h1>
<div class="container">
    <form method="get" style="float: left;">
        <input type="text" name="inputField" style="width:343px;" placeholder="Suchstring"/>
        <hr />
        <input type="submit" name="char" value="Charaktersuche" />
        <input type="submit" name="acc" value="Accountsuche" />
        <input type="submit" name="mail" value="Mailsuche" />
    </form>
    <br /><br />
<?php
	odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['web'] . ']');
	if(!empty($_GET['inputField'])) {
		if(isset($_GET['mail'])) {
			odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['acc'] . ']');
			$select = odbc_exec($odbc_connect, 'select a.Account, a.cash, b.email, b.regdate from ACCOUNT_TBL a, ACCOUNT_TBL_DETAIL b where a.account = b.account and b.email =\''.mssql_escape_string($_GET['inputField']).'\'');
			if(odbc_num_rows($select) > 0) {echo '
<table id="table" style="width: 100%;">
	<thead>
		<tr>
			<td>Account ID</td>
			<td><img src="../images/price.png" /> dPs</td>
			<td>Registrationsdatum</td>
			<td>E-Mail</td>
		</tr>
	</thead>
	<tbody>';
				while($result = odbc_fetch_array($select)) {echo '
		<tr>
			<td><a href="account_users.php?inputField='.$result['Account'].'&acc">'.$result['Account'].'</a></td>
			<td>'.$result['cash'].'</td>
			<td>'.date('d.m.Y, H:i', strtotime($result['regdate'])).' Uhr</td>
			<td><a href="account_users.php?inputField='.$result['email'].'&mail">'.$result['email'].'</a></td>
		</tr>';
				}
				echo '
	</tbody>
</table>';
			}
			else {
				echo '<div class="fail">Search was not successful.</div>';
			}
		}
		elseif(isset($_GET['donlogs'])) {
			$psc = odbc_exec($odbc_connect, 'SELECT * FROM [LOG_DONATIONS] WHERE account=\''.mssql_escape_string($_GET['inputField']).'\' ORDER BY timestamp DESC');
			echo '
<table cellspacing="0">
	<thead>
		<tr>
			<td>Typ</td>
			<td>Account</td>
			<td class="center"><img src="../images/price.png" /> Wert</td>
			<td class="center"><img src="../images/price.png" /> dPs</td>
			<td class="center"><img src="../images/date.png" /> Datum</td>
		</tr>
	</thead>
	<tbody>';
			while($pscresult = odbc_fetch_array($psc)) {
			
				if($pscresult['type'] == 0) {$pscresult['type'] = 'PaysafeCard';}
				elseif ($pscresult['type'] == 1) {$pscresult['type'] = 'Paypal';}
				elseif ($pscresult['type'] == 2) {$pscresult['type'] = 'uKash';}
				
				echo '
				<tr>
					<td>'.$pscresult['type'].'</td>
					<td>'.$pscresult['account'].'</td>
					<td class="center">'.$pscresult['worth'].' &euro;</td>
					<td class="center">'.$pscresult['points'].'</td>
					<td class="center">'.date('d.m.Y, H:i', $pscresult['timestamp']).' Uhr</td>
				</tr>';
			}
			echo '
	</tbody>
</table><br/>
<a href="javascript:history.back(-1);">&laquo; Back</a>';
		} 
		elseif(isset($_GET['buylogs'])) {
			$select = odbc_exec($odbc_connect, 'SELECT * FROM [LOG_PURCHASES] WHERE account=\''.mssql_escape_string($_GET['inputField']).'\' ORDER BY datetime DESC');
			echo '
<table cellspacing="0">
	<thead>
		<tr>
			<td>Username</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</td>
		</tr>
	</thead>
	<tbody>';
			while($result = odbc_fetch_array($select)) {
				echo '
		<tr>
			<td>'.$result['account'].'</td>
			<td>'.$result['itemname'].'</td>
			<td class="center">'.$result['itemcount'].'</td>
			<td class="center">'.$result['itemworth'].'</td>
			<td class="center">'.date('d.m.Y, H:i', strtotime($result['datetime'])).' Uhr</td>
		</tr>';
			}
			echo '
	</tbody>
</table><br />
<a href="javascript:history.back(-1);">&laquo; Back</a>';
		} 
		elseif(isset($_GET['giftlogs'])) {
			$select = odbc_exec($odbc_connect, 'SELECT * FROM [LOG_GIFTS] WHERE accfrom=\''.mssql_escape_string($_GET['inputField']).'\' ORDER BY datetime DESC');
			echo '
<table id="table" style="width: 100%;">
	<thead>
		<tr>
			<td>Von</td>
			<td>An</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</td>
		</tr>
	</thead>
	<tbody>';
			while($result = odbc_fetch_array($select)) {
				echo '
		<tr>
			<td>'.$result['accfrom'].'</td>
			<td>'.$result['accto'].' ('.$result['charto'].')</td>
			<td>'.$result['itemname'].'</td>
			<td class="center">'.$result['itemcount'].'</td>
			<td class="center">'.$result['itemworth'].'</td>
			<td class="center">'.date('d.m.Y, H:i', strtotime($result['datetime'])).'</td>
		</tr>';
			}
			echo '
	</tbody>
</table><br/>
<a href="javascript:history.back(-1);">&laquo; Back</a>';
		}
		elseif(isset($_GET['acc'])) {
			odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['acc'] . ']');
			$accountquery = odbc_exec($odbc_connect, 'SELECT * FROM [ACCOUNT_TBL] WHERE account=\''.mssql_escape_string($_GET['inputField']).'\'');
			$checkcount = odbc_exec($odbc_connect, 'SELECT COUNT([account]) as count FROM [ACCOUNT_TBL] WHERE account=\''.mssql_escape_string($_GET['inputField']).'\'');
			if(odbc_result($checkcount, 'count') > 0) {
				if(isset($_POST['ban_submit'])) {
				
					$blockTimeBeforeNow = strtotime(odbc_result(odbc_exec($odbc_connect, 'SELECT [BlockTime] FROM [ACCOUNT_TBL_DETAIL] WHERE [account] = \'' . $_GET['inputField'] . '\''), 'BlockTime'));
					$blockTimeNow = strtotime($_POST['year'].$_POST['month'].$_POST['day']);
					odbc_exec($odbc_connect, 'UPDATE [ACCOUNT_TBL_DETAIL] SET
							BlockTime=\''.mssql_escape_string($_POST['year']).mssql_escape_string($_POST['month']).mssql_escape_string($_POST['day']).'\'
							WHERE account=\''.mssql_escape_string($_GET['inputField']).'\'');
					odbc_exec($odbc_connect, '
							INSERT INTO [' . $_CONFIG['db_databases']['web'] . '].dbo.[LOG_BANS] (
								account, 
								before,
								now,
								byadmin,
								reason,
								datetime
							) VALUES(
								\''.mssql_escape_string($_GET['inputField']).'\',
								' . $blockTimeBeforeNow . ',
								' . $blockTimeNow . ',
								\''.mssql_escape_string($_SESSION['user']).'\',
								\''.mssql_escape_string($_POST['reason']).'\',
								\''.mssql_escape_string(date('d.m.Y H:i:s')).'\'
							)
						');
					echo '<div class="success">Ban time of account has successfully been changed!</div>';
				}
				odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['chr'] . ']');
				$charquery = odbc_exec($odbc_connect, 'SELECT * FROM [CHARACTER_TBL] WHERE account=\''.mssql_escape_string($_GET['inputField']).'\' AND [isblock] != \'D\'');
				$charquerycount = odbc_exec($odbc_connect, 'SELECT COUNT(*) as count FROM [CHARACTER_TBL] WHERE account=\''.mssql_escape_string($_GET['inputField']).'\' AND [isblock] != \'D\'');
				$account = odbc_fetch_array($accountquery);
				odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['acc'] . ']');
				$detailquery = odbc_exec($odbc_connect, 'SELECT * FROM [ACCOUNT_TBL_DETAIL] WHERE account=\''.mssql_escape_string($_GET['inputField']).'\'');
				$detail = odbc_fetch_array($detailquery);
				echo '
<div id="banpopup"></div>
<h2>Accountinformationen</h2>
<table cellspacing="0">
	<tr>
		<td>Account ID</td>
		<td>'.$account['account'].'</td>
	</tr>
	<tr>
		<td>E-Mail</td>
		<td><a href="account_users.php?inputField='.$detail['email'].'&mail">'.$detail['email'].'</a></td>
	</tr>
	<tr>
		<td>Registrationsdatum</td>
		<td>'.date('d.m.Y', strtotime($detail['regdate'])).'</td>
	</tr>
	<tr>
		<td><img src="../images/price.png" /> dPs</td>
		<td>'.$account['cash'].'</td>
	</tr>
	<tr>
		<td>Charaktere</td>
		<td>';
				if(odbc_result($charquerycount, 'count') == 0) {
					echo '-';
				}
				else {
					while($char = odbc_fetch_array($charquery)) {
						echo '<a href="account_users.php?inputField='.$char['m_szName'].'&char">'.$char['m_szName'].'</a>, ';
					}
				}
				echo '
		</td>
	</tr>
</table>
<p>
	<a href="account_users.php?inputField='.$account['account'].'&donlogs" title="Show donation logs of '.$account['account'].'." rel="tooltip">Donation Logs</a>, 
	<a href="account_users.php?inputField='.$account['account'].'&buylogs" title="Show buying logs of '.$account['account'].'." rel="tooltip">Buying Logs</a>,
	<a href="account_users.php?inputField='.$account['account'].'&giftlogs" title="Show gifting logs of '.$account['account'].'." rel="tooltip">Gifting Logs</a>
</p>
<br />
<h2>Rechte und Bannzeiten</h2>
<table cellspacing="0">
	<tr>
		<td>Spielergruppe</td>
		<td>'.$detail['m_chLoginAuthority'].'</td>
	</tr>
	<tr>
		<td>Gamemaster</td>
		<td>';
				if($detail['m_chLoginAuthority'] == 'N') {
					echo '<input type="checkbox" id="gamemaster" name="gamemaster" onchange="gamemaster(\''.$account['account'].'\', \'no\');" checked />';
				} else {
					echo '<input type="checkbox" id="gamemaster" name="gamemaster" onchange="gamemaster(\''.$account['account'].'\', \'yes\');" />';
				}
				echo '
		</td>
	</tr>
	<tr>
		<td>Gebannt bis</td>
		<td>';
				if($detail['BlockTime'] < date('Ymd')) {
					echo '-';
				} else {
					echo substr($detail['BlockTime'],0,4).'/'.substr($detail['BlockTime'],4,2).'/'.substr($detail['BlockTime'],6);
				}
				echo ' 
			(<a onclick="banPopup(\''.$account['account'].'\');">Edit</a>)
		</td>
	</tr>
</table>';
			}
			else {
				echo '<p class="fail">Der Account existiert nicht.</p>';
			}
		}
		elseif(isset($_GET['char'])) {
			odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['chr'] . ']');
			$select = odbc_exec($odbc_connect, 'SELECT * FROM [CHARACTER_TBL] WHERE m_szName=\''.mssql_escape_string($_GET['inputField']).'\'');
			$checkselect = odbc_exec($odbc_connect, 'SELECT COUNT(*) as count FROM [CHARACTER_TBL] WHERE m_szName=\''.mssql_escape_string($_GET['inputField']).'\'');
			if(odbc_result($checkselect, 'count') > 0) {
				$bankPassword = @odbc_result(@odbc_exec($odbc_connect, '
					SELECT [m_BankPw] FROM [BANK_TBL] WHERE [m_idPlayer] = (SELECT [m_idPlayer] FROM [CHARACTER_TBL] WHERE [m_szName] = \'' . mssql_escape_string($_GET['inputField']) . '\')
				'), 'm_BankPw');
				$result = odbc_fetch_array($select);
				odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['acc'] . ']');
				$select2 = odbc_exec($odbc_connect, 'SELECT * FROM [ACCOUNT_TBL_DETAIL] WHERE account=\''.mssql_escape_string($result['account']).'\'');
				$result2 = odbc_fetch_array($select2);
				$select3 = odbc_exec($odbc_connect, 'SELECT * FROM [ACCOUNT_TBL] WHERE account=\''.mssql_escape_string($result['account']).'\'');
				$result3 = odbc_fetch_array($select3);
				$banned = odbc_exec($odbc_connect, 'SELECT BlockTime FROM [ACCOUNT_TBL_DETAIL] WHERE account=\''.mssql_escape_string($result['account']).'\'');
				$deaths = $result['m_nPvpDeaths'];
				if($deaths == 0) {
					$deaths = 1;
				}
				echo '
<h2>Charakterinformationen</h2>
<table cellspacing="0">
	<tr>
		<td width="50%">Charaktername</td>
		<td>'.$result['m_szName'].'</td>
	</tr>
	<tr>
		<td>Bankpasswort</td>
		<td>' . $bankPassword . '</td>
	</tr>
	<tr>
		<td>Level</td>
		<td>'.$result['m_nLevel'].'</td>
	</tr>
	<tr>
		<td>Jobklasse</td>
		<td>'.getjob($result['m_nJob']).'</td>
	</tr>
	<tr>
		<td>Penya</td>
		<td>'.$result['m_dwGold'].'</td>
	</tr>
	<tr>
		<td>HP</td>
		<td>'.$result['m_nHitPoint'].'</td>
	</tr>
	<tr>
		<td>STR</td>
		<td>'.$result['m_nStr'].'</td>
	</tr>
	<tr>
		<td>STA</td>
		<td>'.$result['m_nSta'].'</td>
	</tr>
	<tr>
		<td>DEX</td>
		<td>'.$result['m_nDex'].'</td>
	</tr>
	<tr>
		<td>INT:</td>
		<td>'.$result['m_nInt'].'</td>
	</tr>
	<tr>
		<td>Position (X)</td>
		<td>'.$result['m_vPos_x'].'</td>
	</tr>
	<tr>
		<td>Position (Y)</td>
		<td>'.$result['m_vPos_y'].'</td>
	</tr>
	<tr>
		<td>Position (Z)</td>
		<td>'.$result['m_vPos_z'].'</td>
	</tr>
</table>
<h2>Accountinformationen</h2>
<table cellspacing="0">
	<tr>
		<td width="50%">Account ID</td>
		<td><a href="account_users.php?inputField='.$result['account'].'&acc">'.$result['account'].'</a></td>
	</tr>
	<tr>
		<td>E-Mail</td>
		<td><a href="account_users.php?inputField='.$result2['email'].'&mail">'.$result2['email'].'</a></td>
	</tr>
	<tr>
		<td>Registrationsdatum</td>
		<td>'.date('d.m.Y, H:i', strtotime($result2['regdate'])).' Uhr</td>
	</tr>
	<tr>
		<td><img src="../images/price.png" /> dPs</td>
		<td>'.$result3['cash'].'</td>
	</tr>
</table>';
			}
			else {
				echo '<div class="fail">The character does not exist!</div>';
			}
		}
	}
?>
</div>
<?php include('inc/footer.php'); ?>