<?php
include 'db.php';

$id = intval($_GET['id']);
$djelatnik_id = intval($_GET['djelatnik_id']);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $datum_od = $_POST['datum_od'];
    $datum_do = $_POST['datum_do'];

    $stmt = $conn->prepare("UPDATE godisnji SET datum_od = ?, datum_do = ? WHERE id = ?");
    $stmt->bind_param("ssi", $datum_od, $datum_do, $id);
    $stmt->execute();

    header("Location: index.php?id=$djelatnik_id");
    exit;
}

$godisnji = $conn->query("SELECT * FROM godisnji WHERE id = $id")->fetch_assoc();
?>

<!DOCTYPE html>
<html lang="hr">
<head>
    <meta charset="UTF-8">
    <title>Uredi godišnji</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="container mt-4">
    <h3>Uredi godišnji odmor</h3>
    <form method="POST">
        <div class="mb-2">
            <label>Datum od:</label>
            <input type="date" name="datum_od" class="form-control" value="<?= $godisnji['datum_od'] ?>" required>
        </div>
        <div class="mb-2">
            <label>Datum do:</label>
            <input type="date" name="datum_do" class="form-control" value="<?= $godisnji['datum_do'] ?>" required>
        </div>
        <button class="btn btn-success">Spremi promjene</button>
        <a href="index.php?id=<?= $djelatnik_id ?>" class="btn btn-secondary">Natrag</a>
    </form>
</body>
</html>
