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

    filename:     currentburnsimulation.php
    description:  simulate current burn from current temps to specified new temps at specified steps
    inputs:       none
    outputs:      probes 1-8 new temps, steps
    actions:      simulate, cancel
    redirections: currentburnsimulationprocess.php

********************************************************************************
-->
<html>
    <head>
        <?php include 'head.html' ?>
        <script src = "navigation.js"></script>
    </head>
    <body>
        <?php include 'navigationmanagehelp.html' ?>
        <h3>SIMULATE CURRENT BURN</h3>
        <div id="content">
        <?php
            include 'functions.php';
            $conn = connectToDB();
/*
            ... get current burn
*/
            $sql = "SELECT numberProbes FROM currentburn WHERE currentBurnId=1";
            $result = mysqli_query($conn, $sql);            
            if (mysqli_num_rows($results) > 0) {
                exit("no current burn");
            }
            $row = mysqli_fetch_assoc($result);
            $numberProbes = $row[numberProbes];
            if (!$numberProbes > 0) {
                exit("no current probes");  
            }
/*
            ... get current probes
*/
            $probePositions = array("");
            $probeTemps = array("");
            $targetTemps = array("");
            $highTemps = array("");
            $lowTemps = array("");
            $sql = "SELECT probePosition, probeTemp, targetTemp, lowTemp, highTemp FROM currentprobes";
            $results = mysqli_query($conn, $sql);
            if (mysqli_num_rows($results) == 0) {
                exit("no current probes");
            } else {
                for ($j=1; $j<=$numberProbes; $j++) {
                    $row = mysqli_fetch_assoc($results);
                    array_push($probePositions, $row["probePosition"]);
                    array_push($probeTemps, $row["probeTemp"]);
                    array_push($targetTemps, $row["targetTemp"]);
                    array_push($highTemps, $row["highTemp"]);
                    array_push($lowTemps, $row["lowTemp"]);
                }
            }

/*
            ... show current probes settings
*/
            echo '<form action="currentburnsimulationprocess.php" method="post">';
                echo "<table>";
                    echo"<tr>";
                        echo "<th>Probe</th>";
                        echo "<th>Current</th>";
                        echo "<th>New</th>";
                        echo "<th>Step</th>";
                        echo "<th>Target</th>";
                        echo "<th>High</th>";
                        echo "<th>Low</th>";
                    echo "</tr>"; 
                    echo"<tr>";
                        echo "<th></th>";
                        echo "<th>Temp</th>";
                        echo "<th>Temp</th>";
                        echo "<th>Temp</th>";
                        echo "<th>Temp</th>";
                        echo "<th>Temp</th>";
                        echo "<th>Temp</th>";
                    echo "</tr>"; 
                    echo "</tr>";
                        for ($j=1; $j<=$numberProbes; $j++) {
                        echo"<tr>";
                            echo "<th>" . $probePositions[$j] . "</th>";
                            echo "<th>" . $probeTemps[$j] . "</th>";
                            echo "<th>";
                                echo '<select name="probe' . $j . 'NewTemp">';
                                for($i = 0; $i <= 1000; $i+=5) {
                                    if ($i == $probeTemps[$j]) {
                                        echo '<option value=' . $i . ' selected>' . $i . '</option>';
                                    } else {
                                        echo '<option value=' . $i . '>' . $i . '</option>';
                                    }
                                }
                                echo '</select>';   
                           echo '</th>';
                            echo "<th>";
                                echo '<select name="probe' . $j . 'StepTemp">';
                                for($i = 0; $i <= 10; $i++) {
                                    if ($i == 0) {
                                        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' . $j . 'NewTemp" maxlength="4" size=5" value="' . $targetTemps[$j] . '">' . "</th>"; 
                            echo "<th>" . '<input type="text" name="probe' . $j . 'StepTemp" maxlength="4" size=5" value="5">' . "</th>"; 
*/
                            echo "<th>" . $targetTemps[$j] . "</th>";
                            echo "<th>" . $highTemps[$j] . "</th>";
                            echo "<th>" . $lowTemps[$j] . "</th>";
                        echo '</tr>';
                        }
                echo "</table>";
                echo '<input type="submit" name="simulate" value="Simulate">';
                echo '<input type="submit" name="cancel" value="Cancel"><br>';
            echo '</form>';
            mysqli_close($conn);
        ?>
        </div>
    </body>
</html>