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

    filename:     currentburninit.php
    description:  Initialized currentburn database table. This table has only one entry for the current burn
    inputs:       none
    outputs:      none
    actions:      none
    redirections: none

********************************************************************************
-->
<html>
    <head>
        <?php include 'head.html' ?>
        <script src = "navigation.js"></script>
    </head>
    <body>
        <?php include 'navigationmanagedatabase.html' ?>
        <h3>Current Burn Table Generation</h3>
        <div id="content">
            <?php
                include 'functions.php';
                $conn = connectToDB();

                /* drop currentburn table */
                $sql = "DROP TABLE IF EXISTS currentburn";
                if (!mysqli_query($conn, $sql)) {
                    echo "Error dropping table: " . mysqli_error($conn);
                }

                /* create currentburn table */
                $sql = "CREATE TABLE currentburn ("
                    . "currentBurnId INT UNSIGNED NOT NULL,"
                    . "burnId INT NULL," //one entry
                    . "mode ENUM('Auto', 'Manual') NULL,"
                    . "burnState ENUM('Ready','Preheating','Cooking','Checking','Done') NULL," // Ready (for cook), Preheating, Cooking, Checking (food temps), Done
                    . "cookState ENUM('Off','Preheating','Near Ready','Ready','Cook Low','Cook OK','Cook High') NULL,"
                    . "foodState ENUM('Raw','Cooking','Near Done','Done','Over Done') NULL,"
                    . "numberProbes INT UNSIGNED NULL," //1-8
                    . "startDateTime DATETIME NULL,"
                    . "endDateTime DATETIME NULL,"
                    . "blowerSpeed INT UNSIGNED NULL," //0-100%
                    . "ventPosition INT UNSIGNED NULL," //0-100%
                    . "foodId INT UNSIGNED NULL,"
                    . "food VARCHAR(256) NULL,"
                    . DONENESSES . ","
                    . "comments VARCHAR(256) NULL,"
                    . "pitId INT UNSIGNED NULL,"
                    . "pitManufacturer VARCHAR(256) NULL,"
                    . "pitModel VARCHAR(256) NULL,"
                    . "blowerP INT UNSIGNED NULL,"
                    . "blowerI INT UNSIGNED NULL,"
                    . "blowerD INT UNSIGNED NULL,"
                    . "ventP INT UNSIGNED NULL,"
                    . "ventI INT UNSIGNED NULL,"
                    . "ventD INT UNSIGNED NULL)";

                if (!mysqli_query($conn, $sql)) {
                    echo "Error creating table: " . mysqli_error($conn);
                }

                /* insert null burn */
                $sql = "INSERT INTO currentburn (
                    currentBurnId,
                    burnId,
                    burnState,
                    numberProbes,
                    startDateTime,
                    endDateTime,
                    blowerSpeed,
                    ventPosition,
                    foodId,
                    food,
                    doneness,
                    comments,
                    pitId,
                    pitManufacturer,
                    pitModel,
                    blowerP,
                    blowerI,
                    blowerD,
                    ventP,
                    ventI,
                    ventD)
                    VALUES (1, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)";
                if (!mysqli_query($conn, $sql)) {
                    echo "Error: " . $sql . "<br>" . mysqli_error($conn);    
                }

                mysqli_close($conn);
                echo '"currentburn" table initialized';

            ?>
        </div>
    </body>
</html>