<? include('checkcookie.php');
echo "<h3>Запросы на выплату</h3><br>";

if(isset($_POST["user_id"])) {
$useru = intval($_POST["user_id"]); 
$money = floatval($_POST["money"]); 
$delwaitid = intval($_POST["id"]); 
mysql_query("UPDATE `b_users` SET `money`=`money`+'$money' WHERE `id`='$useru'"); 
mysql_query("DELETE FROM `tb_payme` WHERE `id`='$delwaitid'"); 
echo "<b><font color=green>Средства возвращены в аккаунт пользователю $useru</font></b>"; 
}
if (isset($_GET["id"])){

$id = intval($_GET["id"]);
$option = strip_tags(stripslashes($_GET["option"]));

if ($option=="paid"){

$usr = strip_tags(stripslashes($_POST["usr"]));

$registroe = mysql_fetch_array(mysql_query("SELECT `id`,`username`,`paid`,`referer` FROM b_users where id='$usr'")); 

$b_payout = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='payout'"),0,0);
$b_payout_ref = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='payout_ref'"),0,0);

$money = floatval($_POST["money"]);

$reyting = $money*$b_payout/100; //рейтинг пользователю за вывод
$r_reyting = $money*$b_payout_ref/100; //рейтинг рефереру за вывод

$paid = $registroe["paid"];

$paid = $paid + $money;


mysql_query("UPDATE `b_users` SET `paid`='$paid', `reyting`=`reyting`+'$reyting' where `id`='$usr'") or die(mysql_error());
mysql_query("UPDATE `b_users` SET `reyting`=`reyting`+'$r_reyting' WHERE `id`='".$registroe["referer"]."'") or die(mysql_error());
mysql_query("INSERT INTO `tb_allhistory` (`idus`,`data`,`doing`,`title`) values ('".$registroe["id"]."','". time()."','5','Выплата WebMoney')") or die(mysql_error()); 
mysql_query("INSERT INTO `tb_history` (`user`, `date`, `str_time`, `amount`, `method`, `status`) VALUES('".$registroe["username"]."','".date("d-m-Y")."','".time()."','$money','WebMoney','Выплата сделана')") or die(mysql_error());
mysql_query("DELETE FROM tb_payme WHERE id='$id'") or die(mysql_error());
mysql_query("UPDATE `tb_payme` SET `status`='1' WHERE `id`='$id'") or die(mysql_error());
echo "<font color=\"red\"><b>Готово</b></font><br><br>";
}

if ($option=="del"){
mysql_query("DELETE FROM `tb_payme` WHERE `id`='$id'") or die(mysql_error());
echo "<font color=\"red\"><b>Удалено</b></font><br><br>";
}

}

?>

После оплаты отметить оплачено.
<br><br>
<table class="adn">
<tr class="lineb">
<td width="50" align="center">№</td>
<td width="50" align="center">ID</td>
<td width="200" align="center">Платёжная система</td>
<td align="center">Кошелёк</td>
<td width="100" align="center">Объем оплаты</td>
<td align="center">Ip</td>
<td></td>
<td></td>
<td></td>
</tr>

<?
function payment($payment) {
switch($payment) {
case 1: $src = "WebMoney";break;
case 2: $src = "QiWi";break;
case 3: $src = "YandexMoney";break;
case 4: $src = "LiqPay";break;
case 5: $src = "PerfectMoney";break;
case 6: $src = "Payeer";break;
}
return $src;
}
$tabla = mysql_query("SELECT * FROM tb_payme WHERE `status`='0' ORDER BY id ASC"); 
while ($registro = mysql_fetch_array($tabla)) { 

echo "<tr class='liney ell'>
<td width=50 align=center>". $registro["id"] ."</td>
<td width=50 align=center>". $registro["user_id"] ."</td>
<td width=200 align=center>". payment($registro["payment"]) ."</td>
<td align=center>". $registro["pemail"] ."</td>
<td width=100 align=center>". $registro["money"] ."</td>
<td align=center>". $registro["ip"] ."</td>";
?>
<td>
<form method="post" action="adminmain.php?p=reqpay&id=<?= $registro["id"] ?>&option=paid">
<input type="hidden" name="money" value="<?= $registro["money"] ?>">
<input type="hidden" name="usr" value="<?= $registro["user_id"] ?>">
<input type="submit" value="Оплачено" class="button">
</form>
</td>
<td>
<form method="post" action="adminmain.php?p=reqpay&id=<?= $registro["id"] ?>&option=del">
<input type="submit" value="Удалить" class="button">
</form>
</td>
<td> 
<form action="" method="POST"> 
<input type="hidden" name="user_id" value="<?=$registro["user_id"]; ?>"> 
<input type="hidden" name="money" value="<?=$registro["money"]; ?>"> 
<input type="hidden" name="id" value="<?=$registro["id"]; ?>"> 
<input type="submit" value="Вернуть средства"></form> 
</td>
</tr>

<?
}
?>
</table>
