<?php
$setup = array();
$setup['title'] = "Opret Bruger";
$setup['headline'] = "Odense Track - Opret";
$setup['keywords'] = "opret,bruger,signup";
$setup['description'] = "Opret dig som bruger hos Odense Track";

Design::header($setup, 0);

if (isset($_POST['username'])) {
    if (Alter::addUser($_POST['username'],$_POST['password'],$_POST['realname'],$_POST['mail'],25)) {
     // Success! User created - Redirect to login
        header('Location: ' . Config::$sys_url . '?page=login');
    } else {
        // Aww, signup failed!
        $success = false;
    }
}
?>

<div class="page">
    <h1>Opret Bruger</h1>
    <div class="border"></div>
    <br />
    <div class="contactform">
        <form method="POST" action="?page=signup">
            <?php if (isset($success)) {
             // If $success is defined, we know we failed.
                echo "<p>Der skete en fejl, prøv igen!</p>";
            }
            ?>
            <div class="form-control">
                <label>Brugernavn: </label>
                <input class="inputfield"  type="text" name="username" placeholder="Brugernavn" <?php if (isset($success)) { echo 'value="' . $_POST['username'] . '"'; } ?> required minlength="3" />
            </div>
            <div class="form-control">
                <label>Password: </label>
                <input class="inputfield"  type="password" name="password" placeholder="Password" required minlength="5" />
            </div>
            <div class="form-control">
                <label>Fuldt navn: </label>
                <input class="inputfield"  type="text" name="realname" placeholder="Fuldt navn" <?php if (isset($success)) { echo 'value="' . $_POST['realname'] . '"'; } ?> required minlength="5" />
            </div>
            
            <div class="form-control">
                <label>E-mail: </label>
                <input class="inputfield"  type="email" name="mail" placeholder="E-mail adresse" <?php if (isset($success)) { echo 'value="' . $_POST['mail'] . '"'; } ?> required minlength="5" />
            </div>
            

            <div class="form-control">
                <input class="contactsubmit" type="submit" value="Opret" />
            </div>
        </form>
    </div>

</div>

<?php
Design::footer(false);
