<?php
include "inc/config.php";
checkAuth();

if(!isset($_POST['action'], $_POST['id'])) exit;

$id = (int)$_POST['id'];
$action = $_POST['action'];

if($action === "approve"){
    // Ödeme talebini al
    $stmt = $pdo->prepare("SELECT username, amount FROM req_payments WHERE id = ?");
    $stmt->execute([$id]);
    $payment = $stmt->fetch(PDO::FETCH_ASSOC);

    if($payment){
        // Logs tablosunda kullanıcının balance'ını güncelle
        $stmt = $pdo->prepare("UPDATE logs SET balance = balance + ? WHERE username = ?");
        $stmt->execute([$payment['amount'], $payment['username']]);

        // Ödeme talebini onayla
        $stmt = $pdo->prepare("UPDATE req_payments SET status = 'approved' WHERE id = ?");
        $stmt->execute([$id]);
    }

    echo "ok";
    exit;
}

if($action === "reject"){
    $stmt = $pdo->prepare("UPDATE req_payments SET status = 'deleted' WHERE id = ?");
    $stmt->execute([$id]);
    echo "ok";
    exit;
}
?>
