<?php include '../db.php'; ?>

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $stmt = $conn->prepare("INSERT INTO hostings (client_id, plan, provider, start_date, expiry_date, price, status) VALUES (?, ?, ?, ?, ?, ?, 'active')");
    $stmt->execute([
        $_POST['client_id'],
        $_POST['plan'],
        $_POST['provider'],
        $_POST['start_date'],
        $_POST['expiry_date'],
        $_POST['price']
    ]);
    header("Location: index.php");
}
?>

<h2>Add Hosting</h2>
<form method="post">
    <label>Client:</label>
    <select name="client_id" required>
        <?php
        $clients = $conn->query("SELECT id, name FROM clients")->fetchAll();
        foreach ($clients as $c) {
            echo "<option value='{$c['id']}'>{$c['name']}</option>";
        }
        ?>
    </select><br>

    <input name="plan" placeholder="Hosting Plan (e.g., Basic, Pro)" required><br>
    <input name="provider" placeholder="Provider" required><br>
    <input type="date" name="start_date" required><br>
    <input type="date" name="expiry_date" required><br>
    <input type="number" step="0.01" name="price" placeholder="Price"><br>

    <button type="submit">Save</button>
</form>
