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

    filename:     currentburnadjust.php
    description:  Adjust current burn probe target, high and low temperatures
                  Probe 1 target temp used to control burn
                  Probes 1-8 target, high and low temps used for alerts
    inputs:       action (set, adjust)
    outputs:      probe parameters
    actions:      adjust
                  cancel
    redirections: currentburnadjustprocess.php

********************************************************************************
-->
<html>
    <head>
        <?php include 'head.html' ?>
        <script src = "navigation.js"></script>
    </head>
    <body>
        <?php include 'navigationmanageburns.html' ?>
        <h3>ADJUST BURN</h3>
        <div id="content">
        <?php
            include 'functions.php';
            $conn = connectToDB();
/*
            ... Get action 
                If "set", from newburnprobesprocess
                If "adjust", from currentburnprocess
*/
            $action = $_GET["action"];
/*
            ... get current burn
*/
            $sql = "SELECT numberProbes, food, doneness FROM currentburn WHERE currentBurnId=1";
            $result = mysqli_query($conn, $sql);            
            $row = mysqli_fetch_assoc($result);
            $numberProbes= $row[numberProbes];
            $food= $row[food];
            $doneness= $row[doneness];
/*
            ... get current probes
*/
            $sql = "SELECT probePosition, targetTemp, lowTemp, highTemp FROM currentprobes";
            $results = mysqli_query($conn, $sql);

/*
            ... show current probes settings
*/
            echo "<table>";
                echo "<tr>";
                    echo "<th>Food:</th>";
                    echo "<th>" . $food . "</th>";
                echo "</tr>";
                echo "<tr>";
                    echo "<th>Doneness:</th>";
                    echo "<th>" . $doneness . "</th>";
                echo "</tr>";
            echo "</table>";
            echo '<form action="currentburnadjustprocess.php" method="post">';
                echo "<table>";
                    echo"<tr>";
                        echo "<th>Probe</th>";
                        echo "<th>Position</th>";
                        echo "<th>Target</th>";
                        echo "<th>High</th>";
                        echo "<th>Low</th>";
                    echo "</tr>"; 
//                      if (mysqli_num_rows($results) > 0) {
                        for ($j=1; $j<=$numberProbes; $j++) {
                        $row = mysqli_fetch_assoc($results);
                        echo"<tr>";
                            echo "<th>" . $row["probePosition"] . "</th>";
                            if ($row["probePosition"] == 1) {
                                $probeLocation = "Dome";
                            } else {
                                $probeLocation = "Food";
                            }
                            echo "<th>" . $probeLocation . "</th>";
                            echo "<th>";
                                echo '<select name="probe' . $row["probePosition"] . 'TargetTemp">';
                                for($i = 100; $i <= 900; $i+=5) {
                                    if ($i == $row["targetTemp"]) {
                                        echo '<option value=' . $i . ' selected>' . $i . '</option>';
                                    } else {
                                        echo '<option value=' . $i . '>' . $i . '</option>';
                                    }
                                }
                                echo '</select>';   
                            echo '</th>';
                            echo "<th>";
                                echo '<select name="probe' . $row["probePosition"] . 'HighTemp">';
                                for($i = 100; $i <= 900; $i+=5) {
                                    if ($i == $row["highTemp"]) {
                                        echo '<option value=' . $i . ' selected>' . $i . '</option>';
                                    } else {
                                        echo '<option value=' . $i . '>' . $i . '</option>';
                                    }
                                }
                                echo '</select>';   
                            echo '</th>';
                            echo "<th>";
                                echo '<select name="probe' . $row["probePosition"] . 'LowTemp">';
                                for($i = 100; $i <= 900; $i+=5) {
                                    if ($i == $row["lowTemp"]) {
                                        echo '<option value=' . $i . ' selected>' . $i . '</option>';
                                    } else {
                                        echo '<option value=' . $i . '>' . $i . '</option>';
                                    }
                                }
                                echo '</select>';   
                            echo '</th>';
/*
                            echo "<th>" . '<input type="text" name="probe' . $row["probePosition"] . 'TargetTemp" maxlength="4" size=5" value="' . $row["targetTemp"] . '">' . "</th>";  
                            echo "<th>" . '<input type="text" name="probe' . $row["probePosition"] . 'HighTemp" maxlength="4" size=5" value="' . $row["highTemp"] . '">' . "</th>";                                               
                            echo "<th>" . '<input type="text" name="probe' . $row["probePosition"] . 'LowTemp" maxlength="4" size=5" value="' . $row["lowTemp"] . '">' . "</th>";
*/
                        echo '</tr>';
                        }
//                     } else {
//                         echo "no probes";
//                    }
                echo "</table>";
                if ($action == "set") {
                    echo '<input type="submit" name="set" value="Set"><br>';
                } else {
/*
                    ... action = adjust
*/
                    echo '<input type="submit" name="adjust" value="Adjust">';
                    echo '<input type="submit" name="cancel" value="Cancel">';
                }
            echo '</form>';
            mysqli_close($conn);
        ?>
</div>
</body>
</html>