<?php 
include('connection.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $itemId = $_POST['item_id'];
    $currentStatus = $_POST['current_status'];
    
    // Check the current status and toggle it
    $newStatus = ($currentStatus == 'complete') ? 'pending' : 'complete';
    
    $updateQuery = "UPDATE update_all_task SET status = '$newStatus' WHERE id = '$itemId'";
    mysqli_query($conn, $updateQuery);
    
    // Redirect back to the view table page
    header('Location: update-all-task.php');
    exit();
}
?>