<?php
header('Content-Type: application/json; charset=utf-8');
require_once 'db_connect.php';

$data = json_decode(file_get_contents("php://input"), true);
$id = $conn->real_escape_string($data['id'] ?? '');
$action = $conn->real_escape_string($data['action'] ?? '');

if ($id && ($action == 'approved' || $action == 'rejected')) {
    $sql = "UPDATE join_requests SET status = '$action' WHERE id = '$id'";
    if ($conn->query($sql)) {
        echo json_encode(['status' => 'success']);
    } else {
        echo json_encode(['status' => 'error']);
    }
} else {
    echo json_encode(['status' => 'error', 'message' => 'بيانات مفقودة']);
}
$conn->close();
?>