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

    filename:     statusesinit.php
    description:  Initialize statuses database table.
                  Each time a temperature measurement is made on a probe,
                  the temperature and associated data is entered in the table.
    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>INITIALIZE STATUSES TABLE</h3>
        <div id="content">
            <?php
/*
                ... connect to database
*/
                include 'functions.php';
                $conn = connectToDB();

/*
                ... drop statuses table
*/
                $sql = "DROP TABLE IF EXISTS statuses";
                if (!mysqli_query($conn, $sql)) {
                    echo "Initialize Statuses Error dropping table: " . mysqli_error($conn);
                    exit('"statuses" NOT initialized');
                }

/*
                ... create statuses table
*/
                $sql = "CREATE TABLE statuses ("
                    . "statusId INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," 
                    . "burnId INT UNSIGNED NULL,"
                    . "mode ENUM('Auto', 'Manual') NULL,"
                    . "burnState ENUM('Ready', 'Preheating','Cooking','Checking','Done') NULL,"
                    . "probeId INT UNSIGNED NULL,"
                    . "probePosition INT UNSIGNED NULL," //1-8
                    . "statusDateTime DATETIME NULL,"
                    . "probeTemp INT UNSIGNED NULL," //0-999 degC
                    . "targetTemp INT UNSIGNED NULL," //0-999 degC
                    . "highTemp INT UNSIGNED NULL," //0-999 degC
                    . "lowTemp INT UNSIGNED NULL," //0-999 degC
                    . "blowerSpeed INT UNSIGNED NULL," //0-100%
                    . "ventPosition INT UNSIGNED NULL)"; //0-100%

                if (!mysqli_query($conn, $sql)) {
                    error_log("Initialize Statuses Error creating table: " . mysqli_error($conn));
                    exit('"statuses" NOT initialized');
                }
                echo '"statuses" initialized';
/*
                ... close database connection
*/
                mysqli_close($conn);
            ?>
        </div>
    </body>
</html>