<?php
include('inc/header.php'); 

echo '<h1>Spendenpunkte hinzufügen / entfernen</h1>
<div class="container">';
if(isset($_POST['submit'])){
	$_POST['worth'] = preg_replace('/[^0-9]/', '', $_POST['worth']);
	if(is_numeric($_POST['worth'])) {
		if(isset($_POST['doneg'])) {$cash = $_POST['worth'] * (-1);} else {$cash = $_POST['worth'];}

		odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['acc'] . ']');
		$select = odbc_exec($odbc_connect, 'SELECT * FROM [ACCOUNT_TBL] WHERE [account] = \''.$_POST['username'].'\'');
		if(odbc_num_rows($select) != 0) {
			odbc_exec($odbc_connect, 'UPDATE [ACCOUNT_TBL] SET [cash] = ([cash] + (\''.$cash.'\')) WHERE [account] = \''.$_POST['username'].'\'');
			echo '<p class="success">Die Punkte wurden dem Account erfolgreich gutgeschrieben.</p>';
		}
		else {
			echo '<p class="fail">Der Account existiert nicht.</p>';
		}
	}
	else {
		echo '<p class="fail">Du musst einen gültigen dP-Wert eingeben.</p>';
	}
}

echo '<form action="" method="post">
<input type="text" name="username" id="username" style="width: 160px;"/>
	<label for="username">'.$lang['wart_user'].'</label><br />
<input type="text" name="worth" id="worth" style="width: 160px;"/>
	<label for="worth">'.$lang['cash_name'].'</label><br />
<input type="checkbox" name="doneg" id="doneg" value="Negativ">
	<label for="doneg">dPs entfernen</label><br />
<input type="submit" name="submit">
</div>';

include('inc/footer.php');
?>