<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();
$work_order_res = $db->query("work_orders", "SELECT * FROM `work_orders` WHERE `in_review` = 1 AND `sent_for_review` = 1 AND `inprogress` = 0 AND `completed` = 0 AND `user_id_review` = {$_SESSION['user_id']}");
if ($work_order_res->num_rows > 0) {
    $work_order = $work_order_res->fetch_assoc();
    echo "<script>window.location.href = 'review.php?record_id=" . $work_order['record_id'] . "';</script>";
} else {
    ?>
    <div class="search_form">
        <h1> ACTIVE REVIEWS</h1>
        <?php
        echo $html->input_html('', '1', 'sent_for_review', 'sent_for_review', '', '', '', 'text', 'hidden');
        echo $html->input_html('', $_SESSION['user_id'], 'user_id_review', 'user_id_review', '', '', '', 'text', 'hidden');
        ?>
        <button id="submit" hidden></button>
    </div>
    <?php
    echo $html->html_form_ajax("search_active_work_orders", "SELECT", "work_orders", '', false, ['project_id', 'name', 'work_order_type_id', 'deadline_date_time'], "review.php"); ?>
    <script>
        search_active_work_orders();
    </script>
<?php } ?>

