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

    filename: probeaddupdate.php
    description:
    inputs:       probeId (update)
    outputs:      probeId, manufacturer, model, a, b, c
    actions:      add, update, cancel
    redirections: probeaddupdateprocess.php

********************************************************************************
-->
<html>
    <head>
        <?php include 'head.html' ?>
        <script src = "navigation.js"></script>
    </head>
    <body>
        <?php include 'navigationmanagefoodspitsprobes.html' ?>
        <?php
            $action = $_GET["action"];
            if ($action == "add") {
                echo "<h3>ADD PROBE</h3>";
            } elseif ($action == "update") {
                echo "<h3>UPDATE PROBE</h3>";
            }
        ?>
        <div id="content">
            <?php
/*
                .. connect to database
*/
                include 'functions.php';
                $conn = connectToDB();
/*
            ... initialize pit parameters
*/
            $manufacturer = "";
            $model = "";
            $a = 0;
            $b = 0;
            $c = 0;
/*
            ... get action
*/
            $probeId = $_GET["probeId"];
            $action = $_GET["action"];
            if ($action == "add") {
            } elseif ($action == "update") {
                if ($probeId == "") {
                    echo "no probe selected<br>";
                } else {
/*
            ... Get probe
*/
                    $sql = "SELECT manufacturer, model, a, b, c FROM probes 
                       WHERE probeId = $probeId";
                    $result = mysqli_query($conn, $sql);
                    if (mysqli_num_rows($result) > 0) {
                        $row = mysqli_fetch_assoc($result);
                        $manufacturer = $row[manufacturer];
                        $model = $row[model];
                        $a= $row[a];
                        $b= $row[b];
                        $c= $row[c];
                    }
                }
           }
/*
                ... generate form to add/update probe
*/
                echo '<form action="probeaddupdateprocess.php?probeId=" . $probeId method="post">';
                    echo "<table>";
                        echo "<tr>";
                            echo '<th>Manufacturer</th>';
                            echo '<th><input type="text" name="manufacturer" size="30" value="' . $manufacturer . '"></th>';
                        echo "</tr>";
                        echo "<tr>";
                            echo '<th>Model</th>';
                            echo '<th><input type="text" name="model" size="30" value="' . $model . '"></th>';
                        echo "</tr>";
                        echo "<tr>";
                    echo '<th>a</th>';
                    echo '<th><input type="text" name="a" size="20" value="' . $a . '"></th>';
                        echo "</tr>";
                        echo "<tr>";
                    echo '<th>b</th>';
                    echo '<th><input type="text" name="b" size="20" value="' . $b . '"></th>';
                        echo "</tr>";
                        echo "<tr>";
                    echo '<th>c</th>';
                    echo '<th><input type="text" name="c" size="20" value="' . $c . '"></th>';
                        echo "</tr>";
                    echo "</table>";
/*
                ... configure buttons
*/
                if ($action == "add") {
                    echo '<input type="submit" name="add" value="Add">';
                } elseif ($action == "update" && $probeId != "") {
                    echo '<input type="submit" name="update" value="Update">';
                }
                    echo '<input type="submit" name="cancel" value="Cancel"><br>';
                echo '</form>';
            mysqli_close($conn);
            ?>
        </div>
    </body>
</html>