<?php
require_once __DIR__ . "/settings.php";
require_once __DIR__ . "/database.php";
$plan = $_GET['plan'];
if (!isset(PLANS[$plan])) {
    header("Location: /#pricing");
    die("Invalid plan chosen.");
}
?>
<!DOCTYPE HTML>
<title><?php echo SITE_TITLE; ?></title>
<?php
include __DIR__ . '/inc/meta.php';
include __DIR__ . '/inc/piwik.php';
?>
<!-- Wrapper -->
<div id="wrapper">

    <?php include __DIR__ . "/inc/header.php"; ?>

    <!-- Section -->
    <section id="one" class="main alt">
        <header class="accent1">
            <h1>Purchase</h1>
        </header>
        <div class="inner alt">
            <div class="content">
                <p>Purchase a month of service.  If you are a new user, enter a username, password, and email to register with.  If you are an existing user, enter your login username and password, check the renewal box, and enter a valid email address.</p>
                <?php
                if ($_GET["err"] == "renewinvaliduser") {
                    echo "<div><b>You have selected the renew option, but the username you gave does not exist.</b></div>";
                } else if ($_GET['err'] == "usernameinvalid") {
                    echo "<div><b>That username is not available.  Please choose another.</b></div>";
                } else if ($_GET['err'] == "renewpasswrong") {
                    echo "<div><b>The password is incorrect.</b></div>";
                } else if ($_GET['err'] == "bademail") {
                    echo "<div><b>The email address is not in a valid format.  Try again.</b></div>";
                } else if ($_GET['err'] == "shortpassword") {
                    echo "<div><b>Your password is too short.  It needs to be at least 8 characters long.</b></div>";
                } else if ($_GET['err'] == "commonpassword") {
                    echo "<div><b>Your chosen password is in a <a href=\"https://github.com/danielmiessler/SecLists/tree/master/Passwords\">public list</a> of 1,000,000 common passwords, and is therefore insecure.  Choose a better one.</b></div>";
                }
                ?>
                <form action="purchase2.php" method="POST">
                    <label for="username">Username:</label>
                    <input type="text" name="username" id="username" placeholder="Username" required />
                    <br />
                    <label for="password">Password:</label>
                    <input type="password" name="password" id="password" placeholder="Password" required />
                    <br />
                    <label for="email">Email:</label>
                    <input type="email" name="email" id="email" placeholder="dsm@example.com" required />
                    <br />
                    <input type="checkbox" name="renewing" id="renewing" value="1" /> <label for="renewing">This is a renewal</label>
                    <br />
                    <input type="hidden" name="plan" value="<?php echo $plan; ?>" />
                    <p>By pressing the Next button, you agree to <a href="terms.php" target="_BLANK">these terms</a>.
                        <br />
                        <button type="submit">Next</button>
                </form>
            </div>
        </div>
    </section>

    <?php include __DIR__ . "/inc/footer.php"; ?>

</div>

<?php include __DIR__ . "/inc/scripts.php"; ?>