<?php
// Check if staff_id is provided in the URL
/*if (isset($_GET['staff_id'])) {
    $staff_id = $_GET['staff_id'];

    include './staff_details_for_recall.php';
    include './conn.php';

    // Assuming $staff_id holds the staff ID
    $sql4 = "SELECT * FROM leave_requests WHERE staff_id = '".$staff_id."' AND (leave_status = 'Approved' OR leave_status = 'Recalled')";
    $result4 = mysqli_query($conn, $sql4);

    // Check if there are any rows returned
    if (mysqli_num_rows($result4) > 0) {
        while($row4 = mysqli_fetch_array($result4)) {
            $leave_status =  $row4['leave_status'];
        }

        if (isset($leave_status) && isset($staff_id)) {
            if ($leave_status == "Approved") {
                // If the current status is "Approved", update it to "Recalled"
                $updateSql = "UPDATE leave_requests SET leave_status = 'Recalled' WHERE staff_id = '".$staff_id."' AND leave_status = 'Approved'";
            } elseif ($leave_status == "Recalled") {
                // If the current status is "Recalled", update it to "Approved"
                $updateSql = "UPDATE leave_requests SET leave_status = 'Approved' WHERE staff_id = '".$staff_id."' AND leave_status = 'Recalled'";
            } else {
                // Handle invalid or unexpected status
                echo "Invalid or unexpected leave status.";
            }

            // Execute the update query if $updateSql is set
            if (isset($updateSql)) {
                $result = mysqli_query($conn, $updateSql);

                // Check if the update was successful
                if ($result) {
                    echo "<script>alert(\"Leave status updated successfully!\"); window.location=\"search_staff_for_recall.php\";</script>";
                } else {
                    echo "<script>alert(\"Failed to update leave status!\"); window.location=\"search_staff_for_recall.php\";</script>";
                }
            }
        } else {
            // Handle missing variables
            echo "Leave status or staff ID not provided.";
        }
    } else {
        echo "<script>alert(\"No leave requests found for the provided staff ID!\"); window.location=\"search_staff_for_recall.php\";</script>";
    }

    // Close database connection
    mysqli_close($conn);
} else {
    // If staff_id is not provided in the URL
    echo "Staff ID is not provided.";
}*/
?>
