<?php
if (!isset($_GET['id'])) {
    header('Location: 505');
    exit;
}
include_once "global.php";

$pageTitle = 'Edit Expense Category - ';
include_once 'header.php';

if (isset($_GET["id"])) {
    $expenseCategoryId = $_GET["id"];

    $sql = "SELECT * FROM `expense_categories` WHERE `id` = ?";
    $expenseCategoryData = $dbF->getRow($sql, [$expenseCategoryId]);
}

$checked = "";
if ($expenseCategoryData['publish'] == '1') {
    $checked = 'checked';
}
?>
<div class="card">
    <div class="card-body p-4">
        <h5 class="mb-4">Edit Expense Category</h5>
        <form id="expensecategoryEditForm" class="row g-3" method="post">
            <input type="hidden" name="expenseCategoryId" value="<?php echo $expenseCategoryId; ?>">
            <div class="row mb-3">
                <label for="expensecategory" class="col-sm-3 col-form-label">Category Title</label>
                <div class="col-sm-9">
                    <input type="text" class="form-control" name="expensecategory" id="expensecategory"
                        value="<?php echo $expenseCategoryData["category"]; ?>">
                </div>
            </div>
            <div class="row mb-3">
                <label for="publish" class="col-sm-3 col-form-label">Publish</label>
                <div class="col-sm-9">
                    <div class="form-check form-switch form-check-success">
                        <input class="form-check-input" type="checkbox" name="publish" role="switch"
                            id="flexSwitchCheckSuccess" value="1" <?php echo $checked; ?>>
                    </div>
                </div>
            </div>
            <div class="col-md-12">
                <button type="submit" class="btn btn-grd-primary px-4">Submit</button>
            </div>
        </form>
    </div>
</div>

<?php
include_once 'footer.php';
?>