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

    filename:     currentprobesinit.php
    description:  Initialize currentprobes database 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>Current Probes Table Initialization</h3>
<div id="content">
<?php
    include 'functions.php';
    $conn = connectToDB();

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

    /* create currentprobes table */
    $sql = "CREATE TABLE currentprobes ("
        . "currentProbeId INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," //8 entries
        . "probePosition INT UNSIGNED NOT NULL," //1-8
        . "probeTemp INT NULL," //0-999 degC
        . "targetTemp INT NULL," //0-999 degC
        . "highTemp INT NULL," //0-999 degC
        . "lowTemp INT NULL," //0-999 degC
        . "probeId INT NULL,"
        . "manufacturer VARCHAR(256) NULL,"
        . "model VARCHAR(256) NULL,"
        . "a FLOAT NULL,"
        . "b FLOAT NULL,"
        . "c FLOAT NULL)";
    if (!mysqli_query($conn, $sql)) {
        echo "Error creating table: " . mysqli_error($conn);
    }

    /* insert null table for 8 probes */
    for ($i = 1; $i <= 8; $i++) {
        $sql = "INSERT INTO currentprobes (probePosition, probeTemp, targetTemp, highTemp, lowTemp, probeId, manufacturer, model, a, b, c) VALUES ($i, null, null, null, null, null, null, null, null, null, null)";
        if (!mysqli_query($conn, $sql)) {
            echo "Error: " . $sql . "<br>" . mysqli_error($conn);    
        }
    }
    echo '"currentprobes" table initialized';
    mysqli_close($conn);
?>
</div>
</body>
</html>