<?php
session_start();
if($_SESSION['role'] != 'admin') die("Unauthorized");
include '../config/db.php';

$desc = $_POST['desc'];
$amount = $_POST['amount'];
$to = $_POST['to'];
$date = date('Y-m-d');

$stmt = $conn->prepare("INSERT INTO fund_distributions (description, amount, distributed_to, date) VALUES (?, ?, ?, ?)");
$stmt->bind_param("sdss", $desc, $amount, $to, $date);
if($stmt->execute()) {
    header("Location: dashboard.php?msg=Distribution added");
} else {
    echo "Error: " . $conn->error;
}
?>