<?php
session_start();
require_once 'config/database.php';
require_once 'includes/auth.php';
requireLogin();

$id = $_GET['id'] ?? 0;
if ($id) {
    $userId = $_SESSION['user_id'];
    $stmt = $pdo->prepare("SELECT id FROM companies WHERE user_id = ? LIMIT 1");
    $stmt->execute([$userId]);
    $company = $stmt->fetch();
    if ($company) {
        $stmt = $pdo->prepare("DELETE FROM documents WHERE id = ? AND company_id = ?");
        $stmt->execute([$id, $company['id']]);
    }
}
header('Location: documents.php?msg=deleted');
?>