?>
</nav>

<?php 
include 'getConnectionObject.php';
include "displayOrdersLogic/displayOrdersLogic.php";
$connectionObject = getConnectionObject();
if (!empty($_POST)) {
    removeKitchenOrder($connectionObject, $_POST, "order_");
}
$queryString = "SELECT order_.id_order, order_.hour,order_.name,order_.quantity,order_.description,meal.display_name_meal,specific_meal.display_name_specific_meal,order_.paid\n\t\t\tFROM order_,meal,specific_meal\n\t\t\tWHERE order_.id_meal = meal.id_meal and order_.id_specific_meal = specific_meal.id_specific_meal and specific_meal.id_meal = order_.id_meal and order_.prepared = 0\n\t\t\tORDER BY hour";
$tempObject = $connectionObject->prepare($queryString);
$tempObject->execute();
$query = $tempObject->fetchAll();
if ($query) {
    generatePostCodeDeleteOrder($query, $_GET, "kitchenMonitoring.php");
}
?>

<table class="centering">
    <tr>
        <th>Payé ?</th>
        <th>Délai</th>
        <th>Nom</th>
        <th>Repas</th>
        <th>Saveur</th>
        <th>Quantité</th>
        <th>Détails</th>
    </tr>

    <script>
        removeCompletedOrder($connectionObject, $_POST);
    } else {
        if (isset($_POST['update'])) {
            updatePaidOrder($connectionObject, $_POST);
        } else {
            error_log("Error in the post logic !!!!!!!");
        }
    }
}
$queryString = "SELECT order_.id_order, order_.hour,order_.name,order_.quantity,order_.description,meal.display_name_meal,specific_meal.display_name_specific_meal,order_.paid\n\t\t\tFROM order_,meal,specific_meal\n\t\t\tWHERE order_.id_meal = meal.id_meal and order_.id_specific_meal = specific_meal.id_specific_meal and specific_meal.id_meal = order_.id_meal\n\t\t\tORDER BY hour";
$tempObject = $connectionObject->prepare($queryString);
$tempObject->execute();
$query = $tempObject->fetchAll();
// put there because we don't want (apparently) forms inside a table
if ($query) {
    generatePostCodeDeleteOrder($query, $_GET, "orderValidation.php");
    generatePostCodeUpdateOrder($query, $_GET, "orderValidation.php");
}
?>

    <script>
        function postDeleteForm(index) {
            document.getElementById('deleteOrderPost' + index).submit();
        }
    </script>
    <script>
        function postUpdateForm(index) {
            document.getElementById('updateOrderPost' + index).submit();
        }
    </script>