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

$pageTitle = 'Edit Designation - ';
include_once 'header.php';

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

    $sql = "SELECT * FROM `designations` WHERE `id` = ?";
    $designationData = $dbF->getRow($sql, [$designationId]);
}

$checked = "";
if ($designationData['publish'] == '1') {
    $checked = 'checked';
}
?>

<div class="card">
    <div class="card-body p-4">
        <h5 class="mb-4">Edit Designation</h5>
        <form id="designationEditForm" class="row g-3" method="post">
            <input type="hidden" name="designationId" value="<?php echo $designationId; ?>">
            <div class="row mb-3">
                <label for="designation" class="col-sm-3 col-form-label">Designation Title</label>
                <div class="col-sm-9">
                    <input type="text" class="form-control" name="designation" id="designation" value="<?php echo $designationData["designation"]; ?>">
                </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';
?>