<?php include 'includes/header.php'; ?>
<?php include 'includes/sidebar.php'; ?>
<?php require 'includes/db_connect.php'; ?>

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $fullname = mysqli_real_escape_string($conn, $_POST['fullname']);
    $email = mysqli_real_escape_string($conn, $_POST['email']);
    $phone = mysqli_real_escape_string($conn, $_POST['phone']);
     $department = mysqli_real_escape_string($conn, $_POST['department']);

    $sql = "INSERT INTO staff (fullname, email, phone, department) VALUES ('$fullname', '$email', '$phone', '$department')";
    if ($conn->query($sql)) {
        $success = "Staff Enrolled Successfully!";
    } else {
        $error = "Error enrolling staff: " . $conn->error;
    }
}
?>

<div class="container mt-4">
    <h4 class="text-orange">Enroll a New Staff</h4>

    <?php if (isset($success)) echo "<div class='alert alert-success'>$success</div>"; ?>
    <?php if (isset($error)) echo "<div class='alert alert-danger'>$error</div>"; ?>

    <form method="post" action="">
        <div class="mb-3">
            <label class="form-label text-orange">Full Name</label>
            <input type="text" name="fullname" class="form-control" required>
        </div>

        <div class="mb-3">
            <label class="form-label text-orange">Email</label>
            <input type="email" name="email" class="form-control" required>
        </div>

        <div class="mb-3">
            <label class="form-label text-orange">Phone</label>
            <input type="text" name="phone" class="form-control" required>
        </div>

        <div class="mb-3">
            <label class="form-label text-orange">Department</label>
            <select class="form-control" name="department" required>
                <option>-----Select Department------</option>
                <option value="Mayor">Mayor</option>
                <option value="Admin Department">Admin Department</option>
                <option value="Information Department">Information Department</option>
                <option value="Account Department">Accounts Department</option>
                <option value="PRS Department">PRS Department</option>
                <option value="Registry">Registry</option>
                <option value="HLGA">HLGA</option>
                <!-- <option value="Christian Pilgrim and Welfare Board">Christian Pilgrim and Welfare Board</option> -->
                <option value="Work / Transport">Work / Transport</option>
                <option value="Store Unit">Store Unit</option>
                <option value="ICT Department">ICT Department</option>
                
            </select>
        </div>

        <button type="submit" class="btn btn-orange text-white" style="background-color: orange;">Enroll Staff</button>
    </form>
</div>

<?php include 'includes/footer.php'; ?>
