<?php
include 'includes/auth.php';
include 'db.php';

if($_SERVER['REQUEST_METHOD']=='POST') {
    foreach($_POST['housekeeper'] as $room_id => $housekeeper) {
        $schedule_date = $_POST['schedule_date'][$room_id];
        $assigned = isset($_POST['assigned'][$room_id]) ? 'Yes' : 'No';

        $stmt = $conn->prepare("
            UPDATE housekeeping_status 
            SET housekeeper=?, schedule_date=?, assigned=?
            WHERE room_id=?
        ");
        $stmt->bind_param("sssi", $housekeeper, $schedule_date, $assigned, $room_id);
        $stmt->execute();
    }
    header("Location: cleaning_schedule.php");
    exit;
}
?>