<?php
// api/member_approve.php
require_once '../config/database.php';
require_once '../includes/functions.php';

session_start();
// Check role
if (!hasRole('roster_manager') && !hasRole('admin')) {
    die("Unauthorized");
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = (int)$_POST['id'];
    $action = $_POST['action']; // 'approve' or 'reject'
    
    if ($action === 'approve') {
        $stmt = $pdo->prepare("UPDATE members SET is_approved = 1 WHERE id = ?");
        $stmt->execute([$id]);
        $msg = "Member approved and added to active list.";
    } elseif ($action === 'reject') {
        // Hard delete
        $stmt = $pdo->prepare("DELETE FROM members WHERE id = ?");
        $stmt->execute([$id]);
        $msg = "Registration rejected and removed.";
    }
    
    header("Location: ../index.php?page=members&msg=" . urlencode($msg));
    exit;
}
header("Location: ../index.php?page=members");
?>
