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

    filename:     systeminit.php
    description:  initialize system settings. Single row containing temp sample interval (1 to 60 seconds/sample), time zone (-12 to +12), temp scale (F/C), mode (auto/manual)
    inputs:       none
    outputs:      none
    redirections: none

********************************************************************************
-->
<html>
    <head>
        <?php include 'head.html' ?>
        <script src = "navigation.js"></script>
    </head>
    <body>
        <?php include 'navigationmanagedatabase.html' ?>
        <h3>INITIALIZE SYSTEM SETTINGS</h3>
        <div id="content">
            <?php
/*
                ... connect to database
*/
                include 'functions.php';
                $conn = connectToDB();

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

/*
                ... create system table
*/
                $sql = "CREATE TABLE system ("
                    . "systemId INT UNSIGNED NOT NULL," 
                    . "sampleInterval INT SIGNED NOT NULL," //1 to 60 seconds per sample
                    . "timeZone INT SIGNED NOT NULL," //-12 to 12
                    . TEMPSCALE . ","
                    . BURNMODE . ")";

                if (!mysqli_query($conn, $sql)) {
                    error_log("Error creating table: " . mysqli_error($conn));
                    exit('"system" table NOT initialized');
                }
/*
                ... populate system table
*/
                $sql = "INSERT INTO system (systemId, sampleInterval, timeZone, tempScale, burnMode) VALUES (1, 5, -5, 'F', 'Auto')";
                if (!mysqli_query($conn, $sql)) {
                    error_log("Error: " . $sql . "<br>" . mysqli_error($conn));
                    exit('"system" table NOT initialized');
                }
                echo '"system" table initialized';
/*
                ... close database connection
*/
                mysqli_close($conn);
            ?>
        </div>
    </body>
</html>