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

    filename:     burnchart.php
    description:  plot the past temps for probes 1 and 2
                  from the start of the selected burn
    inputs:       burnId
    outputs:      none
    actions:      none
    redirections: none

********************************************************************************
-->
<html>
    <head>
        <?php include 'head.html' ?>
        <script src = "navigation.js"></script>
        <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
        <script type="text/javascript">
            google.charts.load('current', {'packages':['corechart']});
            google.charts.setOnLoadCallback(drawChart);
            function drawChart() {
                var data = google.visualization.arrayToDataTable([
                   ['Time', ' Dome Temp', 'Dome Target', 'Food Temp', 'Food Target']
            <?php
                include 'functions.php';
                $conn = connectToDB();
/*
                ... get selected burn passed from burn list
*/
                $burnId = $_GET["burnId"];
/*
                ... get burn data for selected burn
*/
                $burn = getBurn($burnId);
                $pitId = $burn[pitId];
                $startDateTime = $burn[startDateTime];
                $endDateTime = $burn[endDateTime];
                $comments = $burn[comments];
/*
                ... get pit data
*/
                $pit = getPit($pitId); 
                $pitManufacturer = $pit[manufacturer];
/*
                ... get status data
*/
                $statuses = getStatuses($burnId);
                $i = 0;
                foreach($statuses as $status) {
                    $probePosition = $status["probePosition"];
                    if ($probePosition == 1) {
                        echo ", [" . $i . ", " . $status["probeTemp"] . ", " . $status["targetTemp"] . ", ";
                   } elseif ($probePosition == 2) {
                        echo $status["probeTemp"] . ", " . $status["targetTemp"] . "]";
                   }
                       $i++;
               }
?>
        ]);

        var options = {
          title: 'Current Burn',
          curveType: 'function',
          legend: { position: 'bottom' }
        };

        var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

        chart.draw(data, options);
      }
      </script>
    </head>
    <body>
        <?php include 'navigationmanageburns.html' ?>
        <div id="content">
        <h3>CURRENT BURN</h3>
        <?php
            echo "<table>";
                echo "<tr>";
                    echo "<th>Burn ID</th>";
                    echo "<th>$burnId</th>";
                echo "</tr>";
                echo "<tr>";
                    echo "<th>Comments</th>";
                    echo "<th>" . $comments . "</th>";
                echo "</tr>";
                echo"<tr>";
                    echo "<th>Burn State</th>";
                    echo "<th>$burnState</th>";
                echo "</tr>";
                echo "<tr>";
                    echo "<th>Burn Start</th>";
                    echo "<th>" . date_format(date_create($startDateTime), "H:i a") . "</th>";
                echo "</tr>";
                echo "<tr>";
                if ($endDateTime != null) {
                    echo"<tr>";
                    echo "<th>Burn End</th>";
                    echo "<th>" . date_format(date_create($endDateTime), "H:i a") . "</th>";
                    echo "</tr>";
                }
                   $currentDateTime = date('Y-m-d H:i:s');
                    if ($burnState == "Cooking" || $burnState == "Checking") {                  
                        $burnTime = strtotime($currentDateTime) - strtotime($startDateTime);
                    } else if ($burnState == "Done") {
                        $burnTime = strtotime($endDateTime) - strtotime($startDateTime);
                    } else {
                        $burnTime = 0;
                    }
                    $burnMinutes = round($burnTime / 60); 
                    $burnHours = floor($burnMinutes / 60);
                    $burnMinutes = $burnMinutes - $burnHours * 60;
                    echo "<th>Burn Time</th>";
                    echo "<th>" . $burnHours . " hr " . $burnMinutes . " min</th>";
                echo "</tr>";
            echo "</table>";
        ?>
        </div>
        <div id="curve_chart" style="width: 900px; height: 500px"></div>
    </body>
</html>