<?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'])) {
            $team_name = sanitize_input($_POST['team_name']);
            $fire_department = sanitize_input($_POST['fire_department']);
            write_team($con, $team_name, $fire_department);
        }
        header("Location: mannschaft.php");
        die;      
    }

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

<body>
    <div class="center">
        <div class="headline">
            <h2>Mannschaft hinzufügen</h2>
        </div>
        <div class="form_div">
            <form method="post">
                <div class="txt_field">
                    <input type="text" name="team_name" required/>
                    <span></span>
                    <label for="team_name">Mannschaftsname</label>
                </div>
                <div class="txt_field">
                    <input type="text" name="fire_department" list="fire_departments" required/>
                    <datalist id="fire_departments">
                        <?php
                            load_fire_departments($con);
                            ?>
                    </datalist>
                    <span></span>
                    <label for="fire_department">Feuerwehr</label>
                </div>
                <input id="button" type="submit" value="Hinzufügen" class="btn-confirm" name="save"/>
                <a href="mannschaft.php">Schließen</a>
            </form>
        </div>
    </div>
    
</body>

<?php
    $con = null;
    echo file_get_contents("header_footer/footer.html");
?>