<?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">Hacker Attacks</div>
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
								<center><a href="?p=delete-all" class="btn btn-danger">Delete all</a></center><br />
<?php
$broinastranica = 20;

$pageNum = 1;
if (isset($_GET['page'])) {
    $pageNum = $_GET['page'];
}
if (!is_numeric($pageNum)) {
    die("Грешка <script type='text/javascript'>window.location = 'dashboard.php'</script>");
}
$redove = ($pageNum - 1) * $broinastranica;
$sql    = "SELECT * FROM `hacker-attacks` ORDER by id DESC LIMIT $redove, $broinastranica";
$result = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($result);
$id    = $row['id'];
if ($count <= 0) {
    echo 'There are no hacker attacks';
} else {
    echo '
									<table class="table table-bordered table-striped table-hover">
						              <thead>
						                <tr>
						                  <th>IP</th>
						                  <th>Date</th>
						                  <th>Type</th>
										  <th>Actions</th>
						                </tr>
						              </thead>
						              <tbody>
';
    while ($row = mysql_fetch_assoc($result)) {
        echo '
						                <tr>
						                  <td>' . $row['ip'] . '</td>
						                  <td>' . $row['date'] . '</td>
						                  <td>' . $row['type'] . '</td>
										  <td>
											<a href="details.php?id=' . $row['id'] . '" class="btn btn-primary"><i class="icon-eye-open icon-white"></i> Details</a>
											<a href="?delete-id=' . $row['id'] . '" class="btn btn-danger"><i class="icon-remove icon-white"></i> Delete</a>
										  </td>
						                </tr>
';
    }
?>
						              </tbody>
						            </table>
<center><br />Pages:<br />
<?php
    $query = "SELECT COUNT(id) AS numrows FROM `hacker-attacks`";
    $result = mysql_query($query) or die('Error');
    $row     = mysql_fetch_array($result, MYSQL_ASSOC);
    $numrows = $row['numrows'];
    $maxPage = ceil($numrows / $broinastranica);
    
    $nomeranastranici = '';
    
    for ($page = 1; $page <= $maxPage; $page++) {
        if ($page == $pageNum) {
            $nomeranastranici .= " <a href='?page=$page' class=\"btn\">$page</a> ";
        } else {
            $nomeranastranici .= " <a href=\"?page=$page\" class=\"btn\">$page</a> ";
        }
    }
    
    if ($pageNum > 1) {
        $page      = $pageNum - 1;
        $predishna = " <a href=\"?page=$page\" class=\"btn\">Previous</a> ";
        
        $parva = " <a href=\"?page=1\" class=\"btn\">First</a> ";
    } else {
        $predishna = ' ';
        $parva     = ' ';
    }
    
    if ($pageNum < $maxPage) {
        $page       = $pageNum + 1;
        $sledvashta = " <a href=\"?page=$page\" class=\"btn\">Next</a> ";
        
        $posledna = " <a href=\"?page=$maxPage\" class=\"btn\">Last</a> ";
    } else {
        $sledvashta = ' ';
        $posledna   = ' ';
    }
    
    echo "" . $parva . $predishna . $nomeranastranici . $sledvashta . $posledna;
    
}
if ($_GET['delete-id']) {
    $id    = (int) $_GET["delete-id"];
    $query = mysql_query("DELETE FROM `hacker-attacks` where id='$id'");
    echo "<br /><center>The hacker attack was removed successfully</center><br />";
    echo "<meta http-equiv=Refresh content=2;url=dashboard.php>";
}

$p = $_GET['p'];
switch ($p) {
    default:
        header("Location: hacker-attacks.php");
        break;
    case "":
        break;
    case "delete-all":
        $query = mysql_query("TRUNCATE TABLE `hacker-attacks`");
        echo "<br /><center>All hacker attacks were removed successfully</center><br />
<meta http-equiv=Refresh content=2;url=dashboard.php>";
        break;
}
?></center>
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>
   
<?php
footer();
?>