<?php
include"common.php";
head();
?>
                <!--/span-->
                <div class="span9" id="content">

                    <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">Add Ban</div>
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
<?php
if (isset($_POST['submit'])) {
    $ip       = addslashes(htmlspecialchars($_POST['ip']));
    $months   = array(
        "",
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
    );
    $date     = date('d', time()) . ' ' . $months[date('n', time())] . ' ' . date('Y', time());
    $reason   = addslashes(htmlspecialchars($_POST['reason']));
    $redirect = $_POST['redirect'];
    $url      = addslashes(htmlspecialchars($_POST['url']));
    $bannedby = $_SERVER['REMOTE_ADDR'];
    if ($ip == NULL) {
        echo '
    <meta http-equiv="refresh" content="2;url=add_ban.php">';
        exit();
    }
    if ($reason == NULL) {
        echo '
    <meta http-equiv="refresh" content="2;url=add_ban.php">';
        exit();
    }
    $queryvalid = mysql_query("SELECT * FROM `bans` WHERE ip='$ip' LIMIT 1");
    $validator  = mysql_num_rows($queryvalid);
    if ($validator > "0") {
        echo '
    <meta http-equiv="refresh" content="2;url=add_ban.php">';
        exit();
    } else {
        $query = mysql_query("INSERT INTO `bans` (ip, date, reason, redirect, url, bannedby) VALUES('$ip', '$date', '$reason', '$redirect', '$url', '$bannedby')");
        echo "<br /><center>The IP Adress was successfully banned!</center><br />";
        echo "<meta http-equiv=Refresh content=2;url=bans.php>";
    }
} else {
    echo '
<form action="" method="post">
<p>
	<label>IP Address</label>
	<input name="ip" type="text">
</p>
<p>
	<label>Reason</label>
	<input name="reason" type="text">
</p>
<p>
	<label>Redirecting to another page or site</label>
    <select name="redirect">
        <option value="No" selected>No</option>
        <option value="Yes">Yes</option>
    </select>
</p>
<p>
	<label>Redirect URL</label>
	<input name="url" type="text">
</p>
<br><input type="submit" class="btn red" name="submit" value="Ban" />
</form>
';
}
?>
								</div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>
   
<?php
footer();
?>
