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

    filename:     probelist.php
    description:  lists probes and parameters in database
    inputs:       none
    outputs:      probeId
    actions:      add, update, calibrate, chart, delete
    redirections: probelistprocess.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>PROBES</h3>
        <div id="content">
            <?php
                include 'functions.php';
/*
            ... determine if probe not selected
*/
            $probeRequired = "*";
            if ($_GET['probeRequired'] == 'true') {
                $probeRequired = '* Required';
            }
/*
            ... get selected probe
*/
            $selectedProbeId = $_GET['probeId'];
/*
            ... Get probes
*/
            $probes = getProbes();
/*
            .... display probes and parameters
*/
            echo "<table>";
                echo"<tr>";
                    echo "<th>ID</th>";
                    echo "<th>Manufacturer</th>";
                    echo "<th>Model</th>";
                    echo "<th>a</th>";
                    echo "<th>b</th>";
                    echo "<th>c</th>";
                    echo "<th>Low Temp</th>";
                    echo "<th>Low Resistance</th>";
                    echo "<th>Medium Temp</th>";
                    echo "<th>Medium Resistance</th>";
                    echo "<th>High Temp</th>";
                    echo "<th>High Resistance</th>";
                    echo "</tr>";
                    foreach($probes as $probe) {
                        echo "<tr>";
                            echo "<th>" . $probe['probeId'] . "</th>";
                            echo "<th>" . $probe['manufacturer'] . "</th>";
                            echo "<th>" . $probe['model'] . "</th>";
                            echo "<th>" . $probe['a'] . "</th>";
                            echo "<th>" . $probe['b'] . "</th>";
                            echo "<th>" . $probe['c'] . "</th>";
                            echo "<th>" . $probe['lowTemp'] . "</th>";
                            echo "<th>" . $probe['lowResistance'] . "</th>";
                            echo "<th>" . $probe['mediumTemp'] . "</th>";
                            echo "<th>" . $probe['mediumResistance'] . "</th>";
                            echo "<th>" . $probe['highTemp'] . "</th>";
                            echo "<th>" . $probe['highResistance'] . "</th>";
                        echo "</tr>";
                   }
            echo "</table>";
                echo '<form action="probelistprocess.php" method="post">';
                    echo 'Probe <select name="probeId">';
                        foreach($probes as $probe) {
                            $probeId = $probe['probeId'];
                            if ($probeId == $selectedProbeId) {
                                echo '<option value="' . $probe['probeId'] . ' selected">' . $probe['manufacturer'] . ' ' . $probe['model'] . '</option>';
                            } else {
                                echo '<option value="' . $probe['probeId'] . '">' . $probe['manufacturer'] . ' ' . $probe['model'] . '</option>';
                            }
                        }
                    echo '</select>';
                            echo '<span class="error">' . $probeRequired . '</span>';
                    echo '<br>';
                    echo '<input type="submit" name="add" value="Add">';
                    echo '<input type="submit" name="update" value="Update"> ';
                    echo '<input type="submit" name="calibrate" value="Calibrate"> ';
                    echo '<input type="submit" name="chart" value="Chart"> ';
                    echo '<input type="submit" name="delete" value="Delete"><br>';   
                echo '</form>';
                $error = $_GET["error"];
//                if ($error == "error") {
                    echo $error;
//                }
            ?>
        </div>
    </body>
</html>