<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

$date_time = date("Y-m-d H:i", strtotime("+2 Hours"));


$all_batches_res = $db->query("", "SELECT * FROM   WHERE status != 'Closed' ");
$all_batches = $all_batches_res->fetch_assoc();


?>

<br>
<h1>CURRENT BATCH STATUS</h1>

<?php

while ($all_batches = $all_batches_res->fetch_assoc()) {
    $username_res = $db->query("users", "SELECT * FROM users WHERE record_id = '$jobcards[user_id]' AND username != 'DEV'");
    ?>

    <div
        style="display: flex; flex-direction: row; flex-wrap: wrap; justify-content: space-around; align-content: space-around;">
        <div class="searched_data">

            <div class="group_div">

                <label class="labels">Batch Number:</label>
                <label class="labels"><?php echo $all_batches['batch_number']; ?></label>
            </div>
            <div class="group_div">
                <label class="label" for="date_time">DATE CREATED</label>
                <textarea type="text" class="inputs"><?php echo $jobcards['date_created']; ?></textarea>
            </div>
            <?php if ($username = $username_res->fetch_assoc()) {
                ?>
                <div class="group_div">
                    <label class="label" for="user">USER</label>
                    <textarea type="text" class="inputs"><?php echo $username['username']; ?></textarea>
                </div>
                <?php
            } ?>
            <div class="group_div">
                <label class="label" for="type">STATUS</label>
                <?php
                if ($jobcards['status'] == 0) {
                    ?>
                    <textarea type="text" class="inputs">PENDING</textarea>

                    <?php

                } else {
                    ?>
                    <textarea type="text" class="inputs">COMPLETED</textarea>

                    <?php
                }
                ?>
            </div>
        </div>
    </div>

    <script>

        //auto refresh every 1 minute
        setTimeout(function () {
            location.reload();
        }, 60000);

    </script>

    <?php
}