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

    filename:    pitinit.php
    description: initialize pits
    inputs:      none
    outputs:     none
    actions:     none
    redirection: none

********************************************************************************
-->
<html>
    <head>
        <?php include 'head.html' ?>
        <script src = "navigation.js"></script>
    </head>
    <body>
        <?php include 'navigationmanagedatabase.html' ?>
        <h3>INITIALIZE PIT LIST TABLE</h3>
        <div id="content">
            <?php
                include 'functions.php';
                $conn = connectToDB();
/*
                ... drop pits table
*/
                $sql = "DROP TABLE IF EXISTS pits";
                if (!mysqli_query($conn, $sql)) {
                    echo "Error dropping table: " . mysqli_error($conn);
                }
/*
                ... create pits table
*/
                $sql = "CREATE TABLE pits ("
                    . "pitId INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," 
                    . "manufacturer VARCHAR(256) NULL,"
                    . "model 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,"
                    . "comments VARCHAR(256) NULL)";
                if (!mysqli_query($conn, $sql)) {
                    echo "Error creating table: " . mysqli_error($conn);
                }
/*
                ... populate pits table
*/
                $sql = "INSERT INTO pits (manufacturer, model, blowerP, blowerI, blowerD, ventP, ventI, ventD) 
                    VALUES ('Primo', 'Oval JR 200', 20, 5, 100, 20, 5, 100)";

                if (!mysqli_query($conn, $sql)) {
                    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                }

                $sql = "INSERT INTO pits (manufacturer, model, blowerP, blowerI, blowerD, ventP, ventI, ventD) 
                    VALUES ('Primo', 'Oval XL 400', 20, 5, 100, 20, 5, 100)";

                if (!mysqli_query($conn, $sql)) {
                    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                }

                $sql = "INSERT INTO pits (manufacturer, model, blowerP, blowerI, blowerD, ventP, ventI, ventD) 
                    VALUES ('Big Green Egg', 'Large', 20, 5, 100, 20, 5, 100)";

                if (!mysqli_query($conn, $sql)) {
                    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                }

                $sql = "INSERT INTO pits (manufacturer, model, blowerP, blowerI, blowerD, ventP, ventI, ventD) 
                    VALUES ('Chargriller', 'Deluxe Griller 2828', 20, 5, 100, 20, 5, 100)";

                if (!mysqli_query($conn, $sql)) {
                    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                }

                mysqli_close($conn);
                echo '"pits" table initialized';
            ?>
        </div>
    </body>
</html>