<?php
session_start();
require 'config/db.php';
if(!isset($_SESSION['manager_id'])) die('Unauthorized');

$table = strtolower($_SESSION['department']).'_manager_leaves';

$stmt = $pdo->prepare("
INSERT INTO $table (manager_id, leave_date, reason)
VALUES (?,?,?)
");
$stmt->execute([
    $_SESSION['manager_id'],
    $_POST['leave_date'],
    $_POST['reason']
]);

header("Location: manager_apply_leave.php?success=1");
