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

    if($_SERVER['REQUEST_METHOD'] == "POST") {
        if(isset($_POST['save'])){
            $station_name = sanitize_input($_POST['station_name']);
            $station_pos = sanitize_input($_POST['station_pos']);
            $station_direct_points = sanitize_input($_POST['direkte_punkte']);
            write_station($con, $station_name, $station_pos, $station_direct_points);
        }
        header("Location: stationen.php");
        die;
    }

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

<body>
    <div class="center">
        <div class="headline">
            <h2>Station hinzufügen</h2>
        </div>
        <div class="form_div">
            <form method="post">
                <div class="txt_field">
                    <input class="input_field" id="station_name" type="text" name="station_name" required/>
                    <span></span>
                    <label for="station_name">Name</label>
                </div>
                <div class="txt_field">
                    <input class="input_field" id="station_pos" type="text" name="station_pos" required/>
                    <span></span>
                    <label for="station_pos">Standort</label>
                </div>
                <div class="dropdown">
                    <label for="direkte_punkte">Punkte eintragen</label>
                    <select name="direkte_punkte" id="direkte_punkte">
                        <option value="1" selected>Ja</option>
                        <option value="0">Nein</option>
                    </select>
                </div>
                <input id="button" type="submit" value="Hinzufügen" class="btn-confirm" name="save"/>
                <a href="stationen.php" class="btn-close">Schließen</a>
            </form>
        </div>
    </div>
</body>
<?php
    $con = null;
    echo file_get_contents("header_footer/footer.html");
?>