<?php
    session_start();
    include("../scripts/connection.php");
    include("../scripts/functions.php");
    $user_data = check_login($con);

    if($_SERVER['REQUEST_METHOD'] == "POST") {
        $points = $_POST['points'];
        $minutes = $_POST['minutes'];
        $seconds = $_POST['seconds'];
        $miliseconds = $_POST['miliseconds'];

        if($minutes == 0 && $seconds == 0 && $miliseconds == 0){
            $time = null;
        } else {
            $time = "00:" . $minutes . ":" . $seconds . "." . $miliseconds;
        }
        write_points($con, $_GET['station'], $_POST['team'], $points, $time);
        header("Location: statistik.php");
        die;
    }

    include("header_footer/header.php");
?>

<body>
    <div class="center">
        <div class="headline">
            <h2>Ergebniss eintragen</h2>
        </div>
        <div class="form_div">
            <form action="" method="post">
                <div id="team-div" class="dropdown">
                    <label for="team">Mannschaft</label>
                    <select name="team" id="team">
                        <?php load_teams_no_points($con, $_GET['station'])?>
                    </select>
                </div>
                <div class="number_field">
                    <label for="points">Punkte: </label>
                    <input name="points" id="points" type="number" max="15" min="0" value="0" required/>
                </div>
                <div class="headline">
                    <h3>Zeit</h3>
                </div>
                <div id="zeit">
                    <div class="number_field">
                        <label for="minutes">Minuten</label>
                        <input name="minutes" id="minutes" type="number" max="60" min="0" value="0"/>
                    </div>
                    <div class="number_field">
                        <label for="seconds">Sekunden</label>
                        <input name="seconds" id="seconds" type="number" max="60" min="0" value="0"/>
                    </div>
                    <div class="number_field">
                        <label for="miliseconds">Millisekunden</label>
                        <input name="miliseconds" id="miliseconds" type="number" max="99" min="0" value="0"/>
                    </div>
                </div>
                <div>
                    <input id="button" type="submit" value="Eintragen" class="btn-confirm"/>
                </div>
            </form>
        </div>
    </div>
</body>
<?php
    $con = null;
    echo file_get_contents("header_footer/footer.html");
?>