<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

$name_surname = new input();
$name_surname->type("text");
$name_surname->name("name_surname");
$name_surname->id("name_surname");
$name_surname->style("width: 100%; margin:1vw auto;");

$date = new input();
$date->type("datetime-local");
$date->name("datetime");
$date->id("datetime");
$date->style("width: 100%; margin:1vw auto;");

$date_start = new input();
$date_start->type("hidden");
$date_start->name("datetime_start");
$date_start->id("datetime_start");
$date_start->style("width: 100%; margin:1vw auto;");
$date_start->value(date("Y-m-d H:i", strtotime("+2 Hours")));

$designation = new input();
$designation->type("text");
$designation->name("designation");
$designation->id("designation");
$designation->style("width: 100%; margin:1vw auto;");

$test_id = new input();
$test_id->type("hidden");
$test_id->name("test_id");
$test_id->id("test_id");
$test_id->value($_GET['record_id']);

$booking_no = new input();
$booking_no->type("hidden");
$booking_no->name("booking_no");
$booking_no->id("booking_no");
$booking_no->value($_GET['booking_no']);

$passmark = new input();
$passmark->type("hidden");
$passmark->name("passmark");
$passmark->id("passmark");
$passmark->value($_GET['passmark']);

$test_name = new input();
$test_name->type("hidden");
$test_name->name("test_name");
$test_name->id("test_name");
$test_name->value($_GET['test_name']);

$test_desc = new input();
$test_desc->type("hidden");
$test_desc->name("test_desc");
$test_desc->id("test_desc");
$test_desc->value($_GET['test_desc']);

$submit_btn = new input();
$submit_btn->class("submit_btn");
$submit_btn->value("Submit");

$tests_res = $db->query("tests", "SELECT * FROM tests WHERE record_id = {$_GET['record_id']}");

?>

<form action="mark_test.php" method="post">
    <?php
    while ($tests_data = $tests_res->fetch_assoc()) {
        ?>

        <style>
            body {
                background-image: url('');
                /* background-color: white; */
                background-repeat: repeat-y;
            }

            table {
                width: 95%;
                border-collapse: collapse;
            }

            th,
            td {
                padding-left: 10px;
                padding-right: 10px;
                border: 3px solid black;
                text-align: left;
                background-color: white;
            }
        </style>

        <div class="form_down">
            <h1>Test For <?php echo $tests_data['name']; ?></h1>
            <table style="width: 100%;">
                <tr>
                    <th>TEST NAME</th>
                    <th>TEST DESCRIPTION</th>
                    <th>PASSMARK</th>
                </tr>
                <tr>
                    <td>
                        <?php echo $tests_data['name']; ?>
                    </td>
                    <td>
                        <?php echo $tests_data['test_description']; ?>
                    </td>
                    <td>
                        <?php echo $tests_data['passmark']; ?>
                    </td>
                </tr>
            </table>

            <br><br>

            <table style="width: 90%;">
                <tr>
                    <th>DATE</th>
                    <td>
                        <?php
                        $date->add();
                        $date_start->add();
                        ?>
                    </td>
                </tr>
                <tr>

                    <th>NAME AND SURNAME</th>

                    <td>
                        <?php
                        $name_surname->add();
                        ?>
                    </td>

                </tr>
                <tr>
                    <th>DESIGNATION</th>
                    <td>
                        <?php
                        $designation->add();
                        ?>
                    </td>
                </tr>
            </table>
            <br><br>
            <div style="width: 95%;display: flex;flex-direction: column;">
                <?php

                $test_questions_res = $db->query("test_questions", "SELECT * FROM test_questions WHERE test_id = {$_GET['record_id']}");
                while ($test_questions_data = $test_questions_res->fetch_assoc()) {
                    ?>
                    <p
                        style="width: 100%;border-bottom: 2px solid black;border-top: 2px solid black;padding-top: 10px;padding-bottom: 10px; font-weight: bold;">
                        <?php echo $test_questions_data['question_name']; ?>
                    </p>
                    <?php

                    $tests_answers_res = $db->query("test_answers", "SELECT * FROM test_answers WHERE test_question_id = {$test_questions_data['record_id']}");
                    while ($tests_answers_data = $tests_answers_res->fetch_assoc()) {
                        ?>
                        <div style="display: flex;align-items: center;margin-top: 10px;margin-bottom: 10px;">
                            <div>
                                <input type="checkbox" style="height: 2.5vw;width: 2.5vw;"
                                    name="answer_<?= $tests_answers_data['record_id']; ?>"
                                    value="<?= $tests_answers_data['record_id']; ?>" />
                            </div>
                            <div>
                                <?php echo $tests_answers_data['answer']; ?>
                            </div>
                        </div>
                        <?php
                    }
                    ?>
                    <?php
                }
                ?>
            </div>
            <br>
            <?php
            $test_id->add();
            $booking_no->add();
            $passmark->add();
            $test_name->add();
            $test_desc->add();
            $submit_btn->add();
            ?>
        </div>

        <?php
    }
    ?>
</form>