<!DOCTYPE html>
<!--
********************************************************************************

    filename:    foodlist.php
    description: list foods and associated donenesses, external and internal target, high and low temps, comments
    inputs:      none
    outputs:     foodId 
    actions:     add, update, delete
    redirection: foodlistprocess.php

********************************************************************************
-->
<html>
    <head>
        <style>
            table {
                border-collapse: collapse;
            }
            table, td, th {
                border: 1px solid black;
            }
        </style>
        <?php include 'head.html' ?>
        <script src = "navigation.js"></script>
    </head>
    <body>
        <?php include 'navigationmanagefoodspitsprobes.html' ?>
        <h3>FOODS</h3>
        <div id="content">
            <?php
                include 'functions.php';
/*
                ... Get foods
*/
                $foods = getFoods();
                $sortedFoods = array();
                foreach($foods as $food) {
                    $doneness = $food['doneness'];
                    $donenessIndex = getDonenessIndex($doneness);
                    array_push($sortedFoods, $food['food'] . $donenessIndex); 
                }
                sort($sortedFoods);
                foreach($sortedFoods as $sortedFood) {
//                    echo $sortedFood . "<br>";
                }
/*
                ... Display food list
*/
                echo "<table>";
                    echo"<tr>";
                        echo "<th>ID</th>";
                        echo "<th>Food</th>";
                        echo "<th>Doneness</th>";
                        echo "<th>External Temp</th>";
                        echo "<th>External High Temp</th>";
                        echo "<th>External Low Temp</th>";
                        echo "<th>Internal Temp</th>";
                        echo "<th>Internal High Temp</th>";
                        echo "<th>Internal Low Temp</th>";
                        echo "<th>Comments</th>";
                    echo "</tr>";
                    foreach($foods as $food) {
                        echo "<tr>";
                            echo "<th>" . $food['foodId'] . "</th>";
                            echo "<th>" . $food['food'] . "</th>";
                            echo "<th>" . $food['doneness'] . "</th>";
                            echo "<th>" . $food['externalTemp'] . "</th>";
                            echo "<th>" . $food['externalHighTemp'] . "</th>";
                            echo "<th>" . $food['externalLowTemp'] . "</th>";
                            echo "<th>" . $food['internalTemp'] . "</th>";
                            echo "<th>" . $food['internalHighTemp'] . "</th>";
                            echo "<th>" . $food['internalLowTemp'] . "</th>";
                            echo "<th>" . $food['comments'] . "</th>";
                        echo "</tr>";
                   }
               echo "</table>";
               echo '<form action="foodlistprocess.php" method="post">';
                   echo 'Food <select name="foodId">';
                         foreach($foods as $food) {
                           echo '<option value="' .  $food['foodId'] . '">' . $food['food'] . ' ' .  $food['doneness'] . '</option>';
                       }
                   echo '</select>';
                   echo '<br>';
                   echo '<input type="submit" name="add" value="Add">';
                   echo '<input type="submit" name="update" value="Update"> ';
                   echo '<input type="submit" name="delete" value="Delete"><br>';   
                echo '</form>';
        ?>
        </div>
    </body>
</html>